109 lines
3.6 KiB
JavaScript
109 lines
3.6 KiB
JavaScript
function Animal(type, index, x, y) {
|
|
this.animalType = type;
|
|
|
|
this.sprite = null;
|
|
this.posX = x;
|
|
this.posY = 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];
|
|
}
|
|
|
|
|
|
Animal.prototype.setScale = function(value) {
|
|
this.sprite.scale.set(value);
|
|
}
|
|
|
|
Animal.prototype.setSpecies = function(species) {
|
|
console.log(species);
|
|
this.species = species;
|
|
}
|
|
|
|
Animal.prototype.setAlpha = function(value) {
|
|
this.sprite.alpha = value;
|
|
}
|
|
|
|
|
|
Animal.prototype.tweenAnimation = function(animationType) {
|
|
switch(animationType) {
|
|
case Animal.ANIMATION_TYPE_CHANGE:
|
|
this.sprite.width = 100;
|
|
this.sprite.height = 100;
|
|
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;
|
|
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;
|
|
}
|
|
}
|
|
|
|
Animal.prototype.startAnimation = function(species) {
|
|
this.sprite.animations.play("run", this.species.fps, true);
|
|
}
|
|
|
|
Animal.prototype.stopAnimation = function() {
|
|
this.sprite.animations.stop("run");
|
|
}
|
|
|
|
|
|
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))
|
|
return i;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
Animal.getAnimalPracticeTypingCount = function(animalIndex) {
|
|
return Animal.SPECIES_DATA[animalIndex].practiceTypingCount;
|
|
}
|
|
|
|
Animal.typingCount = function(speciesData, gameType) {
|
|
if(gameType === Animal.TYPE_PRACTICE)
|
|
return speciesData.practiceTypingCount;
|
|
else
|
|
return speciesData.testTypingCount;
|
|
}
|
|
|
|
Animal.loadResources = function() {
|
|
game.load.spritesheet('animals', '../../../resources/image/character/animal/animals.png', 50, 50);
|
|
}
|
|
|
|
|
|
Animal.TYPE_ANIMATION = 0;
|
|
Animal.TYPE_ICON = 1;
|
|
|
|
Animal.TYPE_PRACTICE = 0;
|
|
Animal.TYPE_TEST = 1;
|
|
|
|
Animal.ANIMATION_TYPE_CHANGE = 0;
|
|
Animal.ANIMATION_TYPE_DAMAGE = 1;
|
|
|
|
|
|
Animal.SPECIES_DATA = [
|
|
{ "species" : "snail", "fps" : 1, "practiceTypingCount" : 0, "testTypingCount" : 0 },
|
|
{ "species" : "turtle", "fps" : 2, "practiceTypingCount" : 5, "testTypingCount" : 20 },
|
|
{ "species" : "chick", "fps" : 5, "practiceTypingCount" : 10, "testTypingCount" : 40 },
|
|
{ "species" : "mouse", "fps" : 12, "practiceTypingCount" : 15, "testTypingCount" : 70 },
|
|
{ "species" : "chicken", "fps" : 11, "practiceTypingCount" : 20, "testTypingCount" : 100 },
|
|
{ "species" : "pig", "fps" : 5, "practiceTypingCount" : 25, "testTypingCount" : 150 },
|
|
{ "species" : "cat", "fps" : 10, "practiceTypingCount" : 30, "testTypingCount" : 200 },
|
|
{ "species" : "deer", "fps" : 9, "practiceTypingCount" : 40, "testTypingCount" : 250 },
|
|
{ "species" : "kangaroo", "fps" : 4, "practiceTypingCount" : 50, "testTypingCount" : 300 },
|
|
{ "species" : "rabbit", "fps" : 12, "practiceTypingCount" : 60, "testTypingCount" : 350 },
|
|
{ "species" : "dog", "fps" : 9, "practiceTypingCount" : 70, "testTypingCount" : 400 },
|
|
{ "species" : "zebra", "fps" : 12, "practiceTypingCount" : 80, "testTypingCount" : 450 },
|
|
{ "species" : "ostrich", "fps" : 15, "practiceTypingCount" : 90, "testTypingCount" : 500 },
|
|
{ "species" : "lion", "fps" : 10, "practiceTypingCount" : 100, "testTypingCount" : 600 },
|
|
{ "species" : "cheetah", "fps" : 15, "practiceTypingCount" : 110, "testTypingCount" : 700 }
|
|
]; |