Add: animal sprite in the typing button
This commit is contained in:
+92
-28
@@ -1,5 +1,8 @@
|
||||
function Animal(type, index, x, y) {
|
||||
this.animalType = type;
|
||||
this.animalIndex = index;
|
||||
|
||||
this.species = Animal.SPECIES_DATA[index];
|
||||
|
||||
this.sprite = null;
|
||||
this.posX = x;
|
||||
@@ -7,13 +10,53 @@ function Animal(type, index, x, y) {
|
||||
|
||||
this.sprite = game.add.sprite(this.posX, this.posY, "animals");
|
||||
this.sprite.anchor.set(0.5);
|
||||
this.sprite.animations.add("stand", [index * 2]);
|
||||
this.sprite.animations.play("stand");
|
||||
this.sprite.animations.add("run", [index * 2, index * 2 + 1]);
|
||||
|
||||
this.species = Animal.SPECIES_DATA[index];
|
||||
// for(var i = 0; i < Animal.SPECIES_DATA.length; i++) {
|
||||
// for(var i = Animal.SPECIES_DATA.length - 1; i > 0; i--) {
|
||||
// var animalName = this.getSpeciesName(i);
|
||||
|
||||
// var standAnimationName = animalName + "_stand";
|
||||
// this.sprite.animations.add(standAnimationName, i * 2);
|
||||
|
||||
// var runAnimationName = animalName + "_run";
|
||||
// this.sprite.animations.add(runAnimationName, i * 2, i * 2 + 1);
|
||||
// }
|
||||
|
||||
this.sprite.frame = this.animalIndex * 2;
|
||||
|
||||
// game.time.events.add(Phaser.Timer.SECOND * 5, this.showStandAnimation, this);
|
||||
|
||||
// var standAnimationName = this.getSpeciesName(this.animalIndex) + "_stand";
|
||||
// console.log(standAnimationName);
|
||||
// this.sprite.animations.play(standAnimationName);
|
||||
// this.sprite.animations.play("cheetah_stand");
|
||||
|
||||
this.sprite.animations.add("stand", [index * 2]);
|
||||
// this.sprite.animations.play("stand");
|
||||
this.sprite.animations.add("run", [index * 2, index * 2 + 1]);
|
||||
}
|
||||
|
||||
/*
|
||||
Animal.prototype.showStandAnimation = function() {
|
||||
var standAnimationName = this.getSpeciesName(this.animalIndex) + "_stand";
|
||||
console.log(standAnimationName);
|
||||
this.sprite.animations.play(standAnimationName);
|
||||
}
|
||||
*/
|
||||
|
||||
Animal.prototype.getSpeciesName = function(animalIndex) {
|
||||
return Animal.SPECIES_DATA[animalIndex].species;
|
||||
}
|
||||
|
||||
Animal.prototype.chagneStandAnimation = function(animalIndex) {
|
||||
// this.sprite.animations.play(this.getSpeciesName(this.animalIndex) + "stand");
|
||||
this.animalIndex = animalIndex;
|
||||
this.sprite.frame = this.animalIndex * 2;
|
||||
}
|
||||
|
||||
Animal.prototype.changeRunAnimation = function(animalIndex) {
|
||||
this.sprite.animations.play(this.getSpeciesName(this.animalIndex) + "run");
|
||||
}
|
||||
|
||||
Animal.prototype.setScale = function(value) {
|
||||
this.sprite.scale.set(value);
|
||||
@@ -32,14 +75,14 @@ Animal.prototype.setAlpha = function(value) {
|
||||
Animal.prototype.tweenAnimation = function(animationType) {
|
||||
switch(animationType) {
|
||||
case Animal.ANIMATION_TYPE_CHANGE:
|
||||
this.sprite.width = 100;
|
||||
this.sprite.height = 100;
|
||||
this.sprite.width = Animal.SPRITE_WIDTH;
|
||||
this.sprite.height = Animal.SPRITE_HEIGHT;
|
||||
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;
|
||||
this.sprite.height = 50;
|
||||
this.sprite.width = Animal.SPRITE_WIDTH;
|
||||
this.sprite.height = Animal.SPRITE_DAMAGE_HEIGHT;
|
||||
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;
|
||||
@@ -47,10 +90,14 @@ Animal.prototype.tweenAnimation = function(animationType) {
|
||||
}
|
||||
|
||||
Animal.prototype.startAnimation = function(species) {
|
||||
// var runAnimationName = this.getSpeciesName(this.animalIn) + "_run";
|
||||
// this.sprite.animations.play(runAnimationName, this.species.fps, true);
|
||||
this.sprite.animations.play("run", this.species.fps, true);
|
||||
}
|
||||
|
||||
Animal.prototype.stopAnimation = function() {
|
||||
// var runAnimationName = this.getSpeciesName(this.animalIn) + "_run";
|
||||
// this.sprite.animations.stop(runAnimationName);
|
||||
this.sprite.animations.stop("run");
|
||||
}
|
||||
|
||||
@@ -63,6 +110,15 @@ Animal.prototype.hide = function() {
|
||||
}
|
||||
|
||||
|
||||
Animal.animalIndexByRecord = function(record, gameType) {
|
||||
for(var i = Animal.SPECIES_DATA.length - 1; i > 0; i--) {
|
||||
if(record >= this.typingCount(Animal.SPECIES_DATA[i], gameType))
|
||||
return i;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Animal.animalLevelIDByRecord = function(record, gameType) {
|
||||
for(var i = Animal.SPECIES_DATA.length - 1; i > 0; i--) {
|
||||
if(record >= this.typingCount(Animal.SPECIES_DATA[i], gameType))
|
||||
@@ -72,15 +128,19 @@ Animal.animalLevelIDByRecord = function(record, gameType) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Animal.getAnimalFingerPositionTypingCount = function(animalIndex) {
|
||||
return Animal.SPECIES_DATA[animalIndex].fingerPositionTypingCount;
|
||||
Animal.getAnimalTypingPracticeCount = function(animalIndex) {
|
||||
return Animal.SPECIES_DATA[animalIndex].typingPracticeCount;
|
||||
}
|
||||
|
||||
Animal.getAnimalTypingTestCount = function(animalIndex) {
|
||||
return Animal.SPECIES_DATA[animalIndex].typingTestCount;
|
||||
}
|
||||
|
||||
Animal.typingCount = function(speciesData, gameType) {
|
||||
if(gameType === Animal.TYPE_FINGER_POSITION)
|
||||
return speciesData.fingerPositionTypingCount;
|
||||
if(gameType === Animal.TYPE_PRACTICE)
|
||||
return speciesData.typingPracticeCount;
|
||||
else
|
||||
return speciesData.practiceTypingCount;
|
||||
return speciesData.typingTestCount;
|
||||
}
|
||||
|
||||
|
||||
@@ -99,22 +159,26 @@ Animal.TYPE_EXAM = 1;
|
||||
Animal.ANIMATION_TYPE_CHANGE = 0;
|
||||
Animal.ANIMATION_TYPE_DAMAGE = 1;
|
||||
|
||||
Animal.SPRITE_WIDTH = 100;
|
||||
Animal.SPRITE_DAMAGE_WIDTH = 50;
|
||||
Animal.SPRITE_HEIGHT = 100;
|
||||
|
||||
Animal.HIDE_POS_Y = 1000;
|
||||
|
||||
Animal.SPECIES_DATA = [
|
||||
{ "species" : "snail", "fps" : 1, "fingerPositionTypingCount" : 0, "practiceTypingCount" : 0 },
|
||||
{ "species" : "turtle", "fps" : 2, "fingerPositionTypingCount" : 5, "practiceTypingCount" : 20 },
|
||||
{ "species" : "chick", "fps" : 5, "fingerPositionTypingCount" : 10, "practiceTypingCount" : 40 },
|
||||
{ "species" : "mouse", "fps" : 12, "fingerPositionTypingCount" : 15, "practiceTypingCount" : 70 },
|
||||
{ "species" : "chicken", "fps" : 11, "fingerPositionTypingCount" : 20, "practiceTypingCount" : 100 },
|
||||
{ "species" : "pig", "fps" : 5, "fingerPositionTypingCount" : 25, "practiceTypingCount" : 150 },
|
||||
{ "species" : "cat", "fps" : 10, "fingerPositionTypingCount" : 30, "practiceTypingCount" : 200 },
|
||||
{ "species" : "deer", "fps" : 9, "fingerPositionTypingCount" : 40, "practiceTypingCount" : 250 },
|
||||
{ "species" : "kangaroo", "fps" : 4, "fingerPositionTypingCount" : 50, "practiceTypingCount" : 300 },
|
||||
{ "species" : "rabbit", "fps" : 12, "fingerPositionTypingCount" : 60, "practiceTypingCount" : 350 },
|
||||
{ "species" : "dog", "fps" : 9, "fingerPositionTypingCount" : 70, "practiceTypingCount" : 400 },
|
||||
{ "species" : "zebra", "fps" : 12, "fingerPositionTypingCount" : 80, "practiceTypingCount" : 450 },
|
||||
{ "species" : "ostrich", "fps" : 15, "fingerPositionTypingCount" : 90, "practiceTypingCount" : 500 },
|
||||
{ "species" : "lion", "fps" : 10, "fingerPositionTypingCount" : 100, "practiceTypingCount" : 600 },
|
||||
{ "species" : "cheetah", "fps" : 15, "fingerPositionTypingCount" : 110, "practiceTypingCount" : 700 }
|
||||
{ "species" : "snail", "fps" : 1, "typingPracticeCount" : 0, "typingTestCount" : 0 },
|
||||
{ "species" : "turtle", "fps" : 2, "typingPracticeCount" : 5, "typingTestCount" : 20 },
|
||||
{ "species" : "chick", "fps" : 5, "typingPracticeCount" : 10, "typingTestCount" : 40 },
|
||||
{ "species" : "mouse", "fps" : 12, "typingPracticeCount" : 15, "typingTestCount" : 70 },
|
||||
{ "species" : "chicken", "fps" : 11, "typingPracticeCount" : 20, "typingTestCount" : 100 },
|
||||
{ "species" : "pig", "fps" : 5, "typingPracticeCount" : 25, "typingTestCount" : 150 },
|
||||
{ "species" : "cat", "fps" : 10, "typingPracticeCount" : 30, "typingTestCount" : 200 },
|
||||
{ "species" : "deer", "fps" : 9, "typingPracticeCount" : 40, "typingTestCount" : 250 },
|
||||
{ "species" : "kangaroo", "fps" : 4, "typingPracticeCount" : 50, "typingTestCount" : 300 },
|
||||
{ "species" : "rabbit", "fps" : 12, "typingPracticeCount" : 60, "typingTestCount" : 350 },
|
||||
{ "species" : "dog", "fps" : 9, "typingPracticeCount" : 70, "typingTestCount" : 400 },
|
||||
{ "species" : "zebra", "fps" : 12, "typingPracticeCount" : 80, "typingTestCount" : 450 },
|
||||
{ "species" : "ostrich", "fps" : 15, "typingPracticeCount" : 90, "typingTestCount" : 500 },
|
||||
{ "species" : "lion", "fps" : 10, "typingPracticeCount" : 100, "typingTestCount" : 600 },
|
||||
{ "species" : "cheetah", "fps" : 15, "typingPracticeCount" : 110, "typingTestCount" : 700 }
|
||||
];
|
||||
Reference in New Issue
Block a user