From 974bd8e255c08c28af59cac6d02dd4ec96107c9c 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: Mon, 17 Sep 2018 08:39:33 +0900 Subject: [PATCH] Add: prev and next animal icon image in typing practice --- src/game/lib/animal.js | 40 +++++++++++++++++++------------- src/game/result/result.js | 6 ++--- src/game/typing/practice/game.js | 30 ++++++++++++++++++------ src/game/typing/test/game.js | 6 ++--- 4 files changed, 51 insertions(+), 31 deletions(-) diff --git a/src/game/lib/animal.js b/src/game/lib/animal.js index de0f87b..6a98d1f 100644 --- a/src/game/lib/animal.js +++ b/src/game/lib/animal.js @@ -4,6 +4,21 @@ function Animal(type, x, y) { this.sprite = null; this.posX = x; this.posY = y; + + this.sprite = game.add.sprite(this.posX, this.posY); //, "snail_run1"); // this.spriteFrameNames.run1); + this.sprite.anchor.set(0.5); +} + + +Animal.prototype.setIconSprite = function(species) { + this.setSpecies(species); + + this.spriteFrameNames = this.loadSpriteNames(); + this.sprite.loadTexture(this.spriteFrameNames.run1); +} + +Animal.prototype.setSpecies = function(species) { + this.species = species; } Animal.prototype.loadSpriteNames = function() { @@ -17,15 +32,11 @@ Animal.prototype.loadSpriteNames = function() { return spriteNames; } -Animal.prototype.setSpecies = function(species) { - this.species = species; - - if(this.animalType === Animal.TYPE_ICON) - return; - - this.setupAnimation(); +Animal.prototype.setAlpha = function(value) { + this.sprite.alpha = value; } + Animal.prototype.tweenAnimation = function(animationType) { switch(animationType) { case Animal.ANIMATION_TYPE_CHANGE: @@ -41,7 +52,6 @@ Animal.prototype.tweenAnimation = function(animationType) { break; } - } Animal.prototype.setupAnimation = function() { @@ -50,18 +60,14 @@ Animal.prototype.setupAnimation = function() { this.animationFrameID = 1; this.animationSpeedSec = 1000 / this.species.runningFPS; - if(this.sprite === null) { - this.sprite = game.add.sprite(this.posX, this.posY, this.spriteFrameNames.run1); - this.sprite.anchor.set(0.5); - this.sprite.width = 150; - this.sprite.height = 150; - } - this.stopAnimation(); this.animateionUpdate(); } -Animal.prototype.startAnimation = function() { +Animal.prototype.startAnimation = function(species) { + this.setSpecies(species); + this.setupAnimation(); + if(this.timerEvent === null) this.timerEvent = game.time.events.loop(this.animationSpeedSec, this.animateionUpdate, this); } @@ -74,6 +80,8 @@ Animal.prototype.animateionUpdate = function() { } else { this.sprite.loadTexture(this.spriteFrameNames.run1); } + this.sprite.width = 150; + this.sprite.height = 150; } Animal.prototype.stopAnimation = function() { diff --git a/src/game/result/result.js b/src/game/result/result.js index 298cae1..d96e4d6 100644 --- a/src/game/result/result.js +++ b/src/game/result/result.js @@ -74,14 +74,12 @@ var Result = { animalLevelID = Animal.animalLevelIDByRecord(sessionStorageManager.getRecord(), Animal.TYPE_PRACTICE); else animalLevelID = Animal.animalLevelIDByRecord(sessionStorageManager.getRecord(), Animal.TYPE_TEST); - leftAnimal.setSpecies(Animal.SPECIES_DATA[animalLevelID]);; // leftAnimal.tweenAnimation(Animal.ANIMATION_TYPE_CHANGE); - leftAnimal.startAnimation(); + leftAnimal.startAnimation(Animal.SPECIES_DATA[animalLevelID]); var rightAnimal = new Animal(Animal.TYPE_ANIMATION, game.world.centerX + 200, 150); - rightAnimal.setSpecies(Animal.SPECIES_DATA[animalLevelID]);; // rightAnimal.tweenAnimation(Animal.ANIMATION_TYPE_CHANGE); - rightAnimal.startAnimation(); + rightAnimal.startAnimation(Animal.SPECIES_DATA[animalLevelID]); } var scoreText = game.add.text( diff --git a/src/game/typing/practice/game.js b/src/game/typing/practice/game.js index a94164d..5f7e0a4 100644 --- a/src/game/typing/practice/game.js +++ b/src/game/typing/practice/game.js @@ -19,9 +19,16 @@ var TypingPractice = { // this.animalOnTitle = new Animal(Animal.TYPE_ON_TITLE, game.world.centerX - 200, 30); - this.animalOnTitle = new Animal(Animal.TYPE_ON_TITLE, game.world.centerX, 90); - this.animalOnTitle.setSpecies(Animal.SPECIES_DATA[0]); - this.animalOnTitle.startAnimation(); + this.animalOnTitle = new Animal(Animal.TYPE_ON_TITLE, game.world.centerX, 100); + this.animalOnTitle.startAnimation(Animal.SPECIES_DATA[0]); + + this.animalPrev = new Animal(Animal.TYPE_ICON, game.world.centerX - 200, 100); + this.animalPrev.setIconSprite(Animal.SPECIES_DATA[0]); + this.animalPrev.setAlpha(0); + + this.animalNext = new Animal(Animal.TYPE_ICON, game.world.centerX + 200, 100); + this.animalNext.setIconSprite(Animal.SPECIES_DATA[1]); + this.animalNext.setAlpha(0.3); this.typingScore = new TypingScore(); @@ -357,11 +364,21 @@ var TypingPractice = { if(this.isKeyPressed(inputContent, typingContent)) { this.typingScore.increase(); var animalLevelID = Animal.animalLevelIDByRecord(this.typingScore.score(), Animal.TYPE_PRACTICE); + console.log(animalLevelID); + console.log(this.playingAnimalIndex); if(animalLevelID > this.playingAnimalIndex) { this.playingAnimalIndex = animalLevelID; - this.animalOnTitle.setSpecies(Animal.SPECIES_DATA[this.playingAnimalIndex]);; + this.animalOnTitle.startAnimation(Animal.SPECIES_DATA[this.playingAnimalIndex]); this.animalOnTitle.tweenAnimation(Animal.ANIMATION_TYPE_CHANGE); - this.animalOnTitle.startAnimation(); + + if(this.playingAnimalIndex == 1) + this.animalPrev.setAlpha(0.3); + this.animalPrev.setIconSprite(Animal.SPECIES_DATA[this.playingAnimalIndex - 1]); + + if(this.playingAnimalIndex == Animal.SPECIES_DATA.length - 1) + this.animalNext.setAlpha(0); + else + this.animalNext.setIconSprite(Animal.SPECIES_DATA[this.playingAnimalIndex + 1]); } this.playNextContent(); @@ -372,8 +389,7 @@ var TypingPractice = { this.typingScore.reset(); this.playingAnimalIndex = 0; - this.animalOnTitle.setSpecies(Animal.SPECIES_DATA[this.playingAnimalIndex]);; - this.animalOnTitle.startAnimation(); + this.animalOnTitle.startAnimation(Animal.SPECIES_DATA[this.playingAnimalIndex]); this.animalOnTitle.tweenAnimation(Animal.ANIMATION_TYPE_DAMAGE); } }, diff --git a/src/game/typing/test/game.js b/src/game/typing/test/game.js index e3a880a..06dbd8a 100644 --- a/src/game/typing/test/game.js +++ b/src/game/typing/test/game.js @@ -19,8 +19,7 @@ var TypingTest = { // this.animalOnTitle = new Animal(Animal.TYPE_ON_TITLE, game.world.centerX - 200, 30); this.animalOnTitle = new Animal(Animal.TYPE_ON_TITLE, game.world.centerX, GAME_SCREEN_SIZE.y - 110); - this.animalOnTitle.setSpecies(Animal.SPECIES_DATA[0]); - this.animalOnTitle.startAnimation(); + this.animalOnTitle.startAnimation(Animal.SPECIES_DATA[0]); this.averageTypingSpeedText = new AverageTypingSpeed(); @@ -397,9 +396,8 @@ var TypingTest = { // console.log('-----------------------------------'); let animalLevelID = Animal.animalLevelIDByRecord(typingRecordTotalInteger, Animal.TYPE_TEST); - this.animalOnTitle.setSpecies(Animal.SPECIES_DATA[animalLevelID]);; + this.animalOnTitle.startAnimation(Animal.SPECIES_DATA[animalLevelID]); this.animalOnTitle.tweenAnimation(Animal.ANIMATION_TYPE_CHANGE); - this.animalOnTitle.startAnimation(); },