Files
chocomae/src/game/mouse/grilled_meat/game.js
T
2019-12-12 14:36:39 +09:00

409 lines
10 KiB
JavaScript

var Game = {
create: function() {
this.dbConnectManager = new DBConnectManager();
sessionStorageManager.setRecord(0);
this.game.stage.backgroundColor = "#000000"; // '#4d4d4d';
sessionStorageManager.setIsNewAppHighestRecord(false);
// keyboard shortcut
this.keyboardShortcut = new KeyboardShortcut();
this.keyboardShortcut.addCallback(
Phaser.KeyCode.ESC, // keyCode
null, // keyDownHandler
(function() { this.back(); }).bind(this), // keyUpHandler
"card matching" // callerClassName
);
// top ui
var screenTopUI = new ScreenTopUI();
screenTopUI.makeBackButton( (function() { this.back(); }).bind(this) );
screenTopUI.makeFullScreenButton();
this.scoreManager = new ScoreManager();
this.scoreBoard = new ScoreBoard();
this.scoreManager.addOnChangeScoreListener(
(function(score) {
sessionStorageManager.setRecord(score);
this.scoreBoard.printScore(NumberUtil.numberWithCommas(score));
}).bind(this)
);
this.scoreManager.addOnChangeHighScoreListener(
(function(highScore) {
// console.log(highScore);
// sessionStorageManager.setAppHighestRecord(highScore);
sessionStorageManager.setIsNewBestRecrd(true);
// this.screenBottomUI.printLeftTextWithAppHighestRecord(sessionStorageManager.getAppHighestRecord());
}).bind(this)
);
this.setClickEnable(false);
this.makeStageTimerText();
this.realtimeStageTimer = new RealtimeStageTimer(Game.GAME_TIME_SEC);
this.realtimeStageTimer.setTimeUpdateEvent(
(function(timeLeftSec) {
this.textTimer.text = TimeUtil.printHHMMSSFromSec(timeLeftSec);
}).bind(this)
);
this.realtimeStageTimer.setTimeOverEvent(
(function() {
this.textTimer.text = "타임 오버";
this.timeOver();
}).bind(this)
);
this.initVariables();
// game stage
game.stage.backgroundColor = '#4d4d4d';
graphics = game.add.graphics(0, 0);
this.plusScoreGroup = game.add.group();
var table = game.add.tileSprite(0, 340, GAME_SCREEN_SIZE.x, 660, 'wooden_table');
this.god = new God(this);
this.waiter = new Waiter();
this.meatPlate = game.add.image(Game.MEAT_PLATE_POSITION_X, Game.MEAT_PLATE_POSITION_Y, 'plate');
this.meatPlate.anchor.set(0.5);
this.meatPlate.scale.set(0.8);
this.meatPlate.smoothed = false;
this.trashCan = new TrashCan();
this.heatPlate = new HeatPlate();
this.stoveDial = new StoveDial(180, HeatPlate.POSITION_Y + 90);
this.stoveDial.setOnChangeDialLevelHandler(
(function(dialLevel) { this.onChangeDialLevel(dialLevel); }).bind(this)
);
// meat
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.normalMeatGroup = game.add.group();
for(var i = 0; i < Game.MAX_NORMAL_MEAT_COUNT; i++) {
// var meat = new Meat(this);
var normalMeat = new NormalMeat(this);
normalMeat.name = "meat" + i;
normalMeat.setActive(false, -100, -100);
this.normalMeatGroup.add(normalMeat);
}
var experienceAppTimer = new ExperienceAppTimer();
experienceAppTimer.setTimeOverListener(
(function() { this.timeOver(); }).bind(this)
);
// bottom ui
var screenBottomUI = new ScreenBottomUI();
screenBottomUI.printLeftTextWithAppHighestRecord(sessionStorageManager.getAppHighestRecord());
screenBottomUI.printCenterText(sessionStorageManager.getPlayingAppKoreanName());
screenBottomUI.printRightText(sessionStorageManager.getPlayerName());
this.startGame();
// // this.countDown();
},
initVariables: function() {
this.isPlaying = false;
this.playingStageNo = 0;
this.activatedMeatCount = 0;
this.clearedMeatCount = 0;
this.badMeatCount = 0;
this.burnLevel = HeatPlate.BURN_LEVEL_WEAK;
this.plusScoreTextGroup = null;
this.timeEvent = null;
this.gameTimeEvents = [];
},
makeStageTimerText: function() {
var fontStyle = {
font: "38px Arial",
align: "right",
boundsAlignH: "right", // left, center. right
boundsAlignV: "middle", // top, middle, bottom
fill: "#fff"
};
this.textTimer = game.add.text(game.world.width - 300, 0, "", fontStyle)
.setTextBounds(0, 0, 200, 70);
this.textTimer.text = "";
},
onChangeDialLevel: function(dialLevel) {
this.burnLevel = dialLevel;
// console.log(this.burnLevel);
this.heatPlate.onChangeDialLevel(dialLevel);
},
setClickEnable: function(value) {
this.isEnableClick = value;
},
getBurnLevel: function() {
// console.log(this.burnLevel);
return this.burnLevel;
},
back: function() {
sessionStorageManager.resetPlayingAppData();
location.href = '../../web/client/main_menu.html';
},
/*
countDown: function() {
var style = { font: "bold 200px Arial", fill: "#fff", boundsAlignH: "center", boundsAlignV: "middle" };
this.countDownText = game.add.text(0, 0, "", style);
this.countDownText.setTextBounds(0, 0, game.world.width, game.world.height);
this.countDownText.stroke = "#333";
this.countDownText.strokeThickness = 50;
this.countDownNumber = 3;
if(isDebugMode())
this.countDownNumber = 1;
this.tweenCountDown();
},
tweenCountDown: function() {
if(this.countDownNumber === 0) {
this.startGame();
return;
}
this.countDownText.text = this.countDownNumber.toString();
this.countDownText.alpha = 1;
var countDownTween = game.add.tween(this.countDownText);
countDownTween.to( { alpha: 0 }, 1000, Phaser.Easing.Linear.None, true);
countDownTween.onComplete.add(this.tweenCountDown, this);
this.countDownNumber--;
},
*/
startGame: function() {
this.isPlaying = true;
this.playingStageNo = 1;
this.clearedMeatCount = 0;
this.badMeatCount = 0;
this.badMeatCountPrevStage = 0;
this.startStage();
this.realtimeStageTimer.start();
},
startStage: function() {
this.clearedMeatCount = 0;
this.activatedMeatCount = this.playingStageNo + 2;
this.badMeatCountPrevStage = this.badMeatCount;
this.badMeatCount = 0;
if(this.playingStageNo > 1) {
this.waiter.animateServing();
game.time.events.add(Waiter.SERVING_WAIT_TIME_MS, this.serveMeats, this);
} else {
this.serveMeats();
}
},
serveMeats: function() {
this.serveBonusMeat();
this.serveNormalMeats();
},
serveBonusMeat: function() {
if(this.playingStageNo == 1)
return;
if(this.badMeatCountPrevStage > 0)
return;
var bonusMeat = this.bonusMeatGroup.children[this.bonusMeatIndex];
var randX = this.meatPlate.x - game.rnd.integerInRange(-80, 80);
var randY = this.meatPlate.y - game.rnd.integerInRange(-30, 30);
bonusMeat.setActive(true, randX, randY);
this.bonusMeatIndex++;
},
serveNormalMeats: function() {
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 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);
normalMeat.setActive(true, randX, randY);
}
},
isOverHeatPlate: function(x, y) {
return this.heatPlate.isOver(x, y);
},
isOverGod: function(x, y) {
return this.god.isOver(x, y);
},
godEatMeat: function(meat) {
if(!this.isPlaying)
return;
if(meat.getMeatGrade() == MeatBase.DONENESS_WELLDONE) {
this.god.animateHappy();
var score = meat.getScore();
this.scoreManager.plusScore(score);
var tempPlusScore = new PlusScore(this.god.x, this.god.y - 250, score);
this.plusScoreGroup.add(tempPlusScore);
} else if(meat.getMeatGrade() == MeatBase.DONENESS_RARE) {
this.badMeatCount++;
if(meat.getTotalCookingTime() == 0)
this.god.animateAngryWithRare();
else
this.god.animateSmile();
if(meat.getTotalCookingTime() > 0) {
var score = meat.getScore();
this.scoreManager.plusScore(score);
var tempPlusScore = new PlusScore(this.god.x, this.god.y - 250, score);
this.plusScoreGroup.add(tempPlusScore);
}
} else { // meat is burn black
this.badMeatCount++;
this.god.animateAngryWithBurnBlack();
return; // god doesn't eat burned black meat
}
meat.setActive(false, -100, -100);
if(meat.getClassName() == NormalMeat.CLASS_NAME) {
this.clearedMeatCount++;
if(this.clearedMeatCount == this.activatedMeatCount) {
this.clearStage();
}
}
},
isOverTrashCan: function(x, y) {
return this.trashCan.isOver(x, y);
},
throwAwayMeat: function(meat) {
if(!this.isPlaying)
return;
if(meat.getMeatGrade() != MeatBase.DONENESS_BURN_BLACK)
return;
this.badMeatCount++;
this.trashCan.animateAngry();
meat.setActive(false, -100, -100);
var score = meat.getScore();
this.scoreManager.plusScore(score);
var tempPlusScore = new PlusScore(this.trashCan.x, this.trashCan.y - 180, score);
this.plusScoreGroup.add(tempPlusScore);
if(meat.getClassName() == NormalMeat.CLASS_NAME) {
this.clearedMeatCount++;
if(this.clearedMeatCount == this.activatedMeatCount) {
this.clearStage();
}
}
},
clearStage: function() {
this.playingStageNo++;
var startStageTimeEvent = game.time.events.add(Phaser.Timer.SECOND * 1, this.startStage, this);
this.gameTimeEvents[this.gameTimeEvents.length + 1] = startStageTimeEvent;
},
timeOver: function() {
this.isPlaying = false;
var timeOverText = new TimeOverText();
if(!isExperienceMaestroAccount())
this.updateResultRecord();
this.stopAndGoResult();
},
stopAndGoResult: function() {
for(var i = 0; i < this.gameTimeEvents.length; i++) {
game.time.events.remove(this.gameTimeEvents[i]);
}
this.gameTimeEvents = [];
for(var i = 0; i < Game.MAX_BONUS_MEAT_COUNT; i++) {
this.bonusMeatGroup.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);
},
updateResultRecord: function() {
if(sessionStorageManager.getMaestroAccountType() < 100) { // experience account
this.dbConnectManager.updateResultRecord(
sessionStorageManager.getMaestroID(),
sessionStorageManager.getPlayerID(),
sessionStorageManager.getPlayingAppID(),
sessionStorageManager.getRecord()
);
}
},
goResult: function() {
location.href = '../../web/client/result.html';
},
}
Game.GAME_TIME_SEC = 90;
Game.MAX_BONUS_MEAT_COUNT = 10;
Game.MAX_NORMAL_MEAT_COUNT = 20;
Game.MEAT_PLATE_POSITION_X = 180;
Game.MEAT_PLATE_POSITION_Y = 390;