Add: show animals for practice, test stage and result

Fix: change animal graphic resources
This commit is contained in:
2018-08-28 16:36:38 +09:00
parent 5bfa40d68f
commit c7fe3bf4e5
30 changed files with 317 additions and 9 deletions
+131
View File
@@ -0,0 +1,131 @@
class Animal {
constructor(type, x, y) {
this.animalType = type;
this.sprite = null;
this.posX = x;
this.posY = y;
}
animalLevelIDByRecord(record) {
if(sessionStorageManager.playingAppID <= 20) { // practice
for(let i = 0; i < Animal.SPECIES_DATA.length - 1; i++) {
if(record < Animal.SPECIES_DATA[i].practiceTypingCount)
return i;
}
} else { // test
for(let i = 0; i < Animal.SPECIES_DATA.length - 1; i++) {
if(record < Animal.SPECIES_DATA[i].testTypingCount)
return i;
}
}
return Animal.SPECIES_DATA.length - 1;
}
loadSpriteNames() {
let spriteNames = {};
spriteNames.icon = this.species.species + Animal.SPRITE_NAMES.icon;
spriteNames.run1 = this.species.species + Animal.SPRITE_NAMES.run1;
spriteNames.run2 = this.species.species + Animal.SPRITE_NAMES.run2;
return spriteNames;
}
setSpecies(species) {
this.species = species;
if(this.animalType === Animal.TYPE_ICON)
return;
this.setupAnimation();
}
tweenAnimation(animationType) {
switch(animationType) {
case Animal.ANIMATION_TYPE_CHANGE:
this.sprite.width = 70;
this.sprite.height = 70;
game.add.tween(this.sprite).to( { width: 50, height: 50 }, 500, Phaser.Easing.Bounce.Out, true);
break;
case Animal.ANIMATION_TYPE_DAMAGE:
this.sprite.width = 100;
game.add.tween(this.sprite).to( { width: 50 }, 500, Phaser.Easing.Bounce.In, true);
// game.add.tween(this.sprite).to( { width: 50 }, 500, Phaser.Easing.Elastic.Out, true);
break;
}
}
setupAnimation() {
this.spriteFrameNames = this.loadSpriteNames();
this.playingSpriteFrameName = this.spriteFrameNames.run1;
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 = 50;
this.sprite.height = 50;
}
this.stopAnimation();
this.animateionUpdate();
}
startAnimation() {
if(this.timerEvent === null)
this.timerEvent = game.time.events.loop(this.animationSpeedSec, this.animateionUpdate, this);
}
animateionUpdate() {
this.animationFrameID = 1 - this.animationFrameID;
if(this.animationFrameID === 0) {
this.sprite.loadTexture(this.spriteFrameNames.run2);
} else {
this.sprite.loadTexture(this.spriteFrameNames.run1);
}
}
stopAnimation() {
if(this.timerEvent !== null) {
game.time.events.remove(this.timerEvent);
this.timerEvent = null;
}
}
}
Animal.TYPE_ANIMATION = 0;
Animal.TYPE_ICON = 1;
Animal.ANIMATION_TYPE_CHANGE = 0;
Animal.ANIMATION_TYPE_DAMAGE = 1;
Animal.SPECIES_DATA = [
{ "species" : "snail", "runningFPS" : 1.1, "practiceTypingCount" : 5, "testTypingCount" : 10 },
{ "species" : "turtle", "runningFPS" : 5.5, "practiceTypingCount" : 10, "testTypingCount" : 20 },
{ "species" : "cat", "runningFPS" : 10.1, "practiceTypingCount" : 20, "testTypingCount" : 30 },
{ "species" : "lion", "runningFPS" : 15.5, "practiceTypingCount" : 30, "testTypingCount" : 50 },
{ "species" : "rabbit", "runningFPS" : 20.2, "practiceTypingCount" : 40, "testTypingCount" : 100 },
{ "species" : "ostrich", "runningFPS" : 25.5, "practiceTypingCount" : 50, "testTypingCount" : 200 },
{ "species" : "horse", "runningFPS" : 30.3, "practiceTypingCount" : 60, "testTypingCount" : 300 },
{ "species" : "dog", "runningFPS" : 35.5, "practiceTypingCount" : 70, "testTypingCount" : 400 },
{ "species" : "cheetah", "runningFPS" : 40.4, "practiceTypingCount" : 80, "testTypingCount" : 500 },
{ "species" : "eagle", "runningFPS" : 45.5, "practiceTypingCount" : 1000, "testTypingCount" : 1000 }
];
Animal.SPRITE_NAMES = {
"icon" : "_icon",
"run1" : "_run1",
"run2" : "_run2"
};