#3 : Hunting behavior partially implemented, character wanders around inside a box looking for the player. Needs to stop/turn, and for some reason the state never ends.
This commit is contained in:
@@ -461,7 +461,26 @@ var AISprite = function(game, x, y, key, frame) {
|
|||||||
this.action_huntplayer = function()
|
this.action_huntplayer = function()
|
||||||
{
|
{
|
||||||
console.log("I AM HUNTING FOR THE PLAYER");
|
console.log("I AM HUNTING FOR THE PLAYER");
|
||||||
setSpriteMovement(this);
|
if ( this.path.length < 1 ||
|
||||||
|
this.path_index >= this.path.length ) {
|
||||||
|
var curmap = game.state.states.game.map;
|
||||||
|
var intgridx = parseInt(this.state_changed_at.x/32);
|
||||||
|
var intgridy = parseInt(this.state_changed_at.y/32);
|
||||||
|
var boundleft = Math.max(0, (intgridx - this.hunt_radius));
|
||||||
|
var boundtop = Math.max(0, (intgridy - this.hunt_radius));
|
||||||
|
var boundright = Math.min(curmap.width, (intgridx + this.hunt_radius));
|
||||||
|
var boundbottom = Math.min(curmap.height, (intgridy + this.hunt_radius));
|
||||||
|
var destx = game.rnd.integerInRange(boundleft, boundright);
|
||||||
|
var desty = game.rnd.integerInRange(boundtop, boundbottom);
|
||||||
|
this.target = new Phaser.Sprite(game, destx*32, desty*32, null);
|
||||||
|
}
|
||||||
|
if ( isSet(this.target) ) {
|
||||||
|
this.chasetarget(this.target,
|
||||||
|
STATE_NONE,
|
||||||
|
STATE_MOVING,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.action_wander = function()
|
this.action_wander = function()
|
||||||
@@ -523,6 +542,7 @@ var AISprite = function(game, x, y, key, frame) {
|
|||||||
this.clearWordBubble();
|
this.clearWordBubble();
|
||||||
this.state = STATE_UNAWARE;
|
this.state = STATE_UNAWARE;
|
||||||
this.state_changed_at = new Phaser.Point(this.x, this.y);
|
this.state_changed_at = new Phaser.Point(this.x, this.y);
|
||||||
|
this.hunt_radius = parseInt(this.hunt_radius);
|
||||||
this.sprite_can_see_lightmeter = Number(this.sprite_can_see_lightmeter);
|
this.sprite_can_see_lightmeter = Number(this.sprite_can_see_lightmeter);
|
||||||
this.sprite_canmove = parseBoolean(this.sprite_canmove);
|
this.sprite_canmove = parseBoolean(this.sprite_canmove);
|
||||||
this.sprite_awareness_duration = parseInt(this.sprite_awareness_duration);
|
this.sprite_awareness_duration = parseInt(this.sprite_awareness_duration);
|
||||||
@@ -567,6 +587,7 @@ var AISprite = function(game, x, y, key, frame) {
|
|||||||
this.path = [];
|
this.path = [];
|
||||||
this.state_changed_at = new Phaser.Point(this.x, this.y);
|
this.state_changed_at = new Phaser.Point(this.x, this.y);
|
||||||
this.target = null;
|
this.target = null;
|
||||||
|
this.hunt_radius = 5;
|
||||||
this.path_tweens = [];
|
this.path_tweens = [];
|
||||||
this.path_maximum_steps = 4;
|
this.path_maximum_steps = 4;
|
||||||
this.awareness_change_enabled = true;
|
this.awareness_change_enabled = true;
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
|
SCREEN_WIDTH = 640;
|
||||||
|
SCREEN_HEIGHT = 480;
|
||||||
|
|
||||||
SPEED_WALKING = 8;
|
SPEED_WALKING = 8;
|
||||||
SPEED_RUNNING = 14;
|
SPEED_RUNNING = 14;
|
||||||
|
|
||||||
// Millisecond durations per tweens, per tile
|
// Millisecond durations per tweens, per tile
|
||||||
TWEEN_DURATION_PERPIXEL_RUNNING = 5;
|
TWEEN_DURATION_PERPIXEL_RUNNING = 6;
|
||||||
TWEEN_DURATION_PERPIXEL_WALKING = 9;
|
TWEEN_DURATION_PERPIXEL_WALKING = 12;
|
||||||
TWEEN_DURATION_PERTILE_RUNNING = TWEEN_DURATION_PERPIXEL_RUNNING * 32;
|
TWEEN_DURATION_PERTILE_RUNNING = TWEEN_DURATION_PERPIXEL_RUNNING * 32;
|
||||||
TWEEN_DURATION_PERTILE_WALKING = TWEEN_DURATION_PERPIXEL_WALKING * 32;
|
TWEEN_DURATION_PERTILE_WALKING = TWEEN_DURATION_PERPIXEL_WALKING * 32;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
var pathfinder = null;
|
var pathfinder = null;
|
||||||
var pathfinder_grid = null;
|
var pathfinder_grid = null;
|
||||||
|
|
||||||
var game = new Phaser.Game(640, 480, Phaser.AUTO, '');
|
var game = new Phaser.Game(SCREEN_WIDTH, SCREEN_HEIGHT, Phaser.AUTO, '');
|
||||||
|
|
||||||
game.state.add('boot', Boot, false);
|
game.state.add('boot', Boot, false);
|
||||||
game.state.add('preloader', Preloader, false);
|
game.state.add('preloader', Preloader, false);
|
||||||
|
|||||||
Reference in New Issue
Block a user