Fix: revise meat code

This commit is contained in:
2019-12-12 10:09:17 +09:00
parent 8dce19a228
commit 8f9e0e6a87
4 changed files with 62 additions and 51 deletions
+4 -4
View File
@@ -14,8 +14,8 @@ function BonusMeat(mainGame) {
BonusMeat.prototype.setBonusMeatTypeVariables = function() {
this.className = BonusMeat.CLASS_NAME;
this.cookingTimeForGradeArray[MeatBase.DONENESS_WELLDONE] = BonusMeat.COOKING_TIME_WELLDONE_MS;
this.cookingTimeForGradeArray[MeatBase.DONENESS_BURN_BLACK] = BonusMeat.COOKING_TIME_BURN_BLACK_MS;
this.cookingTimeForGradeArray[MeatBase.DONENESS_WELLDONE] = BonusMeat.COOKING_TIME_WELLDONE;
this.cookingTimeForGradeArray[MeatBase.DONENESS_BURN_BLACK] = BonusMeat.COOKING_TIME_BURN_BLACK;
this.scoreArray[MeatBase.DONENESS_RARE] = BonusMeat.SCORE_NAME_RARE;
this.scoreArray[MeatBase.DONENESS_WELLDONE] = BonusMeat.SCORE_NAME_WELLDONE;
@@ -35,8 +35,8 @@ BonusMeat.prototype.setBonusMeatSprite = function() {
BonusMeat.CLASS_NAME = "BonusMeat";
BonusMeat.COOKING_TIME_WELLDONE_MS = 500;
BonusMeat.COOKING_TIME_BURN_BLACK_MS = 700;
BonusMeat.COOKING_TIME_WELLDONE = 600;
BonusMeat.COOKING_TIME_BURN_BLACK = 800;
BonusMeat.SCORE_NAME_RARE = 2; // cooking time * 2
BonusMeat.SCORE_NAME_WELLDONE = 4; // cooking time * 4
+31 -22
View File
@@ -82,16 +82,21 @@ var Game = {
this.trashCan = new TrashCan();
// meat
this.bonusMeat = new BonusMeat(this);
this.bonusMeat.setActive(false, -100, -100);
this.bonusMeatIndex = 0;
this.bonusMeatGroup = game.add.group();
for(var i = 0; i < Game.MAX_BONUS_MEAT_COUNT; i++) {
var bonusMeat = new BonusMeat(this);
bonusMeat.setActive(false, -100, -100);
this.bonusMeatGroup.add(bonusMeat);
}
this.meatGroup = game.add.group();
for(var i = 0; i < Game.MAX_MEAT_COUNT; i++) {
this.normalMeatGroup = game.add.group();
for(var i = 0; i < Game.MAX_NORMAL_MEAT_COUNT; i++) {
// var meat = new Meat(this);
var meat = new NormalMeat(this);
meat.name = "meat" + i;
meat.setActive(false, -100, -100);
this.meatGroup.add(meat);
var normalMeat = new NormalMeat(this);
normalMeat.name = "meat" + i;
normalMeat.setActive(false, -100, -100);
this.normalMeatGroup.add(normalMeat);
}
@@ -231,25 +236,28 @@ var Game = {
if(this.badMeatCountPrevStage > 0)
return;
if(this.bonusMeat.isActivate())
return;
var bonusMeat = this.bonusMeatGroup.children[this.bonusMeatIndex];
var randX = this.meatPlate.x - game.rnd.integerInRange(-100, 100);
var randX = this.meatPlate.x - game.rnd.integerInRange(-80, 80);
var randY = this.meatPlate.y - game.rnd.integerInRange(-30, 30);
this.bonusMeat.setActive(true, randX, randY);
bonusMeat.setActive(true, randX, randY);
this.bonusMeatIndex++;
},
serveNormalMeats: function() {
for(var i = 0; i < Game.MAX_MEAT_COUNT; i++) {
var meat = this.meatGroup.children[i];
meat.setActive(false, -100, -100);
for(var i = 0; i < Game.MAX_NORMAL_MEAT_COUNT; i++) {
var normalMeat = this.normalMeatGroup.children[i];
normalMeat.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 normalMeat = this.normalMeatGroup.children[i];
normalMeat.changeRandomMeat();
var randX = this.meatPlate.x - game.rnd.integerInRange(-80, 80);
var randY = this.meatPlate.y - game.rnd.integerInRange(-30, 30);
meat.setActive(true, randX, randY);
normalMeat.setActive(true, randX, randY);
}
},
@@ -353,8 +361,8 @@ var Game = {
}
this.gameTimeEvents = [];
for(var i = 0; i < Game.MAX_MEAT_COUNT; i++) {
this.meatGroup.children[i].hide();
for(var i = 0; i < Game.MAX_NORMAL_MEAT_COUNT; i++) {
this.normalMeatGroup.children[i].hide();
}
game.time.events.add(Phaser.Timer.SECOND * 2, this.goResult, this);
@@ -378,9 +386,10 @@ var Game = {
}
Game.GAME_TIME_SEC = 90;
Game.GAME_TIME_SEC = 90;
Game.MAX_MEAT_COUNT = 20;
Game.MAX_BONUS_MEAT_COUNT = 10;
Game.MAX_NORMAL_MEAT_COUNT = 20;
Game.MEAT_PLATE_POSITION_X = 180;
Game.MEAT_PLATE_POSITION_Y = 390;
+18 -19
View File
@@ -78,8 +78,8 @@ MeatBase.prototype.initScoreArray = function() {
MeatBase.prototype.initCookingTimeForGradeArray = function() {
this.cookingTimeForGradeArray = [];
this.cookingTimeForGradeArray[MeatBase.DONENESS_WELLDONE] = NormalMeat.COOKING_TIME_WELLDONE_MS;
this.cookingTimeForGradeArray[MeatBase.DONENESS_BURN_BLACK] = NormalMeat.COOKING_TIME_BURN_BLACK_MS;
this.cookingTimeForGradeArray[MeatBase.DONENESS_WELLDONE] = NormalMeat.COOKING_TIME_WELLDONE;
this.cookingTimeForGradeArray[MeatBase.DONENESS_BURN_BLACK] = NormalMeat.COOKING_TIME_BURN_BLACK;
}
MeatBase.prototype.initMouseEventHandler = function() {
@@ -180,7 +180,7 @@ MeatBase.prototype.getScore = function() {
return scoreDoneness;
var totalCookingTime = this.getTotalCookingTime();
return scoreDoneness * totalCookingTime;
return Math.floor(scoreDoneness * totalCookingTime);
}
MeatBase.prototype.isFront = function() {
@@ -234,7 +234,7 @@ MeatBase.prototype.hide = function() {
this.stopCook();
}
MeatBase.prototype.isActivate = function() {
MeatBase.prototype.isActive = function() {
return this.isActivated;
}
@@ -301,27 +301,26 @@ MeatBase.prototype.setActive = function(isActivated, x, y) {
}
MeatBase.prototype.cooking = function() {
var side = this.cookingSide;
var burnLevel = this.mainGame.getBurnLevel();
var cookingSpeed = this.cookingSpeedArray[burnLevel];
this.cookingTimeBySide[this.cookingSide] += 1 * cookingSpeed;
this.cookingTimeBySide[side] += 1 * cookingSpeed;
var cookingTimeBurnBlack = this.cookingTimeForGradeArray[MeatBase.DONENESS_BURN_BLACK];
var cookingTimeWelldone = this.cookingTimeForGradeArray[MeatBase.DONENESS_WELLDONE];
if(this.cookingTimeBySide[this.cookingSide] > cookingTimeBurnBlack) {
if(this.getMeatGradeBySide(this.cookingSide) != MeatBase.DONENESS_BURN_BLACK) {
this.cookingGradeBySide[this.cookingSide] = MeatBase.DONENESS_BURN_BLACK;
this.changeAnimateSmokeColor(MeatBase.DONENESS_BURN_BLACK);
}
} else if(this.cookingTimeBySide[this.cookingSide] > cookingTimeWelldone) {
if(this.getMeatGradeBySide(this.cookingSide) != MeatBase.DONENESS_WELLDONE) {
this.cookingGradeBySide[this.cookingSide] = MeatBase.DONENESS_WELLDONE;
this.changeAnimateSmokeColor(MeatBase.DONENESS_WELLDONE);
}
if(this.cookingTimeBySide[side] > cookingTimeBurnBlack) {
if(this.getMeatGradeBySide(side) != MeatBase.DONENESS_BURN_BLACK)
this.setMeatGrade(side, MeatBase.DONENESS_BURN_BLACK);
} else if(this.cookingTimeBySide[side] > cookingTimeWelldone) {
if(this.getMeatGradeBySide(side) != MeatBase.DONENESS_WELLDONE)
this.setMeatGrade(side, MeatBase.DONENESS_WELLDONE);
}
}
MeatBase.prototype.setMeatGrade = function(side, grade) {
this.cookingGradeBySide[side] = grade;
this.changeAnimateSmokeColor(grade);
}
MeatBase.prototype.stopAnimateSmoke = function() {
@@ -371,9 +370,9 @@ MeatBase.DONENESS_WELLDONE = 1;
MeatBase.DONENESS_BURN_BLACK = 2;
MeatBase.DONENESS_NONE = 3;
MeatBase.COOKING_TIME_WELLDONE_MS = 200;
MeatBase.COOKING_TIME_BURN_BLACK_MS = 400;
MeatBase.COOKING_TIME_WELLDONE = 200;
MeatBase.COOKING_TIME_BURN_BLACK = 400;
MeatBase.COOKING_SPEED_BURN_LEVEL_WEAK = 1;
MeatBase.COOKING_SPEED_BURN_LEVEL_NORMAL = 1.5;
MeatBase.COOKING_SPEED_BURN_LEVEL_WEAK = 0.7;
MeatBase.COOKING_SPEED_BURN_LEVEL_NORMAL = 1;
MeatBase.COOKING_SPEED_BURN_LEVEL_STRONG = 2;
+9 -6
View File
@@ -7,22 +7,25 @@ function NormalMeat(mainGame) {
MeatBase.call(this);
this.setNormalMeatTypeVariables();
this.randomizeMeatType();
this.setNormalMeatSprite();
}
NormalMeat.prototype.setNormalMeatTypeVariables = function() {
this.className = NormalMeat.CLASS_NAME;
this.cookingTimeForGradeArray[MeatBase.DONENESS_WELLDONE] = NormalMeat.COOKING_TIME_WELLDONE_MS;
this.cookingTimeForGradeArray[MeatBase.DONENESS_BURN_BLACK] = NormalMeat.COOKING_TIME_BURN_BLACK_MS;
this.cookingTimeForGradeArray[MeatBase.DONENESS_WELLDONE] = NormalMeat.COOKING_TIME_WELLDONE;
this.cookingTimeForGradeArray[MeatBase.DONENESS_BURN_BLACK] = NormalMeat.COOKING_TIME_BURN_BLACK;
this.scoreArray[MeatBase.DONENESS_RARE] = NormalMeat.SCORE_NAME_RARE;
this.scoreArray[MeatBase.DONENESS_WELLDONE] = NormalMeat.SCORE_WELLDONE;
this.scoreArray[MeatBase.DONENESS_BURN_BLACK] = NormalMeat.SCORE_BURN_BLACK;
}
NormalMeat.prototype.changeRandomMeat = function() {
this.randomizeMeatType();
this.setNormalMeatSprite();
}
NormalMeat.prototype.randomizeMeatType = function() {
this.meatType = Math.floor(Math.random() * 3) + 1;
}
@@ -54,8 +57,8 @@ NormalMeat.prototype.setNormalMeatSprite = function() {
NormalMeat.CLASS_NAME = "NormalMeat";
NormalMeat.COOKING_TIME_WELLDONE_MS = 200;
NormalMeat.COOKING_TIME_BURN_BLACK_MS = 400;
NormalMeat.COOKING_TIME_WELLDONE = 300;
NormalMeat.COOKING_TIME_BURN_BLACK = 600;
NormalMeat.SCORE_RARE = 1; // cooking time * 1
NormalMeat.SCORE_WELLDONE = 2; // cooking time * 2