2014-06-15 23:14:20 -07:00
|
|
|
|
SPEED_WALKING = 8;
|
|
|
|
|
|
SPEED_RUNNING = 14;
|
|
|
|
|
|
|
|
|
|
|
|
// Millisecond durations per tweens, per tile
|
2014-06-18 08:55:16 -07:00
|
|
|
|
TWEEN_DURATION_PERPIXEL_RUNNING = 5;
|
|
|
|
|
|
TWEEN_DURATION_PERPIXEL_WALKING = 9;
|
2014-06-18 08:52:55 -07:00
|
|
|
|
TWEEN_DURATION_PERTILE_RUNNING = TWEEN_DURATION_PERPIXEL_RUNNING * 32;
|
|
|
|
|
|
TWEEN_DURATION_PERTILE_WALKING = TWEEN_DURATION_PERPIXEL_WALKING * 32;
|
2014-06-15 23:14:20 -07:00
|
|
|
|
|
2014-06-14 12:00:08 -07:00
|
|
|
|
STATE_NONE = 0;
|
2014-06-11 21:57:20 -07:00
|
|
|
|
STATE_UNAWARE = 1 << 1;
|
|
|
|
|
|
STATE_CONCERNED = 1 << 2;
|
|
|
|
|
|
STATE_ALERTED = 1 << 3;
|
|
|
|
|
|
STATE_LOSTHIM = 1 << 4;
|
2014-06-14 11:59:41 -07:00
|
|
|
|
|
|
|
|
|
|
STATE_RUNNING = 1 << 5;
|
|
|
|
|
|
STATE_FACE_LEFT = 1 << 6;
|
|
|
|
|
|
STATE_FACE_RIGHT = 1 << 7;
|
|
|
|
|
|
STATE_FACE_UP = 1 << 8;
|
|
|
|
|
|
STATE_FACE_DOWN = 1 << 9;
|
|
|
|
|
|
STATE_MOVING = 1 << 10;
|
|
|
|
|
|
|
2014-06-19 20:47:28 -07:00
|
|
|
|
STATE_RUNNINGTOLIGHT = 1 << 11;
|
|
|
|
|
|
|
2014-06-15 13:37:08 -07:00
|
|
|
|
STATES_AWARENESS = (STATE_UNAWARE | STATE_CONCERNED | STATE_ALERTED | STATE_LOSTHIM);
|
2014-06-14 11:59:41 -07:00
|
|
|
|
STATES_MOVEMENT = (STATE_MOVING | STATE_RUNNING);
|
|
|
|
|
|
STATES_FACE = (STATE_FACE_LEFT | STATE_FACE_RIGHT | STATE_FACE_DOWN | STATE_FACE_UP);
|
2014-06-11 22:25:47 -07:00
|
|
|
|
|
|
|
|
|
|
SPRITE_TOWNSFOLK_MALE = 1;
|
2014-06-11 22:29:49 -07:00
|
|
|
|
SPRITE_TOWNSFOLK_FEMALE = 2;
|
|
|
|
|
|
SPRITE_TOWNSFOLK_GUARD = 3;
|
2014-06-11 21:57:20 -07:00
|
|
|
|
|
|
|
|
|
|
SPRITE_TOWNSFOLK_MALE1 = 1;
|
|
|
|
|
|
SPRITE_TOWNSFOLK_MALE2 = 2;
|
|
|
|
|
|
SPRITE_TOWNSFOLK_MALE3 = 3;
|
|
|
|
|
|
SPRITE_TOWNSFOLK_MALE4 = 4;
|
2014-06-14 11:59:41 -07:00
|
|
|
|
|
2014-06-11 21:57:20 -07:00
|
|
|
|
SPRITE_TOWNSFOLK_FEMALE1 = 5;
|
|
|
|
|
|
SPRITE_TOWNSFOLK_FEMALE2 = 6;
|
|
|
|
|
|
SPRITE_TOWNSFOLK_FEMALE3 = 7;
|
|
|
|
|
|
SPRITE_TOWNSFOLK_FEMALE4 = 8;
|
2014-06-14 11:59:41 -07:00
|
|
|
|
|
2014-06-11 21:57:20 -07:00
|
|
|
|
SPRITE_TOWNSFOLK_GUARD1 = 9;
|
|
|
|
|
|
SPRITE_TOWNSFOLK_GUARD2 = 10;
|
|
|
|
|
|
|
2014-06-15 23:13:53 -07:00
|
|
|
|
var pathfinder = null;
|
2014-06-15 23:14:20 -07:00
|
|
|
|
var pathfinder_grid = null;
|
2014-06-15 23:13:53 -07:00
|
|
|
|
|
2014-06-15 21:15:01 -07:00
|
|
|
|
var game = new Phaser.Game(640, 480, Phaser.AUTO, '');
|
|
|
|
|
|
|
2014-06-12 23:18:40 -07:00
|
|
|
|
// Create torch objects
|
|
|
|
|
|
// Light constructor
|
2014-06-14 20:03:55 -07:00
|
|
|
|
var Light = function(game, x, y, key, frame, radius, fade, color_start, color_stop, flicker, always_render, light_meter) {
|
2014-06-12 23:55:02 -07:00
|
|
|
|
color_start = ( typeof color_start == undefined ? color_start : 'rgba(255, 255, 255, 1.0)');
|
2014-06-12 23:57:46 -07:00
|
|
|
|
color_stop = ( typeof color_stop == undefined ? color_stop : 'rgba(255, 255, 255, 0.0)');
|
2014-06-12 23:43:46 -07:00
|
|
|
|
fade = ( typeof fade == undefined ? fade : 0.25);
|
|
|
|
|
|
radius = ( typeof radius == undefined ? radius : 64);
|
|
|
|
|
|
flicker = ( typeof flicker == undefined ? flicker : false);
|
2014-06-13 01:20:35 -07:00
|
|
|
|
always_render = ( typeof always_render == undefined ? always_render : false);
|
2014-06-15 18:40:05 -07:00
|
|
|
|
light_meter = ( typeof light_meter == undefined ? light_meter : 1.0 );
|
2014-06-12 23:18:40 -07:00
|
|
|
|
Phaser.Sprite.call(this, game, x, y, null);
|
|
|
|
|
|
|
|
|
|
|
|
// Set the pivot point for this sprite to the center
|
|
|
|
|
|
this.anchor.setTo(0.5, 0.5);
|
2014-06-12 23:57:46 -07:00
|
|
|
|
|
2014-06-12 23:55:36 -07:00
|
|
|
|
this.color_start = color_start;
|
|
|
|
|
|
this.color_stop = color_stop;
|
2014-06-12 23:18:40 -07:00
|
|
|
|
this.radius = radius;
|
2014-06-14 20:27:00 -07:00
|
|
|
|
this.rendered_radius = radius;
|
2014-06-12 23:18:40 -07:00
|
|
|
|
this.fade = radius * fade
|
2014-06-15 18:40:05 -07:00
|
|
|
|
this.light_meter = light_meter;
|
2014-06-13 01:20:35 -07:00
|
|
|
|
this.always_render = always_render
|
2014-06-18 09:34:14 -07:00
|
|
|
|
this.rect = positiveRectangle(this.x - radius, this.y - radius, radius * 2, radius * 2)
|
2014-06-12 23:18:40 -07:00
|
|
|
|
this.flicker = flicker;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2014-06-12 23:56:22 -07:00
|
|
|
|
// Lightes are a type of Phaser.Sprite
|
|
|
|
|
|
Light.prototype = Object.create(Phaser.Sprite.prototype);
|
|
|
|
|
|
Light.prototype.constructor = Light;
|
|
|
|
|
|
|
2014-06-13 00:03:27 -07:00
|
|
|
|
Light.prototype.update_new_values = function() {
|
2014-06-15 18:41:09 -07:00
|
|
|
|
this.light_meter = Number(this.light_meter);
|
2014-06-13 00:09:43 -07:00
|
|
|
|
this.radius = parseInt(this.radius);
|
2014-06-13 00:09:01 -07:00
|
|
|
|
this.fade = this.radius * Number(this.fade);
|
2014-06-14 16:46:50 -07:00
|
|
|
|
this.flicker = parseBoolean(this.flicker);
|
|
|
|
|
|
this.always_render = parseBoolean(this.always_render);
|
2014-06-18 09:34:14 -07:00
|
|
|
|
this.rect = positiveRectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2)
|
2014-06-12 23:55:02 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-13 22:35:55 -07:00
|
|
|
|
function SoundSprite(game, x, y, key, frame,
|
|
|
|
|
|
sound_key,
|
|
|
|
|
|
sound_marker,
|
|
|
|
|
|
sound_position,
|
|
|
|
|
|
sound_volume,
|
|
|
|
|
|
sound_loop,
|
2014-06-13 23:07:01 -07:00
|
|
|
|
sound_forcerestart,
|
2014-06-15 11:53:13 -07:00
|
|
|
|
sound_distance,
|
2014-06-13 23:07:01 -07:00
|
|
|
|
sound_nofade)
|
2014-06-13 22:35:55 -07:00
|
|
|
|
{
|
|
|
|
|
|
Phaser.Sprite.call(this, game, x, y, null);
|
|
|
|
|
|
this.sound_key = sound_key;
|
|
|
|
|
|
this.sound_marker = ( typeof sound_marker == undefined ? sound_marker : '');
|
2014-06-14 00:20:53 -07:00
|
|
|
|
this.sound_volume = ( typeof sound_volume == undefined ? sound_volume : 1.0 );
|
|
|
|
|
|
this.sound_position = ( typeof sound_position == undefined ? sound_position : 1.0 );
|
|
|
|
|
|
this.sound_loop = ( typeof sound_loop == undefined ? sound_loop : true );
|
2014-06-15 12:25:44 -07:00
|
|
|
|
this.sound_forcerestart = ( typeof sound_forcerestart == undefined ? sound_forcerestart : false );
|
2014-06-15 11:53:13 -07:00
|
|
|
|
var def_distance = Math.sqrt(
|
|
|
|
|
|
Number((game.camera.width/2) * (game.camera.width/2)) +
|
|
|
|
|
|
Number((game.camera.height/2) * (game.camera.height/2))
|
|
|
|
|
|
);
|
|
|
|
|
|
this.sound_distance = ( typeof sound_distance == undefined ? sound_distance : def_distance);
|
2014-06-14 00:20:53 -07:00
|
|
|
|
this.sound_nofade = (typeof sound_nofade == undefined ? sound_nofade : false);
|
2014-06-13 22:35:55 -07:00
|
|
|
|
|
|
|
|
|
|
this.sound = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SoundSprite.prototype = Object.create(Phaser.Sprite.prototype);
|
|
|
|
|
|
SoundSprite.prototype.constructor = Light;
|
|
|
|
|
|
|
|
|
|
|
|
SoundSprite.prototype.update_new_values = function() {
|
|
|
|
|
|
if ( this.sound_key == null ) {
|
|
|
|
|
|
if ( this.sound !== null ) {
|
|
|
|
|
|
this.sound.stop();
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2014-06-14 00:20:53 -07:00
|
|
|
|
this.sound_position = parseInt(this.sound_position);
|
2014-06-15 11:53:13 -07:00
|
|
|
|
this.sound_distance = Number(this.sound_distance);
|
2014-06-14 00:19:07 -07:00
|
|
|
|
this.sound_volume = Number(this.sound_volume);
|
2014-06-14 16:46:50 -07:00
|
|
|
|
this.sound_loop = parseBoolean(this.sound_loop);
|
|
|
|
|
|
this.sound_forcerestart = parseBoolean(this.sound_forcerestart);
|
|
|
|
|
|
this.sound_nofade = parseBoolean(this.sound_nofade);
|
2014-06-14 00:19:07 -07:00
|
|
|
|
|
2014-06-15 12:11:18 -07:00
|
|
|
|
if ( this.sound !== null )
|
|
|
|
|
|
this.sound.stop();
|
2014-06-15 12:13:04 -07:00
|
|
|
|
this.sound = game.add.audio(this.sound_key, this.sound_volume, this.sound_loop);
|
2014-06-13 22:52:02 -07:00
|
|
|
|
this.sound.play(
|
2014-06-13 22:35:55 -07:00
|
|
|
|
this.sound_marker,
|
|
|
|
|
|
this.sound_position,
|
|
|
|
|
|
this.sound_volume,
|
|
|
|
|
|
this.sound_loop,
|
|
|
|
|
|
this.sound_forcerestart);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-13 23:23:28 -07:00
|
|
|
|
SoundSprite.prototype.adjust_relative_to = function(spr) {
|
|
|
|
|
|
if ( this.sound_nofade == true ) {
|
2014-06-14 00:19:07 -07:00
|
|
|
|
this.sound.volume = this.sound_volume;
|
2014-06-13 23:21:42 -07:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The volume of any given sound is equal to the length of the
|
|
|
|
|
|
// hypotenuse of a triangle drawn from the point (p) to the
|
|
|
|
|
|
// sprite in question
|
|
|
|
|
|
|
2014-06-13 23:23:28 -07:00
|
|
|
|
var xd = (spr.x - this.x);
|
2014-06-13 23:21:42 -07:00
|
|
|
|
if ( xd < 0 )
|
|
|
|
|
|
xd = -(xd);
|
2014-06-13 23:23:28 -07:00
|
|
|
|
var yd = (spr.y - this.y);
|
2014-06-13 23:21:42 -07:00
|
|
|
|
if ( yd < 0 )
|
|
|
|
|
|
yd = -(yd);
|
2014-06-13 23:41:42 -07:00
|
|
|
|
|
2014-06-15 11:53:13 -07:00
|
|
|
|
var hyp = Math.sqrt(Number(xd * xd) + Number(yd * yd));
|
2014-06-13 23:52:43 -07:00
|
|
|
|
|
2014-06-15 11:53:13 -07:00
|
|
|
|
this.sound.volume = (1.0 - Number(hyp / this.sound_distance));
|
2014-06-14 00:06:30 -07:00
|
|
|
|
// Math.max doesn't work here??
|
|
|
|
|
|
if ( this.sound.volume < 0 )
|
|
|
|
|
|
this.sound.volume = 0;
|
2014-06-13 23:56:48 -07:00
|
|
|
|
|
2014-06-13 23:21:42 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-09 22:48:39 -07:00
|
|
|
|
var moonlightSettings = {
|
|
|
|
|
|
'map' : {
|
|
|
|
|
|
'tilesets': [
|
2014-06-15 11:00:21 -07:00
|
|
|
|
{
|
|
|
|
|
|
'name': 'bigtop',
|
|
|
|
|
|
'path': 'gfx/tiles/bigtop.png'
|
|
|
|
|
|
},
|
2014-06-15 12:38:05 -07:00
|
|
|
|
{
|
|
|
|
|
|
'name': '002-Woods01',
|
|
|
|
|
|
'path': 'gfx/tiles/002-Woods01.png'
|
|
|
|
|
|
},
|
2014-06-12 21:57:03 -07:00
|
|
|
|
{
|
2014-06-12 21:58:14 -07:00
|
|
|
|
'name': '009-CastleTown01',
|
|
|
|
|
|
'path': 'gfx/tiles/009-CastleTown01.png'
|
2014-06-09 22:48:39 -07:00
|
|
|
|
},
|
2014-06-12 21:57:03 -07:00
|
|
|
|
{
|
|
|
|
|
|
'name': '010-CastleTown02',
|
2014-06-12 21:58:14 -07:00
|
|
|
|
'path': 'gfx/tiles/010-CastleTown02.png'
|
2014-06-12 21:57:03 -07:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': '025-Castle01',
|
|
|
|
|
|
'path': 'gfx/tiles/025-Castle01.png'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': '026-Castle02',
|
|
|
|
|
|
'path': 'gfx/tiles/026-Castle02.png'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': '027-Castle03',
|
|
|
|
|
|
'path': 'gfx/tiles/027-Castle03.png'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': '027-Castle03',
|
|
|
|
|
|
'path': 'gfx/tiles/027-Castle03.png'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': '028-Church01',
|
|
|
|
|
|
'path': 'gfx/tiles/028-Church01.png'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': '029-Church02',
|
|
|
|
|
|
'path': 'gfx/tiles/029-Church02.png'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': '034-Bridge01',
|
2014-06-12 21:58:14 -07:00
|
|
|
|
'path': 'gfx/tiles/034-Bridge01.png'
|
2014-06-12 21:57:03 -07:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': '035-Ruins01',
|
|
|
|
|
|
'path': 'gfx/tiles/035-Ruins01.png'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': '037-Fort01',
|
|
|
|
|
|
'path': 'gfx/tiles/037-Fort01.png'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': '038-Fort02',
|
|
|
|
|
|
'path': 'gfx/tiles/038-Fort02.png'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': '039-Tower01',
|
|
|
|
|
|
'path': 'gfx/tiles/039-Tower01.png'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': '040-Tower02',
|
|
|
|
|
|
'path': 'gfx/tiles/040-Tower02.png'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': '041-EvilCastle01',
|
|
|
|
|
|
'path': 'gfx/tiles/041-EvilCastle01.png'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': '042-EvilCastle02',
|
|
|
|
|
|
'path': 'gfx/tiles/042-EvilCastle02.png'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': '048-Sewer01',
|
|
|
|
|
|
'path': 'gfx/tiles/048-Sewer01.png'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': '004-Mountain01',
|
|
|
|
|
|
'path': 'gfx/tiles/004-Mountain01.png'
|
2014-06-13 02:37:08 -07:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': '!Door1',
|
|
|
|
|
|
'path': 'gfx/tiles/Doors.png'
|
2014-06-09 22:48:39 -07:00
|
|
|
|
}
|
|
|
|
|
|
],
|
2014-06-12 21:57:03 -07:00
|
|
|
|
'layers': {
|
|
|
|
|
|
'0 - NonCollide Base': {
|
|
|
|
|
|
'collides': false,
|
2014-06-12 23:04:33 -07:00
|
|
|
|
'collisionBetween': [0, 0],
|
2014-06-13 00:25:39 -07:00
|
|
|
|
'type': 'tiles',
|
|
|
|
|
|
'inject_sprites': false
|
2014-06-12 21:57:03 -07:00
|
|
|
|
},
|
|
|
|
|
|
'0 - Collide Base': {
|
|
|
|
|
|
'collides': true,
|
2014-06-12 23:04:33 -07:00
|
|
|
|
'collisionBetween': [0, 9999],
|
2014-06-13 00:25:39 -07:00
|
|
|
|
'type': 'tiles',
|
|
|
|
|
|
'inject_sprites': false
|
2014-06-12 21:57:03 -07:00
|
|
|
|
},
|
2014-06-12 22:19:32 -07:00
|
|
|
|
'0 - NonCollide Overlay - Pathways': {
|
2014-06-12 22:04:42 -07:00
|
|
|
|
'collides': false,
|
2014-06-12 23:04:33 -07:00
|
|
|
|
'collisionBetween': [0, 9999],
|
2014-06-13 00:25:39 -07:00
|
|
|
|
'type': 'tiles',
|
|
|
|
|
|
'inject_sprites': false
|
2014-06-12 21:57:03 -07:00
|
|
|
|
},
|
2014-06-13 02:37:08 -07:00
|
|
|
|
'0 - NonCollide Overlay - Below Player': {
|
|
|
|
|
|
'collides': false,
|
|
|
|
|
|
'collisionBetween': [0, 9999],
|
|
|
|
|
|
'type': 'tiles',
|
|
|
|
|
|
'inject_sprites': false
|
|
|
|
|
|
},
|
2014-06-12 22:17:22 -07:00
|
|
|
|
'0 - Collide Overlay - Ground Objects': {
|
2014-06-12 22:04:42 -07:00
|
|
|
|
'collides': true,
|
2014-06-12 23:04:33 -07:00
|
|
|
|
'collisionBetween': [0, 9999],
|
2014-06-13 00:25:39 -07:00
|
|
|
|
'type': 'tiles',
|
2014-06-13 00:26:50 -07:00
|
|
|
|
'inject_sprites': true
|
2014-06-12 22:18:25 -07:00
|
|
|
|
},
|
2014-06-15 12:44:12 -07:00
|
|
|
|
'0 - NonCollide Overlay - Above Player (Short)': {
|
|
|
|
|
|
'collides': false,
|
|
|
|
|
|
'collisionBetween': [0, 9999],
|
|
|
|
|
|
'type': 'tiles',
|
|
|
|
|
|
'inject_sprites': false
|
|
|
|
|
|
},
|
|
|
|
|
|
'0 - NonCollide Overlay - Above Player (Tall)': {
|
2014-06-12 22:17:22 -07:00
|
|
|
|
'collides': false,
|
2014-06-12 23:04:33 -07:00
|
|
|
|
'collisionBetween': [0, 9999],
|
2014-06-13 00:25:39 -07:00
|
|
|
|
'type': 'tiles',
|
2014-06-13 00:26:50 -07:00
|
|
|
|
'inject_sprites': false
|
2014-06-12 22:17:22 -07:00
|
|
|
|
}
|
2014-06-12 21:57:03 -07:00
|
|
|
|
},
|
2014-06-15 11:00:56 -07:00
|
|
|
|
'path': 'gfx/map.json'
|
2014-06-09 22:48:39 -07:00
|
|
|
|
},
|
2014-06-13 22:35:55 -07:00
|
|
|
|
'sounds': [
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': 'fountain',
|
|
|
|
|
|
'path': 'sfx/fountain.wav'
|
|
|
|
|
|
},
|
2014-06-14 12:48:36 -07:00
|
|
|
|
{
|
|
|
|
|
|
'name': 'fire',
|
|
|
|
|
|
'path': 'sfx/fire.ogg'
|
2014-06-15 11:00:21 -07:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': 'calliope',
|
|
|
|
|
|
'path': 'sfx/calliope.mp3'
|
2014-06-13 22:35:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
],
|
2014-06-09 22:48:39 -07:00
|
|
|
|
'images': [
|
2014-06-10 19:15:55 -07:00
|
|
|
|
{
|
2014-06-14 20:41:32 -07:00
|
|
|
|
'name': 'lightbox',
|
2014-06-14 20:39:03 -07:00
|
|
|
|
'path': 'gfx/ui/lightbox.png'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
2014-06-14 20:41:32 -07:00
|
|
|
|
'name': 'lightbar',
|
2014-06-14 20:39:03 -07:00
|
|
|
|
'path': 'gfx/ui/lightbar.png'
|
2014-06-12 01:46:05 -07:00
|
|
|
|
},
|
|
|
|
|
|
{
|
2014-06-14 10:59:00 -07:00
|
|
|
|
'name': 'wordbubble',
|
|
|
|
|
|
'path': 'gfx/effects/wordbubble.png'
|
2014-06-10 19:15:55 -07:00
|
|
|
|
}
|
2014-06-09 22:48:39 -07:00
|
|
|
|
],
|
|
|
|
|
|
'spritesheets': [
|
2014-06-14 12:38:57 -07:00
|
|
|
|
{
|
|
|
|
|
|
'name': 'flame',
|
|
|
|
|
|
'path': 'gfx/effects/flame.png',
|
|
|
|
|
|
'width': 32,
|
|
|
|
|
|
'height': 32,
|
|
|
|
|
|
'frames': 96
|
|
|
|
|
|
},
|
2014-06-15 13:37:08 -07:00
|
|
|
|
{
|
|
|
|
|
|
'name': 'balloon',
|
|
|
|
|
|
'path': 'gfx/effects/Balloon.png',
|
|
|
|
|
|
'width': 32,
|
|
|
|
|
|
'height': 32,
|
|
|
|
|
|
'frames': 80
|
2014-06-15 13:37:40 -07:00
|
|
|
|
},
|
2014-06-10 01:05:21 -07:00
|
|
|
|
{
|
|
|
|
|
|
'name': 'player',
|
|
|
|
|
|
'path': 'gfx/sprites/sprite-player.png',
|
|
|
|
|
|
'width': 32,
|
|
|
|
|
|
'height': 32,
|
|
|
|
|
|
'frames': 12
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': 'townsfolk-male-1',
|
|
|
|
|
|
'path': 'gfx/sprites/sprite-townsfolk-male-1.png',
|
|
|
|
|
|
'width': 32,
|
|
|
|
|
|
'height': 32,
|
|
|
|
|
|
'frames': 12
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': 'townsfolk-male-2',
|
|
|
|
|
|
'path': 'gfx/sprites/sprite-townsfolk-male-2.png',
|
|
|
|
|
|
'width': 32,
|
|
|
|
|
|
'height': 32,
|
|
|
|
|
|
'frames': 12
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': 'townsfolk-male-3',
|
|
|
|
|
|
'path': 'gfx/sprites/sprite-townsfolk-male-3.png',
|
|
|
|
|
|
'width': 32,
|
|
|
|
|
|
'height': 32,
|
|
|
|
|
|
'frames': 12
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': 'townsfolk-male-4',
|
|
|
|
|
|
'path': 'gfx/sprites/sprite-townsfolk-male-4.png',
|
|
|
|
|
|
'width': 32,
|
|
|
|
|
|
'height': 32,
|
|
|
|
|
|
'frames': 12
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': 'townsfolk-female-1',
|
|
|
|
|
|
'path': 'gfx/sprites/sprite-townsfolk-female-1.png',
|
|
|
|
|
|
'width': 32,
|
|
|
|
|
|
'height': 32,
|
|
|
|
|
|
'frames': 12
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': 'townsfolk-female-2',
|
|
|
|
|
|
'path': 'gfx/sprites/sprite-townsfolk-female-2.png',
|
|
|
|
|
|
'width': 32,
|
|
|
|
|
|
'height': 32,
|
|
|
|
|
|
'frames': 12
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': 'townsfolk-female-3',
|
|
|
|
|
|
'path': 'gfx/sprites/sprite-townsfolk-female-3.png',
|
|
|
|
|
|
'width': 32,
|
|
|
|
|
|
'height': 32,
|
|
|
|
|
|
'frames': 12
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': 'townsfolk-female-4',
|
|
|
|
|
|
'path': 'gfx/sprites/sprite-townsfolk-female-4.png',
|
|
|
|
|
|
'width': 32,
|
|
|
|
|
|
'height': 32,
|
|
|
|
|
|
'frames': 12
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': 'townsfolk-guard-1',
|
|
|
|
|
|
'path': 'gfx/sprites/sprite-townsfolk-guard-1.png',
|
|
|
|
|
|
'width': 32,
|
|
|
|
|
|
'height': 32,
|
|
|
|
|
|
'frames': 12
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
'name': 'townsfolk-guard-2',
|
|
|
|
|
|
'path': 'gfx/sprites/sprite-townsfolk-guard-2.png',
|
|
|
|
|
|
'width': 32,
|
|
|
|
|
|
'height': 32,
|
|
|
|
|
|
'frames': 12
|
|
|
|
|
|
}
|
|
|
|
|
|
],
|
|
|
|
|
|
'animations': {
|
2014-06-15 13:37:08 -07:00
|
|
|
|
'alerted': {
|
|
|
|
|
|
'frames': [0, 1, 2, 3, 4, 5, 6, 7],
|
2014-06-15 13:59:04 -07:00
|
|
|
|
'speed': 4,
|
2014-06-15 13:37:08 -07:00
|
|
|
|
'loop': false
|
|
|
|
|
|
},
|
|
|
|
|
|
'concerned': {
|
|
|
|
|
|
'frames': [8, 9, 10, 11, 12, 13, 14, 15],
|
2014-06-15 13:59:04 -07:00
|
|
|
|
'speed': 4,
|
2014-06-15 13:37:08 -07:00
|
|
|
|
'loop': false
|
|
|
|
|
|
},
|
|
|
|
|
|
'relieved': {
|
2014-06-15 14:07:48 -07:00
|
|
|
|
'frames': [40, 41, 42, 43, 44, 45, 46, 47],
|
2014-06-15 13:59:04 -07:00
|
|
|
|
'speed': 4,
|
2014-06-15 13:37:08 -07:00
|
|
|
|
'loop': false
|
|
|
|
|
|
},
|
|
|
|
|
|
'angry': {
|
2014-06-15 14:06:46 -07:00
|
|
|
|
'frames': [48, 49, 50, 51, 52, 53, 54, 55],
|
2014-06-15 13:59:04 -07:00
|
|
|
|
'speed': 4,
|
2014-06-15 13:37:08 -07:00
|
|
|
|
'loop': false
|
|
|
|
|
|
},
|
2014-06-10 01:05:21 -07:00
|
|
|
|
'bipedwalkdown': {
|
|
|
|
|
|
'frames': [1, 2, 0],
|
|
|
|
|
|
'speed': 4,
|
|
|
|
|
|
'loop': true
|
|
|
|
|
|
},
|
|
|
|
|
|
'bipedwalkleft': {
|
|
|
|
|
|
'frames': [4, 5, 3],
|
|
|
|
|
|
'speed': 4,
|
|
|
|
|
|
'loop': true
|
|
|
|
|
|
},
|
|
|
|
|
|
'bipedwalkright': {
|
|
|
|
|
|
'frames': [7, 8, 6],
|
|
|
|
|
|
'speed': 4,
|
|
|
|
|
|
'loop': true
|
|
|
|
|
|
},
|
|
|
|
|
|
'bipedwalkup': {
|
|
|
|
|
|
'frames': [10, 11, 9],
|
|
|
|
|
|
'speed': 4,
|
|
|
|
|
|
'loop': true
|
|
|
|
|
|
},
|
|
|
|
|
|
'bipedrundown': {
|
|
|
|
|
|
'frames': [1, 2, 0],
|
|
|
|
|
|
'speed': 12,
|
|
|
|
|
|
'loop': true
|
|
|
|
|
|
},
|
|
|
|
|
|
'bipedrunleft': {
|
|
|
|
|
|
'frames': [4, 5, 3],
|
|
|
|
|
|
'speed': 12,
|
|
|
|
|
|
'loop': true
|
|
|
|
|
|
},
|
|
|
|
|
|
'bipedrunright': {
|
|
|
|
|
|
'frames': [7, 8, 6],
|
|
|
|
|
|
'speed': 12,
|
|
|
|
|
|
'loop': true
|
|
|
|
|
|
},
|
|
|
|
|
|
'bipedrunup': {
|
|
|
|
|
|
'frames': [10, 11, 9],
|
|
|
|
|
|
'speed': 12,
|
|
|
|
|
|
'loop': true
|
2014-06-14 12:38:57 -07:00
|
|
|
|
},
|
2014-06-15 18:11:31 -07:00
|
|
|
|
'lantern_small': {
|
2014-06-15 18:12:50 -07:00
|
|
|
|
'frames': [24, 25, 26],
|
2014-06-15 18:11:31 -07:00
|
|
|
|
'speed': 6,
|
|
|
|
|
|
'loop': true
|
|
|
|
|
|
},
|
2014-06-14 12:38:57 -07:00
|
|
|
|
'campfire_small': {
|
|
|
|
|
|
'frames': [6, 7, 8],
|
|
|
|
|
|
'speed': 6,
|
|
|
|
|
|
'loop': true
|
2014-06-15 11:00:21 -07:00
|
|
|
|
},
|
|
|
|
|
|
'fire_small': {
|
|
|
|
|
|
'frames': [9, 10, 11],
|
|
|
|
|
|
'speed': 6,
|
|
|
|
|
|
'loop': true
|
2014-06-10 19:15:55 -07:00
|
|
|
|
}
|
2014-06-10 01:05:21 -07:00
|
|
|
|
}
|
2014-06-09 22:48:39 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2014-06-11 21:56:46 -07:00
|
|
|
|
var moonlightDialog = {
|
|
|
|
|
|
"status": {
|
2014-06-11 22:51:05 -07:00
|
|
|
|
"townsfolk-male" : {
|
|
|
|
|
|
"unaware" : [
|
2014-06-14 09:58:39 -07:00
|
|
|
|
"I'd rather be fishing.",
|
|
|
|
|
|
"Different day, same old stuff.",
|
|
|
|
|
|
"Oi! Where'd that trouble run\noff to now then?",
|
|
|
|
|
|
"The missus is off shoppin', and\nhere I am sittin' on\nme Jack Jones.",
|
|
|
|
|
|
"Oy I'm gonna have a butcher’s at\nthat new tailor's knickers\nhe has for sale.",
|
|
|
|
|
|
"I'm off to the pub to see the\nlads and chew the fat.",
|
|
|
|
|
|
"♪ ♫ Whistling ♪ ♫"
|
2014-06-11 21:56:46 -07:00
|
|
|
|
],
|
2014-06-11 22:51:05 -07:00
|
|
|
|
"concerned" : [
|
2014-06-14 09:58:39 -07:00
|
|
|
|
"Wha… what’s that? Who’s there?",
|
|
|
|
|
|
"Did you hear that?",
|
|
|
|
|
|
"Either I’m hearin’ things, or I\nneed to stop drinkin’ midday.",
|
|
|
|
|
|
"Oi? I don’t want no tomfoolery;\ncome out if you’re there!",
|
|
|
|
|
|
"Must be them darned kids again.",
|
|
|
|
|
|
"What’s that?",
|
|
|
|
|
|
"Did you see that?"
|
2014-06-11 22:02:11 -07:00
|
|
|
|
],
|
2014-06-11 22:51:05 -07:00
|
|
|
|
"alerted" : [
|
2014-06-14 09:58:39 -07:00
|
|
|
|
"Don't you come no closer, you hear?",
|
|
|
|
|
|
"Egads!",
|
|
|
|
|
|
"I'm getting’ outta here!",
|
|
|
|
|
|
"What's going on?!",
|
|
|
|
|
|
"Holy bejeezus!",
|
|
|
|
|
|
"Did you see that?",
|
|
|
|
|
|
"What're you doing?!",
|
|
|
|
|
|
"Get away!",
|
|
|
|
|
|
"Get away from me!",
|
|
|
|
|
|
"Stay away! I know Kung-fu! ... but\nthat would require bravery \nI don't have",
|
|
|
|
|
|
"Guards! GUARDS!"
|
2014-06-11 22:02:11 -07:00
|
|
|
|
],
|
2014-06-11 22:51:05 -07:00
|
|
|
|
"losthim" : [
|
2014-06-14 09:58:39 -07:00
|
|
|
|
"Whew. Glad that’s over.",
|
|
|
|
|
|
"I wasn’t scared!",
|
|
|
|
|
|
"Must’ve been intimidated by\nmy manly physique.",
|
|
|
|
|
|
"That’s right! Run away!",
|
|
|
|
|
|
"Aye, and don’t-cha come back!",
|
|
|
|
|
|
"Spoony Bard...",
|
|
|
|
|
|
"Bloody wanker!"
|
2014-06-11 22:02:11 -07:00
|
|
|
|
]
|
2014-06-11 21:56:46 -07:00
|
|
|
|
},
|
2014-06-11 22:51:05 -07:00
|
|
|
|
"townsfolk-female" : {
|
2014-06-11 23:43:59 -07:00
|
|
|
|
"unaware" : [
|
2014-06-14 09:58:39 -07:00
|
|
|
|
"My retro shake brings all the\nboys to the yard.",
|
|
|
|
|
|
"I'm off to get my Barnet sorted\nout. I’ll be the best looking\nlady at the gala.",
|
|
|
|
|
|
"It's always all itsy bitsy with\nthem boys at the Rub-a-Dub.",
|
|
|
|
|
|
"I need to get this shopping\nsorted out.",
|
|
|
|
|
|
"What a lovely evening. Perfect\nfor skulking, I would imagine."
|
2014-06-11 23:43:59 -07:00
|
|
|
|
],
|
|
|
|
|
|
"concerned" : [
|
2014-06-14 09:58:39 -07:00
|
|
|
|
"Wha… what’s that? Who’s there?",
|
|
|
|
|
|
"Did you hear that?",
|
|
|
|
|
|
"Martha? Is that you?",
|
|
|
|
|
|
"I don't want no tomfoolery.\nGo away!",
|
|
|
|
|
|
"What was that? This is how horror\ntheatre bits start…",
|
|
|
|
|
|
"What's that?",
|
|
|
|
|
|
"Did you see that?"
|
|
|
|
|
|
],
|
2014-06-11 23:43:59 -07:00
|
|
|
|
"alerted" : [
|
2014-06-14 09:58:39 -07:00
|
|
|
|
"Eeeek!",
|
|
|
|
|
|
"Stay away from me!",
|
|
|
|
|
|
"Guards! Guards!",
|
|
|
|
|
|
"What in the nine hells?",
|
|
|
|
|
|
"Get back or I'll swoon!",
|
|
|
|
|
|
"Help! He's after me virtue!"
|
2014-06-11 23:43:59 -07:00
|
|
|
|
],
|
|
|
|
|
|
"losthim" : [
|
2014-06-14 09:58:39 -07:00
|
|
|
|
"Good riddance! There’s too many\nmale protagonists in\ngames anyhow!",
|
|
|
|
|
|
"I sure am glad that’s over.",
|
|
|
|
|
|
"This town is going straight to hell.",
|
|
|
|
|
|
"I hope he doesn’t come back.",
|
|
|
|
|
|
"I hope he’s caught and hanged!"
|
2014-06-11 23:43:59 -07:00
|
|
|
|
]
|
2014-06-11 21:56:46 -07:00
|
|
|
|
},
|
2014-06-11 22:51:05 -07:00
|
|
|
|
"townsfolk-guard" : {
|
2014-06-11 23:43:59 -07:00
|
|
|
|
"unaware" : [
|
2014-06-14 09:58:39 -07:00
|
|
|
|
"Just doing my civic duty.",
|
|
|
|
|
|
"Good day, citizens.",
|
|
|
|
|
|
"Honor. Liberty. Justice.\nOh, and pancakes…\nI love pancakes.",
|
|
|
|
|
|
"No loitering.",
|
|
|
|
|
|
"I am the law.",
|
|
|
|
|
|
"May Evil beware and may\nGood dress warmly and\neat plenty of fresh vegetables.",
|
|
|
|
|
|
"We're sworn to protect The City."
|
2014-06-11 23:43:59 -07:00
|
|
|
|
],
|
|
|
|
|
|
"concerned" : [
|
2014-06-14 09:58:39 -07:00
|
|
|
|
"I sense law-breaking abound.",
|
|
|
|
|
|
"Did you hear something?",
|
|
|
|
|
|
"Did you see that?",
|
|
|
|
|
|
"I know you're around here\nsomewhere, rat…",
|
|
|
|
|
|
"Don't make me look for\nyou in hard-to-reach places!",
|
|
|
|
|
|
"The eyes play tricks\nlike tiny, round devils."
|
2014-06-11 23:43:59 -07:00
|
|
|
|
],
|
|
|
|
|
|
"alerted" : [
|
2014-06-14 09:58:39 -07:00
|
|
|
|
"Surrender lawbreaker!",
|
|
|
|
|
|
"Halt!",
|
|
|
|
|
|
"Halt! In the name of the… umm, er… me!",
|
|
|
|
|
|
"Prepare for justice, criminal!",
|
|
|
|
|
|
"I am justice!",
|
|
|
|
|
|
"There’s no escaping the law!",
|
|
|
|
|
|
"Surrender thief!",
|
|
|
|
|
|
"Prepare to taste steel!",
|
|
|
|
|
|
"Clear the area! Nobody\npanic! I'll catch him!"
|
2014-06-11 23:43:59 -07:00
|
|
|
|
],
|
|
|
|
|
|
"losthim" : [
|
2014-06-14 09:58:39 -07:00
|
|
|
|
"I’ll get you next time,\ncriminal scum.",
|
|
|
|
|
|
"Defeat is a harsh mistress.",
|
|
|
|
|
|
"Evil men may get away, but\njustice fights another day.",
|
|
|
|
|
|
"Wickedness flees, evading the\ncold steel of righteousness."
|
2014-06-11 23:43:59 -07:00
|
|
|
|
]
|
2014-06-11 21:56:46 -07:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
"conversations": {
|
|
|
|
|
|
"townsfolk-male": {
|
|
|
|
|
|
"townsfolk-female": [],
|
|
|
|
|
|
"townsfolk-male": [],
|
|
|
|
|
|
"townsfolk-guard": []
|
|
|
|
|
|
},
|
|
|
|
|
|
"townsfolk-female": {
|
|
|
|
|
|
"townsfolk-male": [],
|
|
|
|
|
|
"townsfolk-female": [],
|
|
|
|
|
|
"townsfolk-guard": [],
|
|
|
|
|
|
},
|
|
|
|
|
|
"townsfolk-guard": {
|
|
|
|
|
|
"townsfolk-male": [],
|
|
|
|
|
|
"townsfolk-female": [],
|
|
|
|
|
|
"townsfolk-guard": []
|
|
|
|
|
|
}
|
2014-06-14 09:58:39 -07:00
|
|
|
|
}
|
2014-06-11 21:56:46 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2014-06-15 23:14:20 -07:00
|
|
|
|
// Return new array with duplicate values removed
|
|
|
|
|
|
function array_unique(arr) {
|
|
|
|
|
|
var a = [];
|
|
|
|
|
|
var l = arr.length;
|
|
|
|
|
|
for(var i=0; i<l; i++) {
|
|
|
|
|
|
for(var j=i+1; j<l; j++) {
|
|
|
|
|
|
// If arr[i] is found later in the array
|
|
|
|
|
|
if (arr[i] === arr[j])
|
|
|
|
|
|
j = ++i;
|
|
|
|
|
|
}
|
|
|
|
|
|
a.push(arr[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
return a;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-14 09:58:39 -07:00
|
|
|
|
function stringSize(str, font)
|
|
|
|
|
|
{
|
2014-06-15 20:18:09 -07:00
|
|
|
|
var width = 0;
|
2014-06-15 19:57:42 -07:00
|
|
|
|
var height = 0;
|
2014-06-15 20:02:28 -07:00
|
|
|
|
var f = font || '12px arial';
|
|
|
|
|
|
str.split("\n").forEach(function(x) {
|
|
|
|
|
|
var o = $('<div>' + x + '</div>')
|
2014-06-15 19:57:42 -07:00
|
|
|
|
.css({'position': 'absolute', 'float': 'left', 'visibility': 'hidden', 'font': f})
|
|
|
|
|
|
.appendTo($('body'));
|
2014-06-15 20:18:09 -07:00
|
|
|
|
if ( o.width() > width )
|
|
|
|
|
|
width = o.width();
|
2014-06-15 19:57:42 -07:00
|
|
|
|
height += 5 + o.height();
|
2014-06-15 19:58:08 -07:00
|
|
|
|
o.remove();
|
2014-06-15 19:57:42 -07:00
|
|
|
|
}, this);
|
2014-06-15 20:18:09 -07:00
|
|
|
|
return [width, height];
|
2014-06-14 09:58:39 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-14 12:38:57 -07:00
|
|
|
|
var EffectSprite = function(game, x, y, key, frame, animation) {
|
|
|
|
|
|
this.update_new_values = function() {
|
|
|
|
|
|
this.animations.destroy();
|
|
|
|
|
|
this.loadTexture(this.sprite_key, 0);
|
|
|
|
|
|
addAnimation(this, this.sprite_animation);
|
2014-06-14 12:42:58 -07:00
|
|
|
|
this.animations.play(this.sprite_animation);
|
2014-06-14 12:38:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Phaser.Sprite.call(this, game, x, y, null);
|
|
|
|
|
|
game.physics.arcade.enable(this);
|
2014-06-14 12:42:21 -07:00
|
|
|
|
this.collide_with_map = true;
|
2014-06-14 12:43:39 -07:00
|
|
|
|
this.collide_with_player = false;
|
2014-06-14 12:38:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-14 12:40:00 -07:00
|
|
|
|
EffectSprite.prototype = Object.create(Phaser.Sprite.prototype);
|
|
|
|
|
|
EffectSprite.prototype.constructor = EffectSprite;
|
|
|
|
|
|
|
2014-06-13 02:00:30 -07:00
|
|
|
|
var AISprite = function(game, x, y, key, frame) {
|
2014-06-14 16:17:08 -07:00
|
|
|
|
this.viewRectangle = function() {
|
2014-06-15 15:20:24 -07:00
|
|
|
|
var offset = [];
|
|
|
|
|
|
var size = [];
|
2014-06-18 16:28:41 -07:00
|
|
|
|
var multiplier = 1.0;
|
|
|
|
|
|
if ( hasState(this, STATE_ALERTED) ) {
|
|
|
|
|
|
multiplier = 2.0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-14 14:54:33 -07:00
|
|
|
|
if ( hasState(this, STATE_FACE_LEFT) ) {
|
2014-06-19 08:06:15 -07:00
|
|
|
|
offset = [0, -32 * multiplier];
|
2014-06-15 15:20:24 -07:00
|
|
|
|
size = [-this.view_distance, 96];
|
2014-06-14 14:54:33 -07:00
|
|
|
|
} else if ( hasState(this, STATE_FACE_RIGHT) ) {
|
2014-06-19 08:06:15 -07:00
|
|
|
|
offset = [32, -32 * multiplier];
|
2014-06-15 15:20:24 -07:00
|
|
|
|
size = [32 + this.view_distance, 96];
|
2014-06-14 14:54:33 -07:00
|
|
|
|
} else if ( hasState(this, STATE_FACE_DOWN) ) {
|
2014-06-19 08:06:15 -07:00
|
|
|
|
offset = [-32 * multiplier, 32];
|
2014-06-15 15:20:24 -07:00
|
|
|
|
size = [96, this.view_distance];
|
2014-06-14 15:36:11 -07:00
|
|
|
|
} else if ( hasState(this, STATE_FACE_UP) ) {
|
2014-06-19 08:06:15 -07:00
|
|
|
|
offset = [-32 * multiplier, 0];
|
2014-06-15 15:20:24 -07:00
|
|
|
|
size = [96, -this.view_distance];
|
2014-06-14 16:38:58 -07:00
|
|
|
|
} else {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2014-06-18 16:28:41 -07:00
|
|
|
|
size[0] *= multiplier;
|
|
|
|
|
|
size[1] *= multiplier;
|
2014-06-18 09:34:14 -07:00
|
|
|
|
return positiveRectangle(this.x + offset[0],
|
|
|
|
|
|
this.y + offset[1],
|
|
|
|
|
|
size[0],
|
|
|
|
|
|
size[1]);
|
2014-06-14 16:38:58 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.canSeeSprite = function(spr, debug) {
|
2014-06-17 23:17:51 -07:00
|
|
|
|
var vd = this.view_distance;
|
2014-06-18 09:09:56 -07:00
|
|
|
|
if ( hasState(this, STATE_FACE_LEFT) ||
|
|
|
|
|
|
hasState(this, STATE_FACE_UP) ) {
|
|
|
|
|
|
// Without this the player can stand in our view distance
|
|
|
|
|
|
// but as long as their left edge is 1 px out we won't see them,
|
|
|
|
|
|
// with this we see their near edge
|
|
|
|
|
|
vd = vd + 32;
|
|
|
|
|
|
}
|
2014-06-17 23:18:29 -07:00
|
|
|
|
if ( hasState(this, STATE_ALERTED) )
|
2014-06-17 23:17:51 -07:00
|
|
|
|
vd = vd * 2;
|
|
|
|
|
|
|
2014-06-17 23:27:33 -07:00
|
|
|
|
var distance = (new Phaser.Line(spr.x, spr.y, this.x, this.y).length);
|
|
|
|
|
|
if ( distance > vd ) {
|
2014-06-14 16:38:58 -07:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var viewrect = this.viewRectangle();
|
2014-06-17 22:43:10 -07:00
|
|
|
|
if ( viewrect == null ) {
|
2014-06-14 16:38:58 -07:00
|
|
|
|
return false;
|
2014-06-17 22:43:10 -07:00
|
|
|
|
}
|
2014-06-18 09:34:14 -07:00
|
|
|
|
var sprrect = positiveRectangle(spr.x, spr.y, 32, 32);
|
2014-06-14 16:38:58 -07:00
|
|
|
|
if ( viewrect.intersects(sprrect) || viewrect.containsRect(sprrect) ) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-15 15:45:29 -07:00
|
|
|
|
this.enableAwarenessChange = function(state) {
|
|
|
|
|
|
this.awareness_change_enabled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-15 15:58:51 -07:00
|
|
|
|
this.startAwarenessTimer = function() {
|
|
|
|
|
|
this.awareness_change_enabled = false;
|
|
|
|
|
|
if ( this.awareness_timer !== null )
|
|
|
|
|
|
this.awareness_timer.stop();
|
|
|
|
|
|
this.awareness_timer = game.time.create(false);
|
|
|
|
|
|
this.awareness_timer.add(this.sprite_awareness_duration,
|
|
|
|
|
|
this.enableAwarenessChange,
|
|
|
|
|
|
this);
|
|
|
|
|
|
this.awareness_timer.start()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-15 13:37:08 -07:00
|
|
|
|
this.setAwarenessEffect = function(state) {
|
|
|
|
|
|
var animkey = "";
|
2014-06-15 14:13:24 -07:00
|
|
|
|
|
2014-06-15 19:45:35 -07:00
|
|
|
|
if ( hasState(this, state) == true ) {
|
|
|
|
|
|
// restart the awareness timer
|
|
|
|
|
|
this.startAwarenessTimer();
|
|
|
|
|
|
return;
|
|
|
|
|
|
} else if ( (state == STATE_LOSTHIM) &&
|
2014-06-15 15:27:21 -07:00
|
|
|
|
(hasState(this, STATE_ALERTED) == false) &&
|
|
|
|
|
|
(hasState(this, STATE_CONCERNED) == false) ) {
|
2014-06-15 14:16:19 -07:00
|
|
|
|
return;
|
2014-06-15 15:24:02 -07:00
|
|
|
|
}
|
2014-06-15 15:27:21 -07:00
|
|
|
|
|
2014-06-15 15:45:29 -07:00
|
|
|
|
if ( this.awareness_change_enabled == false &&
|
|
|
|
|
|
state != STATE_ALERTED ) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2014-06-15 15:58:51 -07:00
|
|
|
|
this.startAwarenessTimer();
|
2014-06-15 15:52:37 -07:00
|
|
|
|
setAwarenessState(this, state);
|
|
|
|
|
|
|
2014-06-15 13:39:55 -07:00
|
|
|
|
if ( this.awareness_effect !== null ) {
|
|
|
|
|
|
this.awareness_effect.alive = false;
|
|
|
|
|
|
this.awareness_effect.destroy();
|
|
|
|
|
|
this.awareness_effect = null;
|
|
|
|
|
|
}
|
2014-06-15 13:37:08 -07:00
|
|
|
|
if ( state == STATE_ALERTED ) {
|
|
|
|
|
|
animkey = "alerted";
|
|
|
|
|
|
} else if ( state == STATE_CONCERNED ) {
|
|
|
|
|
|
animkey = "concerned";
|
|
|
|
|
|
} else if ( state == STATE_LOSTHIM ) {
|
2014-06-15 14:02:48 -07:00
|
|
|
|
if ( this.sprite_group == "townsfolk-guard" ) {
|
2014-06-15 13:37:08 -07:00
|
|
|
|
animkey = "angry";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
animkey = "relieved";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( animkey == "" )
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2014-06-15 18:55:34 -07:00
|
|
|
|
this.bubble_immediate = true;
|
2014-06-15 13:37:08 -07:00
|
|
|
|
this.clearWordBubble();
|
|
|
|
|
|
this.awareness_effect = game.state.states.game.add.sprite(
|
|
|
|
|
|
this.x + 16,
|
|
|
|
|
|
this.y - 16,
|
|
|
|
|
|
'balloon');
|
2014-06-15 13:44:40 -07:00
|
|
|
|
addAnimation(this.awareness_effect, animkey);
|
2014-06-15 13:37:08 -07:00
|
|
|
|
this.awareness_effect.play(animkey, null, false, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-14 16:38:58 -07:00
|
|
|
|
this.enableWordBubble = function() {
|
|
|
|
|
|
this.enable_word_bubble = true;
|
|
|
|
|
|
this.timer = game.time.create(false);
|
2014-06-15 18:55:34 -07:00
|
|
|
|
if ( this.bubble_immediate == true ) {
|
|
|
|
|
|
this.bubble_immediate = false;
|
|
|
|
|
|
this.setWordBubble();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
var timerdelta = 10000 + (game.rnd.integerInRange(0, 20) * 1000);
|
|
|
|
|
|
timerev = this.timer.add(timerdelta, this.setWordBubble, this);
|
|
|
|
|
|
this.timer.start()
|
|
|
|
|
|
}
|
2014-06-14 16:38:58 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.clearWordBubble = function() {
|
|
|
|
|
|
if ( this.bubble_text !== null )
|
|
|
|
|
|
this.clear_bubble = true;
|
|
|
|
|
|
this.enable_word_bubble = false;
|
|
|
|
|
|
this.timer = game.time.create(false);
|
|
|
|
|
|
timerev = this.timer.add(1000, this.enableWordBubble, this);
|
|
|
|
|
|
this.timer.start()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.setWordBubble = function()
|
|
|
|
|
|
{
|
2014-06-15 18:55:34 -07:00
|
|
|
|
if ( this.bubble_text !== null ||
|
|
|
|
|
|
this.sprite_group == undefined ||
|
|
|
|
|
|
this.enable_world_bubble == false) {
|
2014-06-14 16:38:58 -07:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
aistate = this.state & ( STATE_UNAWARE | STATE_CONCERNED | STATE_ALERTED | STATE_LOSTHIM );
|
|
|
|
|
|
switch ( aistate ) {
|
|
|
|
|
|
case STATE_UNAWARE: {
|
|
|
|
|
|
aistate = "unaware";
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
case STATE_CONCERNED: {
|
|
|
|
|
|
aistate = "concerned";
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
case STATE_ALERTED: {
|
|
|
|
|
|
aistate = "alerted";
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
case STATE_LOSTHIM: {
|
|
|
|
|
|
aistate = "losthim";
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var mylines = moonlightDialog['status'][this.sprite_group][aistate];
|
2014-06-15 19:20:00 -07:00
|
|
|
|
bubbleimg = game.cache.getImage('wordbubble');
|
2014-06-15 20:19:16 -07:00
|
|
|
|
text = mylines[game.rnd.integerInRange(0, mylines.length-1)];
|
2014-06-14 16:38:58 -07:00
|
|
|
|
style = {font: '14px Arial Bold', fill: '#ffffff'}
|
|
|
|
|
|
this.text_size = stringSize(text, style['font']);
|
2014-06-15 19:41:05 -07:00
|
|
|
|
this.bubble_sprite = game.add.sprite(this.x, this.y, 'wordbubble');
|
2014-06-15 19:18:50 -07:00
|
|
|
|
this.bubble_sprite.anchor.setTo(0.5, 1.0);
|
2014-06-15 19:39:09 -07:00
|
|
|
|
this.bubble_sprite.scale.x = Number((this.text_size[0] + 16) / bubbleimg.width);
|
|
|
|
|
|
this.bubble_sprite.scale.y = Number((this.text_size[1] + 16) / bubbleimg.height);
|
2014-06-15 19:41:05 -07:00
|
|
|
|
this.bubble_text = game.add.text(this.x, this.y, text, style);
|
2014-06-14 16:38:58 -07:00
|
|
|
|
this.snap_bubble_position();
|
|
|
|
|
|
|
|
|
|
|
|
this.timer = game.time.create(false);
|
|
|
|
|
|
timerev = this.timer.add(5000, this.clearWordBubble, this);
|
|
|
|
|
|
this.timer.start()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.snap_bubble_position = function()
|
|
|
|
|
|
{
|
|
|
|
|
|
this.bubble_sprite.x = this.x + 16;
|
2014-06-15 19:33:58 -07:00
|
|
|
|
this.bubble_sprite.y = this.y;
|
2014-06-15 19:37:23 -07:00
|
|
|
|
var tx = this.bubble_sprite.x - (this.text_size[0]/2);
|
2014-06-15 19:41:41 -07:00
|
|
|
|
var ty = this.bubble_sprite.y - (this.bubble_sprite.height) + 8;
|
2014-06-15 19:33:58 -07:00
|
|
|
|
this.bubble_text.position.x = tx;
|
|
|
|
|
|
this.bubble_text.position.y = ty;
|
2014-06-14 16:38:58 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-15 23:14:20 -07:00
|
|
|
|
this.blocked = function() {
|
|
|
|
|
|
function f() {
|
|
|
|
|
|
if ( hasState(this, STATE_FACE_LEFT) &&
|
|
|
|
|
|
this.body.blocked.left == true )
|
|
|
|
|
|
return true;
|
|
|
|
|
|
if ( hasState(this, STATE_FACE_RIGHT) &&
|
|
|
|
|
|
this.body.blocked.right == true )
|
|
|
|
|
|
return true;
|
|
|
|
|
|
if ( hasState(this, STATE_FACE_DOWN) &&
|
|
|
|
|
|
this.body.blocked.down == true )
|
|
|
|
|
|
return true;
|
|
|
|
|
|
if ( hasState(this, STATE_FACE_UP) &&
|
|
|
|
|
|
this.body.blocked.up == true )
|
|
|
|
|
|
return true;
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return f();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-17 23:34:45 -07:00
|
|
|
|
this.path_purge = function() {
|
|
|
|
|
|
this.path = [];
|
|
|
|
|
|
this.path_index = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-19 20:37:25 -07:00
|
|
|
|
this.path_set = function(target, force, maxsteps) {
|
|
|
|
|
|
maxsteps = (typeof maxsteps == undefined ? this.path_maximum_steps : maxsteps);
|
2014-06-15 23:14:20 -07:00
|
|
|
|
force = ( typeof force == undefined ? false : force );
|
|
|
|
|
|
if ( force == false &&
|
|
|
|
|
|
this.path.length > 0 &&
|
2014-06-19 20:37:25 -07:00
|
|
|
|
this.path_index < this.path.length ) {
|
2014-06-15 23:14:20 -07:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2014-06-17 23:34:45 -07:00
|
|
|
|
this.path_purge();
|
2014-06-15 23:14:20 -07:00
|
|
|
|
tpath = pathfinder.findPath(
|
|
|
|
|
|
parseInt(this.x/32),
|
|
|
|
|
|
parseInt(this.y/32),
|
|
|
|
|
|
parseInt(target.x/32),
|
|
|
|
|
|
parseInt(target.y/32),
|
|
|
|
|
|
pathfinder_grid.clone()
|
|
|
|
|
|
);
|
|
|
|
|
|
prevpoint = [this.x, this.y];
|
2014-06-19 20:37:25 -07:00
|
|
|
|
for ( var i = 0 ; i < Math.min(maxsteps, tpath.length) ; i++ ) {
|
2014-06-15 23:14:20 -07:00
|
|
|
|
if ( (prevpoint[0]+prevpoint[1]) == ((tpath[i][0]*32)+(tpath[i][1]*32)) )
|
|
|
|
|
|
continue;
|
|
|
|
|
|
this.path.push(new Phaser.Line(prevpoint[0], prevpoint[1],
|
|
|
|
|
|
tpath[i][0]*32, tpath[i][1]*32));
|
|
|
|
|
|
prevpoint = [tpath[i][0]*32, tpath[i][1]*32];
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-19 17:30:52 -07:00
|
|
|
|
this.path_tween_start = function(movingstate)
|
2014-06-15 23:14:20 -07:00
|
|
|
|
{
|
2014-06-19 17:33:51 -07:00
|
|
|
|
movingState = (typeof movementState == undefined ? movementState : (STATE_MOVING | STATE_RUNNING));
|
2014-06-15 23:14:20 -07:00
|
|
|
|
this.path_tweens = [];
|
|
|
|
|
|
prevpos = [this.x, this.y]
|
|
|
|
|
|
for ( var i = 0;
|
2014-06-19 20:38:54 -07:00
|
|
|
|
i < this.path.length ;
|
2014-06-15 23:14:20 -07:00
|
|
|
|
i++ ) {
|
|
|
|
|
|
pl = this.path[i];
|
2014-06-18 08:50:37 -07:00
|
|
|
|
movingstate = STATE_MOVING | STATE_RUNNING;
|
2014-06-15 23:14:20 -07:00
|
|
|
|
if ( pl.end.x < prevpos[0]) {
|
|
|
|
|
|
movingstate = movingstate | STATE_FACE_LEFT;
|
|
|
|
|
|
} else if ( pl.end.x > prevpos[0] ) {
|
|
|
|
|
|
movingstate = movingstate | STATE_FACE_RIGHT;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( pl.end.y < prevpos[1] ) {
|
|
|
|
|
|
movingstate = movingstate | STATE_FACE_UP;
|
|
|
|
|
|
} else if ( pl.end.y > prevpos[1] ) {
|
|
|
|
|
|
movingstate = movingstate | STATE_FACE_DOWN;
|
|
|
|
|
|
}
|
|
|
|
|
|
prevpos = [pl.end.x, pl.end.y];
|
|
|
|
|
|
tween = game.add.tween(this);
|
|
|
|
|
|
tween.movingstate = movingstate;
|
|
|
|
|
|
this.path_tweens.push(tween);
|
|
|
|
|
|
tween.to(
|
|
|
|
|
|
{x: (pl.end.x), y: (pl.end.y)},
|
2014-06-18 08:51:51 -07:00
|
|
|
|
(TWEEN_DURATION_PERPIXEL_RUNNING * pl.length),
|
2014-06-15 23:14:20 -07:00
|
|
|
|
null);
|
|
|
|
|
|
tween.onStart.add(function() {
|
|
|
|
|
|
setMovingState(this._object, this.movingstate);
|
2014-06-18 16:39:42 -07:00
|
|
|
|
this._object.animations.play("bipedrun" + spriteFacing(this._object));
|
2014-06-15 23:14:20 -07:00
|
|
|
|
}, tween);
|
|
|
|
|
|
tween.onComplete.add(function() {
|
|
|
|
|
|
this._object.path_index += 1;
|
|
|
|
|
|
setMovingState(this._object, getFaceState(this._object));
|
2014-06-18 16:39:42 -07:00
|
|
|
|
this._object.animations.play("bipedrun" + spriteFacing(this._object));
|
|
|
|
|
|
this._object.animations.stop();
|
2014-06-15 23:14:20 -07:00
|
|
|
|
}, tween);
|
|
|
|
|
|
if ( i > 0 ) {
|
|
|
|
|
|
this.path_tweens[i-1].onComplete.add(tween.start,
|
|
|
|
|
|
tween);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( this.path_tweens.length > 0 )
|
|
|
|
|
|
this.path_tweens[0].start();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.path_tween_stop = function()
|
|
|
|
|
|
{
|
|
|
|
|
|
this.path_tweens.forEach(function(x) {
|
|
|
|
|
|
x.stop();
|
|
|
|
|
|
game.tweens.remove(x);
|
|
|
|
|
|
}, this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-19 07:58:04 -07:00
|
|
|
|
this.turnUnseenDirection = function() {
|
|
|
|
|
|
if ( this.seen_directions.length >= 4 )
|
|
|
|
|
|
this.seen_directions = [];
|
|
|
|
|
|
var directions = [STATE_FACE_DOWN, STATE_FACE_LEFT,
|
|
|
|
|
|
STATE_FACE_RIGHT, STATE_FACE_UP];
|
|
|
|
|
|
var newdirection = directions[game.rnd.integerInRange(0, 3)];
|
|
|
|
|
|
while ( this.seen_directions.indexOf(newdirection) !== -1 ) {
|
|
|
|
|
|
newdirection = directions[game.rnd.integerInRange(0, 3)];
|
2014-06-18 09:02:38 -07:00
|
|
|
|
}
|
2014-06-19 07:58:04 -07:00
|
|
|
|
setMovingState(this, newdirection);
|
2014-06-18 16:44:01 -07:00
|
|
|
|
this.animations.stop();
|
2014-06-18 16:45:51 -07:00
|
|
|
|
this.animations.play("bipedrun" + spriteFacing(this));
|
2014-06-18 16:44:01 -07:00
|
|
|
|
this.animations.stop();
|
2014-06-19 08:23:50 -07:00
|
|
|
|
if ( this.rotation_timer !== null ) {
|
|
|
|
|
|
this.rotation_timer.stop();
|
|
|
|
|
|
this.rotation_timer = null;
|
|
|
|
|
|
}
|
2014-06-18 09:02:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-19 20:37:25 -07:00
|
|
|
|
this.chasetarget = function(target, alertedState, movingstate, visual, maxsteps)
|
2014-06-14 16:38:58 -07:00
|
|
|
|
{
|
2014-06-19 17:39:25 -07:00
|
|
|
|
alertedState = (typeof alertedState == undefined ? STATE_ALERTED : alertedState);
|
|
|
|
|
|
visual = (typeof visual == undefined ? false : visual);
|
|
|
|
|
|
movingstate = (typeof alertedState == undefined ? STATE_NONE : movingstate);
|
2014-06-19 17:30:52 -07:00
|
|
|
|
if ( game.physics.arcade.collide(this, target) )
|
2014-06-15 23:14:20 -07:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if ( this.path_index >= this.path.length ) {
|
|
|
|
|
|
this.path_tween_stop();
|
2014-06-19 17:30:52 -07:00
|
|
|
|
if ( (visual == false) || (this.canSeeSprite(target, false) == true )) {
|
|
|
|
|
|
this.setAwarenessEffect(alertedState);
|
2014-06-19 20:37:25 -07:00
|
|
|
|
this.path_set(target, true, maxsteps);
|
2014-06-19 17:30:52 -07:00
|
|
|
|
this.path_tween_start(movingstate);
|
2014-06-17 21:06:56 -07:00
|
|
|
|
} else {
|
2014-06-18 09:04:37 -07:00
|
|
|
|
if ( this.rotation_timer == null ) {
|
|
|
|
|
|
this.rotation_timer = game.time.create(false);
|
2014-06-19 08:03:54 -07:00
|
|
|
|
timerev = this.rotation_timer.add(250, this.turnUnseenDirection, this);
|
2014-06-18 09:04:37 -07:00
|
|
|
|
this.rotation_timer.start()
|
|
|
|
|
|
}
|
2014-06-17 21:02:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2014-06-19 20:37:25 -07:00
|
|
|
|
if ( this.path_set(target, this.blocked(true), maxsteps) == true ) {
|
2014-06-19 17:30:52 -07:00
|
|
|
|
if ( (visual == false) || (this.canSeeSprite(target, false) == false )) {
|
2014-06-17 23:34:45 -07:00
|
|
|
|
this.path_purge();
|
2014-06-17 21:02:19 -07:00
|
|
|
|
this.path_tween_stop();
|
|
|
|
|
|
} else {
|
2014-06-19 17:30:52 -07:00
|
|
|
|
this.setAwarenessEffect(alertedState);
|
|
|
|
|
|
this.path_tween_start(movingstate);
|
2014-06-17 21:02:19 -07:00
|
|
|
|
}
|
2014-06-17 22:41:28 -07:00
|
|
|
|
}
|
2014-06-15 23:13:53 -07:00
|
|
|
|
}
|
2014-06-19 17:30:52 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.action_chaseplayer = function()
|
|
|
|
|
|
{
|
2014-06-19 17:35:09 -07:00
|
|
|
|
this.chasetarget(player,
|
|
|
|
|
|
STATE_ALERTED,
|
|
|
|
|
|
STATE_MOVING | STATE_RUNNING,
|
|
|
|
|
|
true);
|
2014-06-15 23:14:20 -07:00
|
|
|
|
return;
|
2014-06-15 22:15:07 -07:00
|
|
|
|
}
|
2014-06-14 16:38:58 -07:00
|
|
|
|
|
2014-06-15 22:15:07 -07:00
|
|
|
|
this.action_reportplayer = function()
|
|
|
|
|
|
{
|
2014-06-19 17:49:26 -07:00
|
|
|
|
if ( (this.path.length < 1) || this.path_index >= this.path.length) {
|
2014-06-19 20:14:12 -07:00
|
|
|
|
var aiSprites = game.state.states.game.aiSprites;
|
2014-06-19 20:33:30 -07:00
|
|
|
|
this.target = nearestInGroup(this, aiSprites, "townsfolk-guard");
|
2014-06-19 17:49:26 -07:00
|
|
|
|
}
|
2014-06-19 19:33:57 -07:00
|
|
|
|
if ( this.target !== null ) {
|
2014-06-19 20:47:28 -07:00
|
|
|
|
if ( (this.target.canSeeSprite(this) == true) ||
|
|
|
|
|
|
(game.physics.arcade.collide(this, this.target) == true) ) {
|
|
|
|
|
|
if ( hasState(this, STATE_RUNNINGTOLIGHT) == true ) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.log("My target can see me!");
|
|
|
|
|
|
this.path_tween_stop();
|
|
|
|
|
|
this.path_purge();
|
|
|
|
|
|
var staticLights = game.state.states.game.staticLights;
|
|
|
|
|
|
this.target = nearestInGroup(this, staticLights);
|
|
|
|
|
|
console.log("Running to the nearest light");
|
|
|
|
|
|
console.log(this.target);
|
|
|
|
|
|
addState(this, STATE_RUNNINGTOLIGHT);
|
|
|
|
|
|
}
|
2014-06-19 19:33:57 -07:00
|
|
|
|
}
|
2014-06-19 20:02:43 -07:00
|
|
|
|
this.chasetarget(this.target,
|
2014-06-19 20:37:25 -07:00
|
|
|
|
STATE_ALERTED,
|
2014-06-19 20:30:47 -07:00
|
|
|
|
STATE_MOVING | STATE_RUNNING,
|
2014-06-19 20:37:25 -07:00
|
|
|
|
false,
|
|
|
|
|
|
1000);
|
2014-06-19 19:33:57 -07:00
|
|
|
|
}
|
2014-06-15 22:15:07 -07:00
|
|
|
|
}
|
2014-06-15 13:37:08 -07:00
|
|
|
|
|
2014-06-15 22:15:07 -07:00
|
|
|
|
this.action_huntplayer = function()
|
|
|
|
|
|
{
|
|
|
|
|
|
console.log("I AM HUNTING FOR THE PLAYER");
|
2014-06-15 23:14:20 -07:00
|
|
|
|
setSpriteMovement(this);
|
2014-06-15 22:15:07 -07:00
|
|
|
|
}
|
2014-06-14 16:38:58 -07:00
|
|
|
|
|
2014-06-15 22:15:07 -07:00
|
|
|
|
this.action_wander = function()
|
|
|
|
|
|
{
|
2014-06-15 22:19:14 -07:00
|
|
|
|
var newstate = STATE_NONE;
|
2014-06-15 13:00:57 -07:00
|
|
|
|
if ( this.sprite_canmove == false) {
|
2014-06-14 16:38:58 -07:00
|
|
|
|
return;
|
2014-06-15 13:00:57 -07:00
|
|
|
|
}
|
2014-06-14 16:38:58 -07:00
|
|
|
|
if ( game.rnd.integerInRange(0, 100) < 95 )
|
|
|
|
|
|
return;
|
2014-06-19 08:15:17 -07:00
|
|
|
|
this.turnUnseenDirection();
|
2014-06-19 17:30:52 -07:00
|
|
|
|
addState(this, STATE_MOVING);
|
|
|
|
|
|
setSpriteMovement(this);
|
2014-06-15 22:15:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.update = function()
|
|
|
|
|
|
{
|
2014-06-19 08:19:52 -07:00
|
|
|
|
if ( this.ready_to_update == false )
|
|
|
|
|
|
return;
|
2014-06-15 22:15:07 -07:00
|
|
|
|
if ( this.awareness_effect !== null ) {
|
|
|
|
|
|
if ( this.awareness_effect.alive == false ) {
|
|
|
|
|
|
this.awareness_effect.destroy();
|
|
|
|
|
|
this.awareness_effect = null;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.awareness_effect.x = this.x + 16;
|
|
|
|
|
|
this.awareness_effect.y = this.y - 16;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( this.bubble_text !== null ) {
|
|
|
|
|
|
if ( this.clear_bubble == true ) {
|
|
|
|
|
|
this.bubble_text.destroy();
|
|
|
|
|
|
this.bubble_sprite.destroy();
|
|
|
|
|
|
this.bubble_text = null;
|
|
|
|
|
|
this.bubble_sprite = null;
|
|
|
|
|
|
this.clear_bubble = false;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.snap_bubble_position();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( hasState(this, STATE_ALERTED) ) {
|
|
|
|
|
|
if ( this.sprite_group == "townsfolk-guard" ) {
|
|
|
|
|
|
this.action_chaseplayer();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.action_reportplayer();
|
|
|
|
|
|
}
|
2014-06-15 22:22:17 -07:00
|
|
|
|
} else if ( hasAnyState(this, [STATE_CONCERNED, STATE_LOSTHIM]) ) {
|
2014-06-15 22:15:07 -07:00
|
|
|
|
this.action_huntplayer();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.action_wander();
|
|
|
|
|
|
}
|
2014-06-14 16:38:58 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.update_new_values = function() {
|
|
|
|
|
|
if ( this.timer !== null )
|
|
|
|
|
|
this.timer.stop();
|
|
|
|
|
|
this.animations.destroy();
|
2014-06-13 01:57:06 -07:00
|
|
|
|
this.clearWordBubble();
|
|
|
|
|
|
this.state = STATE_UNAWARE;
|
2014-06-15 15:20:24 -07:00
|
|
|
|
this.sprite_can_see_lightmeter = Number(this.sprite_can_see_lightmeter);
|
2014-06-15 12:53:45 -07:00
|
|
|
|
this.sprite_canmove = parseBoolean(this.sprite_canmove);
|
2014-06-15 15:45:29 -07:00
|
|
|
|
this.sprite_awareness_duration = parseInt(this.sprite_awareness_duration);
|
2014-06-14 16:46:50 -07:00
|
|
|
|
this.collide_with_player = parseBoolean(this.collide_with_player);
|
|
|
|
|
|
this.collide_with_map = parseBoolean(this.collide_with_map);
|
|
|
|
|
|
this.carries_light = parseBoolean(this.carries_light);
|
2014-06-13 02:20:02 -07:00
|
|
|
|
|
2014-06-15 23:14:20 -07:00
|
|
|
|
this.path_maximum_steps = parseInt(this.path_maximum_steps);
|
2014-06-13 02:20:02 -07:00
|
|
|
|
this.loadTexture(this.sprite_name, 0);
|
|
|
|
|
|
addAnimation(this, 'bipedwalkleft');
|
|
|
|
|
|
addAnimation(this, 'bipedwalkright');
|
|
|
|
|
|
addAnimation(this, 'bipedwalkup');
|
|
|
|
|
|
addAnimation(this, 'bipedwalkdown');
|
|
|
|
|
|
addAnimation(this, 'bipedrunleft');
|
|
|
|
|
|
addAnimation(this, 'bipedrunright');
|
|
|
|
|
|
addAnimation(this, 'bipedrunup');
|
|
|
|
|
|
addAnimation(this, 'bipedrundown');
|
2014-06-14 12:10:24 -07:00
|
|
|
|
setMovingState(this, STATE_FACE_DOWN);
|
2014-06-14 11:59:41 -07:00
|
|
|
|
setSpriteMovement(this);
|
2014-06-19 08:19:52 -07:00
|
|
|
|
this.ready_to_update = true;
|
2014-06-13 01:57:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-11 20:43:05 -07:00
|
|
|
|
var spritenames_by_type = [
|
|
|
|
|
|
'townsfolk-male-1',
|
|
|
|
|
|
'townsfolk-male-2',
|
|
|
|
|
|
'townsfolk-male-3',
|
|
|
|
|
|
'townsfolk-male-4',
|
|
|
|
|
|
'townsfolk-female-1',
|
|
|
|
|
|
'townsfolk-female-2',
|
|
|
|
|
|
'townsfolk-female-3',
|
|
|
|
|
|
'townsfolk-female-4',
|
|
|
|
|
|
'townsfolk-guard-1',
|
|
|
|
|
|
'townsfolk-guard-2'
|
|
|
|
|
|
];
|
2014-06-14 10:09:46 -07:00
|
|
|
|
|
2014-06-19 08:19:52 -07:00
|
|
|
|
this.ready_to_update = false;
|
2014-06-14 10:25:20 -07:00
|
|
|
|
Phaser.Sprite.call(this, game, x, y, null);
|
2014-06-11 21:03:01 -07:00
|
|
|
|
game.physics.arcade.enable(this);
|
2014-06-15 17:50:24 -07:00
|
|
|
|
this.body.immovable = true;
|
2014-06-15 23:14:20 -07:00
|
|
|
|
pathfinder_grid = [];
|
|
|
|
|
|
this.walkables = [];
|
|
|
|
|
|
this.path = [];
|
2014-06-19 18:59:12 -07:00
|
|
|
|
this.target = null;
|
2014-06-15 23:14:20 -07:00
|
|
|
|
this.path_tweens = [];
|
|
|
|
|
|
this.path_maximum_steps = 4;
|
2014-06-15 15:45:29 -07:00
|
|
|
|
this.awareness_change_enabled = true;
|
2014-06-15 15:20:24 -07:00
|
|
|
|
this.lightmeter = 1.0;
|
2014-06-15 18:14:16 -07:00
|
|
|
|
this.sprite_can_see_lightmeter = 0.3;
|
2014-06-15 13:37:08 -07:00
|
|
|
|
this.awareness_effect = null;
|
2014-06-15 15:45:29 -07:00
|
|
|
|
this.awareness_timer = null;
|
2014-06-19 20:14:12 -07:00
|
|
|
|
this.lastSawPlayerAt = null;
|
2014-06-19 07:58:04 -07:00
|
|
|
|
this.seen_directions = [];
|
2014-06-15 15:53:44 -07:00
|
|
|
|
this.sprite_awareness_duration = 60000;
|
2014-06-15 12:53:45 -07:00
|
|
|
|
this.sprite_canmove = 'true';
|
2014-06-14 16:37:18 -07:00
|
|
|
|
this.collide_with_player = 'true';
|
|
|
|
|
|
this.collide_with_map = 'true';
|
|
|
|
|
|
this.carries_light = 'false';
|
2014-06-14 14:44:37 -07:00
|
|
|
|
this.view_distance = 32 * 5;
|
2014-06-14 10:22:10 -07:00
|
|
|
|
this.timer = null;
|
2014-06-18 09:02:38 -07:00
|
|
|
|
this.rotation_timer = null;
|
2014-06-15 22:15:07 -07:00
|
|
|
|
this.origin = new Phaser.Point(x, y);
|
2014-06-15 18:55:34 -07:00
|
|
|
|
this.bubble_immediate = false;
|
2014-06-14 11:01:47 -07:00
|
|
|
|
this.bubble_text = null;
|
2014-06-14 10:26:09 -07:00
|
|
|
|
this.enable_word_bubble = false;
|
2014-06-11 21:19:34 -07:00
|
|
|
|
this.body.collideWorldBounds = true;
|
2014-06-13 02:00:30 -07:00
|
|
|
|
this.sprite_name = "townsfolk-male-1";
|
|
|
|
|
|
this.sprite_group = "townsfolk-male";
|
2014-06-14 10:25:08 -07:00
|
|
|
|
this.update_new_values();
|
2014-06-11 21:00:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-11 22:05:54 -07:00
|
|
|
|
AISprite.prototype = Object.create(Phaser.Sprite.prototype);
|
|
|
|
|
|
AISprite.prototype.constructor = AISprite;
|
2014-06-11 20:43:05 -07:00
|
|
|
|
|
2014-06-14 14:44:37 -07:00
|
|
|
|
function rotatePoints(arr, x, y, degrees)
|
|
|
|
|
|
{
|
|
|
|
|
|
arr.forEach(function(p) {
|
|
|
|
|
|
p.rotate(x, y, degrees, true);
|
|
|
|
|
|
}, this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-18 09:34:14 -07:00
|
|
|
|
function positiveRectangle(x, y, w, h) {
|
|
|
|
|
|
if ( w < 0 ) {
|
|
|
|
|
|
w = -(w);
|
|
|
|
|
|
x = x - w;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( h < 0 ) {
|
|
|
|
|
|
h = -(h);
|
|
|
|
|
|
y = y - h;
|
|
|
|
|
|
}
|
|
|
|
|
|
return new Phaser.Rectangle(x, y, w, h);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-19 20:33:30 -07:00
|
|
|
|
function nearestInGroup(sprite, group, sprite_group) {
|
2014-06-19 20:14:12 -07:00
|
|
|
|
var nearest = null;
|
|
|
|
|
|
var lastdist = 0.0;
|
2014-06-19 20:16:45 -07:00
|
|
|
|
for ( var i = 0 ; i < group.length; i++ ) {
|
2014-06-19 20:33:30 -07:00
|
|
|
|
console.log("Checking distance to group[" + i + "]");
|
2014-06-19 20:16:45 -07:00
|
|
|
|
var spr = group.getChildAt(i);
|
2014-06-19 20:14:12 -07:00
|
|
|
|
console.log(spr);
|
2014-06-19 20:33:30 -07:00
|
|
|
|
if ( (typeof sprite_group !== undefined) &&
|
|
|
|
|
|
spr.sprite_group !== sprite_group )
|
2014-06-19 20:14:12 -07:00
|
|
|
|
continue;
|
|
|
|
|
|
var dist = new Phaser.Line(sprite.x, sprite.y, spr.x, spr.y);
|
|
|
|
|
|
if ( (lastdist == 0.0 ) || (dist.length < lastdist) ) {
|
2014-06-19 20:40:48 -07:00
|
|
|
|
lastdist = dist.length;
|
2014-06-19 20:14:12 -07:00
|
|
|
|
nearest = spr;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return nearest;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-11 21:17:23 -07:00
|
|
|
|
function addAnimation(obj, anim)
|
2014-06-10 01:05:21 -07:00
|
|
|
|
{
|
|
|
|
|
|
a = moonlightSettings['animations'][anim]
|
|
|
|
|
|
obj.animations.add(anim, a['frames'], a['speed'], a['loop'])
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-15 21:20:15 -07:00
|
|
|
|
var GameState = function(game) {
|
2014-06-15 21:19:35 -07:00
|
|
|
|
}
|
2014-06-12 22:11:16 -07:00
|
|
|
|
|
|
|
|
|
|
GameState.prototype.create = function()
|
|
|
|
|
|
{
|
|
|
|
|
|
this.map = this.add.tilemap('map');
|
2014-06-09 22:48:39 -07:00
|
|
|
|
for (var k in moonlightSettings['map']['tilesets']) {
|
|
|
|
|
|
var ts = moonlightSettings['map']['tilesets'][k];
|
2014-06-12 22:10:12 -07:00
|
|
|
|
this.map.addTilesetImage(ts['name']);
|
2014-06-09 22:48:39 -07:00
|
|
|
|
}
|
2014-06-12 21:57:03 -07:00
|
|
|
|
this.map_collision_layers = [];
|
2014-06-15 23:14:20 -07:00
|
|
|
|
pfgrid = [];
|
2014-06-12 21:57:03 -07:00
|
|
|
|
|
|
|
|
|
|
for (var ln in moonlightSettings['map']['layers']) {
|
2014-06-12 21:58:51 -07:00
|
|
|
|
lp = moonlightSettings['map']['layers'][ln];
|
2014-06-12 23:04:33 -07:00
|
|
|
|
if ( lp['type'] == "tiles" ) {
|
2014-06-15 23:13:53 -07:00
|
|
|
|
layer = this.map.createLayer(ln);
|
2014-06-12 23:04:33 -07:00
|
|
|
|
this.map.setCollisionBetween(
|
|
|
|
|
|
lp['collisionBetween'][0],
|
|
|
|
|
|
lp['collisionBetween'][1],
|
|
|
|
|
|
lp['collides'],
|
|
|
|
|
|
ln
|
|
|
|
|
|
);
|
2014-06-13 00:25:39 -07:00
|
|
|
|
if ( lp['inject_sprites'] == true ) {
|
|
|
|
|
|
this.aiSprites = game.add.group();
|
2014-06-15 23:14:20 -07:00
|
|
|
|
this.aiSprites.debug = true;
|
2014-06-13 01:57:06 -07:00
|
|
|
|
this.map.createFromObjects('AI', 3544, 'player', 0, true, false, this.aiSprites, AISprite);
|
|
|
|
|
|
this.aiSprites.forEach(function(spr) {
|
|
|
|
|
|
spr.update_new_values();
|
|
|
|
|
|
}, this)
|
2014-06-15 18:55:34 -07:00
|
|
|
|
player = this.add.sprite((19 * 32), (21 * 32), 'player');
|
2014-06-15 11:55:00 -07:00
|
|
|
|
player.lightmeter = 0;
|
2014-06-14 12:38:57 -07:00
|
|
|
|
|
2014-06-13 00:25:39 -07:00
|
|
|
|
};
|
2014-06-12 23:04:33 -07:00
|
|
|
|
if ( lp['collides'] == true ) {
|
|
|
|
|
|
this.map_collision_layers.push(layer);
|
2014-06-15 23:14:20 -07:00
|
|
|
|
for (var i = 0; i < layer.layer.data.length; i++)
|
2014-06-15 23:13:53 -07:00
|
|
|
|
{
|
2014-06-15 23:14:20 -07:00
|
|
|
|
if ( i >= pfgrid.length )
|
|
|
|
|
|
pfgrid[i] = [];
|
|
|
|
|
|
for (var j = 0; j < layer.layer.data[i].length; j++)
|
2014-06-15 23:13:53 -07:00
|
|
|
|
{
|
2014-06-15 23:14:20 -07:00
|
|
|
|
if (layer.layer.data[i][j].index > 0) {
|
|
|
|
|
|
pfgrid[i][j] = 1;
|
|
|
|
|
|
} else if ( pfgrid[i][j] != 1 ) {
|
|
|
|
|
|
pfgrid[i][j] = 0;
|
|
|
|
|
|
}
|
2014-06-15 23:13:53 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-06-12 23:04:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
layer.resizeWorld();
|
2014-06-12 22:20:58 -07:00
|
|
|
|
}
|
2014-06-12 21:57:03 -07:00
|
|
|
|
}
|
2014-06-15 23:14:20 -07:00
|
|
|
|
|
|
|
|
|
|
pathfinder_grid = new PF.Grid(this.map.width,
|
|
|
|
|
|
this.map.height,
|
|
|
|
|
|
pfgrid);
|
|
|
|
|
|
pathfinder = new PF.AStarFinder({allowDiagonal: false});
|
|
|
|
|
|
|
2014-06-10 19:15:55 -07:00
|
|
|
|
this.physics.arcade.enable(player);
|
2014-06-12 22:33:32 -07:00
|
|
|
|
player.body.center = new Phaser.Point(player.body.width / 2, player.body.height + player.body.halfHeight);
|
2014-06-10 19:15:55 -07:00
|
|
|
|
player.body.collideWorldBounds = true;
|
2014-06-17 20:33:44 -07:00
|
|
|
|
//player.body.immovable = true;
|
2014-06-10 01:05:21 -07:00
|
|
|
|
|
2014-06-11 21:17:23 -07:00
|
|
|
|
addAnimation(player, 'bipedwalkleft');
|
|
|
|
|
|
addAnimation(player, 'bipedwalkright');
|
|
|
|
|
|
addAnimation(player, 'bipedwalkup');
|
|
|
|
|
|
addAnimation(player, 'bipedwalkdown');
|
|
|
|
|
|
addAnimation(player, 'bipedrunleft');
|
|
|
|
|
|
addAnimation(player, 'bipedrunright');
|
|
|
|
|
|
addAnimation(player, 'bipedrunup');
|
|
|
|
|
|
addAnimation(player, 'bipedrundown');
|
2014-06-10 01:05:21 -07:00
|
|
|
|
|
2014-06-09 22:48:39 -07:00
|
|
|
|
this.camera.follow(player, Phaser.Camera.FOLLOW_TOPDOWN);
|
|
|
|
|
|
controls = game.input.keyboard.createCursorKeys();
|
2014-06-10 19:15:55 -07:00
|
|
|
|
|
2014-06-15 11:54:14 -07:00
|
|
|
|
this.effectSprites = game.add.group();
|
|
|
|
|
|
this.map.createFromObjects('EffectSprites', 5, 'player', 0, true, false, this.effectSprites, EffectSprite);
|
|
|
|
|
|
this.effectSprites.forEach(function(spr) {
|
|
|
|
|
|
spr.update_new_values();
|
|
|
|
|
|
}, this)
|
|
|
|
|
|
|
2014-06-11 20:48:04 -07:00
|
|
|
|
this.shadowTexture = game.add.bitmapData(game.world.width, game.world.height);
|
2014-06-11 21:26:31 -07:00
|
|
|
|
// drop this lower to make the map darker
|
2014-06-18 08:55:16 -07:00
|
|
|
|
this.shadowTextureColor = 'rgb(60, 60, 60)';
|
2014-06-11 20:48:04 -07:00
|
|
|
|
this.shadowSprite = game.add.image(0, 0, this.shadowTexture);
|
|
|
|
|
|
|
|
|
|
|
|
this.shadowSprite.blendMode = Phaser.blendModes.MULTIPLY;
|
|
|
|
|
|
|
2014-06-12 23:28:15 -07:00
|
|
|
|
this.staticLights = game.add.group();
|
2014-06-12 23:31:36 -07:00
|
|
|
|
this.map.createFromObjects('Lights', 97, 'player', 0, true, false, this.staticLights, Light);
|
2014-06-12 23:55:02 -07:00
|
|
|
|
this.staticLights.forEach(function(light) {
|
2014-06-13 00:03:27 -07:00
|
|
|
|
light.update_new_values();
|
2014-06-12 23:55:02 -07:00
|
|
|
|
}, this)
|
|
|
|
|
|
|
2014-06-13 22:35:55 -07:00
|
|
|
|
this.staticSounds = game.add.group();
|
2014-06-14 00:16:17 -07:00
|
|
|
|
this.map.createFromObjects('Sounds', 11, 'player', 0, true, false, this.staticSounds, SoundSprite);
|
2014-06-13 22:35:55 -07:00
|
|
|
|
this.staticSounds.forEach(function(snd) {
|
2014-06-13 22:40:13 -07:00
|
|
|
|
snd.update_new_values();
|
2014-06-13 22:35:55 -07:00
|
|
|
|
}, this)
|
2014-06-14 20:39:03 -07:00
|
|
|
|
|
2014-06-15 19:18:50 -07:00
|
|
|
|
this.bubble_group = game.add.group();
|
|
|
|
|
|
|
2014-06-14 20:39:03 -07:00
|
|
|
|
this.uigroup = game.add.group();
|
|
|
|
|
|
this.game.time.advancedTiming = true;
|
|
|
|
|
|
this.fpsText = this.game.add.text(
|
|
|
|
|
|
20, 20, '', { font: '16px Arial', fill: '#ffffff' }, this.uigroup
|
|
|
|
|
|
);
|
|
|
|
|
|
this.lightbox = this.game.add.image(game.camera.width / 2 - 50,
|
|
|
|
|
|
game.camera.height - 40,
|
|
|
|
|
|
'lightbox',
|
|
|
|
|
|
0,
|
|
|
|
|
|
this.uigroup);
|
|
|
|
|
|
this.lightbar = this.game.add.image(this.lightbox.x + 3,
|
|
|
|
|
|
this.lightbox.y + 3,
|
|
|
|
|
|
'lightbar',
|
|
|
|
|
|
0,
|
|
|
|
|
|
this.uigroup);
|
2014-06-14 20:48:38 -07:00
|
|
|
|
this.lightbar_image = game.cache.getImage('lightbar');
|
2014-06-18 09:34:14 -07:00
|
|
|
|
this.lightbar_crop = positiveRectangle(0,
|
|
|
|
|
|
0,
|
|
|
|
|
|
this.lightbar_image.width,
|
|
|
|
|
|
this.lightbar_image.height);
|
2014-06-14 20:39:03 -07:00
|
|
|
|
this.uigroup.setAll('fixedToCamera', true);
|
2014-06-09 22:48:39 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-11 10:06:03 -07:00
|
|
|
|
GameState.prototype.updateShadowTexture = function() {
|
2014-06-11 20:24:07 -07:00
|
|
|
|
this.shadowTexture.context.fillStyle = this.shadowTextureColor;
|
2014-06-11 11:05:59 -07:00
|
|
|
|
this.shadowTexture.context.fillRect(0, 0, game.world.width, game.world.height);
|
2014-06-10 19:15:55 -07:00
|
|
|
|
|
2014-06-11 19:57:11 -07:00
|
|
|
|
this.staticLights.forEach(function(light) {
|
2014-06-13 01:21:50 -07:00
|
|
|
|
if ( light.always_render !== true ) {
|
2014-06-18 09:34:14 -07:00
|
|
|
|
var r1 = positiveRectangle(this.game.camera.x,
|
|
|
|
|
|
this.game.camera.y,
|
|
|
|
|
|
this.game.camera.width,
|
|
|
|
|
|
this.game.camera.height);
|
2014-06-14 17:06:04 -07:00
|
|
|
|
if ( ! light.rect.intersects(r1) ) {
|
2014-06-13 01:21:50 -07:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2014-06-11 20:01:00 -07:00
|
|
|
|
}
|
2014-06-11 20:24:07 -07:00
|
|
|
|
|
2014-06-11 20:17:34 -07:00
|
|
|
|
if ( light.flicker ) {
|
|
|
|
|
|
var radius = light.radius + game.rnd.integerInRange(1,10);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
var radius = light.radius;
|
|
|
|
|
|
}
|
2014-06-14 20:27:00 -07:00
|
|
|
|
light.rendered_radius = radius;
|
2014-06-10 19:15:55 -07:00
|
|
|
|
|
|
|
|
|
|
var gradient =
|
|
|
|
|
|
this.shadowTexture.context.createRadialGradient(
|
2014-06-11 11:00:09 -07:00
|
|
|
|
light.x + 16, light.y + 16, light.fade,
|
2014-06-11 10:49:02 -07:00
|
|
|
|
light.x + 16, light.y + 16, radius);
|
2014-06-12 23:55:02 -07:00
|
|
|
|
gradient.addColorStop(0, light.color_start);
|
|
|
|
|
|
gradient.addColorStop(1, light.color_stop);
|
2014-06-10 19:15:55 -07:00
|
|
|
|
|
|
|
|
|
|
this.shadowTexture.context.beginPath();
|
|
|
|
|
|
this.shadowTexture.context.fillStyle = gradient;
|
2014-06-11 10:49:39 -07:00
|
|
|
|
this.shadowTexture.context.arc(light.x + 16, light.y + 16, radius, 0, Math.PI*2);
|
2014-06-10 19:15:55 -07:00
|
|
|
|
this.shadowTexture.context.fill();
|
|
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
|
|
|
|
this.shadowTexture.dirty = true;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2014-06-15 23:14:20 -07:00
|
|
|
|
function getFaceState(spr)
|
|
|
|
|
|
{
|
2014-06-17 23:14:46 -07:00
|
|
|
|
if ( hasState(spr, STATE_FACE_LEFT) )
|
|
|
|
|
|
return STATE_FACE_LEFT;
|
|
|
|
|
|
if ( hasState(spr, STATE_FACE_RIGHT) )
|
|
|
|
|
|
return STATE_FACE_RIGHT;
|
|
|
|
|
|
if ( hasState(spr, STATE_FACE_DOWN) )
|
|
|
|
|
|
return STATE_FACE_DOWN;
|
|
|
|
|
|
if ( hasState(spr, STATE_FACE_UP) )
|
|
|
|
|
|
return STATE_FACE_UP;
|
2014-06-15 23:14:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getMoveState(spr)
|
|
|
|
|
|
{
|
|
|
|
|
|
return ( hasState(spr, STATE_MOVING) ||
|
|
|
|
|
|
hasState(spr, STATE_RUNNING) );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-14 11:59:41 -07:00
|
|
|
|
function delState(spr, state)
|
|
|
|
|
|
{
|
2014-06-14 12:10:24 -07:00
|
|
|
|
if ( hasState(spr, state) )
|
|
|
|
|
|
spr.state = spr.state ^ state;
|
2014-06-14 11:59:41 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function addState(spr, state)
|
|
|
|
|
|
{
|
|
|
|
|
|
spr.state = spr.state | state;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-14 12:10:24 -07:00
|
|
|
|
function setMovingState(spr, state)
|
|
|
|
|
|
{
|
|
|
|
|
|
delState(spr, STATE_FACE_LEFT);
|
|
|
|
|
|
delState(spr, STATE_FACE_RIGHT);
|
2014-06-14 12:10:50 -07:00
|
|
|
|
delState(spr, STATE_FACE_DOWN);
|
2014-06-14 12:10:24 -07:00
|
|
|
|
delState(spr, STATE_FACE_UP);
|
|
|
|
|
|
delState(spr, STATE_MOVING);
|
|
|
|
|
|
delState(spr, STATE_RUNNING);
|
2014-06-14 12:11:59 -07:00
|
|
|
|
addState(spr, state);
|
2014-06-14 12:10:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-15 13:37:08 -07:00
|
|
|
|
function setAwarenessState(spr, state)
|
|
|
|
|
|
{
|
|
|
|
|
|
delState(spr, STATE_UNAWARE);
|
|
|
|
|
|
delState(spr, STATE_CONCERNED);
|
|
|
|
|
|
delState(spr, STATE_ALERTED);
|
|
|
|
|
|
delState(spr, STATE_LOSTHIM);
|
|
|
|
|
|
addState(spr, state);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-14 11:59:41 -07:00
|
|
|
|
function exchangeState(spr, state1, state2)
|
|
|
|
|
|
{
|
|
|
|
|
|
delState(spr, state1);
|
|
|
|
|
|
addState(spr, state2);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-15 22:22:17 -07:00
|
|
|
|
function hasAnyState(spr, states)
|
|
|
|
|
|
{
|
|
|
|
|
|
var hasstate = false;
|
|
|
|
|
|
states.forEach(function(x) {
|
|
|
|
|
|
if ( hasState(spr, x) )
|
|
|
|
|
|
hasstate = true;
|
|
|
|
|
|
}, this);
|
|
|
|
|
|
return hasstate;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-14 11:59:41 -07:00
|
|
|
|
function hasState(spr, state)
|
|
|
|
|
|
{
|
2014-06-14 12:05:34 -07:00
|
|
|
|
if ( (spr.state & state) == state )
|
2014-06-14 12:03:53 -07:00
|
|
|
|
return true;
|
|
|
|
|
|
return false;
|
2014-06-14 11:59:41 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function spriteFacing(spr)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ( hasState(spr, STATE_FACE_LEFT) )
|
|
|
|
|
|
return "left";
|
|
|
|
|
|
if ( hasState(spr, STATE_FACE_RIGHT) )
|
|
|
|
|
|
return "right";
|
|
|
|
|
|
if ( hasState(spr, STATE_FACE_DOWN) )
|
|
|
|
|
|
return "down";
|
|
|
|
|
|
if ( hasState(spr, STATE_FACE_UP) )
|
|
|
|
|
|
return "up";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-14 16:46:50 -07:00
|
|
|
|
function parseBoolean(val)
|
|
|
|
|
|
{
|
|
|
|
|
|
return ( val == 'true' || val == true );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-15 23:14:20 -07:00
|
|
|
|
function setSpriteMovement(spr, velocity)
|
2014-06-10 01:05:21 -07:00
|
|
|
|
{
|
|
|
|
|
|
var x = 0;
|
|
|
|
|
|
var y = 0;
|
2014-06-14 11:59:41 -07:00
|
|
|
|
var dir = spriteFacing(spr);
|
2014-06-15 23:14:20 -07:00
|
|
|
|
velocity = ( typeof velocity == undefined ? velocity : [SPEED_WALKING,
|
|
|
|
|
|
SPEED_RUNNING] );
|
2014-06-14 11:59:41 -07:00
|
|
|
|
|
|
|
|
|
|
spr.body.setSize(16, 16, 8, 16);
|
2014-06-10 01:05:21 -07:00
|
|
|
|
|
2014-06-14 11:59:41 -07:00
|
|
|
|
if ( hasState(spr, STATE_RUNNING) ) {
|
2014-06-15 23:14:20 -07:00
|
|
|
|
if ( velocity !== false )
|
|
|
|
|
|
velocity = velocity[1];
|
2014-06-10 01:05:21 -07:00
|
|
|
|
spr.animations.play("bipedrun" + dir);
|
2014-06-14 11:59:41 -07:00
|
|
|
|
} else if ( hasState(spr, STATE_MOVING) ) {
|
2014-06-15 23:14:20 -07:00
|
|
|
|
if ( velocity !== false )
|
|
|
|
|
|
velocity = velocity[0];
|
2014-06-10 01:05:21 -07:00
|
|
|
|
spr.animations.play("bipedwalk" + dir);
|
2014-06-14 11:59:41 -07:00
|
|
|
|
} else {
|
2014-06-15 23:14:20 -07:00
|
|
|
|
if ( velocity !== false ) {
|
|
|
|
|
|
spr.body.velocity.x = 0;
|
|
|
|
|
|
spr.body.velocity.y = 0;
|
|
|
|
|
|
}
|
2014-06-14 11:59:41 -07:00
|
|
|
|
spr.animations.stop();
|
|
|
|
|
|
return;
|
2014-06-10 01:05:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-15 23:14:20 -07:00
|
|
|
|
if ( velocity !== false ) {
|
|
|
|
|
|
if ( dir == "left" ) {
|
|
|
|
|
|
spr.body.velocity.x = -(velocity * velocity);
|
|
|
|
|
|
spr.body.velocity.y = 0;
|
|
|
|
|
|
} else if ( dir == "right" ) {
|
|
|
|
|
|
spr.body.velocity.x = (velocity * velocity);
|
|
|
|
|
|
spr.body.velocity.y = 0;
|
|
|
|
|
|
} else if ( dir == "up" ) {
|
|
|
|
|
|
spr.body.velocity.x = 0;
|
|
|
|
|
|
spr.body.velocity.y = -(velocity * velocity);
|
|
|
|
|
|
} else if ( dir == "down" ) {
|
|
|
|
|
|
spr.body.velocity.x = 0;
|
|
|
|
|
|
spr.body.velocity.y = (velocity * velocity);
|
|
|
|
|
|
}
|
2014-06-10 01:05:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-11 10:06:03 -07:00
|
|
|
|
GameState.prototype.check_input = function()
|
2014-06-09 22:48:39 -07:00
|
|
|
|
{
|
|
|
|
|
|
player.body.velocity.x = 0;
|
|
|
|
|
|
player.body.velocity.y = 0;
|
2014-06-10 01:05:21 -07:00
|
|
|
|
velocityMod = 0;
|
2014-06-14 11:59:41 -07:00
|
|
|
|
var newstate = 0;
|
2014-06-10 01:05:21 -07:00
|
|
|
|
|
2014-06-09 22:48:39 -07:00
|
|
|
|
if ( controls.up.isDown) {
|
2014-06-14 11:59:41 -07:00
|
|
|
|
if ( controls.up.shiftKey ) {
|
2014-06-14 12:12:38 -07:00
|
|
|
|
newstate = (STATE_FACE_UP | STATE_MOVING | STATE_RUNNING);
|
2014-06-14 11:59:41 -07:00
|
|
|
|
} else {
|
2014-06-14 12:12:38 -07:00
|
|
|
|
newstate = (STATE_FACE_UP | STATE_MOVING );
|
2014-06-14 11:59:41 -07:00
|
|
|
|
}
|
2014-06-09 22:48:39 -07:00
|
|
|
|
} else if ( controls.down.isDown ) {
|
2014-06-14 11:59:41 -07:00
|
|
|
|
if ( controls.down.shiftKey ) {
|
|
|
|
|
|
newstate = (STATE_FACE_DOWN | STATE_MOVING | STATE_RUNNING);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
newstate = (STATE_FACE_DOWN | STATE_MOVING );
|
|
|
|
|
|
}
|
2014-06-10 01:05:21 -07:00
|
|
|
|
} else if ( controls.left.isDown ) {
|
2014-06-14 11:59:41 -07:00
|
|
|
|
if ( controls.left.shiftKey ) {
|
|
|
|
|
|
newstate = (STATE_FACE_LEFT | STATE_MOVING | STATE_RUNNING);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
newstate = (STATE_FACE_LEFT | STATE_MOVING );
|
|
|
|
|
|
}
|
2014-06-09 22:48:39 -07:00
|
|
|
|
} else if ( controls.right.isDown ) {
|
2014-06-14 11:59:41 -07:00
|
|
|
|
if ( controls.right.shiftKey ) {
|
|
|
|
|
|
newstate = (STATE_FACE_RIGHT | STATE_MOVING | STATE_RUNNING);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
newstate = (STATE_FACE_RIGHT | STATE_MOVING );
|
|
|
|
|
|
}
|
2014-06-10 01:05:21 -07:00
|
|
|
|
} else {
|
2014-06-14 11:59:41 -07:00
|
|
|
|
newstate = STATE_NONE;
|
2014-06-13 01:57:32 -07:00
|
|
|
|
}
|
2014-06-14 11:59:41 -07:00
|
|
|
|
|
2014-06-14 12:10:24 -07:00
|
|
|
|
setMovingState(player, newstate);
|
2014-06-14 11:59:41 -07:00
|
|
|
|
setSpriteMovement(player);
|
2014-06-09 22:48:39 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-14 20:04:21 -07:00
|
|
|
|
GameState.prototype.update_player_lightmeter = function() {
|
2014-06-14 20:03:55 -07:00
|
|
|
|
lightValue = 0;
|
|
|
|
|
|
this.staticLights.forEach(function(light) {
|
2014-06-14 20:30:17 -07:00
|
|
|
|
var left = player.x;
|
2014-06-14 20:31:33 -07:00
|
|
|
|
var top = player.y + 32;
|
2014-06-14 20:30:17 -07:00
|
|
|
|
|
|
|
|
|
|
if ( player.y < this.y )
|
2014-06-14 20:31:33 -07:00
|
|
|
|
top = player.y;
|
2014-06-14 20:30:17 -07:00
|
|
|
|
if ( player.x + this.x )
|
|
|
|
|
|
left = player.x + 32;
|
|
|
|
|
|
|
|
|
|
|
|
line = new Phaser.Line(left, top, light.x + 16, light.y + 16);
|
2014-06-14 20:27:00 -07:00
|
|
|
|
if ( line.length > light.rendered_radius)
|
2014-06-14 20:03:55 -07:00
|
|
|
|
return;
|
2014-06-14 20:24:01 -07:00
|
|
|
|
var length = line.length;
|
2014-06-15 18:48:18 -07:00
|
|
|
|
var lv = light.light_meter - (Number(length) / Number(light.rendered_radius));
|
2014-06-14 20:03:55 -07:00
|
|
|
|
if ( lv > lightValue ) {
|
|
|
|
|
|
lightValue = lv;
|
|
|
|
|
|
}
|
|
|
|
|
|
}, this)
|
2014-06-15 15:20:24 -07:00
|
|
|
|
player.lightmeter = lightValue;
|
2014-06-14 20:50:45 -07:00
|
|
|
|
this.lightbar_crop.width = (this.lightbar_image.width * lightValue);
|
2014-06-14 20:48:38 -07:00
|
|
|
|
this.lightbar.crop(this.lightbar_crop);
|
2014-06-14 20:03:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-11 10:06:03 -07:00
|
|
|
|
GameState.prototype.update = function()
|
2014-06-09 22:48:39 -07:00
|
|
|
|
{
|
2014-06-11 10:06:32 -07:00
|
|
|
|
this.check_input();
|
2014-06-14 20:03:55 -07:00
|
|
|
|
this.update_player_lightmeter();
|
|
|
|
|
|
|
2014-06-12 22:26:57 -07:00
|
|
|
|
for (var ln in this.map_collision_layers ) {
|
|
|
|
|
|
layer = this.map_collision_layers[ln];
|
2014-06-12 21:57:03 -07:00
|
|
|
|
this.physics.arcade.collide(player, layer);
|
|
|
|
|
|
}
|
2014-06-11 21:09:22 -07:00
|
|
|
|
|
2014-06-13 22:54:06 -07:00
|
|
|
|
function _fix_audio_relative(x) {
|
2014-06-13 23:23:28 -07:00
|
|
|
|
x.adjust_relative_to(player);
|
2014-06-13 22:54:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
this.staticSounds.forEach(_fix_audio_relative, this);
|
|
|
|
|
|
|
2014-06-11 21:46:32 -07:00
|
|
|
|
function _inner_collide(x) {
|
2014-06-14 12:42:21 -07:00
|
|
|
|
if ( x.collide_with_map == true ) {
|
|
|
|
|
|
for ( var ln in this.map_collision_layers ) {
|
|
|
|
|
|
layer = this.map_collision_layers[ln];
|
|
|
|
|
|
this.physics.arcade.collide(x, layer);
|
|
|
|
|
|
}
|
2014-06-12 21:57:03 -07:00
|
|
|
|
}
|
2014-06-14 12:42:21 -07:00
|
|
|
|
if ( x.collide_with_player == false )
|
|
|
|
|
|
return;
|
2014-06-15 13:37:08 -07:00
|
|
|
|
if ( x.canSeeSprite(player, false) == true ) {
|
2014-06-19 20:14:12 -07:00
|
|
|
|
x.lastSawPlayerAt = new Phaser.Point(player.x, player.y);
|
2014-06-15 17:50:24 -07:00
|
|
|
|
if ( this.physics.arcade.collide(x, player) ) {
|
|
|
|
|
|
x.setAwarenessEffect(STATE_ALERTED);
|
|
|
|
|
|
} else if ( player.lightmeter >= x.sprite_can_see_lightmeter ) {
|
2014-06-15 15:20:24 -07:00
|
|
|
|
x.setAwarenessEffect(STATE_ALERTED);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
x.setAwarenessEffect(STATE_CONCERNED);
|
|
|
|
|
|
}
|
2014-06-15 17:50:24 -07:00
|
|
|
|
return;
|
2014-06-15 13:39:55 -07:00
|
|
|
|
} else {
|
2014-06-15 18:59:25 -07:00
|
|
|
|
if ( hasState(x, STATE_LOSTHIM) == false ) {
|
|
|
|
|
|
x.setAwarenessEffect(STATE_LOSTHIM);
|
|
|
|
|
|
} else {
|
2014-06-15 19:02:44 -07:00
|
|
|
|
x.setAwarenessEffect(STATE_UNAWARE);
|
2014-06-15 18:59:25 -07:00
|
|
|
|
}
|
2014-06-15 13:37:08 -07:00
|
|
|
|
}
|
2014-06-11 21:46:32 -07:00
|
|
|
|
this.physics.arcade.collide(x, player);
|
2014-06-11 21:42:36 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-14 12:42:21 -07:00
|
|
|
|
this.effectSprites.forEach(_inner_collide, this);
|
|
|
|
|
|
|
2014-06-11 22:05:54 -07:00
|
|
|
|
this.aiSprites.forEach(_inner_collide, this);
|
2014-06-10 19:15:55 -07:00
|
|
|
|
this.updateShadowTexture();
|
2014-06-14 16:17:08 -07:00
|
|
|
|
|
2014-06-17 23:42:35 -07:00
|
|
|
|
if ( this.aiSprites.debug == true ) {
|
|
|
|
|
|
function _draw_viewrect(x) {
|
|
|
|
|
|
var r = x.viewRectangle();
|
|
|
|
|
|
if ( r == null )
|
|
|
|
|
|
return;
|
|
|
|
|
|
this.shadowTexture.context.fillStyle = 'rgb(128, 128, 128)';
|
|
|
|
|
|
this.shadowTexture.context.fillRect(r.left,
|
|
|
|
|
|
r.top,
|
|
|
|
|
|
r.width,
|
|
|
|
|
|
r.height);
|
|
|
|
|
|
}
|
|
|
|
|
|
this.aiSprites.forEach(_draw_viewrect, this);
|
|
|
|
|
|
function _draw_aipath(x) {
|
|
|
|
|
|
var p = x.path;
|
|
|
|
|
|
if ( p == null )
|
|
|
|
|
|
return;
|
|
|
|
|
|
this.shadowTexture.context.fillStyle = 'rgb(255, 128, 128)';
|
|
|
|
|
|
p.forEach(function(r) {
|
|
|
|
|
|
this.shadowTexture.context.fillRect(r.start.x,
|
|
|
|
|
|
r.start.y,
|
|
|
|
|
|
r.end.x - r.start.x,
|
|
|
|
|
|
r.end.y - r.start.y);
|
|
|
|
|
|
}, this);
|
|
|
|
|
|
}
|
|
|
|
|
|
this.aiSprites.forEach(_draw_aipath, this);
|
|
|
|
|
|
}
|
2014-06-12 00:23:31 -07:00
|
|
|
|
if (game.time.fps !== 0) {
|
|
|
|
|
|
this.fpsText.setText(game.time.fps + ' FPS');
|
|
|
|
|
|
}
|
2014-06-09 22:48:39 -07:00
|
|
|
|
}
|
2014-06-11 10:05:02 -07:00
|
|
|
|
|
2014-06-15 21:12:08 -07:00
|
|
|
|
function Boot()
|
|
|
|
|
|
{
|
|
|
|
|
|
Phaser.State.call(game, this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var Boot = function(game) {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-15 21:20:15 -07:00
|
|
|
|
Boot.prototype.preload = function()
|
2014-06-15 21:12:08 -07:00
|
|
|
|
{
|
|
|
|
|
|
game.load.image('preloader', 'gfx/ui/preloader.png');
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2014-06-15 21:20:15 -07:00
|
|
|
|
Boot.prototype.create = function()
|
2014-06-15 21:12:08 -07:00
|
|
|
|
{
|
|
|
|
|
|
this.input.maxPointers = 1;
|
2014-06-15 23:14:20 -07:00
|
|
|
|
this.stage.disableVisibilityChange = false;
|
2014-06-15 21:12:08 -07:00
|
|
|
|
this.stage.scale.pageAlignHoritzontally = true;
|
|
|
|
|
|
game.state.start('preloader', true, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var Preloader = function(game) {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Preloader.prototype.preload = function()
|
|
|
|
|
|
{
|
|
|
|
|
|
this.preloadBar = game.add.sprite(0, 0, 'preloader');
|
|
|
|
|
|
this.preloadBar.anchor.setTo(0.5, 0.5);
|
|
|
|
|
|
this.preloadBar.x = game.camera.x + (game.camera.width / 2);
|
|
|
|
|
|
this.preloadBar.y = game.camera.y + (game.camera.width / 2);
|
|
|
|
|
|
game.load.setPreloadSprite(this.preloadBar, 0);
|
|
|
|
|
|
|
|
|
|
|
|
for (var k in moonlightSettings['map']['tilesets']) {
|
|
|
|
|
|
var ts = moonlightSettings['map']['tilesets'][k];
|
|
|
|
|
|
this.load.image(ts['name'], ts['path']);
|
|
|
|
|
|
}
|
|
|
|
|
|
for (var k in moonlightSettings['images']) {
|
|
|
|
|
|
var i = moonlightSettings['images'][k];
|
|
|
|
|
|
this.load.image(i['name'], i['path']);
|
|
|
|
|
|
}
|
|
|
|
|
|
for (var k in moonlightSettings['sounds']) {
|
|
|
|
|
|
var s = moonlightSettings['sounds'][k];
|
|
|
|
|
|
this.load.audio(s['name'], s['path']);
|
|
|
|
|
|
}
|
|
|
|
|
|
for (var k in moonlightSettings['spritesheets']) {
|
|
|
|
|
|
var s = moonlightSettings['spritesheets'][k]
|
|
|
|
|
|
game.load.spritesheet(s['name'], s['path'], s['width'], s['height'], s['frames'])
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.load.tilemap('map',
|
|
|
|
|
|
moonlightSettings['map']['path'],
|
|
|
|
|
|
null,
|
|
|
|
|
|
Phaser.Tilemap.TILED_JSON);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Preloader.prototype.create = function()
|
|
|
|
|
|
{
|
|
|
|
|
|
function goalready() {
|
|
|
|
|
|
this.preloadBar.destroy();
|
|
|
|
|
|
game.state.start('game', true, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var tween = this.add.tween(this.preloadBar).to({ alpha: 0 }, 1000, Phaser.Easing.Linear.None, true);
|
|
|
|
|
|
tween.onComplete.add(goalready, this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-15 21:15:01 -07:00
|
|
|
|
game.state.add('boot', Boot, false);
|
|
|
|
|
|
game.state.add('preloader', Preloader, false);
|
|
|
|
|
|
game.state.add('game', GameState, false);
|
2014-06-15 21:13:20 -07:00
|
|
|
|
|
2014-06-15 21:15:01 -07:00
|
|
|
|
game.state.start('boot');
|