Made state changes in the AI affect the player score

This commit is contained in:
2014-06-28 08:48:26 -07:00
parent 6a5fa90484
commit e166d580fc
4 changed files with 26 additions and 3 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -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()

View File

@@ -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;
}
}
}