Meta Script S Cript Body Div Div Script: Charset
Meta Script S Cript Body Div Div Script: Charset
DOCTYP
E html>
<meta charset="utf-8">
<script
src="http://cdnjs.cloudflare.com/ajax/libs/phaser/2.0.3/phaser.min.js"></s
cript>
<body>
<div id="game" style="overflow: hidden;"></div>
<script>
/*
A GAME MECHANIC EXPLORER DEMO
http://gamemechanicexplorer.com/#thrust-4
*/
// Turn on gravity
game.physics.arcade.gravity.y = this.GRAVITY;
// Show FPS
this.game.time.advancedTiming = true;
this.fpsText = this.game.add.text(
20, 20, '', { font: '16px Arial', fill: '#ffffff' }
);
};
// Add an animation for the explosion that kills the sprite when
the
// animation is complete
var animation = explosion.animations.add('boom', [0,1,2,3], 60,
false);
animation.killOnComplete = true;
GameState.prototype.resetShip = function() {
// Move the ship back to the top of the stage
this.ship.x = 32;
this.ship.y = 32;
this.ship.body.acceleration.setTo(0, 0);
if (this.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
// If the LEFT key is down, rotate left
this.ship.body.angularVelocity = -this.ROTATION_SPEED;
} else if (this.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
// If the RIGHT key is down, rotate right
this.ship.body.angularVelocity = this.ROTATION_SPEED;
} else {
// Stop rotating
this.ship.body.angularVelocity = 0;
}
// Set a variable that is true when the ship is touching the ground
var onTheGround = this.ship.body.touching.down;
if (onTheGround) {
if (Math.abs(this.ship.body.velocity.y) > 20 ||
Math.abs(this.ship.body.velocity.x) > 30) {
// The ship hit the ground too hard.
// Blow it up and start the game over.
this.getExplosion(this.ship.x, this.ship.y);
this.resetShip();
} else {
// We've landed!
// Stop rotating and moving and aim the ship up.
this.ship.body.angularVelocity = 0;
this.ship.body.velocity.setTo(0, 0);
this.ship.angle = -90;
}
if (this.input.keyboard.isDown(Phaser.Keyboard.UP)) {
// If the UP key is down, thrust
// Calculate acceleration vector based on this.angle and
this.ACCELERATION
this.ship.body.acceleration.x = Math.cos(this.ship.rotation) *
this.ACCELERATION;
this.ship.body.acceleration.y = Math.sin(this.ship.rotation) *
this.ACCELERATION;
// Show the frame from the spritesheet with the engine off
this.ship.frame = 0;
}
};
window.focus();
</script>