Fix: library path

This commit is contained in:
2018-12-24 10:25:08 +09:00
parent 618bc4453a
commit 1a2dde8a94
30 changed files with 116 additions and 99 deletions
+109
View File
@@ -0,0 +1,109 @@
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 }
];
+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);
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;