numbers display and they go down

This commit is contained in:
Tyrel Souza 2016-04-07 00:31:20 -04:00
parent 7b3000256e
commit 586864c9e3

View File

@ -15,12 +15,19 @@ game.state.add('play', {
game.load.image('bg:talltrees', 'assets/bg/talltrees.png');
alienData = [
{name: 'Pink', image: 'alien:pink'},
{name: 'Green', image: 'alien:green'},
{name: 'Grey', image: 'alien:grey'},
{name: 'Blue', image: 'alien:blue'}
{name: 'Pink', image: 'alien:pink', maxHealth: 20 },
{name: 'Green', image: 'alien:green', maxHealth: 25 },
{name: 'Grey', image: 'alien:grey', maxHealth: 10 },
{name: 'Blue', image: 'alien:blue', maxHealth: 33 }
];
this.player = {
clickDmg: 1,
gold: 0
};
},
create: function(){
var state = this;
@ -30,8 +37,8 @@ game.state.add('play', {
state.game.world.height, 'bg:castle', '', state.background);
bg.tileScale.setTo(0.5, 0.5);
// Alien Group
this.aliens = this.game.add.group();
var alien;
alienData.forEach(function(data){
alien = state.aliens.create(1000, state.game.world.centerY, data.image);
@ -42,10 +49,30 @@ game.state.add('play', {
alien.inputEnabled = true;
alien.events.onInputDown.add(state.onClickAlien, state);
alien.health = alien.maxHealth = data.maxHealth;
alien.events.onKilled.add(state.onKilledAlien, state);
alien.events.onRevived.add(state.onRevivedAlien, state);
});
// Current Alien
this.currentAlien = this.aliens.getRandom();
this.currentAlien.position.set(this.game.world.centerX + 100, this.game.world.centerY);
// UI
this.alienInfoUI = this.game.add.group();
this.alienInfoUI.position.setTo(this.currentAlien.x - 220, this.currentAlien.y + 120);
this.alienNameText = this.alienInfoUI.addChild(this.game.add.text(0, 0, this.currentAlien.details.name, {
font: '48px Arial Black',
fill: '#fff',
strokeThickness: 4
}));
this.alienHealthText = this.alienInfoUI.addChild(this.game.add.text(0, 80, this.currentAlien.health + ' HP', {
font: '32px Arial Black',
fill: '#ff0000',
strokeThickness: 4
}));
},
render: function(){
@ -56,9 +83,20 @@ game.state.add('play', {
},
onClickAlien: function(){
this.currentAlien.position.set(1000, this.game.world.centerY);
this.currentAlien.damage(this.player.clickDmg);
this.alienHealthText.text = this.currentAlien.alive ? this.currentAlien.health + " HP" : "DEAD";
},
onKilledAlien: function(alien){
alien.position.set(1000, this.game.world.centerY);
this.currentAlien = this.aliens.getRandom();
this.currentAlien.revive(this.currentAlien.maxHealth);
},
onRevivedAlien: function(alien){
this.currentAlien.position.set(this.game.world.centerX + 100, this.game.world.centerY);
this.alienNameText.text = alien.details.name;
this.alienHealthText.text = alien.health + " HP";
}