Skip to content

Instantly share code, notes, and snippets.

@ingrid
Created April 15, 2012 05:38
Show Gist options
  • Save ingrid/2390285 to your computer and use it in GitHub Desktop.
Save ingrid/2390285 to your computer and use it in GitHub Desktop.
Player movement in vertical shooter.
var player = jam.Sprite(400, 500);
player.setImage("ship.png");
player.update = jam.extend(player.update, function(elapsed){
player.velocity.x = 0;
player.velocity.y = 0;
if( jam.Input.keyDown("UP") ){
player.velocity.y = -250;
}
if( jam.Input.keyDown("DOWN") ){
player.velocity.y = 250;
}
if( jam.Input.keyDown("LEFT") ){
player.velocity.x = -250;
}
if( jam.Input.keyDown("RIGHT") ){
player.velocity.x = 250;
}
});
game.add(player);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment