From 429e4398f57e36fff275acacbabd324bf07d2e5a Mon Sep 17 00:00:00 2001 From: Andrew Kesterson Date: Fri, 27 Jun 2014 21:41:57 -0700 Subject: [PATCH] Close #12 : UI now shows a timer that counts from 8 pm to 5 am --- moonlight/src/Constants.js | 4 ++++ moonlight/src/GameStates.js | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/moonlight/src/Constants.js b/moonlight/src/Constants.js index cc6b4cf..c77c0cc 100644 --- a/moonlight/src/Constants.js +++ b/moonlight/src/Constants.js @@ -10,6 +10,10 @@ TWEEN_DURATION_PERPIXEL_WALKING = 12; TWEEN_DURATION_PERTILE_RUNNING = TWEEN_DURATION_PERPIXEL_RUNNING * 32; TWEEN_DURATION_PERTILE_WALKING = TWEEN_DURATION_PERPIXEL_WALKING * 32; +DAYLIGHT_TIMER_TOTALTIME = (9 * 60 * 60 * 1000); +DAYLIGHT_TIMER_REPEAT = 1000 / 20; +DAYLIGHT_TIMER_REPEATCOUNT = (DAYLIGHT_TIMER_TOTALTIME / DAYLIGHT_TIMER_REPEAT ) + 1; + STATE_NONE = 0; STATE_UNAWARE = 1 << 1; STATE_CONCERNED = 1 << 2; diff --git a/moonlight/src/GameStates.js b/moonlight/src/GameStates.js index 4612a83..f399370 100644 --- a/moonlight/src/GameStates.js +++ b/moonlight/src/GameStates.js @@ -1,6 +1,12 @@ var GameState = function(game) { } +GameState.prototype.updateClock = function() +{ + this.clock.setSeconds(this.clock.getSeconds() + 1); + this.clock.setMilliseconds(0); +} + GameState.prototype.create = function() { this.map = this.add.tilemap('map'); @@ -103,6 +109,18 @@ GameState.prototype.create = function() this.uigroup = game.add.group(); this.game.time.advancedTiming = true; + + this.clockText = this.game.add.text( + 20, SCREEN_HEIGHT - 40, '', { font : '16px Arial', fill: '#ffffff' }, this.uigroup + ); + this.clock = new Date(); + this.clock.setHours(22, 0, 0, 0); + this.clockTimer = game.time.create(true); + this.clockTimer.repeat(DAYLIGHT_TIMER_REPEAT, + DAYLIGHT_TIMER_REPEATCOUNT, + this.updateClock, + this); + this.clockTimer.start(); this.fpsText = this.game.add.text( 20, 20, '', { font: '16px Arial', fill: '#ffffff' }, this.uigroup ); @@ -314,6 +332,7 @@ GameState.prototype.update = function() if (game.time.fps !== 0) { this.fpsText.setText(game.time.fps + ' FPS'); } + this.clockText.setText("" + this.clock.getHours() + ":" + this.clock.getMinutes() + ":" + this.clock.getSeconds()); } function Boot()