Edgerunner first demo
phaser framework, javascript and canvas
by Jon Eyrick
HTML
<script src="http://labs.phaser.io/js/phaser.min.js"></script>
<div id="game"></div>
JavaScript
EnemyTank = function (index, game, player, bullets) {
var x = game.world.randomX;
var y = game.world.randomY;
this.game = game;
this.health = 3;
this.player = player;
this.bullets = bullets;
this.fireRate = 300;
this.nextFire = 0;
this.alive = true;
//this.shadow = game.add.sprite(x, y, 'enemy', 'shadow');
var r = Math.random();
if ( r > 0.94 ) {
this.tank = game.add.sprite(x, y, 'tank');
this.health+= this.game.rnd.integerInRange(7,16);
} else if ( r > 0.65 ) {
this.health+= this.game.rnd.integerInRange(1,7);
this.tank = game.add.sprite(x, y, 'tank3');
} else {
this.tank = game.add.sprite(x, y, 'tank2');
}
//this.tank.setScale(0.6,0.6);
this.turret = game.add.sprite(x, y, 'turret');
//this.shadow.anchor.set(0.5);
this.tank.anchor.set(0.5);
this.turret.anchor.set(0.3, 0.5);
this.tank.name = index.toString();
game.physics.enable(this.tank, Phaser.Physics.ARCADE);
this.tank.body.immovable = false;
this.tank.body.collideWorldBounds = true;
this.tank.body.bounce.setTo(0.35, 0.35);
this.tank.body.width = 100;
this.tank.body.height = 190;
this.tank.angle = game.rnd.angle();
game.physics.arcade.velocityFromRotation(this.tank.rotation, 100, this.tank.body.velocity);
};
EnemyTank.prototype.damage = function() {
hitSound.play("hit");
this.health -= 1;
if (this.health <= 0) {
this.alive = false;
//this.shadow.kill();
this.tank.kill();
this.turret.kill();
setTimeout(function(){dieSound.play("die");},55);
return true;
}
return false;
}
EnemyTank.prototype.update = function() {
//this.shadow.x = this.tank.x;
//this.shadow.y = this.tank.y;
//this.shadow.rotation = this.tank.rotation;
this.turret.x = this.tank.x;
this.turret.y = this.tank.y;
//this.turret.rotation = this.game.physics.arcade.angleBetween(this.tank,...