From b44f78ed871220484ac415af61304bff61ea6974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A2=E1=84=91=E1=85=B3=E1=86=AF=20=E1=84=82?= =?UTF-8?q?=E1=85=A9=E1=84=90=E1=85=B3=E1=84=87=E1=85=AE=E1=86=A8?= Date: Tue, 3 Dec 2019 17:29:53 +0900 Subject: [PATCH] Add: God --- src/game/mouse/just_on_time/god.js | 83 +++++++++++++++++++++ src/game/mouse/just_on_time/just_on_time.js | 62 ++++++++++++--- src/game/mouse/just_on_time/timer_stage.js | 82 ++++++++++++-------- src/game/mouse/just_on_time/timer_text.js | 1 - src/web/client/just_on_time.html | 3 + 5 files changed, 187 insertions(+), 44 deletions(-) create mode 100644 src/game/mouse/just_on_time/god.js diff --git a/src/game/mouse/just_on_time/god.js b/src/game/mouse/just_on_time/god.js new file mode 100644 index 0000000..af88762 --- /dev/null +++ b/src/game/mouse/just_on_time/god.js @@ -0,0 +1,83 @@ +God.prototype = Object.create(Phaser.Sprite.prototype); +God.constructor = God; + +function God() { + this.isActivated = true; + + Phaser.Sprite.call(this, game, GAME_SCREEN_SIZE.x / 2, GAME_SCREEN_SIZE.y - 50, 'god_smile'); + this.anchor.setTo(0.5, 1); + this.scale.set(0.5); + + game.add.existing(this); +} + +God.prototype.setScale = function(size) { + this.scale.set(size); + this.backupScale = size; +} + + +God.prototype.animateBigHappy = function(type) { + this.loadTexture('god_happy'); + + var tween = game.add.tween(this.scale); + // tween.to({x:0.7, y:0.7}, 500, Phaser.Easing.Quadratic.Out, true, 0); + tween.to({x:1, y:1}, 1000, Phaser.Easing.Bounce.Out, true, 0); + // tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Elastic.InOut, true, 0, 2, true); + // tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Linear.None, true, 0); + tween.onComplete.add(this.smileAgain, this); + tween.start(); +} + +God.prototype.animateBigSmile = function(type) { + this.loadTexture('god_happy'); + + var tween = game.add.tween(this.scale); + // tween.to({x:0.7, y:0.7}, 500, Phaser.Easing.Quadratic.Out, true, 0); + tween.to({x:0.8, y:0.8}, 1000, Phaser.Easing.Bounce.Out, true, 0); + // tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Elastic.InOut, true, 0, 2, true); + // tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Linear.None, true, 0); + tween.onComplete.add(this.smileAgain, this); + tween.start(); +} + +God.prototype.animateLittleSmile = function(type) { + this.loadTexture('god_happy'); + + var tween = game.add.tween(this.scale); + // tween.to({x:0.7, y:0.7}, 500, Phaser.Easing.Quadratic.Out, true, 0); + tween.to({x:0.6, y:0.6}, 1000, Phaser.Easing.Bounce.Out, true, 0); + // tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Elastic.InOut, true, 0, 2, true); + // tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Linear.None, true, 0); + tween.onComplete.add(this.smileAgain, this); + tween.start(); +} + +God.prototype.animateBigAngry = function(type) { + this.loadTexture('god_angry'); + + var tween = game.add.tween(this.scale); + // tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Bounce.Out, true, 0); + tween.to({x:1.5, y:1.5}, 1000, Phaser.Easing.Bounce.Out, true, 0); + // tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Elastic.InOut, true, 0, 2, true); + // tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Linear.None, true, 0); + // tween.onComplete.add(this.smileAgain, this); + tween.start(); +} + +God.prototype.animateLittleAngry = function(type) { + this.loadTexture('god_angry'); + + var tween = game.add.tween(this.scale); + // tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Bounce.Out, true, 0); + tween.to({x:0.6, y:0.6}, 1000, Phaser.Easing.Bounce.Out, true, 0); + // tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Elastic.InOut, true, 0, 2, true); + // tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Linear.None, true, 0); + tween.onComplete.add(this.smileAgain, this); + tween.start(); +} + +God.prototype.smileAgain = function() { + this.scale.set(0.5); + this.loadTexture('god_smile'); +} \ No newline at end of file diff --git a/src/game/mouse/just_on_time/just_on_time.js b/src/game/mouse/just_on_time/just_on_time.js index 8c3a613..738b8ca 100644 --- a/src/game/mouse/just_on_time/just_on_time.js +++ b/src/game/mouse/just_on_time/just_on_time.js @@ -7,6 +7,10 @@ function JustOnTime() { JustOnTime.prototype.preload = function() { game.load.image('icon_fullscreen', '../../../resources/image/icon/fullscreen_white.png'); + game.load.image('god_angry', '../../../resources/image/character/god/god_hungry.png'); + game.load.image('god_smile', '../../../resources/image/character/god/god_smile.png'); + game.load.image('god_happy', '../../../resources/image/character/god/god_happy.png'); + game.load.script('webfont', '//ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js'); } @@ -71,6 +75,8 @@ JustOnTime.prototype.create = function() { graphics = game.add.graphics(0, 0); + this.god = new God(); + // bottom ui var screenBottomUI = new ScreenBottomUI(); screenBottomUI.printLeftTextWithAppHighestRecord(sessionStorageManager.getAppHighestRecord()); @@ -85,17 +91,45 @@ JustOnTime.prototype.initVariables = function() { } JustOnTime.prototype.fontLoaded = function() { - this.leftTimerStage = new TimerStage( - JustOnTime.TIMER_STAGE_POS_X, JustOnTime.TIMER_STAGE_POS_Y + JustOnTime.TIMER_STAGE_POS_X, + JustOnTime.TIMER_STAGE_POS_Y ); + this.leftTimerStage.setOnPlusScore( + (function(score, timeLeft) { this.plusScore(score, timeLeft); }).bind(this) + ); + this.leftTimerStage.setOnGameOver( + (function() { this.gameOver(); }).bind(this) + ); + this.rightTimerStage = new TimerStage( - GAME_SCREEN_SIZE.x - JustOnTime.TIMER_STAGE_POS_X, JustOnTime.TIMER_STAGE_POS_Y + GAME_SCREEN_SIZE.x - JustOnTime.TIMER_STAGE_POS_X, + JustOnTime.TIMER_STAGE_POS_Y + ); + this.rightTimerStage.setOnPlusScore( + (function(score) { this.plusScore(score); }).bind(this) + ); + this.rightTimerStage.setOnGameOver( + (function() { this.gameOver(); }).bind(this) ); // this.startGame(); } + +JustOnTime.prototype.plusScore = function(score, timeLeft) { + this.scoreManager.plusScore(score); + + if(timeLeft < TimerStage.GRADE_GREAT_MS) + this.god.animateBigHappy(); + else if(timeLeft < TimerStage.GRADE_GOOD_MS) + this.god.animateBigSmile(); + else if(timeLeft < TimerStage.GRADE_SOSO_MS) + this.god.animateLittleSmile(); + else + this.god.animateLittleAngry(); +} + JustOnTime.prototype.back = function() { sessionStorageManager.resetPlayingAppData(); location.href = '../../web/client/main_menu.html'; @@ -139,20 +173,28 @@ JustOnTime.prototype.startGame = function() { JustOnTime.prototype.timeOver = function() { + this.god.animateAngry(); + var timeOverText = new TimeOverText(); if(!isExperienceMaestroAccount()) this.updateResultRecord(); // game.time.events.remove(this.timeEvent); - for(var i = 0; i < this.gameTimeEvents.length; i++) { - game.time.events.remove(this.gameTimeEvents[i]); - } - this.gameTimeEvents = []; - - game.time.events.add(Phaser.Timer.SECOND * 2, this.goResult, this); + // game.time.events.add(Phaser.Timer.SECOND * 2, this.goResult, this); } +JustOnTime.prototype.gameOver = function() { + this.god.animateBigAngry(); + + var gameOverText = new GameOverText(); + if(!isExperienceMaestroAccount()) + this.updateResultRecord(); + + // game.time.events.add(Phaser.Timer.SECOND * 2, this.goResult, this); +} + + JustOnTime.prototype.updateResultRecord = function() { if(sessionStorageManager.getMaestroAccountType() < 100) { // experience account this.dbConnectManager.updateResultRecord( @@ -171,5 +213,5 @@ JustOnTime.prototype.goResult = function() { JustOnTime.GAME_TIME_SEC = 60; -JustOnTime.TIMER_STAGE_POS_X = 300; +JustOnTime.TIMER_STAGE_POS_X = 250; JustOnTime.TIMER_STAGE_POS_Y = 200; diff --git a/src/game/mouse/just_on_time/timer_stage.js b/src/game/mouse/just_on_time/timer_stage.js index 6c58c05..a00cbba 100644 --- a/src/game/mouse/just_on_time/timer_stage.js +++ b/src/game/mouse/just_on_time/timer_stage.js @@ -18,6 +18,14 @@ function TimerStage(x, y) { } +TimerStage.prototype.setOnPlusScore = function(eventHandler) { + this.onPlusScoreEventHandler = eventHandler; +} + +TimerStage.prototype.setOnGameOver = function(eventHandler) { + this.onGameOverEventHandler = eventHandler; +} + TimerStage.prototype.makeTimeStopButton = function(x, y) { var setting = new RoundRectButtonSetting(x, y, 240, 100); setting.fontStyle.fontWeight = "bold"; @@ -49,6 +57,9 @@ TimerStage.prototype.initialize = function() { this.state = TimerStage.STATE_READY; this.mainTimer = game.time.create(false); + this.onPlusScoreEventHandler = null; + this.onGameOverEventHandler = null; + this.timerEvent = null; this.timerEvent = this.mainTimer.loop( 10, @@ -61,13 +72,16 @@ TimerStage.prototype.initialize = function() { TimerStage.prototype.updateTimer = function() { // console.log(game.time.totalElapsedSeconds()); - console.log(this.mainTimer.ms); + // console.log(this.mainTimer.ms); var timeLeft = this.timeLimitMS - this.mainTimer.ms; this.mainTimerText.setMSTimeText(timeLeft); // this.mainTimerText.setMSTimeText(this.mainTimer.ms); if(timeLeft < 0) { console.log("Game Over"); + + this.mainTimer.stop(); + this.onGameOverEventHandler(); } } @@ -102,57 +116,54 @@ TimerStage.prototype.buttonClicked = function() { } TimerStage.prototype.decideGrade = function(timeLeft) { - console.log(timeLeft); + // console.log(timeLeft); if(timeLeft < 0) { console.log("Game Over") } - else if(timeLeft < 200) this.gradeGreat(timeLeft); - else if(timeLeft < 500) this.gradeGood(timeLeft); - else if(timeLeft < 1000) this.gradeSoSo(timeLeft); - else this.gradeBad(timeLeft); + else if(timeLeft < TimerStage.GRADE_GREAT_MS) this.gradeGreat(timeLeft); + else if(timeLeft < TimerStage.GRADE_GOOD_MS) this.gradeGood(timeLeft); + else if(timeLeft < TimerStage.GRADE_SOSO_MS) this.gradeSoSo(timeLeft); + else this.gradeBad(timeLeft); this.updateTimeScoreRecordArray(); } TimerStage.prototype.gradeGreat = function(timeLeft) { - console.log("Great") - var score = this.timeLimitMS * 10; - this.timeLimitMS = this.timeLimitMS + 3000; + // console.log("Great") + var score = Math.floor(this.timeLimitMS / 1000) * 10; + this.onPlusScoreEventHandler(score, timeLeft); + this.timeLimitMS = this.timeLimitMS + 3000; this.recordArray.push( { timeLeft, score } ); } TimerStage.prototype.gradeGood = function(timeLeft) { - console.log("Good") - var score = this.timeLimitMS * 3; - this.timeLimitMS = this.timeLimitMS + 1000; + // console.log("Good") + var score = Math.floor(this.timeLimitMS / 1000) * 3; + this.onPlusScoreEventHandler(score, timeLeft); + this.timeLimitMS = this.timeLimitMS + 1000; this.recordArray.push( { timeLeft, score } ); } TimerStage.prototype.gradeSoSo = function(timeLeft) { - console.log("SoSo") - var score = this.timeLimitMS * 2; + // console.log("SoSo") + var score = Math.floor(this.timeLimitMS / 1000) * 2; + this.onPlusScoreEventHandler(score, timeLeft); + this.timeLimitMS = this.timeLimitMS + 500; this.recordArray.push( { timeLeft, score } ); } TimerStage.prototype.gradeBad = function(timeLeft) { - console.log("Bad") - var score = this.timeLimitMS; + // console.log("Bad") + var score = Math.floor(this.timeLimitMS / 1000); + this.onPlusScoreEventHandler(score, timeLeft); - // this.recordArray.push( { timeLeft, score } ); - var record = { - timeLeft: 0.0, - score: 0 - } - record.timeLeft = timeLeft; - record.score = score; - - this.recordArray.push(record); + this.recordArray.push( { timeLeft, score } ); } @@ -168,14 +179,14 @@ TimerStage.prototype.updateTimeScoreRecordArray = function() { var record = this.recordArray[recordIndex]; // console.log(record); this.timeScoreRecordArray[timeScoreRecordIndex].setContent(record.timeLeft, record.score); - if(record.timeLeft < 200) - this.timeScoreRecordArray[timeScoreRecordIndex].setTextColorString("gold"); - else if(record.timeLeft < 500) - this.timeScoreRecordArray[timeScoreRecordIndex].setTextColorString("orange"); - else if(record.timeLeft < 1000) - this.timeScoreRecordArray[timeScoreRecordIndex].setTextColorString("red"); + if(record.timeLeft < TimerStage.GRADE_GREAT_MS) + this.timeScoreRecordArray[timeScoreRecordIndex].setTextColorString("Brown"); + else if(record.timeLeft < TimerStage.GRADE_GOOD_MS) + this.timeScoreRecordArray[timeScoreRecordIndex].setTextColorString("Chocolate"); + else if(record.timeLeft < TimerStage.GRADE_SOSO_MS) + this.timeScoreRecordArray[timeScoreRecordIndex].setTextColorString("GoldenRod"); else - this.timeScoreRecordArray[timeScoreRecordIndex].setTextColorString("white"); + this.timeScoreRecordArray[timeScoreRecordIndex].setTextColorString("LightGoldenRodYellow"); } } @@ -193,4 +204,9 @@ TimerStage.BUTTON_OFFSET_Y = 100; TimerStage.RECORD_OFFSET_Y = 200; TimerStage.RECORD_GAP_Y = 50; -TimerStage.RECORD_COUNT = 5; \ No newline at end of file +TimerStage.RECORD_COUNT = 5; + + +TimerStage.GRADE_GREAT_MS = 200; +TimerStage.GRADE_GOOD_MS = 500; +TimerStage.GRADE_SOSO_MS = 1000; \ No newline at end of file diff --git a/src/game/mouse/just_on_time/timer_text.js b/src/game/mouse/just_on_time/timer_text.js index f653db5..71940ea 100644 --- a/src/game/mouse/just_on_time/timer_text.js +++ b/src/game/mouse/just_on_time/timer_text.js @@ -35,7 +35,6 @@ TimerText.prototype.setMSTimeText = function(ms) { var sec2Digit = ("00" + sec).slice(-2); var millisec = ms % 1000; - console.log("millisec : " + millisec); var millisec2Digit = "" + millisec; if(millisec < 10) millisec2Digit = ("000" + millisec).substring(0, 2); diff --git a/src/web/client/just_on_time.html b/src/web/client/just_on_time.html index c7f3365..871fe5a 100644 --- a/src/web/client/just_on_time.html +++ b/src/web/client/just_on_time.html @@ -47,6 +47,7 @@ + @@ -63,6 +64,8 @@ + +