Making townsfolk report you to a guard
This commit is contained in:
@@ -1053,32 +1053,19 @@ var AISprite = function(game, x, y, key, frame) {
|
|||||||
|
|
||||||
this.action_reportplayer = function()
|
this.action_reportplayer = function()
|
||||||
{
|
{
|
||||||
var aiSprites = game.state.states.game.aiSprites;
|
|
||||||
var nearest = null;
|
|
||||||
var lastdist = 0.0;
|
|
||||||
if ( (this.path.length < 1) || this.path_index >= this.path.length) {
|
if ( (this.path.length < 1) || this.path_index >= this.path.length) {
|
||||||
for ( var i = 0 ; i < aiSprites.length; i++ ) {
|
var aiSprites = game.state.states.game.aiSprites;
|
||||||
console.log("Checking out aiSprite[" + i + "]");
|
this.target = nearestInGroup(this, aiSprites);
|
||||||
spr = aiSprites.getChildAt(i);
|
|
||||||
console.log(spr);
|
|
||||||
if ( spr.sprite_group !== "townsfolk-guard" )
|
|
||||||
continue;
|
|
||||||
var dist = new Phaser.Line(this.x, this.y, spr.x, spr.y);
|
|
||||||
if ( (lastdist == 0.0 ) || (dist.length < lastdist) ) {
|
|
||||||
lastdist = dist;
|
|
||||||
nearest = spr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
console.log("Running to nearest for help");
|
|
||||||
console.log(nearest);
|
|
||||||
this.target = nearest;
|
|
||||||
}
|
}
|
||||||
if ( this.target !== null ) {
|
if ( this.target !== null ) {
|
||||||
if ( this.target.canSeeSprite(this) == true ) {
|
if ( this.target.canSeeSprite(this) == true ) {
|
||||||
console.log("My target can see me!");
|
console.log("My target can see me!");
|
||||||
this.path_tween_stop();
|
this.path_tween_stop();
|
||||||
this.path_purge();
|
this.path_purge();
|
||||||
|
var staticLights = game.state.states.game.staticLights;
|
||||||
|
this.target = nearestInGroup(staticLights);
|
||||||
}
|
}
|
||||||
|
var chaseState = STATE_ALERTED;
|
||||||
this.chasetarget(this.target,
|
this.chasetarget(this.target,
|
||||||
STATE_ALERTED,
|
STATE_ALERTED,
|
||||||
STATE_MOVING | STATE_RUNNING,
|
STATE_MOVING | STATE_RUNNING,
|
||||||
@@ -1200,6 +1187,7 @@ var AISprite = function(game, x, y, key, frame) {
|
|||||||
this.sprite_can_see_lightmeter = 0.3;
|
this.sprite_can_see_lightmeter = 0.3;
|
||||||
this.awareness_effect = null;
|
this.awareness_effect = null;
|
||||||
this.awareness_timer = null;
|
this.awareness_timer = null;
|
||||||
|
this.lastSawPlayerAt = null;
|
||||||
this.seen_directions = [];
|
this.seen_directions = [];
|
||||||
this.sprite_awareness_duration = 60000;
|
this.sprite_awareness_duration = 60000;
|
||||||
this.sprite_canmove = 'true';
|
this.sprite_canmove = 'true';
|
||||||
@@ -1241,6 +1229,24 @@ function positiveRectangle(x, y, w, h) {
|
|||||||
return new Phaser.Rectangle(x, y, w, h);
|
return new Phaser.Rectangle(x, y, w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function nearestInGroup(sprite, group) {
|
||||||
|
var nearest = null;
|
||||||
|
var lastdist = 0.0;
|
||||||
|
for ( var i = 0 ; i < aiSprites.length; i++ ) {
|
||||||
|
console.log("Checking out aiSprite[" + i + "]");
|
||||||
|
var spr = aiSprites.getChildAt(i);
|
||||||
|
console.log(spr);
|
||||||
|
if ( spr.sprite_group !== "townsfolk-guard" )
|
||||||
|
continue;
|
||||||
|
var dist = new Phaser.Line(sprite.x, sprite.y, spr.x, spr.y);
|
||||||
|
if ( (lastdist == 0.0 ) || (dist.length < lastdist) ) {
|
||||||
|
lastdist = dist;
|
||||||
|
nearest = spr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nearest;
|
||||||
|
}
|
||||||
|
|
||||||
function addAnimation(obj, anim)
|
function addAnimation(obj, anim)
|
||||||
{
|
{
|
||||||
a = moonlightSettings['animations'][anim]
|
a = moonlightSettings['animations'][anim]
|
||||||
@@ -1633,6 +1639,7 @@ GameState.prototype.update = function()
|
|||||||
if ( x.collide_with_player == false )
|
if ( x.collide_with_player == false )
|
||||||
return;
|
return;
|
||||||
if ( x.canSeeSprite(player, false) == true ) {
|
if ( x.canSeeSprite(player, false) == true ) {
|
||||||
|
x.lastSawPlayerAt = new Phaser.Point(player.x, player.y);
|
||||||
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 ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user