Add: AnimalRecordList for main menu

This commit is contained in:
2019-08-05 21:53:47 +09:00
parent a4767fee13
commit f04bf286d9
3 changed files with 160 additions and 76 deletions
+129
View File
@@ -0,0 +1,129 @@
function AnimalRecordList(type) {
this.type = type;
this.animals = [];
this.activeAnimalIndex = -1;
var animalCount = Animal.SPECIES_DATA.length;
var lineWidth = GAME_SCREEN_SIZE.x - AnimalRecordList.MARGIN_X * 2;
// console.log("lineWidth : " + lineWidth);
var offsetAnimal = lineWidth / (animalCount - 1);
// console.log("animalCount : " + animalCount);
// console.log("offsetAnimal : " + offsetAnimal);
this.activeAnimalIndex = 0;
var bgColor = AnimalRecordList.COLOR_BG;
var posY = AnimalRecordList.ANIMAL_LIST_POS_Y;
if(this.type === AnimalRecordList.TYPE_MENU) {
bgColor = MainColor.LIGHT_CHOCO_HEX;
posY = AnimalRecordList.ANIMAL_LIST_MENU_POS_Y;
}
game.add.graphics()
.beginFill(bgColor, 1)
.drawRect(
0, posY,
game.world.width, 80
);
for(var i = 0; i < animalCount; i++) {
this.animals[i] = new Animal(
Animal.TYPE_ICON,
i,
AnimalRecordList.MARGIN_X + offsetAnimal * i,
posY + AnimalRecordList.ANIMAL_OFFSET_Y
);
// this.inactivate(i);
}
// this.activate(this.activeAnimalIndex);
// this.tweenAnimation(Animal.ANIMATION_TYPE_DAMAGE);
}
AnimalRecordList.prototype.printScore = function(type) {
var animalCount = Animal.SPECIES_DATA.length;
var lineWidth = GAME_SCREEN_SIZE.x - AnimalRecordList.MARGIN_X * 2;
// console.log("lineWidth : " + lineWidth);
var offsetAnimal = lineWidth / (animalCount - 1);
var titleTextStyle = { font: "16px Arial", fill: "#fff", align: "center"};
var typingCount = 0;
var animalData = null;
var posY = AnimalRecordList.ANIMAL_LIST_POS_Y + AnimalRecordList.RECORD_TEXT_OFFSET_Y;
if(this.type === AnimalRecordList.TYPE_MENU)
posY = AnimalRecordList.ANIMAL_LIST_MENU_POS_Y + AnimalRecordList.RECORD_TEXT_MENU_OFFSET_Y;
for(var i = 0; i < animalCount; i++) {
animalData = Animal.SPECIES_DATA[i];
if(type == AnimalRecordList.TYPE_PRACTICE)
typingCount = RecordUtil.getRecordValueWithUnit(animalData.practiceTypingCount, 1);
else
typingCount = RecordUtil.getRecordValueWithUnit(animalData.testTypingCount, 1);
var recordText = game.add.text(
AnimalRecordList.MARGIN_X + offsetAnimal * i,
posY,
typingCount, titleTextStyle
);
recordText.anchor.set(0.5);
if(this.type === AnimalRecordList.TYPE_MENU)
recordText.addColor(MainColor.LIGHTER_CHOCO_STRING, 0);
else
recordText.addColor(AnimalRecordList.COLOR_SCORE_DEFAULT_TEXT, 0);
recordText.stroke = "#333";
recordText.strokeThickness = 3;
recordText.setShadow(1, 1, 'rgba(0, 0, 0, 0.5)', 2);
}
}
AnimalRecordList.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);
}
AnimalRecordList.prototype.inactivate = function(index) {
this.animals[index].stopAnimation();
this.animals[index].setScale(1);
this.animals[index].setAlpha(AnimalRecordList.ALPHA_INACTIVE);
}
AnimalRecordList.prototype.animate = function(index) {
var animalData = Animal.SPECIES_DATA[index];
this.animals[index].startAnimation(animalData);
}
AnimalRecordList.prototype.stopAnimation = function() {
this.animals[this.activeAnimalIndex].stopAnimation();
}
AnimalRecordList.prototype.tweenAnimation = function(animationType) {
this.animals[this.activeAnimalIndex].tweenAnimation(animationType);
}
AnimalRecordList.POS_Y = 800;
AnimalRecordList.MARGIN_X = 100;
AnimalRecordList.ANIMAL_LIST_POS_Y = 90;
AnimalRecordList.RECORD_TEXT_OFFSET_Y = 36;
AnimalRecordList.ALPHA_INACTIVE = 0.3;
AnimalRecordList.TYPE_MENU = 0;
AnimalRecordList.TYPE_PRACTICE = 1;
AnimalRecordList.TYPE_TEST = 2;
AnimalRecordList.ANIMAL_LIST_MENU_POS_Y = 640;
AnimalRecordList.ANIMAL_OFFSET_Y = 30;
AnimalRecordList.RECORD_TEXT_MENU_OFFSET_Y = 70;
AnimalRecordList.COLOR_BG = MainColor.CHOCO_HEX; // 0x77aadd; //0x99ccff;
AnimalRecordList.COLOR_SCORE_DEFAULT_TEXT = MainColor.LIGHTER_CHOCO_STRING; // "#bbddff";
AnimalRecordList.COLOR_SCORE_CLEARED_TEXT = "#ffffff";