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-11 22:25:47 -07:00
|
|
|
STATE_RUN = 1 << 5;
|
|
|
|
|
STATE_MOVE_LEFT = 1 << 6;
|
|
|
|
|
STATE_MOVE_RIGHT = 1 << 7;
|
|
|
|
|
STATE_MOVE_UP = 1 << 8;
|
|
|
|
|
STATE_MOVE_DOWN = 1 << 9;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
SPRITE_TOWNSFOLK_FEMALE1 = 5;
|
|
|
|
|
SPRITE_TOWNSFOLK_FEMALE2 = 6;
|
|
|
|
|
SPRITE_TOWNSFOLK_FEMALE3 = 7;
|
|
|
|
|
SPRITE_TOWNSFOLK_FEMALE4 = 8;
|
|
|
|
|
SPRITE_TOWNSFOLK_GUARD1 = 9;
|
|
|
|
|
SPRITE_TOWNSFOLK_GUARD2 = 10;
|
|
|
|
|
|
2014-06-09 22:48:39 -07:00
|
|
|
var moonlightSettings = {
|
|
|
|
|
'map' : {
|
|
|
|
|
'tilesets': [
|
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-09 22:48:39 -07:00
|
|
|
}
|
|
|
|
|
],
|
2014-06-12 21:57:03 -07:00
|
|
|
'layers': {
|
|
|
|
|
'0 - NonCollide Base': {
|
|
|
|
|
'collides': false,
|
2014-06-12 22:00:46 -07:00
|
|
|
'collisionBetween': [0, 0],
|
|
|
|
|
'resizeWorld': true
|
2014-06-12 21:57:03 -07:00
|
|
|
},
|
|
|
|
|
'0 - Collide Base': {
|
|
|
|
|
'collides': true,
|
2014-06-12 22:00:46 -07:00
|
|
|
'collisionBetween': [0, 9999],
|
|
|
|
|
'resizeWorld': false
|
2014-06-12 21:57:03 -07:00
|
|
|
},
|
2014-06-12 22:04:42 -07:00
|
|
|
'0 - Collide Overlay - Pathways': {
|
|
|
|
|
'collides': false,
|
2014-06-12 22:00:46 -07:00
|
|
|
'collisionBetween': [0, 9999],
|
|
|
|
|
'resizeWorld': false
|
2014-06-12 21:57:03 -07:00
|
|
|
},
|
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 22:00:46 -07:00
|
|
|
'collisionBetween': [0, 9999],
|
|
|
|
|
'resizeWorld': false
|
2014-06-12 21:57:03 -07:00
|
|
|
}
|
2014-06-12 22:17:22 -07:00
|
|
|
'0 - NonCollide Overlay - Ground Objects': {
|
|
|
|
|
'collides': false,
|
|
|
|
|
'collisionBetween': [0, 9999],
|
|
|
|
|
'resizeWorld': false
|
|
|
|
|
}
|
2014-06-12 21:57:03 -07:00
|
|
|
},
|
2014-06-12 22:17:22 -07:00
|
|
|
'path': 'gfx/map.json'
|
2014-06-09 22:48:39 -07:00
|
|
|
},
|
|
|
|
|
'images': [
|
2014-06-10 19:15:55 -07:00
|
|
|
{
|
|
|
|
|
'name': 'simplelight',
|
|
|
|
|
'path': 'gfx/lights/light-white-256px.png'
|
2014-06-12 01:46:05 -07:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-female/alerted/1.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-female/alerted/1.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-female/alerted/2.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-female/alerted/2.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-female/alerted/3.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-female/alerted/3.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-female/alerted/4.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-female/alerted/4.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-female/alerted/5.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-female/alerted/5.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-female/alerted/6.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-female/alerted/6.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-female/concerned/2.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-female/concerned/2.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-female/concerned/3.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-female/concerned/3.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-female/concerned/4.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-female/concerned/4.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-female/concerned/6.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-female/concerned/6.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-female/concerned/7.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-female/concerned/7.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-female/losthim/3.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-female/losthim/3.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-female/unaware/1.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-female/unaware/1.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-female/unaware/3.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-female/unaware/3.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-female/unaware/4.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-female/unaware/4.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-female/unaware/5.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-female/unaware/5.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-guard/alerted/1.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-guard/alerted/1.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-guard/alerted/2.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-guard/alerted/2.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-guard/alerted/4.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-guard/alerted/4.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-guard/alerted/5.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-guard/alerted/5.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-guard/alerted/7.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-guard/alerted/7.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-guard/alerted/8.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-guard/alerted/8.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-guard/alerted/9.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-guard/alerted/9.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-guard/concerned/1.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-guard/concerned/1.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-guard/concerned/2.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-guard/concerned/2.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-guard/concerned/3.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-guard/concerned/3.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-guard/concerned/5.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-guard/concerned/5.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-guard/concerned/6.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-guard/concerned/6.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-guard/losthim/2.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-guard/losthim/2.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-guard/losthim/3.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-guard/losthim/3.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-guard/losthim/4.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-guard/losthim/4.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-guard/unaware/1.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-guard/unaware/1.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-guard/unaware/2.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-guard/unaware/2.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-guard/unaware/4.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-guard/unaware/4.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-guard/unaware/5.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-guard/unaware/5.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-guard/unaware/6.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-guard/unaware/6.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-guard/unaware/7.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-guard/unaware/7.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-male/alerted/10.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-male/alerted/10.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-male/alerted/11.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-male/alerted/11.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-male/alerted/1.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-male/alerted/1.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-male/alerted/2.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-male/alerted/2.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-male/alerted/4.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-male/alerted/4.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-male/alerted/5.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-male/alerted/5.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-male/alerted/6.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-male/alerted/6.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-male/alerted/7.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-male/alerted/7.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-male/alerted/8.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-male/alerted/8.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-male/alerted/9.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-male/alerted/9.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-male/concerned/2.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-male/concerned/2.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-male/concerned/5.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-male/concerned/5.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-male/concerned/7.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-male/concerned/7.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-male/losthim/6.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-male/losthim/6.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-male/losthim/7.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-male/losthim/7.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-male/unaware/1.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-male/unaware/1.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-male/unaware/2.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-male/unaware/2.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-male/unaware/3.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-male/unaware/3.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-male/unaware/4.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-male/unaware/4.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-male/unaware/6.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-male/unaware/6.png"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "townsfolk-male/unaware/7.png",
|
|
|
|
|
"path": "gfx/bubbles/townsfolk-male/unaware/7.png"
|
2014-06-10 19:15:55 -07:00
|
|
|
}
|
2014-06-12 01:46:05 -07:00
|
|
|
|
2014-06-09 22:48:39 -07:00
|
|
|
],
|
|
|
|
|
'spritesheets': [
|
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': {
|
|
|
|
|
'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-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-12 01:46:05 -07:00
|
|
|
"townsfolk-male/unaware/1.png",
|
|
|
|
|
"townsfolk-male/unaware/2.png",
|
|
|
|
|
"townsfolk-male/unaware/3.png",
|
|
|
|
|
"townsfolk-male/unaware/4.png",
|
|
|
|
|
"townsfolk-male/unaware/6.png",
|
|
|
|
|
"townsfolk-male/unaware/7.png"
|
2014-06-11 21:56:46 -07:00
|
|
|
],
|
2014-06-11 22:51:05 -07:00
|
|
|
"concerned" : [
|
2014-06-12 01:46:05 -07:00
|
|
|
"townsfolk-male/concerned/2.png",
|
|
|
|
|
"townsfolk-male/concerned/5.png",
|
|
|
|
|
"townsfolk-male/concerned/7.png"
|
2014-06-11 22:02:11 -07:00
|
|
|
],
|
2014-06-11 22:51:05 -07:00
|
|
|
"alerted" : [
|
2014-06-12 01:46:05 -07:00
|
|
|
"townsfolk-male/alerted/10.png",
|
|
|
|
|
"townsfolk-male/alerted/11.png",
|
|
|
|
|
"townsfolk-male/alerted/1.png",
|
|
|
|
|
"townsfolk-male/alerted/2.png",
|
|
|
|
|
"townsfolk-male/alerted/4.png",
|
|
|
|
|
"townsfolk-male/alerted/5.png",
|
|
|
|
|
"townsfolk-male/alerted/6.png",
|
|
|
|
|
"townsfolk-male/alerted/7.png",
|
|
|
|
|
"townsfolk-male/alerted/8.png",
|
|
|
|
|
"townsfolk-male/alerted/9.png"
|
2014-06-11 22:02:11 -07:00
|
|
|
],
|
2014-06-11 22:51:05 -07:00
|
|
|
"losthim" : [
|
2014-06-12 01:46:05 -07:00
|
|
|
"townsfolk-male/losthim/6.png",
|
|
|
|
|
"townsfolk-male/losthim/7.png"
|
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-12 01:46:05 -07:00
|
|
|
"townsfolk-female/unaware/1.png",
|
|
|
|
|
"townsfolk-female/unaware/3.png",
|
|
|
|
|
"townsfolk-female/unaware/4.png",
|
|
|
|
|
"townsfolk-female/unaware/5.png"
|
2014-06-11 23:43:59 -07:00
|
|
|
],
|
|
|
|
|
"concerned" : [
|
2014-06-12 01:46:05 -07:00
|
|
|
"townsfolk-female/concerned/2.png",
|
|
|
|
|
"townsfolk-female/concerned/3.png",
|
|
|
|
|
"townsfolk-female/concerned/4.png",
|
|
|
|
|
"townsfolk-female/concerned/6.png",
|
|
|
|
|
"townsfolk-female/concerned/7.png" ],
|
2014-06-11 23:43:59 -07:00
|
|
|
"alerted" : [
|
2014-06-12 01:46:05 -07:00
|
|
|
"townsfolk-female/alerted/1.png",
|
|
|
|
|
"townsfolk-female/alerted/2.png",
|
|
|
|
|
"townsfolk-female/alerted/3.png",
|
|
|
|
|
"townsfolk-female/alerted/4.png",
|
|
|
|
|
"townsfolk-female/alerted/5.png",
|
|
|
|
|
"townsfolk-female/alerted/6.png"
|
2014-06-11 23:43:59 -07:00
|
|
|
],
|
|
|
|
|
"losthim" : [
|
2014-06-12 01:46:05 -07:00
|
|
|
"townsfolk-female/losthim/3.png"
|
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-12 01:46:05 -07:00
|
|
|
"townsfolk-guard/unaware/1.png",
|
|
|
|
|
"townsfolk-guard/unaware/2.png",
|
|
|
|
|
"townsfolk-guard/unaware/4.png",
|
|
|
|
|
"townsfolk-guard/unaware/5.png",
|
|
|
|
|
"townsfolk-guard/unaware/6.png",
|
|
|
|
|
"townsfolk-guard/unaware/7.png"
|
2014-06-11 23:43:59 -07:00
|
|
|
],
|
|
|
|
|
"concerned" : [
|
2014-06-12 01:46:05 -07:00
|
|
|
"townsfolk-guard/concerned/1.png",
|
|
|
|
|
"townsfolk-guard/concerned/2.png",
|
|
|
|
|
"townsfolk-guard/concerned/3.png",
|
|
|
|
|
"townsfolk-guard/concerned/5.png",
|
|
|
|
|
"townsfolk-guard/concerned/6.png"
|
2014-06-11 23:43:59 -07:00
|
|
|
],
|
|
|
|
|
"alerted" : [
|
2014-06-12 01:46:05 -07:00
|
|
|
"townsfolk-guard/alerted/1.png",
|
|
|
|
|
"townsfolk-guard/alerted/2.png",
|
|
|
|
|
"townsfolk-guard/alerted/4.png",
|
|
|
|
|
"townsfolk-guard/alerted/5.png",
|
|
|
|
|
"townsfolk-guard/alerted/7.png",
|
|
|
|
|
"townsfolk-guard/alerted/8.png",
|
|
|
|
|
"townsfolk-guard/alerted/9.png"
|
2014-06-11 23:43:59 -07:00
|
|
|
],
|
|
|
|
|
"losthim" : [
|
2014-06-12 01:46:05 -07:00
|
|
|
"townsfolk-guard/losthim/2.png",
|
|
|
|
|
"townsfolk-guard/losthim/3.png",
|
|
|
|
|
"townsfolk-guard/losthim/4.png"
|
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-11 10:05:02 -07:00
|
|
|
// Create torch objects
|
2014-06-11 20:17:34 -07:00
|
|
|
// Light constructor
|
|
|
|
|
var Light = function(game, x, y, radius, fade, color, flicker) {
|
2014-06-11 11:08:16 -07:00
|
|
|
color = ( typeof color == undefined ? [255, 255, 255] : color );
|
|
|
|
|
fade = ( typeof fade == undefined ? 0.25 : fade );
|
|
|
|
|
radius = ( typeof radius == undefined ? 64 : radius );
|
2014-06-11 20:17:34 -07:00
|
|
|
flicker = ( typeof flicker == undefined ? false : flicker );
|
2014-06-11 10:48:05 -07:00
|
|
|
Phaser.Sprite.call(this, game, x, y, null);
|
2014-06-11 10:05:02 -07:00
|
|
|
|
|
|
|
|
// Set the pivot point for this sprite to the center
|
|
|
|
|
this.anchor.setTo(0.5, 0.5);
|
2014-06-11 11:01:43 -07:00
|
|
|
this.color = color;
|
|
|
|
|
this.radius = radius;
|
2014-06-11 11:00:09 -07:00
|
|
|
this.fade = radius * fade
|
2014-06-12 00:26:58 -07:00
|
|
|
this.rect = new Phaser.Rectangle(this.x - radius, this.y - radius, radius * 2, radius * 2)
|
2014-06-11 20:17:34 -07:00
|
|
|
this.flicker = flicker;
|
2014-06-11 20:12:13 -07:00
|
|
|
|
2014-06-11 10:05:02 -07:00
|
|
|
};
|
|
|
|
|
|
2014-06-11 20:17:34 -07:00
|
|
|
// Lightes are a type of Phaser.Sprite
|
|
|
|
|
Light.prototype = Object.create(Phaser.Sprite.prototype);
|
|
|
|
|
Light.prototype.constructor = Light;
|
2014-06-11 10:05:02 -07:00
|
|
|
|
2014-06-11 22:05:54 -07:00
|
|
|
var AISprite = function(game, x, y, spritetype) {
|
2014-06-12 00:15:51 -07:00
|
|
|
this.enableWordBubble = function() {
|
|
|
|
|
this.enable_word_bubble = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.clearWordBubble = function() {
|
2014-06-12 02:09:20 -07:00
|
|
|
if ( this.bubble !== null )
|
|
|
|
|
this.bubble.destroy();
|
2014-06-12 01:46:05 -07:00
|
|
|
this.bubble = null;
|
2014-06-12 00:15:51 -07:00
|
|
|
this.enable_word_bubble = false;
|
|
|
|
|
timer = game.time.create(false);
|
2014-06-12 02:14:25 -07:00
|
|
|
timerev = timer.add(20000 + (game.rnd.integerInRange(0, 30) * 1000), this.enableWordBubble, this);
|
2014-06-12 00:15:51 -07:00
|
|
|
timer.start()
|
2014-06-12 00:11:08 -07:00
|
|
|
}
|
|
|
|
|
|
2014-06-11 22:25:47 -07:00
|
|
|
this.setWordBubble = function()
|
|
|
|
|
{
|
2014-06-12 02:07:28 -07:00
|
|
|
if ( this.bubble !== null || this.sprite_group == undefined || this.enable_word_bubble == false) {
|
2014-06-11 22:25:47 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
aistate = this.state & ( STATE_UNAWARE | STATE_CONCERNED | STATE_ALERTED | STATE_LOSTHIM );
|
2014-06-11 22:51:05 -07:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-11 23:06:50 -07:00
|
|
|
|
2014-06-11 22:25:47 -07:00
|
|
|
var mylines = moonlightDialog['status'][this.sprite_group][aistate];
|
2014-06-12 01:49:02 -07:00
|
|
|
var myline = mylines[game.rnd.integerInRange(0, mylines.length)]
|
2014-06-12 01:53:28 -07:00
|
|
|
this.bubble = game.add.sprite(this.x, this.y, myline);
|
2014-06-12 01:47:02 -07:00
|
|
|
game.physics.arcade.enable(this.bubble);
|
2014-06-11 23:46:03 -07:00
|
|
|
|
2014-06-12 01:57:56 -07:00
|
|
|
this.bubble.x = this.x - (this.bubble.width / 2);
|
|
|
|
|
this.bubble.y = this.y - (this.bubble.height);
|
|
|
|
|
|
2014-06-12 00:13:46 -07:00
|
|
|
timer = game.time.create(false);
|
2014-06-12 00:15:51 -07:00
|
|
|
timerev = timer.add(5000, this.clearWordBubble, this);
|
2014-06-12 00:11:08 -07:00
|
|
|
timer.start()
|
2014-06-11 22:25:47 -07:00
|
|
|
}
|
|
|
|
|
|
2014-06-11 21:05:18 -07:00
|
|
|
this.update = function()
|
|
|
|
|
{
|
2014-06-11 21:14:18 -07:00
|
|
|
var running = false;
|
2014-06-11 21:05:18 -07:00
|
|
|
|
2014-06-11 23:46:41 -07:00
|
|
|
if ( game.rnd.integerInRange(0, 500) > 450 ) {
|
2014-06-11 22:25:47 -07:00
|
|
|
this.setWordBubble();
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-12 01:51:56 -07:00
|
|
|
if ( this.bubble !== null ) {
|
2014-06-12 01:57:56 -07:00
|
|
|
this.bubble.body.velocity.x = this.body.velocity.x;
|
|
|
|
|
this.bubble.body.velocity.y = this.body.velocity.y;
|
2014-06-12 02:06:04 -07:00
|
|
|
//this.bubble.x = this.x - (this.bubble.width / 2);
|
|
|
|
|
//this.bubble.y = this.y - (this.bubble.height);
|
2014-06-12 01:51:56 -07:00
|
|
|
}
|
|
|
|
|
|
2014-06-12 02:05:01 -07:00
|
|
|
if ( game.rnd.integerInRange(0, 100) < 95 )
|
|
|
|
|
return;
|
|
|
|
|
if ( game.rnd.integerInRange(0, 100) > 90 ) {
|
|
|
|
|
running = true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-11 21:05:18 -07:00
|
|
|
switch ( game.rnd.integerInRange(0, 4) ) {
|
|
|
|
|
case 0: {
|
2014-06-11 21:06:33 -07:00
|
|
|
setSpriteMovement(this, running, 'up');
|
2014-06-11 21:05:18 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 1: {
|
2014-06-11 21:06:33 -07:00
|
|
|
setSpriteMovement(this, running, 'down');
|
2014-06-11 21:05:18 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 2: {
|
2014-06-11 21:06:33 -07:00
|
|
|
setSpriteMovement(this, running, 'left');
|
2014-06-11 21:05:18 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 3: {
|
2014-06-11 21:06:33 -07:00
|
|
|
setSpriteMovement(this, running, 'right');
|
2014-06-11 21:05:18 -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-12 02:09:46 -07:00
|
|
|
this.bubble = null;
|
|
|
|
|
|
2014-06-12 02:09:20 -07:00
|
|
|
this.clearWordBubble();
|
2014-06-11 23:53:49 -07:00
|
|
|
|
2014-06-11 22:25:47 -07:00
|
|
|
this.state = STATE_UNAWARE;
|
2014-06-11 20:43:05 -07:00
|
|
|
Phaser.Sprite.call(this, game, x, y, spritenames_by_type[spritetype]);
|
2014-06-11 21:03:01 -07:00
|
|
|
game.physics.arcade.enable(this);
|
2014-06-11 21:19:34 -07:00
|
|
|
this.body.collideWorldBounds = true;
|
2014-06-11 21:17:23 -07:00
|
|
|
|
2014-06-11 23:59:54 -07:00
|
|
|
var ARGH = spritenames_by_type[spritetype];
|
2014-06-12 00:00:20 -07:00
|
|
|
ARGH = ARGH.split("-");
|
2014-06-11 23:59:04 -07:00
|
|
|
this.sprite_group = ARGH[0] + "-" + ARGH[1];
|
2014-06-11 22:25:47 -07:00
|
|
|
|
2014-06-11 21:17:23 -07:00
|
|
|
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-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-11 10:05:44 -07:00
|
|
|
var GameState = function(game) {
|
2014-06-11 10:05:02 -07:00
|
|
|
}
|
|
|
|
|
|
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-11 10:06:03 -07:00
|
|
|
GameState.prototype.preload = function()
|
2014-06-10 19:15:55 -07:00
|
|
|
{
|
2014-06-09 22:48:39 -07:00
|
|
|
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']);
|
|
|
|
|
}
|
2014-06-10 01:05:21 -07:00
|
|
|
for (var k in moonlightSettings['spritesheets']) {
|
|
|
|
|
var s = moonlightSettings['spritesheets'][k]
|
|
|
|
|
game.load.spritesheet(s['name'], s['path'], s['width'], s['height'], s['frames'])
|
|
|
|
|
}
|
2014-06-12 22:09:23 -07:00
|
|
|
|
2014-06-10 19:15:55 -07:00
|
|
|
this.load.tilemap('map',
|
|
|
|
|
moonlightSettings['map']['path'],
|
|
|
|
|
null,
|
2014-06-09 22:48:39 -07:00
|
|
|
Phaser.Tilemap.TILED_JSON);
|
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 = [];
|
|
|
|
|
|
|
|
|
|
for (var ln in moonlightSettings['map']['layers']) {
|
2014-06-12 22:02:29 -07:00
|
|
|
console.log("Preparing layer " + ln);
|
2014-06-12 21:58:51 -07:00
|
|
|
lp = moonlightSettings['map']['layers'][ln];
|
2014-06-12 22:10:12 -07:00
|
|
|
layer = this.map.createLayer(ln);
|
2014-06-12 22:06:40 -07:00
|
|
|
console.log("Setting collisions on " + ln);
|
2014-06-12 22:10:12 -07:00
|
|
|
this.map.setCollisionBetween(
|
2014-06-12 21:57:03 -07:00
|
|
|
lp['collisionBetween'][0],
|
|
|
|
|
lp['collisionBetween'][1],
|
|
|
|
|
lp['collides']
|
|
|
|
|
);
|
|
|
|
|
if ( lp['collides'] == true )
|
|
|
|
|
this.map_collision_layers.push(layer);
|
|
|
|
|
if ( lp['resizeWorld'] == true )
|
|
|
|
|
layer.resizeWorld();
|
|
|
|
|
}
|
2014-06-09 22:48:39 -07:00
|
|
|
|
2014-06-10 01:05:21 -07:00
|
|
|
player = this.add.sprite(10, 10, 'player');
|
2014-06-10 19:15:55 -07:00
|
|
|
this.physics.arcade.enable(player);
|
|
|
|
|
player.body.collideWorldBounds = 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
|
|
|
|
|
|
|
|
this.game.time.advancedTiming = true;
|
|
|
|
|
this.fpsText = this.game.add.text(
|
|
|
|
|
20, 20, '', { font: '16px Arial', fill: '#ffffff' }
|
|
|
|
|
);
|
2014-06-11 10:46:14 -07:00
|
|
|
this.fpsText.fixedToCamera = true;
|
2014-06-10 19:15:55 -07:00
|
|
|
|
2014-06-11 20:43:05 -07:00
|
|
|
// Create the wandering sprites
|
2014-06-11 22:05:54 -07:00
|
|
|
this.aiSprites = game.add.group();
|
2014-06-12 00:24:20 -07:00
|
|
|
for ( i = 0; i < 50 ; i++ ) {
|
2014-06-11 22:05:54 -07:00
|
|
|
this.aiSprites.add(
|
|
|
|
|
new AISprite(game,
|
2014-06-12 00:24:20 -07:00
|
|
|
game.rnd.integerInRange(0, game.world.width),
|
|
|
|
|
game.rnd.integerInRange(0, game.world.height),
|
2014-06-12 00:02:33 -07:00
|
|
|
game.rnd.integerInRange(0, 9)
|
2014-06-11 20:43:05 -07:00
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
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-12 00:25:31 -07:00
|
|
|
this.shadowTextureColor = 'rgb(50, 50, 50)';
|
2014-06-11 20:48:04 -07:00
|
|
|
|
|
|
|
|
// Create an object that will use the bitmap as a texture
|
|
|
|
|
this.shadowSprite = game.add.image(0, 0, this.shadowTexture);
|
|
|
|
|
|
|
|
|
|
// Set the blend mode to MULTIPLY. This will darken the colors of
|
|
|
|
|
// everything below this sprite.
|
|
|
|
|
this.shadowSprite.blendMode = Phaser.blendModes.MULTIPLY;
|
|
|
|
|
|
2014-06-10 19:15:55 -07:00
|
|
|
// Create the lights
|
2014-06-11 19:40:05 -07:00
|
|
|
this.staticLights = game.add.group();
|
2014-06-12 00:24:42 -07:00
|
|
|
for (i = 0; i < 50 ; i++ ) {
|
2014-06-12 00:21:22 -07:00
|
|
|
this.staticLights.add(
|
|
|
|
|
new Light(game,
|
2014-06-12 00:24:42 -07:00
|
|
|
game.rnd.integerInRange(0, game.world.width),
|
|
|
|
|
game.rnd.integerInRange(0, game.world.height),
|
2014-06-12 00:21:22 -07:00
|
|
|
game.rnd.integerInRange(0, 128),
|
|
|
|
|
game.rnd.realInRange(0.0, 1.0),
|
|
|
|
|
[
|
|
|
|
|
game.rnd.integerInRange(0, 255),
|
|
|
|
|
game.rnd.integerInRange(0, 255),
|
|
|
|
|
game.rnd.integerInRange(0, 255)
|
|
|
|
|
],
|
|
|
|
|
flicker = [true, false][game.rnd.integerInRange(0, 1)]
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
2014-06-11 20:17:34 -07:00
|
|
|
//this.movingLight = new Light(game, game.width/2, game.height/2);
|
2014-06-11 11:09:45 -07:00
|
|
|
//this.lights.add(this.movingLight);
|
2014-06-09 22:48:39 -07:00
|
|
|
}
|
|
|
|
|
|
2014-06-11 10:06:03 -07:00
|
|
|
GameState.prototype.updateShadowTexture = function() {
|
2014-06-10 19:15:55 -07:00
|
|
|
// This function updates the shadow texture (this.shadowTexture).
|
|
|
|
|
// First, it fills the entire texture with a dark shadow color.
|
|
|
|
|
// Then it draws a white circle centered on the pointer position.
|
|
|
|
|
// Because the texture is drawn to the screen using the MULTIPLY
|
|
|
|
|
// blend mode, the dark areas of the texture make all of the colors
|
|
|
|
|
// underneath it darker, while the white area is unaffected.
|
|
|
|
|
|
|
|
|
|
// Draw shadow
|
2014-06-12 01:59:37 -07:00
|
|
|
//this.shadowSprite.bringToTop();
|
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
|
|
|
|
|
|
|
|
// Iterate through each of the lights and draw the glow
|
2014-06-11 19:57:11 -07:00
|
|
|
this.staticLights.forEach(function(light) {
|
2014-06-11 20:24:07 -07:00
|
|
|
// Don't draw lights that aren't on screen
|
2014-06-11 20:12:13 -07:00
|
|
|
var r1 = new Phaser.Rectangle(this.game.camera.x,
|
|
|
|
|
this.game.camera.y,
|
|
|
|
|
this.game.camera.width,
|
|
|
|
|
this.game.camera.height);
|
|
|
|
|
if ( ! light.rect.intersects(r1) ) {
|
2014-06-11 20:01:44 -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 ) {
|
2014-06-11 20:24:07 -07:00
|
|
|
// Randomly change the radius each frame
|
2014-06-11 20:17:34 -07:00
|
|
|
var radius = light.radius + game.rnd.integerInRange(1,10);
|
|
|
|
|
} else {
|
|
|
|
|
var radius = light.radius;
|
|
|
|
|
}
|
2014-06-10 19:15:55 -07:00
|
|
|
|
|
|
|
|
// Draw circle of light with a soft edge
|
|
|
|
|
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-11 11:00:09 -07:00
|
|
|
gradient.addColorStop(0, 'rgba(' + light.color[0] + ',' + light.color[1] + ',' + light.color[2] +', 1.0)');
|
|
|
|
|
gradient.addColorStop(1, 'rgba(' + light.color[0] + ',' + light.color[1] + ',' + light.color[2] +', 0.0)');
|
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 just tells the engine it should update the texture cache
|
|
|
|
|
this.shadowTexture.dirty = true;
|
|
|
|
|
};
|
|
|
|
|
|
2014-06-11 21:06:33 -07:00
|
|
|
function setSpriteMovement(spr, running, dir)
|
2014-06-10 01:05:21 -07:00
|
|
|
{
|
|
|
|
|
var x = 0;
|
|
|
|
|
var y = 0;
|
|
|
|
|
|
|
|
|
|
if ( running ) {
|
|
|
|
|
x = 200;
|
|
|
|
|
y = 200;
|
|
|
|
|
spr.animations.play("bipedrun" + dir);
|
|
|
|
|
} else {
|
|
|
|
|
x = 75;
|
|
|
|
|
y = 75;
|
|
|
|
|
spr.animations.play("bipedwalk" + dir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( dir == "left" ) {
|
|
|
|
|
spr.body.velocity.x = -x;
|
|
|
|
|
spr.body.velocity.y = 0;
|
|
|
|
|
} else if ( dir == "right" ) {
|
|
|
|
|
spr.body.velocity.x = x;
|
|
|
|
|
spr.body.velocity.y = 0;
|
|
|
|
|
} else if ( dir == "up" ) {
|
|
|
|
|
spr.body.velocity.x = 0;
|
|
|
|
|
spr.body.velocity.y = -y;
|
|
|
|
|
} else if ( dir == "down" ) {
|
|
|
|
|
spr.body.velocity.x = 0;
|
|
|
|
|
spr.body.velocity.y = y;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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-09 22:48:39 -07:00
|
|
|
if ( controls.up.isDown) {
|
2014-06-11 21:06:33 -07:00
|
|
|
setSpriteMovement(player, controls.up.shiftKey, 'up');
|
2014-06-09 22:48:39 -07:00
|
|
|
} else if ( controls.down.isDown ) {
|
2014-06-11 21:06:33 -07:00
|
|
|
setSpriteMovement(player, controls.up.shiftKey, 'down');
|
2014-06-10 01:05:21 -07:00
|
|
|
} else if ( controls.left.isDown ) {
|
2014-06-11 21:06:33 -07:00
|
|
|
setSpriteMovement(player, controls.up.shiftKey, 'left');
|
2014-06-09 22:48:39 -07:00
|
|
|
} else if ( controls.right.isDown ) {
|
2014-06-11 21:06:33 -07:00
|
|
|
setSpriteMovement(player, controls.up.shiftKey, 'right');
|
2014-06-10 01:05:21 -07:00
|
|
|
} else {
|
|
|
|
|
player.animations.stop(null, true);
|
2014-06-09 22:48:39 -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-12 21:57:03 -07:00
|
|
|
|
|
|
|
|
for (var layer in this.map_collision_layers ) {
|
|
|
|
|
this.physics.arcade.collide(player, layer);
|
|
|
|
|
}
|
2014-06-11 21:09:22 -07:00
|
|
|
|
2014-06-11 21:46:32 -07:00
|
|
|
function _inner_collide(x) {
|
2014-06-12 21:57:03 -07:00
|
|
|
for ( var layer in this.map_collision_layers ) {
|
|
|
|
|
this.physics.arcade.collide(x, layer);
|
|
|
|
|
}
|
2014-06-11 21:46:32 -07:00
|
|
|
this.physics.arcade.collide(x, player);
|
2014-06-11 21:42:36 -07:00
|
|
|
}
|
|
|
|
|
|
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-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-11 10:05:25 -07:00
|
|
|
var game = new Phaser.Game(640, 480, Phaser.AUTO, '');
|
2014-06-11 10:05:02 -07:00
|
|
|
game.state.add('game', GameState, true);
|