AI returns to their origin when they cant move and are in wandering state. AI gets their facing state from the map. Guards can re-encounter you while traveling back to the origin.
This commit is contained in:
@@ -277,7 +277,7 @@
|
||||
"visible":true,
|
||||
"width":0,
|
||||
"x":320,
|
||||
"y":521
|
||||
"y":512
|
||||
},
|
||||
{
|
||||
"gid":3544,
|
||||
@@ -323,8 +323,8 @@
|
||||
"type":"AI",
|
||||
"visible":true,
|
||||
"width":0,
|
||||
"x":158,
|
||||
"y":830
|
||||
"x":160,
|
||||
"y":832
|
||||
}],
|
||||
"opacity":1,
|
||||
"type":"objectgroup",
|
||||
|
||||
@@ -514,15 +514,18 @@ var AISprite = function(game, x, y, key, frame) {
|
||||
|
||||
this.action_wander = function()
|
||||
{
|
||||
var newstate = STATE_NONE;
|
||||
if ( this.sprite_canmove == false) {
|
||||
if ( this.x !== this.origin.x ||
|
||||
this.y !== this.origin.y ) {
|
||||
this.chasetarget(this.origin,
|
||||
STATE_NONE,
|
||||
STATE_MOVING,
|
||||
false,
|
||||
1000);
|
||||
false);
|
||||
} else {
|
||||
setMovingState(this, faceStateFromString(this.sprite_facing));
|
||||
this.animations.stop();
|
||||
this.animations.play(getMovingAnimationName(this));
|
||||
this.animations.stop();
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -597,7 +600,7 @@ var AISprite = function(game, x, y, key, frame) {
|
||||
addAnimation(this, 'bipedrunright');
|
||||
addAnimation(this, 'bipedrunup');
|
||||
addAnimation(this, 'bipedrundown');
|
||||
setMovingState(this, STATE_FACE_DOWN);
|
||||
setMovingState(this, faceStateFromString(this.sprite_facing));
|
||||
setSpriteMovement(this);
|
||||
this.ready_to_update = true;
|
||||
}
|
||||
@@ -620,6 +623,7 @@ var AISprite = function(game, x, y, key, frame) {
|
||||
game.physics.arcade.enable(this);
|
||||
this.body.immovable = true;
|
||||
pathfinder_grid = [];
|
||||
this.sprite_facing = "down";
|
||||
this.walkables = [];
|
||||
this.path = [];
|
||||
this.state_changed_at = new Phaser.Point(this.x, this.y);
|
||||
@@ -642,7 +646,7 @@ var AISprite = function(game, x, y, key, frame) {
|
||||
this.view_distance = 32 * 5;
|
||||
this.timer = null;
|
||||
this.rotation_timer = null;
|
||||
this.origin = new Phaser.Point(x/32, y/32);
|
||||
this.origin = new Phaser.Point(x, y);
|
||||
this.bubble_immediate = false;
|
||||
this.bubble_text = null;
|
||||
this.enable_word_bubble = false;
|
||||
|
||||
@@ -23,7 +23,7 @@ GameState.prototype.create = function()
|
||||
);
|
||||
if ( lp['inject_sprites'] == true ) {
|
||||
this.aiSprites = game.add.group();
|
||||
this.aiSprites.debug = false;
|
||||
this.aiSprites.debug = true;
|
||||
this.map.createFromObjects('AI', 3544, 'player', 0, true, false, this.aiSprites, AISprite);
|
||||
this.aiSprites.forEach(function(spr) {
|
||||
spr.update_new_values();
|
||||
@@ -285,7 +285,7 @@ GameState.prototype.update = function()
|
||||
this.aiSprites.forEach(_inner_collide, this);
|
||||
this.updateShadowTexture();
|
||||
|
||||
if ( this.aiSprites.debug == true ) {
|
||||
if ( this.aiSprites.debug == false ) {
|
||||
function _draw_viewrect(x) {
|
||||
var r = x.viewRectangle();
|
||||
if ( isSet(r) == false )
|
||||
|
||||
@@ -101,6 +101,9 @@ function nearestWalkableTile(spr)
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( grid.nodes[spr.y/32][spr.x/32].walkable == true )
|
||||
return [spr.x/32, spr.y/32];
|
||||
|
||||
for ( var i = 1 ; i < 100 ; i++ ) {
|
||||
var rv = _walkable_inner(i);
|
||||
if ( isSet(rv) ) {
|
||||
@@ -109,11 +112,7 @@ function nearestWalkableTile(spr)
|
||||
return rv
|
||||
}
|
||||
}
|
||||
//if ( multiplier >= 10 )
|
||||
console.log("Couldn't find a near walkable tile");
|
||||
console.log([spr.x / 32, spr.y / 32]);
|
||||
return [parseInt(spr.x / 32), parseInt(spr.y / 32)];
|
||||
//return nearestWalkableTile(spr, multiplier + 1);
|
||||
}
|
||||
|
||||
function addAnimation(obj, anim)
|
||||
@@ -134,6 +133,15 @@ function getAwarenessState(spr)
|
||||
return STATE_LOSTHIM;
|
||||
}
|
||||
|
||||
function faceStateFromString(face)
|
||||
{
|
||||
var states = { "up": STATE_FACE_UP,
|
||||
"down": STATE_FACE_DOWN,
|
||||
"left": STATE_FACE_LEFT,
|
||||
"right": STATE_FACE_RIGHT };
|
||||
return states[face.toLowerCase()];
|
||||
}
|
||||
|
||||
function getFaceState(spr)
|
||||
{
|
||||
if ( hasState(spr, STATE_FACE_LEFT) )
|
||||
|
||||
Reference in New Issue
Block a user