Fix: refactoring source codes

This commit is contained in:
2019-12-11 10:04:06 +09:00
parent 0ee3ce04f9
commit c7fb4aca9b
7 changed files with 80 additions and 115 deletions
+18 -95
View File
@@ -74,7 +74,7 @@ var Game = {
this.meatPlate.smoothed = false;
this.heatPlate = new HeatPlate();
this.stoveDial = new StoveDial(80, Game.HEAT_PLATE_POSITION_Y + 70);
this.stoveDial = new StoveDial(80, HeatPlate.POSITION_Y + 70);
this.stoveDial.setOnChangeDialLevelHandler(
(function(dialLevel) { this.onChangeDialLevel(dialLevel); }).bind(this)
);
@@ -83,14 +83,14 @@ var Game = {
// meat
this.bonusMeat = new BonusMeat(this);
this.bonusMeat.setActive(false, -100, -100, "");
this.bonusMeat.setActive(false, -100, -100);
this.meatGroup = game.add.group();
for(var i = 0; i < Game.MAX_MEAT_COUNT; i++) {
// var meat = new Meat(this);
var meat = new NormalMeat(this);
meat.name = "meat" + i;
meat.setActive(false, -100, -100, "");
meat.setActive(false, -100, -100);
this.meatGroup.add(meat);
}
@@ -186,20 +186,21 @@ var Game = {
startGame: function() {
this.playingStageNo = 1;
this.clearedMeatCount = 0;
this.badMeatCount = 0;
this.startStage();
// this.stageTimer.start();
this.realtimeStageTimer.start();
},
startStage: function() {
this.clearedMeatCount = 0;
this.badMeatCount = 0;
console.log("badMeatCount : " + this.badMeatCount);
this.activatedMeatCount = this.getStageMeatCount();
this.serveBonusMeat();
this.serveNormalMeats();
this.serveBonusMeat();
this.badMeatCount = 0;
if(this.playingStageNo > 1)
this.waiter.animateServing();
},
@@ -225,74 +226,31 @@ var Game = {
var randX = this.meatPlate.x - game.rnd.integerInRange(-100, 100);
var randY = this.meatPlate.y - game.rnd.integerInRange(-30, 30);
this.bonusMeat.setActive(true, randX, randY, "");
this.bonusMeat.setActive(true, randX, randY);
},
serveNormalMeats: function() {
for(var i = 0; i < Game.MAX_MEAT_COUNT; i++) {
var meat = this.meatGroup.children[i];
meat.setActive(false, -100, -100, "");
meat.setActive(false, -100, -100);
}
for(var i = 0; i < this.activatedMeatCount; i++) {
var meat = this.meatGroup.children[i];
var randX = this.meatPlate.x - game.rnd.integerInRange(-100, 100);
var randY = this.meatPlate.y - game.rnd.integerInRange(-30, 30);
meat.setActive(true, randX, randY, "");
meat.setActive(true, randX, randY);
}
},
getScore: function() {
return this.playingStageNo * 10;
},
getBonusTime: function() {
if(this.badMeatCount > 0)
return 0;
if(this.playingStageNo == 1)
return 5;
else if(this.playingStageNo == 2)
return 7;
else
return 6 + this.playingStageNo;
},
isOverHeatPlate: function(x, y, width, height) {
var plateHalfWidth = (this.heatPlate.width - Game.HEAT_PLATE_HANDLE_WIDTH) / 2;
var plateHalfHeight = this.heatPlate.height / 2;
if(x < this.heatPlate.x - plateHalfWidth) {
return false;
} else if(this.heatPlate.x + plateHalfWidth < x) {
return false;
} else if(y < this.heatPlate.y - plateHalfHeight + Game.HEAT_PLATE_START_OFFSET_Y) {
return false;
} else if(this.heatPlate.y + plateHalfHeight + Game.HEAT_PLATE_START_OFFSET_Y - Game.HEAT_PLATE_HEIGHT< y) {
return false;
}
return true;
isOverHeatPlate: function(x, y) {
return this.heatPlate.isOver(x, y);
},
isOverGod: function(x, y) {
// console.log("isOverGod : " + x + ", " + y + ", " + width + ", " + height);
var godHalfWidth = (this.god.width - Game.GOD_OUT_OF_FACE_WIDTH) / 2;
var godHalfHeight = this.god.height / 2;
if(x < this.god.x - godHalfWidth) {
return false;
} else if(this.god.x + godHalfWidth < x) {
return false;
} else if(y < this.god.y - this.god.height + Game.GOD_OUT_OF_FACE_HEIGHT) {
return false;
} else if(this.god.y - Game.GOD_OUT_OF_FACE_HEIGHT < y) {
return false;
}
return true;
return this.god.isOver(x, y);
},
godEatMeat: function(meat) {
@@ -308,11 +266,9 @@ var Game = {
this.plusScoreGroup.add(tempPlusScore);
} else if(meat.getMeatGrade() == MeatBase.DONENESS_RARE) {
this.badMeatCount++;
console.log("badMeatCount : " + this.badMeatCount);
this.god.animateAngryWithRare(meat);
// var score = this.getScore();
if(meat.getTotalCookingTime() > 0) {
var score = meat.getScore();
this.scoreManager.plusScore(score);
@@ -322,14 +278,13 @@ var Game = {
}
} else { // meat is burn black
this.badMeatCount++;
console.log("badMeatCount : " + this.badMeatCount);
this.god.animateAngryWithBurnBlack(meat);
return; // god doesn't eat burned black meat
}
meat.setActive(false, -100, -100, '');
meat.setActive(false, -100, -100);
if(meatClassName == NormalMeat.CLASS_NAME) {
this.clearedMeatCount++;
@@ -340,20 +295,7 @@ var Game = {
},
isOverTrashCan: function(x, y) {
var trashCanHalfWidth = this.trashCan.width / 2;
var trashCanHalfHeight = this.trashCan.height;
if(x < this.trashCan.x - trashCanHalfWidth) {
return false;
} else if(this.trashCan.x + trashCanHalfWidth < x) {
return false;
} else if(y < this.trashCan.y - this.trashCan.height) {
return false;
} else if(this.trashCan.y < y) {
return false;
}
return true;
return this.trashCan.isOver(x, y);
},
throwAway: function(meat) {
@@ -361,10 +303,9 @@ var Game = {
return;
this.badMeatCount++;
console.log("badMeatCount : " + this.badMeatCount);
this.trashCan.animateAngry();
meat.setActive(false, -100, -100, '');
meat.setActive(false, -100, -100);
var score = meat.getScore();
this.scoreManager.plusScore(score);
@@ -381,8 +322,6 @@ var Game = {
},
clearStage: function() {
// this.stageTimer.addBonusTime(this.getBonusTime());
this.playingStageNo++;
var startStageTimeEvent = game.time.events.add(Phaser.Timer.SECOND * 1, this.startStage, this);
@@ -391,12 +330,6 @@ var Game = {
animateTextAlpha: function(targetText, startAlpha, endAlpha, msTime, effectType) {
targetText.alpha = startAlpha;
game.add.tween(targetText).to({alpha: endAlpha}, msTime, effectType, true);
},
timeOver: function() {
var timeOverText = new TimeOverText();
if(!isExperienceMaestroAccount())
@@ -436,18 +369,8 @@ var Game = {
Game.GAME_TIME_SEC = 90;
Game.NEXT_STAGE_DELAY_MS = 500;
Game.MAX_MEAT_COUNT = 20;
Game.HEAT_PLATE_HANDLE_WIDTH = 440;
Game.HEAT_PLATE_START_OFFSET_Y = 80;
Game.HEAT_PLATE_HEIGHT = 220;
Game.GOD_OUT_OF_FACE_WIDTH = 30;
Game.GOD_OUT_OF_FACE_HEIGHT = 30;
Game.MEAT_PLATE_POSITION_X = 180;
Game.MEAT_PLATE_POSITION_Y = 390;
Game.HEAT_PLATE_POSITION_Y = GAME_SCREEN_SIZE.y / 2 + 200;
Game.MEAT_PLATE_POSITION_Y = 390;