59 lines
1.5 KiB
JavaScript
59 lines
1.5 KiB
JavaScript
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);
|
|
|
|
this.activeAnimalIndex = 0;
|
|
|
|
for(var i = 0; i < animalCount; i++) {
|
|
this.animals[i] = new Animal(
|
|
Animal.TYPE_ICON,
|
|
i,
|
|
AnimalList.MARGIN_X + offsetAnimal * i,
|
|
y
|
|
);
|
|
this.inactivate(i);
|
|
}
|
|
|
|
this.activate(this.activeAnimalIndex);
|
|
this.tweenAnimation(Animal.ANIMATION_TYPE_DAMAGE);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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 = 100;
|
|
AnimalList.ALPHA_INACTIVE = 0.1; |