var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'racing_game', { preload: preload, create: create, update: update }); function preload() { game.load.image('circuito','http://imgur.com/omJhWl3.png'); game.load.image('coche','http://imgur.com/T7OdhYY.png'); } var cursors; var velocidad = 0; function create() { var circuito = game.add.sprite(0,0,'circuito'); coche = game.add.sprite(300,100,'coche'); cursors = game.input.keyboard.createCursorKeys(); game.physics.startSystem(Phaser.Physics.P2JS); game.physics.p2.enable(coche); coche.body.angle = 90; } function update() { if (cursors.up.isDown && velocidad <= 400) { velocidad+=7; } else { if (velocidad >= 7) velocidad -= 7; } coche.body.velocity.x = velocidad * Math.cos((coche.angle-90)*0.01745); coche.body.velocity.y = velocidad * Math.sin((coche.angle-90)*0.01745); if (cursors.left.isDown) coche.body.angularVelocity = -5*(velocidad/1000); else if (cursors.right.isDown) coche.body.angularVelocity = 5*(velocidad/1000); else coche.body.angularVelocity = 0; }