From e166d580fc7924e63fd5924217c6a9540402c603 Mon Sep 17 00:00:00 2001 From: Andrew Kesterson Date: Sat, 28 Jun 2014 08:48:26 -0700 Subject: [PATCH] Made state changes in the AI affect the player score --- moonlight/src/AISprite.js | 1 + moonlight/src/Constants.js | 5 +++++ moonlight/src/GameStates.js | 8 +++++--- moonlight/src/Util.js | 15 +++++++++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/moonlight/src/AISprite.js b/moonlight/src/AISprite.js index da45a9e..51ef882 100644 --- a/moonlight/src/AISprite.js +++ b/moonlight/src/AISprite.js @@ -93,6 +93,7 @@ var AISprite = function(game, x, y, key, frame) { state != STATE_ALERTED ) { return; } + awardPlayerScoreByState(state); this.state_changed_at = new Phaser.Point(this.x, this.y); this.startAwarenessTimer(); setAwarenessState(this, state); diff --git a/moonlight/src/Constants.js b/moonlight/src/Constants.js index c77c0cc..e4a7298 100644 --- a/moonlight/src/Constants.js +++ b/moonlight/src/Constants.js @@ -51,3 +51,8 @@ SPRITE_TOWNSFOLK_FEMALE4 = 8; SPRITE_TOWNSFOLK_GUARD1 = 9; SPRITE_TOWNSFOLK_GUARD2 = 10; + +SCORE_PERSECOND = 1; +SCORE_LOSTHIM = 0; +SCORE_ALERTED = -50; +SCORE_CONCERNED = 0; diff --git a/moonlight/src/GameStates.js b/moonlight/src/GameStates.js index 304b92a..42cfe95 100644 --- a/moonlight/src/GameStates.js +++ b/moonlight/src/GameStates.js @@ -4,6 +4,8 @@ var GameState = function(game) { GameState.prototype.updateClock = function() { this.clock.setSeconds(this.clock.getSeconds() + 1); + if ( this.clock.getSeconds() == 59) + player.score += SCORE_PERSECOND; this.clock.setMilliseconds(0); } @@ -35,6 +37,7 @@ GameState.prototype.create = function() spr.update_new_values(); }, this) player = this.add.sprite((19 * 32), (21 * 32), 'player'); + player.score = 0; player.lightmeter = 0; }; @@ -125,7 +128,6 @@ GameState.prototype.create = function() 20, 20, '', { font: '16px Arial', fill: '#ffffff' }, this.uigroup ); - this.score = 0; this.scoreText = this.game.add.text( SCREEN_WIDTH - 80, SCREEN_HEIGHT - 40, '', { font: '16px Arial', fill: '#ffffff' }, this.uigroup @@ -300,7 +302,7 @@ GameState.prototype.update = function() if ( this.physics.arcade.collide(x, player) ) { x.setAwarenessEffect(STATE_ALERTED); } else if ( player.lightmeter >= x.sprite_can_see_lightmeter ) { - x.setAwarenessEffect(STATE_ALERTED); + x.setAwarenessEffect(STATE_ALERTED); } else { x.setAwarenessEffect(STATE_CONCERNED); } @@ -352,7 +354,7 @@ GameState.prototype.update = function() this.fpsText.setText(game.time.fps + ' FPS'); } this.clockText.setText("" + this.clock.getHours() + ":" + this.clock.getMinutes() + ":" + this.clock.getSeconds()); - this.scoreText.setText("" + this.score); + this.scoreText.setText("" + player.score); } function Boot() diff --git a/moonlight/src/Util.js b/moonlight/src/Util.js index c820565..3100552 100644 --- a/moonlight/src/Util.js +++ b/moonlight/src/Util.js @@ -316,3 +316,18 @@ function isSet(x) function getDOMValue(name) { return document.getElementById(name).value } + +function awardPlayerScoreByState(state) +{ + switch ( state ) { + case STATE_ALERTED: { + player.score += SCORE_ALERTED; + } + case STATE_CONCERNED: { + player.score += SCORE_CONCERNED; + } + case STATE_LOSTHIM: { + player.score += SCORE_LOSTHIM; + } + } +}