Skip to content

Instantly share code, notes, and snippets.

@Godzil
Created December 24, 2013 16:50
Show Gist options
  • Save Godzil/8115534 to your computer and use it in GitHub Desktop.
Save Godzil/8115534 to your computer and use it in GitHub Desktop.
My Kano's Pong : Pongito
if (gameEvents.key.W) {
game.players.a.move( -1 );
}
if (gameEvents.hit) {
if (game.balls[0].velocity.x * (Math.abs(game.balls[0].velocity.x) + 5) > 0) {
var x = (Math.abs(game.balls[0].velocity.x) + 5);
} else {
var x = -(Math.abs(game.balls[0].velocity.x) + 5);
}
if (game.balls[0].velocity.y * (Math.abs(game.balls[0].velocity.x) + 5) > 0) {
var y = (Math.abs(game.balls[0].velocity.x) + 5);
} else {
var y = -(Math.abs(game.balls[0].velocity.x) + 5);
}
window.pongSettings.ball.velocity = [x,y];
game.setBallVelocity([ x, y ]);
game.players.b.speed = Math.abs(game.players.b.speed) + 2;
game.players.b.speed = Math.abs(game.players.a.speed) + 2;
game.setBallSize(game.balls[0].size - 2);
}
pongSettings.backgroundColor = '#000000';
pongSettings.linesColor = '#009900';
pongSettings.width = 800;
pongSettings.height = 440;
if (gameEvents.key.S) {
game.players.a.move( 1 );
}
pongSettings.ball.size = 30;
pongSettings.ball.color = '#009900';
pongSettings.ball.velocity[0] = 5;
pongSettings.ball.velocity[1] = 5;
pongSettings.title = 'Pongito';
if (Math.abs(game.balls[0].velocity.x) >= 30) {
if (game.balls[0].velocity.x * (30) > 0) {
var x = (30);
} else {
var x = -(30);
}
if (game.balls[0].velocity.y * (30) > 0) {
var y = (30);
} else {
var y = -(30);
}
window.pongSettings.ball.velocity = [x,y];
game.setBallVelocity([ x, y ]);
}
if (gameEvents.goal.a) {
game.players.b.speed = Math.abs(game.players.b.speed) - 5;
game.players.a.speed = Math.abs(game.players.a.speed) + 5;
}
if (game.balls[0].size <= 5) {
game.setBallSize(5);
}
if (gameEvents.goal.b) {
game.players.b.speed = Math.abs(game.players.b.speed) + 5;
game.players.a.speed = Math.abs(game.players.a.speed) - 5;
}
if (game.players.a.score == 10) {
game.win('Player 2 wins!');
}
if (game.players.b.score == 10) {
game.win('Player 1 wins!');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment