From daeda4aa59128e90b287369867b28a7b587c8bcb Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Thu, 7 Apr 2016 00:38:08 -0400 Subject: [PATCH] numbers fly everywhere --- src/game.js | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/game.js b/src/game.js index 33313d1..0152e16 100644 --- a/src/game.js +++ b/src/game.js @@ -74,6 +74,29 @@ game.state.add('play', { strokeThickness: 4 })); + // DMG POOL + this.dmgTextPool = this.add.group() + var dmgText; + for(var d=0;d<50;d++){ + dmgText = this.add.text(0,1, '1', { + font: '64px Arial Black', + fill: '#fff', + strokeThickness: 4 + }); + dmgText.exists = false; + dmgText.tween = game.add.tween(dmgText).to({ + alpha: 0, + y: 100, + x: this.game.rnd.integerInRange(100,700) + }, 1000, Phaser.Easing.Cubic.Out); + + dmgText.tween.onComplete.add(function(text, tween){ + text.kill(); + }); + this.dmgTextPool.add(dmgText); + } + + }, render: function(){ game.debug.text( @@ -82,10 +105,19 @@ game.state.add('play', { this.game.world.centerY - this.currentAlien.height / 2); }, - onClickAlien: function(){ + onClickAlien: function(alien, pointer){ this.currentAlien.damage(this.player.clickDmg); this.alienHealthText.text = this.currentAlien.alive ? this.currentAlien.health + " HP" : "DEAD"; + + var dmgText = this.dmgTextPool.getFirstExists(false); + if (dmgText){ + dmgText.text = this.player.clickDmg; + dmgText.reset(pointer.positionDown.x, pointer.positionDown.y); + dmgText.alpha = 1; + dmgText.tween.start(); + } + }, onKilledAlien: function(alien){ alien.position.set(1000, this.game.world.centerY);