Skip to content

Instantly share code, notes, and snippets.

@pr00thmatic
Created August 5, 2014 21:40
Show Gist options
  • Save pr00thmatic/0d9ad74651d27e23d3f9 to your computer and use it in GitHub Desktop.
Save pr00thmatic/0d9ad74651d27e23d3f9 to your computer and use it in GitHub Desktop.
function move_x(alguien, dir) {
alguien.scale.x = dir;
alguien.body.velocity.x = dir*velocity;
lastDirection = 'right'; //right will be flipped if left
}
function move_y(alguien, dir) {
uno.body.velocity.y = dir*velocity;
if (dir > 0)
lastDirection = 'front';
else
lastDirection = 'back';
}
function move(alguien, dir, axis) {
var wasmoving = ismoving;
ismoving = true;
if (axis == 'x') {
move_x(alguien, dir);
} else {
move_y(alguien, dir);
}
if(!wasmoving)
uno.animations.play(lastDirection);
}
function update() {
ismoving=false;
game.physics.arcade.collide(uno, walls);
cursores = game.input.keyboard.createCursorKeys();
uno.body.velocity.x=0;
uno.body.velocity.y=0;
if (cursores.right.isDown) {
move(uno, 1, 'x');
}
if(cursores.left.isDown) {
move(uno, -1, 'x');
}
if(cursores.up.isDown) {
move(uno, -1, 'y');
}
if(cursores.down.isDown) {
move(uno, 1, 'y');
}
if(!ismoving) {
uno.animations.play('stand_' + lastDirection);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment