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
+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;