Add: animal_list for typing practice and test

This commit is contained in:
2018-10-07 00:00:42 +09:00
parent cb74f9ec32
commit dbcc8b3848
6 changed files with 81 additions and 44 deletions
+4
View File
@@ -10,6 +10,10 @@ function Animal(type, x, y) {
}
Animal.prototype.setScale = function(value) {
this.sprite.scale.set(value);
}
Animal.prototype.setIconSprite = function(species) {
this.setSpecies(species);
+59
View File
@@ -0,0 +1,59 @@
function AnimalList(y) {
this.animals = [];
this.activeAnimalIndex = -1;
var animalCount = Animal.SPECIES_DATA.length;
var lineWidth = GAME_SCREEN_SIZE.x - AnimalList.MARGIN_X * 2;
console.log("lineWidth : " + lineWidth);
var offsetAnimal = lineWidth / (animalCount - 1);
console.log("animalCount : " + animalCount);
console.log("offsetAnimal : " + offsetAnimal);
for(var i = 0; i < animalCount; i++) {
this.animals[i] = new Animal(
Animal.TYPE_ICON,
AnimalList.MARGIN_X + offsetAnimal * i,
y
);
this.inactivate(i);
}
this.activeAnimalIndex = 0;
this.activate(this.activeAnimalIndex);
}
AnimalList.prototype.activate = function(index) {
this.inactivate(this.activeAnimalIndex);
this.activeAnimalIndex = index;
this.animals[this.activeAnimalIndex].setScale(2);
this.animals[index].setAlpha(1);
this.animate(this.activeAnimalIndex);
}
AnimalList.prototype.inactivate = function(index) {
this.animals[index].stopAnimation();
this.animals[index].setScale(1);
this.animals[index].setAlpha(AnimalList.ALPHA_INACTIVE);
var animalData = Animal.SPECIES_DATA[index];
this.animals[index].setIconSprite(animalData);
}
AnimalList.prototype.animate = function(index) {
var animalData = Animal.SPECIES_DATA[index];
this.animals[index].startAnimation(animalData);
}
AnimalList.prototype.stopAnimation = function() {
this.animals[this.activeAnimalIndex].stopAnimation();
}
AnimalList.prototype.tweenAnimation = function(animationType) {
this.animals[this.activeAnimalIndex].tweenAnimation(animationType);
}
AnimalList.MARGIN_X = 160;
AnimalList.ALPHA_INACTIVE = 0.1;