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(); this.whiteSmokeParticle = new Smoke(MeatBase.DONENESS_RARE, 0, 0); this.redSmokeParticle = new Smoke(MeatBase.DONENESS_WELLDONE, 0, 0); this.blackSmokeParticle = new Smoke(MeatBase.DONENESS_BURN_BLACK, 0, 0); } MeatBase.prototype.update = function() { var posY = this.y; if(posY <= God.POSITION_Y) { this.scale.set(this.baseScale); } 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(this.baseScale + 0.3 * scaleRate); } else { this.scale.set(this.baseScale + 0.3); } if(this.isOnHeatPlate == true && game.input.mousePointer.isUp == true) { this.cooking(); } } MeatBase.prototype.initMeatTypeVariables = function() { this.className = "MeatBase"; this.baseScale = 0.5; this.cookingSide = MeatBase.MEAT_NONE; this.cookingTimeBySide = []; this.cookingTimeBySide[MeatBase.MEAT_BACK] = 0; this.cookingTimeBySide[MeatBase.MEAT_FRONT] = 0; this.cookingGradeBySide = []; this.cookingGradeBySide[MeatBase.MEAT_BACK] = MeatBase.DONENESS_RARE; this.cookingGradeBySide[MeatBase.MEAT_FRONT] = MeatBase.DONENESS_RARE; this.isActivated = true; this.isStartCook = false; this.isOnHeatPlate = false; this.spriteNameRare = ""; this.spriteNameWelldone = ""; this.spriteNameBurnBlack = ""; this.initCookingSpeedArray(); this.initScoreArray(); this.initCookingTimeForGradeArray(); } MeatBase.prototype.initCookingSpeedArray = function() { this.cookingSpeedArray = []; this.cookingSpeedArray[HeatPlate.BURN_LEVEL_WEAK] = MeatBase.COOKING_SPEED_BURN_LEVEL_WEAK; this.cookingSpeedArray[HeatPlate.BURN_LEVEL_NORMAL] = MeatBase.COOKING_SPEED_BURN_LEVEL_NORMAL; this.cookingSpeedArray[HeatPlate.BURN_LEVEL_STRONG] = MeatBase.COOKING_SPEED_BURN_LEVEL_STRONG; } MeatBase.prototype.initScoreArray = function() { this.scoreArray = []; this.scoreArray[MeatBase.DONENESS_RARE] = 0; this.scoreArray[MeatBase.DONENESS_WELLDONE] = 0; this.scoreArray[MeatBase.DONENESS_BURN_BLACK] = 0; } MeatBase.prototype.initCookingTimeForGradeArray = function() { this.cookingTimeForGradeArray = []; this.cookingTimeForGradeArray[MeatBase.DONENESS_WELLDONE] = NormalMeat.COOKING_TIME_WELLDONE; this.cookingTimeForGradeArray[MeatBase.DONENESS_BURN_BLACK] = NormalMeat.COOKING_TIME_BURN_BLACK; } 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.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); } else if(this.mainGame.isOverTrashCan(this.x, this.y) == true) { this.mainGame.throwAwayMeat(this); } } MeatBase.prototype.getClassName = function() { return this.className; } MeatBase.prototype.getTotalCookingTime = function() { return this.cookingTimeBySide[MeatBase.MEAT_BACK] + this.cookingTimeBySide[MeatBase.MEAT_FRONT]; } MeatBase.prototype.getScore = function() { var meatDoneness = this.getMeatGrade(); var scoreDoneness = this.scoreArray[meatDoneness]; // console.log("meatDoneness : " + meatDoneness); // console.log("this.scoreArray : " + this.scoreArray); // console.log("scoreDoneness : " + scoreDoneness); if(meatDoneness == MeatBase.DONENESS_BURN_BLACK) return scoreDoneness; var totalCookingTime = this.getTotalCookingTime(); var totalScore = Math.floor(scoreDoneness * totalCookingTime); // console.log("totalScore : " + totalScore); return totalScore; } 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.upsideDownSprite(MeatBase.MEAT_FRONT); } 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.upsideDownSprite(MeatBase.MEAT_BACK); } MeatBase.prototype.upsideDownSprite = function(meatDirection) { if(this.getMeatGradeBySide(meatDirection) == MeatBase.DONENESS_BURN_BLACK) { // console.log("sprite burn black"); this.loadTexture(this.spriteNameBurnBlack); } else if(this.getMeatGradeBySide(meatDirection) == MeatBase.DONENESS_WELLDONE) { // console.log("sprite welldone"); this.loadTexture(this.spriteNameWelldone); } else { // console.log("sprite rare"); 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.isActive = function() { return this.isActivated; } 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.cookingGradeBySide[MeatBase.MEAT_FRONT] == MeatBase.DONENESS_WELLDONE && this.cookingGradeBySide[MeatBase.MEAT_BACK] == MeatBase.DONENESS_WELLDONE ) { return MeatBase.DONENESS_WELLDONE; } else if( this.cookingGradeBySide[MeatBase.MEAT_FRONT] == MeatBase.DONENESS_BURN_BLACK || this.cookingGradeBySide[MeatBase.MEAT_BACK] == MeatBase.DONENESS_BURN_BLACK ) { return MeatBase.DONENESS_BURN_BLACK; } else return MeatBase.DONENESS_RARE; } MeatBase.prototype.getMeatGradeBySide = function(cookingSide) { return this.cookingGradeBySide[cookingSide]; } MeatBase.prototype.setActive = function(isActivated, x, y) { this.isActivated = isActivated; if(isActivated == false) { this.alpha = 0; this.x = -100; this.y = -100; return; } this.cookingSide = MeatBase.MEAT_NONE; this.cookingTimeBySide[MeatBase.MEAT_BACK] = 0; this.cookingTimeBySide[MeatBase.MEAT_FRONT] = 0; this.cookingGradeBySide[MeatBase.MEAT_BACK] = MeatBase.DONENESS_RARE; this.cookingGradeBySide[MeatBase.MEAT_FRONT] = MeatBase.DONENESS_RARE; this.x = x; this.y = y; this.loadTexture(this.spriteNameRare); this.angle = MeatBase.ANGLE_NONE; this.alpha = 1; } MeatBase.prototype.cooking = function() { var side = this.cookingSide; var burnLevel = this.mainGame.getBurnLevel(); var cookingSpeed = this.cookingSpeedArray[burnLevel]; this.cookingTimeBySide[side] += 1 * cookingSpeed; var cookingTimeBurnBlack = this.cookingTimeForGradeArray[MeatBase.DONENESS_BURN_BLACK]; var cookingTimeWelldone = this.cookingTimeForGradeArray[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() { this.whiteSmokeParticle.stop(); this.redSmokeParticle.stop(); this.blackSmokeParticle.stop(); } MeatBase.prototype.startAnimateSmoke = function() { var cookingSideGrade = this.cookingGradeBySide[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.CLASS_NAME = "MeatBase"; MeatBase.MEAT_NONE = 0; MeatBase.MEAT_FRONT = 1; MeatBase.MEAT_BACK = 2; MeatBase.ANGLE_NONE = 0; MeatBase.ANGLE_FRONT = 30; MeatBase.ANGLE_BACK = -30; MeatBase.DONENESS_RARE = 0; MeatBase.DONENESS_WELLDONE = 1; MeatBase.DONENESS_BURN_BLACK = 2; MeatBase.DONENESS_NONE = 3; MeatBase.COOKING_TIME_WELLDONE = 200; MeatBase.COOKING_TIME_BURN_BLACK = 400; MeatBase.COOKING_SPEED_BURN_LEVEL_WEAK = 0.7; MeatBase.COOKING_SPEED_BURN_LEVEL_NORMAL = 1; MeatBase.COOKING_SPEED_BURN_LEVEL_STRONG = 2;