From 1aeff260728a52dd5df4cded377d66bab7a89d0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A2=E1=84=91=E1=85=B3=E1=86=AF=20=E1=84=82?= =?UTF-8?q?=E1=85=A9=E1=84=90=E1=85=B3=E1=84=87=E1=85=AE=E1=86=A8?= Date: Fri, 4 Jan 2019 17:04:34 +0900 Subject: [PATCH] Add: check input text and explode and restart --- .../typing/word_flyingsaucer/flyingsaucer.js | 37 ++++++++----------- src/game/typing/word_flyingsaucer/game.js | 2 +- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/game/typing/word_flyingsaucer/flyingsaucer.js b/src/game/typing/word_flyingsaucer/flyingsaucer.js index 3227a14..7b2c53d 100644 --- a/src/game/typing/word_flyingsaucer/flyingsaucer.js +++ b/src/game/typing/word_flyingsaucer/flyingsaucer.js @@ -39,7 +39,7 @@ function FlyingSaucer(lineIndex) { this.wordText = game.add.text(0, 0, "text", style); this.wordText.anchor.set(0.5); - this.moveInitialPos(); + this.startAttack(); // this.setActive(true); } @@ -76,7 +76,6 @@ FlyingSaucer.prototype.makeShipBody = function(posX, posY) { } - FlyingSaucer.prototype.update = function() { if(this.isActivated) { var deltaTime = game.time.elapsed / 1000; @@ -91,12 +90,16 @@ FlyingSaucer.prototype.update = function() { } } - FlyingSaucer.prototype.setup = function(wordLevel, speedLevel) { this.wordLevel = wordLevel; this.speedLevel = speedLevel; } +FlyingSaucer.prototype.setWord = function(wordText) { + this.wordText.text = wordText; +} + + FlyingSaucer.prototype.stop = function() { @@ -110,37 +113,30 @@ FlyingSaucer.prototype.setActive = function(isActivated) { this.alpha = 1; } else { this.alpha = 0; - this.wordText.text = ""; } } FlyingSaucer.prototype.moveInitialPos = function() { - console.log("moveInitialPos"); this.x = 100 + this.lineIndex * 200; this.y = 100; this.wordText.x = this.x; this.wordText.y = this.y + FlyingSaucer.WORD_TEXT_OFFSET_Y; + this.wordText.clearColors(); + this.wordText.addColor(FlyingSaucer.TEXT_COLOR_NORMAL, 0); - this.explodeEmitter = game.add.emitter( - this.x, - this.y, - 10 - ); + this.explodeEmitter = game.add.emitter(this.x, this.y, 10); this.explodeEmitter.makeParticles('star'); this.explodeEmitter.minParticleScale = 1; this.explodeEmitter.maxParticleScale = 3; - this.explodeEmitter.forEach( - function(particle) { - particle.tint = 0xadff2f; - } - ); + this.explodeEmitter.forEach( function(particle) { particle.tint = 0xadff2f; } ); this.explodeEmitter.gravity = 0; } -FlyingSaucer.prototype.reset = function() { + +FlyingSaucer.prototype.startAttack = function() { this.moveInitialPos(); - this.wordText.text = "text"; + this.setWord("text"); this.setActive(true); } @@ -173,13 +169,14 @@ FlyingSaucer.prototype.checkInputText = function(inputText) { this.wordText.addColor(FlyingSaucer.TEXT_COLOR_NORMAL, index); } -FlyingSaucer.prototype.attack = function(inputText) { +FlyingSaucer.prototype.checkWord = function(inputText) { // console.log("inputText : " + inputText); // console.log("this.wordText : " + this.wordText); var word = this.wordText.text; if(word == inputText) { + this.setWord(""); this.explode(); return; } @@ -187,10 +184,8 @@ FlyingSaucer.prototype.attack = function(inputText) { FlyingSaucer.prototype.explode = function(inputText) { this.setActive(false); - this.explodeEmitter.start(true, 1000, null, 100); - - this.timerEvent = game.time.events.add(Phaser.Timer.SECOND, this.reset, this); + this.timerEvent = game.time.events.add(Phaser.Timer.SECOND, this.startAttack, this); } diff --git a/src/game/typing/word_flyingsaucer/game.js b/src/game/typing/word_flyingsaucer/game.js index 45bfe5d..e2c6f42 100644 --- a/src/game/typing/word_flyingsaucer/game.js +++ b/src/game/typing/word_flyingsaucer/game.js @@ -138,7 +138,7 @@ var WordFlyingSaucer = { var count = this.flyingsaucers.length; if(event.keyCode == Phaser.Keyboard.ENTER) { for(var i = 0; i < count; i++) { - this.flyingsaucers[i].attack(this.inputText.canvasInput.value()); + this.flyingsaucers[i].checkWord(this.inputText.canvasInput.value()); } this.inputText.canvasInput.value("");