Add: meat classes

This commit is contained in:
2019-12-09 11:10:33 +09:00
parent 1dc49cfb94
commit 36298d7621
7 changed files with 439 additions and 13 deletions
+37
View File
@@ -0,0 +1,37 @@
BonusMeat.prototype = MeatBase.prototype;
BonusMeat.constructor = BonusMeat;
function BonusMeat() {
MeatBase.call(this);
this.loadTexture("bonus_meat");
this.setMeatTypeVariables()
}
BonusMeat.prototype.setMeatTypeVariables = function() {
this.cookingSpeed = BonusMeat.COOKING_SPEED_BURN_LEVEL_WEAK;
this.loadTexture('meat_burn1');
} else if(this.getMeatGradeBySide(Meat.MEAT_FRONT) == Meat.DONENESS_WELLDONE) {
this.loadTexture('meat_welldone1');
} else {
this.loadTexture('meat1');
this.spriteMeatBurnBlack =
}
BonusMeat.COOKING_SPEED_BURN_LEVEL_WEAK = 0.1;
BonusMeat.COOKING_SPEED_BURN_LEVEL_NORMAL = 0.2;
BonusMeat.COOKING_SPEED_BURN_LEVEL_STRONG = 0.3;
BonusMeat.SCORE_NAME_RARE = 10;
BonusMeat.SCORE_NAME_WELLDONE = 100;
BonusMeat.SCORE_NAME_BURN_BLACK = 0;
BonusMeat.SPRITE_NAME_RARE = "bonus_meat";
BonusMeat.SPRITE_NAME_WELLDONE = "bonus_meat_welldone";
BonusMeat.SPRITE_NAME_BURN_BLACK = "bonus_meat_burn";
+4
View File
@@ -86,6 +86,10 @@ var Game = {
this.meatGroup.add(meat); this.meatGroup.add(meat);
} }
this.normalMeat = new NormalMeat();
// this.meatBase = new MeatBase();
// speech bubble // speech bubble
this.speechBubble = new SpeechBubble(game.world.centerX + 100, game.world.centerY - 160); this.speechBubble = new SpeechBubble(game.world.centerX + 100, game.world.centerY - 160);
this.speechBubble.hideSpeechBubble(); this.speechBubble.hideSpeechBubble();
+9 -9
View File
@@ -44,15 +44,15 @@ var Loading = {
game.load.image('meat1', '../../../resources/image/object/grilled_meat/meat1.png'); game.load.image('meat1', '../../../resources/image/object/grilled_meat/meat1.png');
game.load.image('meat2', '../../../resources/image/object/grilled_meat/meat2.png'); game.load.image('meat2', '../../../resources/image/object/grilled_meat/meat2.png');
game.load.image('meat3', '../../../resources/image/object/grilled_meat/meat3.png'); game.load.image('meat3', '../../../resources/image/object/grilled_meat/meat3.png');
game.load.image('meatBonus', '../../../resources/image/object/grilled_meat/meat_bonus.png'); game.load.image('bonus_meat', '../../../resources/image/object/grilled_meat/meat_bonus.png');
game.load.image('meatWellDone1', '../../../resources/image/object/grilled_meat/meat1_welldone.png'); game.load.image('meat_welldone1', '../../../resources/image/object/grilled_meat/meat1_welldone.png');
game.load.image('meatWellDone2', '../../../resources/image/object/grilled_meat/meat2_welldone.png'); game.load.image('meat_welldone2', '../../../resources/image/object/grilled_meat/meat2_welldone.png');
game.load.image('meatWellDone3', '../../../resources/image/object/grilled_meat/meat3_welldone.png'); game.load.image('meat_welldone3', '../../../resources/image/object/grilled_meat/meat3_welldone.png');
game.load.image('meatBonusWellDone', '../../../resources/image/object/grilled_meat/meat_bonus_welldone.png'); game.load.image('bonus_meat_welldone', '../../../resources/image/object/grilled_meat/meat_bonus_welldone.png');
game.load.image('meatBurn1', '../../../resources/image/object/grilled_meat/meat1_burn.png'); game.load.image('meat_burn1', '../../../resources/image/object/grilled_meat/meat1_burn.png');
game.load.image('meatBurn2', '../../../resources/image/object/grilled_meat/meat2_burn.png'); game.load.image('meat_burn2', '../../../resources/image/object/grilled_meat/meat2_burn.png');
game.load.image('meatBurn3', '../../../resources/image/object/grilled_meat/meat3_burn.png'); game.load.image('meat_burn3', '../../../resources/image/object/grilled_meat/meat3_burn.png');
game.load.image('meatBonusBurn', '../../../resources/image/object/grilled_meat/meat_bonus_burn.png'); game.load.image('bonus_meat_burn', '../../../resources/image/object/grilled_meat/meat_bonus_burn.png');
game.load.image('smoke', '../../../resources/image/ui/smoke.png'); game.load.image('smoke', '../../../resources/image/ui/smoke.png');
+4 -4
View File
@@ -170,9 +170,9 @@ Meat.prototype.flipToFront = function() {
// console.log("flipToFront"); // console.log("flipToFront");
// console.log("back : " + this.getMeatGradeBySide(Meat.MEAT_BACK) + ", front : " + this.getMeatGradeBySide(Meat.MEAT_FRONT)); // console.log("back : " + this.getMeatGradeBySide(Meat.MEAT_BACK) + ", front : " + this.getMeatGradeBySide(Meat.MEAT_FRONT));
if(this.getMeatGradeBySide(Meat.MEAT_FRONT) == Meat.DONENESS_BURN_BLACK) { if(this.getMeatGradeBySide(Meat.MEAT_FRONT) == Meat.DONENESS_BURN_BLACK) {
this.loadTexture('meatBurn1'); this.loadTexture('meat_burn1');
} else if(this.getMeatGradeBySide(Meat.MEAT_FRONT) == Meat.DONENESS_WELLDONE) { } else if(this.getMeatGradeBySide(Meat.MEAT_FRONT) == Meat.DONENESS_WELLDONE) {
this.loadTexture('meatWellDone1'); this.loadTexture('meat_welldone1');
} else { } else {
this.loadTexture('meat1'); this.loadTexture('meat1');
} }
@@ -186,9 +186,9 @@ Meat.prototype.flipToBack = function() {
// console.log("flipToBack"); // console.log("flipToBack");
// console.log("back : " + this.getMeatGradeBySide(Meat.MEAT_BACK) + ", front : " + this.getMeatGradeBySide(Meat.MEAT_FRONT)); // console.log("back : " + this.getMeatGradeBySide(Meat.MEAT_BACK) + ", front : " + this.getMeatGradeBySide(Meat.MEAT_FRONT));
if(this.getMeatGradeBySide(Meat.MEAT_BACK) == Meat.DONENESS_BURN_BLACK) { if(this.getMeatGradeBySide(Meat.MEAT_BACK) == Meat.DONENESS_BURN_BLACK) {
this.loadTexture('meatBurn1'); this.loadTexture('meat_burn1');
} else if(this.getMeatGradeBySide(Meat.MEAT_BACK) == Meat.DONENESS_WELLDONE) { } else if(this.getMeatGradeBySide(Meat.MEAT_BACK) == Meat.DONENESS_WELLDONE) {
this.loadTexture('meatWellDone1'); this.loadTexture('meat_welldone1');
} else { } else {
this.loadTexture('meat1'); this.loadTexture('meat1');
} }
+331
View File
@@ -0,0 +1,331 @@
MeatBase.prototype = Object.create(Phaser.Sprite.prototype);
MeatBase.constructor = MeatBase;
function MeatBase() {
Phaser.Sprite.call(this, game, 500, Game.MEAT_PLATE_POSITION_Y, '');
this.anchor.set(0.5);
this.smoothed = false;
game.add.existing(this);
this.initMeatTypeVariables();
this.initMouseEventHandler();
}
MeatBase.prototype.update = function() {
var posY = this.y;
if(posY <= God.POSITION_Y) {
this.scale.set(0.4);
} else if(posY > God.POSITION_Y && posY < HeatPlate.POSITION_Y) {
var scaleRate = (posY - God.POSITION_Y) / (HeatPlate.POSITION_Y - God.POSITION_Y);
this.scale.set(0.4 + 0.3 * scaleRate);
} else {
this.scale.set(0.4 + 0.3);
}
// if(this.isOnHeatPlate == true && game.input.mousePointer.isUp == true) {
// this.cooking();
// }
}
MeatBase.prototype.initMeatTypeVariables = function() {
this.cookingSpeed = 0.0;
this.rareScore = 0;
this.welldoneScore = 0;
this.burnBlackScore = 0;
}
MeatBase.prototype.initMeatTypeVariables = function() {
this.cookingSide = MeatBase.MEAT_NONE;
this.cookingTime = [];
this.cookingGrade = [];
this.cookingTime[MeatBase.MEAT_BACK] = 0;
this.cookingTime[MeatBase.MEAT_FRONT] = 0;
this.cookingGrade[MeatBase.MEAT_BACK] = MeatBase.DONENESS_RARE;
this.cookingGrade[MeatBase.MEAT_FRONT] = MeatBase.DONENESS_RARE;
this.isActivated = true;
this.isStartCook = false;
this.isOnHeatPlate = false;
this.spriteNameRare = "";
this.spriteNameWelldone = "";
this.spriteNameBurnBlack = "";
}
MeatBase.prototype.initMouseEventHandler = function() {
this.downPositionX;
this.downPositionY;
this.inputEnabled = true;
this.input.enableDrag();
this.events.onInputDown.add(this.onInputDown, this);
this.events.onInputUp.add(this.onInputUp, this);
}
MeatBase.prototype.onInputDown = function(sprite, pointer) {
// console.log("-------------------------");
// console.log("onInputDown : " + pointer.x + ", " + pointer.y);
this.downPositionX = Math.floor(sprite.x);
this.downPositionY = Math.floor(sprite.y);
// this.stopCook();
}
MeatBase.prototype.onInputUp = function(sprite, pointer) {
// console.log("-------------------------");
// console.log("onInputUp : " + pointer.x + ", " + pointer.y);
var upPositionX = Math.floor(sprite.x);
var upPositionY = Math.floor(sprite.y);
// console.log("downPositionX : + " + this.downPositionX + ", downPositY : " + this.downPositionY);
// console.log("upPositionX : + " + upPositionX + ", upPositionY : " + upPositionY);
if(this.isInClickArea(this.downPositionX, this.downPositionY, upPositionX, upPositionY) == true)
this.onClickListener();
else {
this.onDragStopListener();
}
}
MeatBase.prototype.isInClickArea = function(downX, downY, upX, upY) {
if(downX - 5 < upX && upX < downX + 5 && downY - 5 < upY && upY < downY + 5)
return true;
return false;
}
MeatBase.prototype.onClickListener = function(pointer) {
console.log("onClickListener");
if(this.isFront() == true)
this.flipToBack()
else
this.flipToFront();
// console.log("flip cooking side : " + this.cookingSide);
/*
if(this.mainGame.isOverHeatPlate(this.x, this.y, this.width, this.height) == true) {
if(this.isFront() == true)
this.flipToBack()
else
this.flipToFront();
// console.log("flip cooking side : " + this.cookingSide);
this.startCook();
}
*/
}
MeatBase.prototype.onDragStopListener = function(pointer) {
console.log("onDragStop");
/*
if(this.mainGame.isOverHeatPlate(this.x, this.y, this.width, this.height) == true) {
// console.log("isOverHeatPlate : " + isOverHeatPlate(this.x, this.y, this.width, this.height));
this.startCook();
} else {
this.stopCook();
}
if(this.mainGame.isOverGod(this.x, this.y) == true) {
// console.log("isOverGod : " + isOverGod(this.x, this.y));
this.mainGame.godEatMeat(this);
}
*/
}
MeatBase.prototype.isFront = function() {
if(this.cookingSide == MeatBase.MEAT_BACK)
return true;
return false;
}
MeatBase.prototype.flipToFront = function() {
this.cookingSide = MeatBase.MEAT_BACK;
// console.log("flipToFront : " + this.cookingSide);
this.angle = MeatBase.ANGLE_FRONT;
// console.log("flipToFront");
// console.log("back : " + this.getMeatGradeBySide(MeatBase.MEAT_BACK) + ", front : " + this.getMeatGradeBySide(MeatBase.MEAT_FRONT));
this.updateSprite();
}
MeatBase.prototype.flipToBack = function() {
this.cookingSide = MeatBase.MEAT_FRONT;
// console.log("flipToBack : " + this.cookingSide);
this.angle = MeatBase.ANGLE_BACK;
// console.log("flipToBack");
// console.log("back : " + this.getMeatGradeBySide(MeatBase.MEAT_BACK) + ", front : " + this.getMeatGradeBySide(MeatBase.MEAT_FRONT));
this.updateSprite();
}
MeatBase.prototype.updateSprite = function() {
if(this.getMeatGradeBySide(MeatBase.MEAT_FRONT) == MeatBase.DONENESS_BURN_BLACK) {
this.loadTexture(this.spriteNameBurnBlack);
} else if(this.getMeatGradeBySide(MeatBase.MEAT_FRONT) == MeatBase.DONENESS_WELLDONE) {
this.loadTexture(this.spriteNameWelldone);
} else {
this.loadTexture(this.spriteNameRare);
}
}
MeatBase.prototype.show = function() {
this.isActivated = true;
this.alpha = 1;
}
MeatBase.prototype.hide = function() {
this.isActivated = false;
this.alpha = 0;
this.stopCook();
}
MeatBase.prototype.startCook = function() {
this.isStartCook = true;
this.isOnHeatPlate = true;
// console.log("this.isOnHeatPlate : " + this.isOnHeatPlate);
// console.log("startCook : " + this.cookingSide);
if(this.cookingSide == MeatBase.MEAT_NONE)
this.flipToFront();
this.startAnimateSmoke();
}
MeatBase.prototype.stopCook = function() {
this.isOnHeatPlate = false;
// console.log("this.isOnHeatPlate : " + this.isOnHeatPlate);
this.stopAnimateSmoke();
}
MeatBase.prototype.getMeatGrade = function() {
if(this.cookingGrade[MeatBase.MEAT_FRONT] == MeatBase.DONENESS_WELLDONE && this.cookingGrade[MeatBase.MEAT_BACK] == MeatBase.DONENESS_WELLDONE)
return MeatBase.DONENESS_WELLDONE;
else if(this.cookingGrade[MeatBase.MEAT_FRONT] == MeatBase.DONENESS_BURN_BLACK || this.cookingGrade[MeatBase.MEAT_BACK] == MeatBase.DONENESS_BURN_BLACK)
return MeatBase.DONENESS_BURN_BLACK;
else
return MeatBase.DONENESS_RARE;
}
MeatBase.prototype.getMeatGradeBySide = function(cookingSide) {
return this.cookingGrade[cookingSide];
}
MeatBase.prototype.setActive = function(isActivated, x, y, meat_type) {
this.isActivated = isActivated;
if(isActivated == false) {
this.alpha = 0;
this.x = -100;
this.y = -100;
return;
}
this.cookingSide = MeatBase.MEAT_NONE;
this.cookingTime[MeatBase.MEAT_BACK] = 0;
this.cookingTime[MeatBase.MEAT_FRONT] = 0;
this.cookingGrade[MeatBase.MEAT_BACK] = MeatBase.DONENESS_RARE;
this.cookingGrade[MeatBase.MEAT_FRONT] = MeatBase.DONENESS_RARE;
this.x = x;
this.y = y;
this.loadTexture('meat1');
this.angle = MeatBase.ANGLE_NONE;
this.alpha = 1;
}
MeatBase.prototype.cooking = function() {
this.cookingTime[this.cookingSide] += 1;
// console.log("back : " + this.cookingTime[MeatBase.MEAT_BACK] + ", front : " + this.cookingTime[MeatBase.MEAT_FRONT]);
if(this.cookingTime[MeatBase.MEAT_BACK] > MeatBase.COOK_TIME_BURN) {
if(this.getMeatGradeBySide(MeatBase.MEAT_BACK) != MeatBase.DONENESS_BURN_BLACK) {
this.cookingGrade[MeatBase.MEAT_BACK] = MeatBase.DONENESS_BURN_BLACK;
this.changeAnimateSmokeColor(MeatBase.DONENESS_BURN_BLACK);
}
} else if(this.cookingTime[MeatBase.MEAT_BACK] > MeatBase.COOK_TIME_WELLDONE) {
if(this.getMeatGradeBySide(MeatBase.MEAT_BACK) != MeatBase.DONENESS_WELLDONE) {
this.cookingGrade[MeatBase.MEAT_BACK] = MeatBase.DONENESS_WELLDONE;
this.changeAnimateSmokeColor(MeatBase.DONENESS_WELLDONE);
}
}
if(this.cookingTime[MeatBase.MEAT_FRONT] > MeatBase.COOK_TIME_BURN) {
if(this.getMeatGradeBySide(MeatBase.MEAT_FRONT) != MeatBase.DONENESS_BURN_BLACK) {
this.cookingGrade[MeatBase.MEAT_FRONT] = MeatBase.DONENESS_BURN_BLACK;
this.changeAnimateSmokeColor(MeatBase.DONENESS_BURN_BLACK);
}
} else if(this.cookingTime[MeatBase.MEAT_FRONT] > MeatBase.COOK_TIME_WELLDONE) {
if(this.getMeatGradeBySide(MeatBase.MEAT_FRONT) != MeatBase.DONENESS_WELLDONE) {
this.cookingGrade[MeatBase.MEAT_FRONT] = MeatBase.DONENESS_WELLDONE;
this.changeAnimateSmokeColor(MeatBase.DONENESS_WELLDONE);
}
}
}
MeatBase.prototype.stopAnimateSmoke = function() {
this.whiteSmokeParticle.stop();
this.redSmokeParticle.stop();
this.blackSmokeParticle.stop();
}
MeatBase.prototype.startAnimateSmoke = function() {
var cookingSideGrade = this.cookingGrade[this.cookingSide];
this.changeAnimateSmokeColor(cookingSideGrade);
}
MeatBase.prototype.changeAnimateSmokeColor = function(type) {
// console.log("changeAnimateSmokeColor : " + type);
this.stopAnimateSmoke();
switch(type) {
case MeatBase.DONENESS_RARE:
this.whiteSmokeParticle.start(this.x, this.y);
break;
case MeatBase.DONENESS_WELLDONE:
this.redSmokeParticle.start(this.x, this.y);
break;
case MeatBase.DONENESS_BURN_BLACK:
this.blackSmokeParticle.start(this.x, this.y);
break;
}
}
MeatBase.MEAT_NONE = 0;
MeatBase.MEAT_FRONT = 1;
MeatBase.MEAT_BACK = 2;
MeatBase.DONENESS_RARE = 0;
MeatBase.DONENESS_WELLDONE = 1;
MeatBase.DONENESS_BURN_BLACK = 2;
MeatBase.DONENESS_NONE = 3;
MeatBase.ANGLE_NONE = 0;
MeatBase.ANGLE_FRONT = 30;
MeatBase.ANGLE_BACK = -30;
MeatBase.COOK_TIME_WELLDONE = 200;
MeatBase.COOK_TIME_BURN = 400;
@@ -0,0 +1,52 @@
NormalMeat.prototype = MeatBase.prototype;
NormalMeat.constructor = NormalMeat;
function NormalMeat() {
MeatBase.call(this);
this.setMeatTypeVariables();
this.randomizeMeatType();
}
NormalMeat.prototype.setMeatTypeVariables = function() {
this.cookingSpeed = NormalMeat.COOKING_SPEED_BURN_LEVEL_WEAK;
}
NormalMeat.prototype.randomizeMeatType = function() {
this.meatType = Math.floor(Math.random() * 3) + 1;
switch(this.meatType) {
case 1:
this.scale.set(0.5);
break;
case 2:
this.scale.set(0.5);
break;
case 3:
this.scale.set(0.5);
break;
}
this.spriteNameRare = NormalMeat.SPRITE_NAME_RARE + this.meatType;
this.spriteNameWelldone = NormalMeat.SPRITE_NAME_WELLDONE + this.meatType;
this.spriteNameBurnBlack = NormalMeat.SPRITE_NAME_BURN_BLACK + this.meatType;
this.loadTexture(this.spriteNameRare);
}
NormalMeat.COOKING_SPEED_BURN_LEVEL_WEAK = 0.1;
NormalMeat.COOKING_SPEED_BURN_LEVEL_NORMAL = 0.2;
NormalMeat.COOKING_SPEED_BURN_LEVEL_STRONG = 0.3;
NormalMeat.SCORE_NAME_RARE = 10;
NormalMeat.SCORE_NAME_WELLDONE = 100;
NormalMeat.SCORE_NAME_BURN_BLACK = 0;
NormalMeat.SPRITE_NAME_RARE = "meat";
NormalMeat.SPRITE_NAME_WELLDONE = "meat_welldone";
NormalMeat.SPRITE_NAME_BURN_BLACK = "meat_burn";
+2
View File
@@ -67,6 +67,8 @@
<script src="../../game/mouse/grilled_meat/god.js"></script> <script src="../../game/mouse/grilled_meat/god.js"></script>
<script src="../../game/mouse/grilled_meat/smoke.js"></script> <script src="../../game/mouse/grilled_meat/smoke.js"></script>
<script src="../../game/mouse/grilled_meat/meat.js"></script> <script src="../../game/mouse/grilled_meat/meat.js"></script>
<script src="../../game/mouse/grilled_meat/meat_base.js"></script>
<script src="../../game/mouse/grilled_meat/normal_meat.js"></script>
<script src="../../game/mouse/grilled_meat/plus_score.js"></script> <script src="../../game/mouse/grilled_meat/plus_score.js"></script>
<script src="../../game/mouse/grilled_meat/speech_bubble.js"></script> <script src="../../game/mouse/grilled_meat/speech_bubble.js"></script>
<script src="../../game/mouse/grilled_meat/heat_plate.js"></script> <script src="../../game/mouse/grilled_meat/heat_plate.js"></script>