Close #1 : AI now follows polyline routes on the Routes layer of the map
This commit is contained in:
@@ -291,7 +291,8 @@
|
|||||||
"sprite_facing":"left",
|
"sprite_facing":"left",
|
||||||
"sprite_group":"townsfolk-female",
|
"sprite_group":"townsfolk-female",
|
||||||
"sprite_has_treasure":"true",
|
"sprite_has_treasure":"true",
|
||||||
"sprite_name":"townsfolk-female-2"
|
"sprite_name":"townsfolk-female-2",
|
||||||
|
"sprite_route":"BigTopRoute1"
|
||||||
},
|
},
|
||||||
"type":"AI",
|
"type":"AI",
|
||||||
"visible":true,
|
"visible":true,
|
||||||
@@ -600,6 +601,71 @@
|
|||||||
"width":50,
|
"width":50,
|
||||||
"x":0,
|
"x":0,
|
||||||
"y":0
|
"y":0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"height":50,
|
||||||
|
"name":"Routes",
|
||||||
|
"objects":[
|
||||||
|
{
|
||||||
|
"height":0,
|
||||||
|
"name":"BigTopRoute1",
|
||||||
|
"polyline":[
|
||||||
|
{
|
||||||
|
"x":0,
|
||||||
|
"y":0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"x":0,
|
||||||
|
"y":128
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"x":-64,
|
||||||
|
"y":192
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"x":-64,
|
||||||
|
"y":320
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"x":96,
|
||||||
|
"y":320
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"x":96,
|
||||||
|
"y":128
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"x":128,
|
||||||
|
"y":32
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"x":128,
|
||||||
|
"y":-64
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"x":32,
|
||||||
|
"y":-64
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"x":0,
|
||||||
|
"y":0
|
||||||
|
}],
|
||||||
|
"properties":
|
||||||
|
{
|
||||||
|
|
||||||
|
},
|
||||||
|
"type":"",
|
||||||
|
"visible":true,
|
||||||
|
"width":0,
|
||||||
|
"x":640,
|
||||||
|
"y":160
|
||||||
|
}],
|
||||||
|
"opacity":1,
|
||||||
|
"type":"objectgroup",
|
||||||
|
"visible":true,
|
||||||
|
"width":50,
|
||||||
|
"x":0,
|
||||||
|
"y":0
|
||||||
}],
|
}],
|
||||||
"orientation":"orthogonal",
|
"orientation":"orthogonal",
|
||||||
"properties":
|
"properties":
|
||||||
|
|||||||
@@ -605,11 +605,33 @@ var AISprite = function(game, x, y, key, frame) {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ( game.rnd.integerInRange(0, 100) < 95 )
|
if ( isSet(this.sprite_route) == true ) {
|
||||||
return;
|
if ( this.path.length > 0 && this.path_index >= this.path.length ) {
|
||||||
this.turnUnseenDirection();
|
this.sprite_route_index += 1;
|
||||||
addState(this, STATE_MOVING);
|
if ( this.sprite_route_index >= this.sprite_route.polyline.length )
|
||||||
setSpriteMovement(this);
|
this.sprite_route_index = 0;
|
||||||
|
this.path_purge();
|
||||||
|
}
|
||||||
|
var dpoint = this.sprite_route.polyline[this.sprite_route_index];
|
||||||
|
if ( isSet(this.target) == false ) {
|
||||||
|
this.target = new Phaser.Sprite(null,
|
||||||
|
this.sprite_route.x + dpoint[0],
|
||||||
|
this.sprite_route.y + dpoint[1]);
|
||||||
|
} else {
|
||||||
|
this.target.x = this.sprite_route.x + dpoint[0];
|
||||||
|
this.target.y = this.sprite_route.y + dpoint[1];
|
||||||
|
}
|
||||||
|
this.chasetarget(this.target,
|
||||||
|
STATE_NONE,
|
||||||
|
STATE_MOVING,
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if ( game.rnd.integerInRange(0, 100) < 95 )
|
||||||
|
// return;
|
||||||
|
// this.turnUnseenDirection();
|
||||||
|
// addState(this, STATE_MOVING);
|
||||||
|
// setSpriteMovement(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.update = function()
|
this.update = function()
|
||||||
@@ -677,8 +699,9 @@ var AISprite = function(game, x, y, key, frame) {
|
|||||||
if ( this.sprite_has_treasure ) {
|
if ( this.sprite_has_treasure ) {
|
||||||
this.sprite_treasure = getRandomTreasure();
|
this.sprite_treasure = getRandomTreasure();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.path_maximum_steps = parseInt(this.path_maximum_steps);
|
this.path_maximum_steps = parseInt(this.path_maximum_steps);
|
||||||
|
if ( isSet(this.sprite_route) == true )
|
||||||
|
this.sprite_route = getRouteByName(this.sprite_route);
|
||||||
this.loadTexture(this.sprite_name, 0);
|
this.loadTexture(this.sprite_name, 0);
|
||||||
addAnimation(this, 'bipedwalkleft');
|
addAnimation(this, 'bipedwalkleft');
|
||||||
addAnimation(this, 'bipedwalkright');
|
addAnimation(this, 'bipedwalkright');
|
||||||
@@ -745,6 +768,8 @@ var AISprite = function(game, x, y, key, frame) {
|
|||||||
this.body.collideWorldBounds = true;
|
this.body.collideWorldBounds = true;
|
||||||
this.sprite_name = "townsfolk-male-1";
|
this.sprite_name = "townsfolk-male-1";
|
||||||
this.sprite_group = "townsfolk-male";
|
this.sprite_group = "townsfolk-male";
|
||||||
|
this.sprite_route = null;
|
||||||
|
this.sprite_route_index = 0;
|
||||||
this.update_new_values();
|
this.update_new_values();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -343,3 +343,13 @@ function getRandomTreasure()
|
|||||||
var treasure = treasures[game.rnd.integerInRange(0, treasures.length-1)];
|
var treasure = treasures[game.rnd.integerInRange(0, treasures.length-1)];
|
||||||
return treasure;
|
return treasure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getRouteByName(name)
|
||||||
|
{
|
||||||
|
var routes = game.state.states.game.map.collision.Routes;
|
||||||
|
for ( var i = 0 ; i < routes.length ; i++ ) {
|
||||||
|
if ( routes[i]['name'] == name )
|
||||||
|
return routes[i];
|
||||||
|
}
|
||||||
|
throw("Could not locate path " + name);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user