From 40f1da6e8a32098ad0b1246c1efccf2cec80ceed 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: Sun, 6 Jan 2019 07:20:16 +0900 Subject: [PATCH] Fix: go next word level with timing --- .../typing/word_flyingsaucer/flyingsaucer.js | 62 +++++++++++++------ .../word_flyingsaucer/game_level_manager.js | 24 ++++++- .../typing/word_flyingsaucer/word_manager.js | 1 + 3 files changed, 65 insertions(+), 22 deletions(-) diff --git a/src/game/typing/word_flyingsaucer/flyingsaucer.js b/src/game/typing/word_flyingsaucer/flyingsaucer.js index 8d28644..0019786 100644 --- a/src/game/typing/word_flyingsaucer/flyingsaucer.js +++ b/src/game/typing/word_flyingsaucer/flyingsaucer.js @@ -34,6 +34,8 @@ function FlyingSaucer(lineIndex) { var shipBody = this.makeShipBody(0, BODY_OFFSET_Y); this.addChild(shipBody); + this.explodeEmitter = this.makeExplodeEmitter(); + var style = { font: "20px Arial", fill: FlyingSaucer.TEXT_COLOR_NORMAL}; this.wordText = game.add.text(0, 0, "text", style); @@ -46,7 +48,7 @@ function FlyingSaucer(lineIndex) { FlyingSaucer.prototype.initVariables = function() { this.isActivated = false; this.wordLevel = 0; - this.score = 0; + this.wordScore = 0; this.speed = FlyingSaucer.DEFAULT_SPEED; this.scoreManager = null; @@ -81,6 +83,17 @@ FlyingSaucer.prototype.makeShipBody = function(posX, posY) { return body; } +FlyingSaucer.prototype.makeExplodeEmitter = function() { + explodeEmitter = game.add.emitter(this.x, this.y, 10); + explodeEmitter.makeParticles('star'); + explodeEmitter.minParticleScale = 1; + explodeEmitter.maxParticleScale = 3; + explodeEmitter.forEach( function(particle) { particle.tint = 0xadff2f; } ); + explodeEmitter.gravity = 0; + + return explodeEmitter; +} + FlyingSaucer.prototype.update = function() { if(this.isActivated) { @@ -89,7 +102,7 @@ FlyingSaucer.prototype.update = function() { this.wordText.y = this.y + FlyingSaucer.WORD_TEXT_OFFSET_Y; - if(this.y > GAME_SCREEN_SIZE.y - 200) + if(this.y > FlyingSaucer.CRASH_POS_Y) this.crash(); } else { this.stop(); @@ -136,28 +149,22 @@ FlyingSaucer.prototype.setActive = function(isActivated) { FlyingSaucer.prototype.moveInitialPos = function() { this.x = 100 + this.lineIndex * 200; - this.y = 100; + this.y = FlyingSaucer.START_POS_Y; 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.makeParticles('star'); - this.explodeEmitter.minParticleScale = 1; - this.explodeEmitter.maxParticleScale = 3; - this.explodeEmitter.forEach( function(particle) { particle.tint = 0xadff2f; } ); - this.explodeEmitter.gravity = 0; } FlyingSaucer.prototype.startAttack = function() { this.moveInitialPos(); - var wordLevel = this.gameLevelManager.getWordLevel(); - var word = this.wordManager.getWord(wordLevel); - this.setWord(word); - this.score = this.gameLevelManager.getWordScore(); + this.wordLevel = this.gameLevelManager.getWordLevel(); + this.word = this.wordManager.getWord(this.wordLevel); + this.setWord(this.word); + this.wordScore = this.gameLevelManager.getWordScore(); + // console.log(this.wordScore); this.setActive(true); } @@ -190,13 +197,21 @@ FlyingSaucer.prototype.checkInputText = function(inputText) { this.wordText.addColor(FlyingSaucer.TEXT_COLOR_NORMAL, index); } +FlyingSaucer.prototype.getClearTiming = function(inputText) { + var heightDown = FlyingSaucer.CRASH_POS_Y - FlyingSaucer.START_POS_Y; + var distanceDown = this.y - FlyingSaucer.START_POS_Y; + return (heightDown - distanceDown) / heightDown; +} + FlyingSaucer.prototype.checkWord = function(inputText) { // console.log("inputText : " + inputText); // console.log("this.wordText : " + this.wordText); - var word = this.wordText.text; + // var word = this.wordText.text; - if(word == inputText) { + if(this.word == inputText) { + this.gameLevelManager.clearWord(this.wordLevel, this.getClearTiming()); + this.wordManager.removeWord(this.wordLevel, this.word); this.setWord(""); this.setActive(false); @@ -207,13 +222,19 @@ FlyingSaucer.prototype.checkWord = function(inputText) { } FlyingSaucer.prototype.explode = function(inputText) { + this.explodeEmitter.x = this.x; + this.explodeEmitter.y = this.y; this.explodeEmitter.start(true, 1000, null, 100); + this.timerEvent = game.time.events.add(Phaser.Timer.SECOND, this.startAttack, this); } FlyingSaucer.prototype.plusScore = function(inputText) { - this.scoreManager.plusScore(this.score); - var scoreText = new ScoreText(this.x, this.y, this.score); + console.log(this.wordScore); + console.log(this.getClearTiming()); + var totalScore = Math.floor(this.wordScore * (this.getClearTiming() * 100)); + this.scoreManager.plusScore(totalScore); + var scoreText = new ScoreText(this.x, this.y, totalScore); } FlyingSaucer.prototype.crash = function() { @@ -243,7 +264,10 @@ FlyingSaucer.loadResource = function() { -FlyingSaucer.DEFAULT_SPEED = 10; // dot per sec +FlyingSaucer.DEFAULT_SPEED = 10; // dot per sec + +FlyingSaucer.START_POS_Y = 100; // px +FlyingSaucer.CRASH_POS_Y = GAME_SCREEN_SIZE.y - 200; // px FlyingSaucer.WORD_TEXT_OFFSET_Y = 30; // px diff --git a/src/game/typing/word_flyingsaucer/game_level_manager.js b/src/game/typing/word_flyingsaucer/game_level_manager.js index 8b48e7a..2f7d475 100644 --- a/src/game/typing/word_flyingsaucer/game_level_manager.js +++ b/src/game/typing/word_flyingsaucer/game_level_manager.js @@ -1,13 +1,31 @@ function GameLevelManager() { + this.wordLevel = 1; + this.difficulty = 1; + this.clearPoint = 0.1; } GameLevelManager.prototype.getWordLevel = function() { - return 0; + return this.wordLevel; } GameLevelManager.prototype.getWordScore = function() { - return 10; + return this.wordLevel * this.difficulty; } -// GameLevelManager.HEART_MAX_COUNT = 5; \ No newline at end of file +GameLevelManager.prototype.clearWord = function(wordLevel, clearTiming) { + console.log("wordLevel : " + wordLevel); + console.log("clearTiming : " + clearTiming); + + if(this.wordLevel == wordLevel && clearTiming > 0.9) { + if(this.wordLevel < GameLevelManager.MAX_KOR_WORD_LEVEL) + this.wordLevel++; + + console.log("this.wordLevel : " + this.wordLevel); + } +} + + +GameLevelManager.LEVELUP_TIMING = 0.9; + +GameLevelManager.MAX_KOR_WORD_LEVEL = 7; \ No newline at end of file diff --git a/src/game/typing/word_flyingsaucer/word_manager.js b/src/game/typing/word_flyingsaucer/word_manager.js index 2e70eb4..ff0959c 100644 --- a/src/game/typing/word_flyingsaucer/word_manager.js +++ b/src/game/typing/word_flyingsaucer/word_manager.js @@ -13,6 +13,7 @@ WordManager.prototype.getWord = function(wordLevel) { } WordManager.prototype.removeWord = function(wordLevel, word) { + console.log("remove : " + wordLevel + ", " + word); }