This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function update() { | |
game.physics.arcade.collide(uno, walls); | |
cursores = game.input.keyboard.createCursorKeys(); | |
uno.animations.play('stand_' + lastDirection); // importante!! "uno" se queda quieto. | |
if(cursores.left.isDown) { | |
lastDirection = 'left'; | |
uno.scale.x = -1; | |
uno.body.velocity.x = -1*velocity; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cursores = game.input.keyboard.createCursorKeys(); | |
if(cursores.left.isDown) { | |
... | |
} else if (cursores.right.isDown) { | |
... | |
} else if (cursores.up.isDown) { | |
uno.body.velocity.y = -1; | |
uno.animations.play('front') | |
lastDirection = 'front'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cursores = game.input.keyboard.createCursorKeys(); | |
if(cursores.left.isDown) { | |
lastDirection = 'left'; | |
uno.scale.x = -1; | |
uno.body.velocity.x = -1*velocity; | |
uno.animations.play('right'); //uno.scale.x=-1 hace que right se voltee a left | |
} else if (cursores.right.isDown) { | |
lastDirection = 'right'; | |
uno.scale.x = 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Física | |
game.physics.arcade.enable(uno); | |
uno.collideWorldBounds = true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//creando al personaje | |
uno = game.add.sprite(game.world.width/2-16, | |
game.world.height/2-16, | |
'uno'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uno.animations.add('stand_front', [15], fps, true); | |
uno.animations.add('stand_right', [5], fps, true); | |
uno.animations.add('stand_back', [10], fps, true); | |
uno.animations.add('front', [1,2,3,4], fps, true); | |
uno.animations.add('right', [6,7,8,9], fps, true); | |
uno.animations.add('back', [11,12,13,14], fps, true); | |
uno.animations.play('stand_front'); //empezará viendo hacia el frente |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
game.add.tileSprite(0,0, | |
game.world.width, | |
game.world.height, | |
'acera', | |
0 | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// función indispensable para phaser. | |
function preload() { //Cargando los recursos que necesitaremos. | |
game.load.image('wall', 'assets/wall.png'); | |
game.load.image('acera', 'assets/acera.png'); | |
game.load.spritesheet('uno', 'assets/uno.png', 16, 16); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var game = new Phaser.Game(800, 600, | |
Phaser.AUTO, '', | |
{ preload: preload, | |
create: create, | |
update: update | |
} | |
); |