Skip to content

Instantly share code, notes, and snippets.

View pr00thmatic's full-sized avatar

Ruth García pr00thmatic

View GitHub Profile
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;
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)
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';
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;
// Física
game.physics.arcade.enable(uno);
uno.collideWorldBounds = true;
//creando al personaje
uno = game.add.sprite(game.world.width/2-16,
game.world.height/2-16,
'uno');
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
game.add.tileSprite(0,0,
game.world.width,
game.world.height,
'acera',
0
);
// 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);
}
var game = new Phaser.Game(800, 600,
Phaser.AUTO, '',
{ preload: preload,
create: create,
update: update
}
);