Made state changes in the AI affect the player score
This commit is contained in:
@@ -93,6 +93,7 @@ var AISprite = function(game, x, y, key, frame) {
|
|||||||
state != STATE_ALERTED ) {
|
state != STATE_ALERTED ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
awardPlayerScoreByState(state);
|
||||||
this.state_changed_at = new Phaser.Point(this.x, this.y);
|
this.state_changed_at = new Phaser.Point(this.x, this.y);
|
||||||
this.startAwarenessTimer();
|
this.startAwarenessTimer();
|
||||||
setAwarenessState(this, state);
|
setAwarenessState(this, state);
|
||||||
|
|||||||
@@ -51,3 +51,8 @@ SPRITE_TOWNSFOLK_FEMALE4 = 8;
|
|||||||
|
|
||||||
SPRITE_TOWNSFOLK_GUARD1 = 9;
|
SPRITE_TOWNSFOLK_GUARD1 = 9;
|
||||||
SPRITE_TOWNSFOLK_GUARD2 = 10;
|
SPRITE_TOWNSFOLK_GUARD2 = 10;
|
||||||
|
|
||||||
|
SCORE_PERSECOND = 1;
|
||||||
|
SCORE_LOSTHIM = 0;
|
||||||
|
SCORE_ALERTED = -50;
|
||||||
|
SCORE_CONCERNED = 0;
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ var GameState = function(game) {
|
|||||||
GameState.prototype.updateClock = function()
|
GameState.prototype.updateClock = function()
|
||||||
{
|
{
|
||||||
this.clock.setSeconds(this.clock.getSeconds() + 1);
|
this.clock.setSeconds(this.clock.getSeconds() + 1);
|
||||||
|
if ( this.clock.getSeconds() == 59)
|
||||||
|
player.score += SCORE_PERSECOND;
|
||||||
this.clock.setMilliseconds(0);
|
this.clock.setMilliseconds(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,6 +37,7 @@ GameState.prototype.create = function()
|
|||||||
spr.update_new_values();
|
spr.update_new_values();
|
||||||
}, this)
|
}, this)
|
||||||
player = this.add.sprite((19 * 32), (21 * 32), 'player');
|
player = this.add.sprite((19 * 32), (21 * 32), 'player');
|
||||||
|
player.score = 0;
|
||||||
player.lightmeter = 0;
|
player.lightmeter = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -125,7 +128,6 @@ GameState.prototype.create = function()
|
|||||||
20, 20, '', { font: '16px Arial', fill: '#ffffff' }, this.uigroup
|
20, 20, '', { font: '16px Arial', fill: '#ffffff' }, this.uigroup
|
||||||
);
|
);
|
||||||
|
|
||||||
this.score = 0;
|
|
||||||
this.scoreText = this.game.add.text(
|
this.scoreText = this.game.add.text(
|
||||||
SCREEN_WIDTH - 80, SCREEN_HEIGHT - 40, '',
|
SCREEN_WIDTH - 80, SCREEN_HEIGHT - 40, '',
|
||||||
{ font: '16px Arial', fill: '#ffffff' }, this.uigroup
|
{ font: '16px Arial', fill: '#ffffff' }, this.uigroup
|
||||||
@@ -300,7 +302,7 @@ GameState.prototype.update = function()
|
|||||||
if ( this.physics.arcade.collide(x, player) ) {
|
if ( this.physics.arcade.collide(x, player) ) {
|
||||||
x.setAwarenessEffect(STATE_ALERTED);
|
x.setAwarenessEffect(STATE_ALERTED);
|
||||||
} else if ( player.lightmeter >= x.sprite_can_see_lightmeter ) {
|
} else if ( player.lightmeter >= x.sprite_can_see_lightmeter ) {
|
||||||
x.setAwarenessEffect(STATE_ALERTED);
|
x.setAwarenessEffect(STATE_ALERTED);
|
||||||
} else {
|
} else {
|
||||||
x.setAwarenessEffect(STATE_CONCERNED);
|
x.setAwarenessEffect(STATE_CONCERNED);
|
||||||
}
|
}
|
||||||
@@ -352,7 +354,7 @@ GameState.prototype.update = function()
|
|||||||
this.fpsText.setText(game.time.fps + ' FPS');
|
this.fpsText.setText(game.time.fps + ' FPS');
|
||||||
}
|
}
|
||||||
this.clockText.setText("" + this.clock.getHours() + ":" + this.clock.getMinutes() + ":" + this.clock.getSeconds());
|
this.clockText.setText("" + this.clock.getHours() + ":" + this.clock.getMinutes() + ":" + this.clock.getSeconds());
|
||||||
this.scoreText.setText("" + this.score);
|
this.scoreText.setText("" + player.score);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Boot()
|
function Boot()
|
||||||
|
|||||||
@@ -316,3 +316,18 @@ function isSet(x)
|
|||||||
function getDOMValue(name) {
|
function getDOMValue(name) {
|
||||||
return document.getElementById(name).value
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user