Fix: restructing session manager, ES6 -> ES5
This commit is contained in:
+123
-126
@@ -1,150 +1,147 @@
|
||||
class Animal {
|
||||
function Animal(type, x, y) {
|
||||
this.animalType = type;
|
||||
|
||||
constructor(type, x, y) {
|
||||
this.animalType = type;
|
||||
this.sprite = null;
|
||||
this.posX = x;
|
||||
this.posY = y;
|
||||
}
|
||||
|
||||
this.sprite = null;
|
||||
this.posX = x;
|
||||
this.posY = y;
|
||||
}
|
||||
Animal.prototype.loadSpriteNames = function() {
|
||||
let spriteNames = {};
|
||||
|
||||
loadSpriteNames() {
|
||||
let spriteNames = {};
|
||||
spriteNames.icon = this.species.species + Animal.SPRITE_NAMES.icon;
|
||||
|
||||
spriteNames.icon = this.species.species + Animal.SPRITE_NAMES.icon;
|
||||
spriteNames.run1 = this.species.species + Animal.SPRITE_NAMES.run1;
|
||||
spriteNames.run2 = this.species.species + Animal.SPRITE_NAMES.run2;
|
||||
|
||||
spriteNames.run1 = this.species.species + Animal.SPRITE_NAMES.run1;
|
||||
spriteNames.run2 = this.species.species + Animal.SPRITE_NAMES.run2;
|
||||
return spriteNames;
|
||||
}
|
||||
|
||||
return spriteNames;
|
||||
}
|
||||
Animal.prototype.setSpecies = function(species) {
|
||||
this.species = species;
|
||||
|
||||
setSpecies(species) {
|
||||
this.species = species;
|
||||
if(this.animalType === Animal.TYPE_ICON)
|
||||
return;
|
||||
|
||||
if(this.animalType === Animal.TYPE_ICON)
|
||||
return;
|
||||
this.setupAnimation();
|
||||
}
|
||||
|
||||
this.setupAnimation();
|
||||
}
|
||||
Animal.prototype.tweenAnimation = function(animationType) {
|
||||
switch(animationType) {
|
||||
case Animal.ANIMATION_TYPE_CHANGE:
|
||||
this.sprite.width = 200;
|
||||
this.sprite.height = 200;
|
||||
game.add.tween(this.sprite).to( { width: 150, height: 150 }, 500, Phaser.Easing.Bounce.Out, true);
|
||||
break;
|
||||
|
||||
tweenAnimation(animationType) {
|
||||
switch(animationType) {
|
||||
case Animal.ANIMATION_TYPE_CHANGE:
|
||||
this.sprite.width = 200;
|
||||
this.sprite.height = 200;
|
||||
game.add.tween(this.sprite).to( { width: 150, height: 150 }, 500, Phaser.Easing.Bounce.Out, true);
|
||||
break;
|
||||
|
||||
case Animal.ANIMATION_TYPE_DAMAGE:
|
||||
this.sprite.width = 200;
|
||||
game.add.tween(this.sprite).to( { width: 150 }, 500, Phaser.Easing.Bounce.In, true);
|
||||
// game.add.tween(this.sprite).to( { width: 50 }, 500, Phaser.Easing.Elastic.Out, true);
|
||||
break;
|
||||
|
||||
}
|
||||
case Animal.ANIMATION_TYPE_DAMAGE:
|
||||
this.sprite.width = 200;
|
||||
game.add.tween(this.sprite).to( { width: 150 }, 500, Phaser.Easing.Bounce.In, true);
|
||||
// game.add.tween(this.sprite).to( { width: 50 }, 500, Phaser.Easing.Elastic.Out, true);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
setupAnimation() {
|
||||
this.spriteFrameNames = this.loadSpriteNames();
|
||||
this.playingSpriteFrameName = this.spriteFrameNames.run1;
|
||||
this.animationFrameID = 1;
|
||||
this.animationSpeedSec = 1000 / this.species.runningFPS;
|
||||
}
|
||||
|
||||
if(this.sprite === null) {
|
||||
this.sprite = game.add.sprite(this.posX, this.posY, this.spriteFrameNames.run1);
|
||||
this.sprite.anchor.set(0.5);
|
||||
this.sprite.width = 150;
|
||||
this.sprite.height = 150;
|
||||
}
|
||||
Animal.prototype.setupAnimation = function() {
|
||||
this.spriteFrameNames = this.loadSpriteNames();
|
||||
this.playingSpriteFrameName = this.spriteFrameNames.run1;
|
||||
this.animationFrameID = 1;
|
||||
this.animationSpeedSec = 1000 / this.species.runningFPS;
|
||||
|
||||
this.stopAnimation();
|
||||
this.animateionUpdate();
|
||||
if(this.sprite === null) {
|
||||
this.sprite = game.add.sprite(this.posX, this.posY, this.spriteFrameNames.run1);
|
||||
this.sprite.anchor.set(0.5);
|
||||
this.sprite.width = 150;
|
||||
this.sprite.height = 150;
|
||||
}
|
||||
|
||||
startAnimation() {
|
||||
if(this.timerEvent === null)
|
||||
this.timerEvent = game.time.events.loop(this.animationSpeedSec, this.animateionUpdate, this);
|
||||
this.stopAnimation();
|
||||
this.animateionUpdate();
|
||||
}
|
||||
|
||||
Animal.prototype.startAnimation = function() {
|
||||
if(this.timerEvent === null)
|
||||
this.timerEvent = game.time.events.loop(this.animationSpeedSec, this.animateionUpdate, this);
|
||||
}
|
||||
|
||||
Animal.prototype.animateionUpdate = function() {
|
||||
this.animationFrameID = 1 - this.animationFrameID;
|
||||
|
||||
if(this.animationFrameID === 0) {
|
||||
this.sprite.loadTexture(this.spriteFrameNames.run2);
|
||||
} else {
|
||||
this.sprite.loadTexture(this.spriteFrameNames.run1);
|
||||
}
|
||||
}
|
||||
|
||||
Animal.prototype.stopAnimation = function() {
|
||||
if(this.timerEvent !== null) {
|
||||
game.time.events.remove(this.timerEvent);
|
||||
this.timerEvent = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Animal.animalLevelIDByRecord = function(record, gameType) {
|
||||
for(let i = Animal.SPECIES_DATA.length - 1; i > 0; i--) {
|
||||
if(record >= this.typingCount(Animal.SPECIES_DATA[i], gameType))
|
||||
return i;
|
||||
}
|
||||
|
||||
animateionUpdate() {
|
||||
this.animationFrameID = 1 - this.animationFrameID;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(this.animationFrameID === 0) {
|
||||
this.sprite.loadTexture(this.spriteFrameNames.run2);
|
||||
} else {
|
||||
this.sprite.loadTexture(this.spriteFrameNames.run1);
|
||||
}
|
||||
}
|
||||
Animal.typingCount = function(speciesData, gameType) {
|
||||
if(gameType === Animal.TYPE_PRACTICE)
|
||||
return speciesData.practiceTypingCount;
|
||||
else
|
||||
return speciesData.testTypingCount;
|
||||
}
|
||||
|
||||
stopAnimation() {
|
||||
if(this.timerEvent !== null) {
|
||||
game.time.events.remove(this.timerEvent);
|
||||
this.timerEvent = null;
|
||||
}
|
||||
}
|
||||
Animal.loadResources = function() {
|
||||
game.load.image('snail_shadow', '../../../resources/image/character/animal/snail/shadow.png');
|
||||
|
||||
game.load.image('snail_icon', '../../../resources/image/character/animal/snail/run2.png');
|
||||
game.load.image('snail_run1', '../../../resources/image/character/animal/snail/run1.png');
|
||||
game.load.image('snail_run2', '../../../resources/image/character/animal/snail/run2.png');
|
||||
|
||||
static animalLevelIDByRecord(record, gameType) {
|
||||
for(let i = Animal.SPECIES_DATA.length - 1; i > 0; i--) {
|
||||
if(record >= this.typingCount(Animal.SPECIES_DATA[i], gameType))
|
||||
return i;
|
||||
}
|
||||
game.load.image('turtle_icon', '../../../resources/image/character/animal/turtle/run2.png');
|
||||
game.load.image('turtle_run1', '../../../resources/image/character/animal/turtle/run1.png');
|
||||
game.load.image('turtle_run2', '../../../resources/image/character/animal/turtle/run2.png');
|
||||
|
||||
return 0;
|
||||
}
|
||||
game.load.image('cat_icon', '../../../resources/image/character/animal/cat/run2.png');
|
||||
game.load.image('cat_run1', '../../../resources/image/character/animal/cat/run1.png');
|
||||
game.load.image('cat_run2', '../../../resources/image/character/animal/cat/run2.png');
|
||||
|
||||
static typingCount(speciesData, gameType) {
|
||||
if(gameType === Animal.TYPE_PRACTICE)
|
||||
return speciesData.practiceTypingCount;
|
||||
else
|
||||
return speciesData.testTypingCount;
|
||||
}
|
||||
game.load.image('lion_icon', '../../../resources/image/character/animal/lion/run2.png');
|
||||
game.load.image('lion_run1', '../../../resources/image/character/animal/lion/run1.png');
|
||||
game.load.image('lion_run2', '../../../resources/image/character/animal/lion/run2.png');
|
||||
|
||||
static loadResources() {
|
||||
game.load.image('snail_shadow', '../../../resources/image/character/animal/snail/shadow.png');
|
||||
game.load.image('rabbit_icon', '../../../resources/image/character/animal/rabbit/run2.png');
|
||||
game.load.image('rabbit_run1', '../../../resources/image/character/animal/rabbit/run1.png');
|
||||
game.load.image('rabbit_run2', '../../../resources/image/character/animal/rabbit/run2.png');
|
||||
|
||||
game.load.image('snail_icon', '../../../resources/image/character/animal/snail/run2.png');
|
||||
game.load.image('snail_run1', '../../../resources/image/character/animal/snail/run1.png');
|
||||
game.load.image('snail_run2', '../../../resources/image/character/animal/snail/run2.png');
|
||||
game.load.image('ostrich_icon', '../../../resources/image/character/animal/ostrich/run2.png');
|
||||
game.load.image('ostrich_run1', '../../../resources/image/character/animal/ostrich/run1.png');
|
||||
game.load.image('ostrich_run2', '../../../resources/image/character/animal/ostrich/run2.png');
|
||||
|
||||
game.load.image('turtle_icon', '../../../resources/image/character/animal/turtle/run2.png');
|
||||
game.load.image('turtle_run1', '../../../resources/image/character/animal/turtle/run1.png');
|
||||
game.load.image('turtle_run2', '../../../resources/image/character/animal/turtle/run2.png');
|
||||
game.load.image('horse_icon', '../../../resources/image/character/animal/horse/run2.png');
|
||||
game.load.image('horse_run1', '../../../resources/image/character/animal/horse/run1.png');
|
||||
game.load.image('horse_run2', '../../../resources/image/character/animal/horse/run2.png');
|
||||
|
||||
game.load.image('cat_icon', '../../../resources/image/character/animal/cat/run2.png');
|
||||
game.load.image('cat_run1', '../../../resources/image/character/animal/cat/run1.png');
|
||||
game.load.image('cat_run2', '../../../resources/image/character/animal/cat/run2.png');
|
||||
game.load.image('dog_icon', '../../../resources/image/character/animal/dog/run2.png');
|
||||
game.load.image('dog_run1', '../../../resources/image/character/animal/dog/run1.png');
|
||||
game.load.image('dog_run2', '../../../resources/image/character/animal/dog/run2.png');
|
||||
|
||||
game.load.image('lion_icon', '../../../resources/image/character/animal/lion/run2.png');
|
||||
game.load.image('lion_run1', '../../../resources/image/character/animal/lion/run1.png');
|
||||
game.load.image('lion_run2', '../../../resources/image/character/animal/lion/run2.png');
|
||||
game.load.image('cheetah_icon', '../../../resources/image/character/animal/cheetah/run2.png');
|
||||
game.load.image('cheetah_run1', '../../../resources/image/character/animal/cheetah/run1.png');
|
||||
game.load.image('cheetah_run2', '../../../resources/image/character/animal/cheetah/run2.png');
|
||||
|
||||
game.load.image('rabbit_icon', '../../../resources/image/character/animal/rabbit/run2.png');
|
||||
game.load.image('rabbit_run1', '../../../resources/image/character/animal/rabbit/run1.png');
|
||||
game.load.image('rabbit_run2', '../../../resources/image/character/animal/rabbit/run2.png');
|
||||
|
||||
game.load.image('ostrich_icon', '../../../resources/image/character/animal/ostrich/run2.png');
|
||||
game.load.image('ostrich_run1', '../../../resources/image/character/animal/ostrich/run1.png');
|
||||
game.load.image('ostrich_run2', '../../../resources/image/character/animal/ostrich/run2.png');
|
||||
|
||||
game.load.image('horse_icon', '../../../resources/image/character/animal/horse/run2.png');
|
||||
game.load.image('horse_run1', '../../../resources/image/character/animal/horse/run1.png');
|
||||
game.load.image('horse_run2', '../../../resources/image/character/animal/horse/run2.png');
|
||||
|
||||
game.load.image('dog_icon', '../../../resources/image/character/animal/dog/run2.png');
|
||||
game.load.image('dog_run1', '../../../resources/image/character/animal/dog/run1.png');
|
||||
game.load.image('dog_run2', '../../../resources/image/character/animal/dog/run2.png');
|
||||
|
||||
game.load.image('cheetah_icon', '../../../resources/image/character/animal/cheetah/run2.png');
|
||||
game.load.image('cheetah_run1', '../../../resources/image/character/animal/cheetah/run1.png');
|
||||
game.load.image('cheetah_run2', '../../../resources/image/character/animal/cheetah/run2.png');
|
||||
|
||||
game.load.image('eagle_icon', '../../../resources/image/character/animal/eagle/run2.png');
|
||||
game.load.image('eagle_run1', '../../../resources/image/character/animal/eagle/run1.png');
|
||||
game.load.image('eagle_run2', '../../../resources/image/character/animal/eagle/run2.png');
|
||||
}
|
||||
game.load.image('eagle_icon', '../../../resources/image/character/animal/eagle/run2.png');
|
||||
game.load.image('eagle_run1', '../../../resources/image/character/animal/eagle/run1.png');
|
||||
game.load.image('eagle_run2', '../../../resources/image/character/animal/eagle/run2.png');
|
||||
}
|
||||
|
||||
|
||||
@@ -159,16 +156,16 @@ Animal.ANIMATION_TYPE_DAMAGE = 1;
|
||||
|
||||
|
||||
Animal.SPECIES_DATA = [
|
||||
{ "species" : "snail", "runningFPS" : 1.1, "practiceTypingCount" : 0, "testTypingCount" : 0 },
|
||||
{ "species" : "turtle", "runningFPS" : 2.2, "practiceTypingCount" : 5, "testTypingCount" : 20 },
|
||||
{ "species" : "cat", "runningFPS" : 3.3, "practiceTypingCount" : 10, "testTypingCount" : 50 },
|
||||
{ "species" : "lion", "runningFPS" : 4.4, "practiceTypingCount" : 15, "testTypingCount" : 100 },
|
||||
{ "species" : "rabbit", "runningFPS" : 5.5, "practiceTypingCount" : 20, "testTypingCount" : 200 },
|
||||
{ "species" : "ostrich", "runningFPS" : 7.7, "practiceTypingCount" : 25, "testTypingCount" : 300 },
|
||||
{ "species" : "horse", "runningFPS" : 9.9, "practiceTypingCount" : 30, "testTypingCount" : 400 },
|
||||
{ "species" : "dog", "runningFPS" : 12.2, "practiceTypingCount" : 35, "testTypingCount" : 500 },
|
||||
{ "species" : "cheetah", "runningFPS" : 16, "practiceTypingCount" : 40, "testTypingCount" : 600 },
|
||||
{ "species" : "eagle", "runningFPS" : 20, "practiceTypingCount" : 50, "testTypingCount" : 700 }
|
||||
{ "species" : "snail", "runningFPS" : 1.1, "practiceTypingCount" : 0, "testTypingCount" : 0 },
|
||||
{ "species" : "turtle", "runningFPS" : 2.2, "practiceTypingCount" : 5, "testTypingCount" : 20 },
|
||||
{ "species" : "cat", "runningFPS" : 3.3, "practiceTypingCount" : 10, "testTypingCount" : 50 },
|
||||
{ "species" : "lion", "runningFPS" : 4.4, "practiceTypingCount" : 15, "testTypingCount" : 100 },
|
||||
{ "species" : "rabbit", "runningFPS" : 5.5, "practiceTypingCount" : 20, "testTypingCount" : 200 },
|
||||
{ "species" : "ostrich", "runningFPS" : 7.7, "practiceTypingCount" : 25, "testTypingCount" : 300 },
|
||||
{ "species" : "horse", "runningFPS" : 9.9, "practiceTypingCount" : 30, "testTypingCount" : 400 },
|
||||
{ "species" : "dog", "runningFPS" : 12.2, "practiceTypingCount" : 35, "testTypingCount" : 500 },
|
||||
{ "species" : "cheetah", "runningFPS" : 16, "practiceTypingCount" : 40, "testTypingCount" : 600 },
|
||||
{ "species" : "eagle", "runningFPS" : 20, "practiceTypingCount" : 50, "testTypingCount" : 700 }
|
||||
];
|
||||
|
||||
Animal.SPRITE_NAMES = {
|
||||
|
||||
Reference in New Issue
Block a user