2014-06-22 09:58:25 -07:00
|
|
|
var GameState = function(game) {
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-27 21:41:57 -07:00
|
|
|
GameState.prototype.updateClock = function()
|
|
|
|
|
{
|
|
|
|
|
this.clock.setSeconds(this.clock.getSeconds() + 1);
|
2014-06-28 08:48:26 -07:00
|
|
|
if ( this.clock.getSeconds() == 59)
|
|
|
|
|
player.score += SCORE_PERSECOND;
|
2014-06-27 21:41:57 -07:00
|
|
|
this.clock.setMilliseconds(0);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-22 09:58:25 -07:00
|
|
|
GameState.prototype.create = function()
|
|
|
|
|
{
|
|
|
|
|
this.map = this.add.tilemap('map');
|
|
|
|
|
for (var k in moonlightSettings['map']['tilesets']) {
|
|
|
|
|
var ts = moonlightSettings['map']['tilesets'][k];
|
|
|
|
|
this.map.addTilesetImage(ts['name']);
|
|
|
|
|
}
|
|
|
|
|
this.map_collision_layers = [];
|
|
|
|
|
pfgrid = [];
|
|
|
|
|
|
|
|
|
|
for (var ln in moonlightSettings['map']['layers']) {
|
|
|
|
|
lp = moonlightSettings['map']['layers'][ln];
|
|
|
|
|
if ( lp['type'] == "tiles" ) {
|
|
|
|
|
layer = this.map.createLayer(ln);
|
|
|
|
|
this.map.setCollisionBetween(
|
|
|
|
|
lp['collisionBetween'][0],
|
|
|
|
|
lp['collisionBetween'][1],
|
|
|
|
|
lp['collides'],
|
|
|
|
|
ln
|
|
|
|
|
);
|
|
|
|
|
if ( lp['inject_sprites'] == true ) {
|
|
|
|
|
this.aiSprites = game.add.group();
|
2014-06-27 18:04:34 -07:00
|
|
|
this.aiSprites.debug = true;
|
2014-06-22 09:58:25 -07:00
|
|
|
this.map.createFromObjects('AI', 3544, 'player', 0, true, false, this.aiSprites, AISprite);
|
|
|
|
|
this.aiSprites.forEach(function(spr) {
|
|
|
|
|
spr.update_new_values();
|
|
|
|
|
}, this)
|
|
|
|
|
player = this.add.sprite((19 * 32), (21 * 32), 'player');
|
2014-06-28 08:48:26 -07:00
|
|
|
player.score = 0;
|
2014-06-22 09:58:25 -07:00
|
|
|
player.lightmeter = 0;
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
if ( lp['collides'] == true ) {
|
|
|
|
|
this.map_collision_layers.push(layer);
|
|
|
|
|
for (var i = 0; i < layer.layer.data.length; i++)
|
|
|
|
|
{
|
|
|
|
|
if ( i >= pfgrid.length )
|
|
|
|
|
pfgrid[i] = [];
|
|
|
|
|
for (var j = 0; j < layer.layer.data[i].length; j++)
|
|
|
|
|
{
|
|
|
|
|
if (layer.layer.data[i][j].index > 0) {
|
|
|
|
|
pfgrid[i][j] = 1;
|
|
|
|
|
} else if ( pfgrid[i][j] != 1 ) {
|
|
|
|
|
pfgrid[i][j] = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
layer.resizeWorld();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-12 10:49:00 -07:00
|
|
|
this.map_collision_layers.forEach(function(layer) {
|
|
|
|
|
layer.layer.data.forEach(function(row) {
|
|
|
|
|
row.forEach(function(column) {
|
|
|
|
|
setTileProperties(column);
|
|
|
|
|
}, this);
|
|
|
|
|
}, this);
|
|
|
|
|
}, this);
|
|
|
|
|
|
2014-06-22 09:58:25 -07:00
|
|
|
pathfinder_grid = new PF.Grid(this.map.width,
|
|
|
|
|
this.map.height,
|
|
|
|
|
pfgrid);
|
|
|
|
|
pathfinder = new PF.AStarFinder({allowDiagonal: false});
|
|
|
|
|
|
|
|
|
|
this.physics.arcade.enable(player);
|
2014-06-29 23:00:11 -07:00
|
|
|
player.body.setSize(16, 16, 8, 16);
|
2014-06-22 09:58:25 -07:00
|
|
|
player.body.center = new Phaser.Point(player.body.width / 2, player.body.height + player.body.halfHeight);
|
|
|
|
|
player.body.collideWorldBounds = true;
|
|
|
|
|
//player.body.immovable = true;
|
|
|
|
|
|
|
|
|
|
addAnimation(player, 'bipedwalkleft');
|
|
|
|
|
addAnimation(player, 'bipedwalkright');
|
|
|
|
|
addAnimation(player, 'bipedwalkup');
|
|
|
|
|
addAnimation(player, 'bipedwalkdown');
|
|
|
|
|
addAnimation(player, 'bipedrunleft');
|
|
|
|
|
addAnimation(player, 'bipedrunright');
|
|
|
|
|
addAnimation(player, 'bipedrunup');
|
|
|
|
|
addAnimation(player, 'bipedrundown');
|
|
|
|
|
|
|
|
|
|
this.camera.follow(player, Phaser.Camera.FOLLOW_TOPDOWN);
|
|
|
|
|
controls = game.input.keyboard.createCursorKeys();
|
2014-07-13 23:03:51 -07:00
|
|
|
controls.run = game.input.keyboard.addKey(Phaser.Keyboard.SHIFT);
|
2014-06-29 12:13:02 -07:00
|
|
|
controls.steal = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
|
2014-06-22 09:58:25 -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)
|
|
|
|
|
|
|
|
|
|
this.shadowTexture = game.add.bitmapData(game.world.width, game.world.height);
|
|
|
|
|
// drop this lower to make the map darker
|
2014-06-27 22:46:34 -07:00
|
|
|
this.shadowTextureColor = [20, 20, 20];
|
2014-06-22 09:58:25 -07:00
|
|
|
this.shadowSprite = game.add.image(0, 0, this.shadowTexture);
|
|
|
|
|
|
|
|
|
|
this.shadowSprite.blendMode = Phaser.blendModes.MULTIPLY;
|
|
|
|
|
|
|
|
|
|
this.staticLights = game.add.group();
|
|
|
|
|
this.map.createFromObjects('Lights', 97, 'player', 0, true, false, this.staticLights, Light);
|
|
|
|
|
this.staticLights.forEach(function(light) {
|
|
|
|
|
light.update_new_values();
|
|
|
|
|
}, this)
|
2014-06-29 11:03:23 -07:00
|
|
|
|
|
|
|
|
this.aiSpriteEffects = game.add.group();
|
2014-06-22 09:58:25 -07:00
|
|
|
|
|
|
|
|
this.staticSounds = game.add.group();
|
|
|
|
|
this.map.createFromObjects('Sounds', 11, 'player', 0, true, false, this.staticSounds, SoundSprite);
|
|
|
|
|
this.staticSounds.forEach(function(snd) {
|
|
|
|
|
snd.update_new_values();
|
|
|
|
|
}, this)
|
|
|
|
|
|
|
|
|
|
this.bubble_group = game.add.group();
|
|
|
|
|
|
|
|
|
|
this.uigroup = game.add.group();
|
2014-06-29 19:36:10 -07:00
|
|
|
this.recentlyStolenGroup = game.add.group();
|
2014-06-22 09:58:25 -07:00
|
|
|
this.game.time.advancedTiming = true;
|
2014-06-27 21:41:57 -07:00
|
|
|
|
|
|
|
|
this.clock = new Date();
|
2014-07-11 23:50:07 -07:00
|
|
|
this.clock.setHours(20, 00, 0, 0);
|
2014-06-27 21:41:57 -07:00
|
|
|
this.clockTimer = game.time.create(true);
|
|
|
|
|
this.clockTimer.repeat(DAYLIGHT_TIMER_REPEAT,
|
|
|
|
|
DAYLIGHT_TIMER_REPEATCOUNT,
|
|
|
|
|
this.updateClock,
|
|
|
|
|
this);
|
|
|
|
|
this.clockTimer.start();
|
2014-07-11 19:53:38 -07:00
|
|
|
|
2014-07-12 00:01:25 -07:00
|
|
|
game.camera.deadzone.height -= 68;
|
|
|
|
|
|
2014-07-11 23:49:20 -07:00
|
|
|
var hudoffset = game.camera.height - 68;
|
|
|
|
|
this.hud = this.game.add.image(0, hudoffset, 'hud', 0, this.uigroup);
|
|
|
|
|
this.hud_hourhand = this.game.add.sprite(39,
|
|
|
|
|
hudoffset + 36,
|
|
|
|
|
'clock_hourhand',
|
|
|
|
|
0,
|
|
|
|
|
this.uigroup);
|
|
|
|
|
this.hud_hourhand.anchor.setTo(0.5, 0.5);
|
|
|
|
|
this.hud_minutehand = this.game.add.sprite(39,
|
|
|
|
|
hudoffset + 36,
|
|
|
|
|
'clock_minutehand',
|
|
|
|
|
0,
|
|
|
|
|
this.uigroup);
|
|
|
|
|
this.hud_minutehand.anchor.setTo(0.5, 0.5);
|
|
|
|
|
this.hud_clockoverlay = this.game.add.image(39,
|
|
|
|
|
hudoffset + 36,
|
|
|
|
|
'clock_overlay',
|
|
|
|
|
0,
|
|
|
|
|
this.uigroup);
|
|
|
|
|
this.hud_clockoverlay.anchor.setTo(0.5, 0.5);
|
|
|
|
|
|
|
|
|
|
// this.clockText = this.game.add.text(
|
|
|
|
|
// 20, SCREEN_HEIGHT - 40, '', { font : '16px Arial', fill: '#ffffff' }, this.uigroup
|
|
|
|
|
// );
|
2014-07-11 19:53:38 -07:00
|
|
|
|
2014-07-13 23:39:37 -07:00
|
|
|
this.scoreTextBitmap = bitmapText('', FONTSIZE_MEDIUM);
|
|
|
|
|
this.scoreText = this.game.add.image(516,
|
|
|
|
|
480 - 68 + 31,
|
|
|
|
|
this.scoreTextBitmap,
|
|
|
|
|
0,
|
|
|
|
|
this.uigroup);
|
2014-06-28 08:30:33 -07:00
|
|
|
|
2014-07-12 08:30:38 -07:00
|
|
|
this.lightbar = this.game.add.sprite(256,
|
2014-07-12 08:21:22 -07:00
|
|
|
hudoffset + 7 + 6,
|
|
|
|
|
'lightbar',
|
|
|
|
|
0,
|
|
|
|
|
this.uigroup);
|
|
|
|
|
this.lightbar.anchor.setTo(0, 0.5)
|
2014-06-22 09:58:25 -07:00
|
|
|
this.uigroup.setAll('fixedToCamera', true);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-27 22:46:34 -07:00
|
|
|
GameState.prototype.getClockGamma = function() {
|
|
|
|
|
var clockgamma = 60 - this.clock.getMinutes();
|
|
|
|
|
if ( this.clock.getHours() >= 20 ) {
|
|
|
|
|
clockgamma += (23 - this.clock.getHours()) * 60;
|
|
|
|
|
} else {
|
|
|
|
|
clockgamma += this.clock.getHours() * 60;
|
|
|
|
|
}
|
|
|
|
|
clockgamma = parseInt(clockgamma / 6);
|
|
|
|
|
return clockgamma;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-22 09:58:25 -07:00
|
|
|
GameState.prototype.updateShadowTexture = function() {
|
2014-06-25 07:56:22 -07:00
|
|
|
var cv = this.shadowTextureColor;
|
2014-06-26 21:55:58 -07:00
|
|
|
var uigamma = parseInt(getDOMValue("uiGamma"));
|
2014-06-27 22:46:34 -07:00
|
|
|
var clockgamma = this.getClockGamma();
|
|
|
|
|
this.shadowTexture.context.fillStyle = ("rgb(" + (cv[0] + clockgamma + uigamma) +
|
|
|
|
|
"," + (cv[1] + clockgamma + uigamma) +
|
|
|
|
|
"," + (cv[2] + clockgamma + uigamma) + ")"
|
2014-06-26 21:55:58 -07:00
|
|
|
);
|
2014-06-22 09:58:25 -07:00
|
|
|
this.shadowTexture.context.fillRect(0, 0, game.world.width, game.world.height);
|
|
|
|
|
|
|
|
|
|
this.staticLights.forEach(function(light) {
|
|
|
|
|
if ( light.always_render !== true ) {
|
|
|
|
|
var r1 = positiveRectangle(this.game.camera.x,
|
|
|
|
|
this.game.camera.y,
|
|
|
|
|
this.game.camera.width,
|
|
|
|
|
this.game.camera.height);
|
|
|
|
|
if ( ! light.rect.intersects(r1) ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( light.flicker ) {
|
|
|
|
|
var radius = light.radius + game.rnd.integerInRange(1,10);
|
|
|
|
|
} else {
|
|
|
|
|
var radius = light.radius;
|
|
|
|
|
}
|
|
|
|
|
light.rendered_radius = radius;
|
|
|
|
|
|
|
|
|
|
var gradient =
|
|
|
|
|
this.shadowTexture.context.createRadialGradient(
|
|
|
|
|
light.x + 16, light.y + 16, light.fade,
|
|
|
|
|
light.x + 16, light.y + 16, radius);
|
|
|
|
|
gradient.addColorStop(0, light.color_start);
|
|
|
|
|
gradient.addColorStop(1, light.color_stop);
|
|
|
|
|
|
|
|
|
|
this.shadowTexture.context.beginPath();
|
|
|
|
|
this.shadowTexture.context.fillStyle = gradient;
|
|
|
|
|
this.shadowTexture.context.arc(light.x + 16, light.y + 16, radius, 0, Math.PI*2);
|
|
|
|
|
this.shadowTexture.context.fill();
|
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
|
|
this.shadowTexture.dirty = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
GameState.prototype.check_input = function()
|
|
|
|
|
{
|
|
|
|
|
player.body.velocity.x = 0;
|
|
|
|
|
player.body.velocity.y = 0;
|
|
|
|
|
velocityMod = 0;
|
|
|
|
|
var newstate = 0;
|
|
|
|
|
|
2014-06-29 12:13:02 -07:00
|
|
|
if ( controls.steal.justReleased() == true ) {
|
|
|
|
|
addState(player, STATE_STEALING);
|
2014-06-29 19:36:10 -07:00
|
|
|
} else {
|
|
|
|
|
delState(player, STATE_STEALING);
|
2014-06-29 12:13:02 -07:00
|
|
|
}
|
|
|
|
|
|
2014-06-22 09:58:25 -07:00
|
|
|
if ( controls.up.isDown) {
|
2014-07-13 23:03:51 -07:00
|
|
|
if ( controls.run.isDown ) {
|
2014-06-22 09:58:25 -07:00
|
|
|
newstate = (STATE_FACE_UP | STATE_MOVING | STATE_RUNNING);
|
|
|
|
|
} else {
|
|
|
|
|
newstate = (STATE_FACE_UP | STATE_MOVING );
|
|
|
|
|
}
|
|
|
|
|
} else if ( controls.down.isDown ) {
|
2014-07-13 23:03:51 -07:00
|
|
|
if ( controls.run.isDown ) {
|
2014-06-22 09:58:25 -07:00
|
|
|
newstate = (STATE_FACE_DOWN | STATE_MOVING | STATE_RUNNING);
|
|
|
|
|
} else {
|
|
|
|
|
newstate = (STATE_FACE_DOWN | STATE_MOVING );
|
|
|
|
|
}
|
|
|
|
|
} else if ( controls.left.isDown ) {
|
2014-07-13 23:03:51 -07:00
|
|
|
if ( controls.run.isDown ) {
|
2014-06-22 09:58:25 -07:00
|
|
|
newstate = (STATE_FACE_LEFT | STATE_MOVING | STATE_RUNNING);
|
|
|
|
|
} else {
|
|
|
|
|
newstate = (STATE_FACE_LEFT | STATE_MOVING );
|
|
|
|
|
}
|
|
|
|
|
} else if ( controls.right.isDown ) {
|
2014-07-13 23:03:51 -07:00
|
|
|
if ( controls.run.isDown ) {
|
2014-06-22 09:58:25 -07:00
|
|
|
newstate = (STATE_FACE_RIGHT | STATE_MOVING | STATE_RUNNING);
|
|
|
|
|
} else {
|
|
|
|
|
newstate = (STATE_FACE_RIGHT | STATE_MOVING );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2014-06-29 12:13:02 -07:00
|
|
|
newstate = getFaceState(player);
|
2014-06-22 09:58:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setMovingState(player, newstate);
|
|
|
|
|
setSpriteMovement(player);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GameState.prototype.update_player_lightmeter = function() {
|
2014-06-26 21:55:58 -07:00
|
|
|
var avg_shadow = Number(array_average(this.shadowTextureColor));
|
2014-06-27 22:46:34 -07:00
|
|
|
player.lightmeter = ((avg_shadow + this.getClockGamma()) / 255.0);
|
2014-06-22 09:58:25 -07:00
|
|
|
lightValue = 0;
|
|
|
|
|
this.staticLights.forEach(function(light) {
|
|
|
|
|
var left = player.x;
|
|
|
|
|
var top = player.y + 32;
|
|
|
|
|
|
|
|
|
|
if ( player.y < this.y )
|
|
|
|
|
top = player.y;
|
|
|
|
|
if ( player.x + this.x )
|
|
|
|
|
left = player.x + 32;
|
|
|
|
|
|
|
|
|
|
line = new Phaser.Line(left, top, light.x + 16, light.y + 16);
|
|
|
|
|
if ( line.length > light.rendered_radius)
|
|
|
|
|
return;
|
|
|
|
|
var length = line.length;
|
|
|
|
|
var lv = light.light_meter - (Number(length) / Number(light.rendered_radius));
|
|
|
|
|
if ( lv > lightValue ) {
|
|
|
|
|
lightValue = lv;
|
|
|
|
|
}
|
|
|
|
|
}, this)
|
2014-06-25 07:56:22 -07:00
|
|
|
player.lightmeter += lightValue;
|
|
|
|
|
player.lightmeter = Math.min(player.lightmeter, 1.0);
|
2014-07-12 08:21:22 -07:00
|
|
|
this.lightbar.scale.y = player.lightmeter;
|
2014-07-12 08:38:31 -07:00
|
|
|
this.lightbar.alpha = 0.5 + (player.lightmeter / 2);
|
2014-07-12 08:21:22 -07:00
|
|
|
//this.lightbar_crop.width = ((this.lightbar_image.width) * player.lightmeter);
|
2014-07-11 19:53:38 -07:00
|
|
|
//this.lightbar.crop(this.lightbar_crop);
|
2014-06-22 09:58:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GameState.prototype.update = function()
|
|
|
|
|
{
|
|
|
|
|
this.check_input();
|
|
|
|
|
this.update_player_lightmeter();
|
|
|
|
|
|
|
|
|
|
for (var ln in this.map_collision_layers ) {
|
|
|
|
|
layer = this.map_collision_layers[ln];
|
|
|
|
|
this.physics.arcade.collide(player, layer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _fix_audio_relative(x) {
|
|
|
|
|
x.adjust_relative_to(player);
|
|
|
|
|
}
|
|
|
|
|
this.staticSounds.forEach(_fix_audio_relative, this);
|
|
|
|
|
|
2014-07-09 22:14:20 -07:00
|
|
|
function _player_collide(x) {
|
2014-06-22 09:58:25 -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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( x.collide_with_player == false )
|
|
|
|
|
return;
|
|
|
|
|
if ( x.canSeeSprite(player, false) == true ) {
|
2014-07-12 08:29:41 -07:00
|
|
|
x.sawPlayer(game, player);
|
2014-06-29 12:13:02 -07:00
|
|
|
if ( player.lightmeter >= x.sprite_can_see_lightmeter ) {
|
2014-06-28 08:48:26 -07:00
|
|
|
x.setAwarenessEffect(STATE_ALERTED);
|
2014-06-22 09:58:25 -07:00
|
|
|
} else {
|
|
|
|
|
x.setAwarenessEffect(STATE_CONCERNED);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
2014-07-05 12:20:33 -07:00
|
|
|
if ( this.physics.arcade.overlap(x, player) ) {
|
2014-06-26 23:39:32 -07:00
|
|
|
x.setAwarenessEffect(STATE_CONCERNED);
|
|
|
|
|
} else if ( hasState(x, STATE_LOSTHIM) == false ) {
|
2014-06-22 09:58:25 -07:00
|
|
|
x.setAwarenessEffect(STATE_LOSTHIM);
|
|
|
|
|
} else {
|
|
|
|
|
x.setAwarenessEffect(STATE_UNAWARE);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-12 08:29:41 -07:00
|
|
|
if ( this.physics.arcade.overlap(x, player) == true ) {
|
|
|
|
|
x.sawPlayer(game, player);
|
2014-06-29 12:13:02 -07:00
|
|
|
x.setAwarenessEffect(STATE_ALERTED);
|
2014-07-12 08:29:41 -07:00
|
|
|
}
|
2014-06-29 19:36:10 -07:00
|
|
|
if ( hasState(player, STATE_STEALING) == true &&
|
|
|
|
|
x.sprite_has_treasure == true ) {
|
2014-06-29 12:13:02 -07:00
|
|
|
var prevpos = player.body.position;
|
2014-07-06 15:48:27 -07:00
|
|
|
var prevwidth = player.body.width;
|
|
|
|
|
var prevheight = player.body.height;
|
2014-06-29 12:13:02 -07:00
|
|
|
player.body.position = new Phaser.Point();
|
|
|
|
|
player.body.x = prevpos.x;
|
|
|
|
|
player.body.y = prevpos.y;
|
|
|
|
|
switch ( getFaceState(player) ) {
|
|
|
|
|
case STATE_FACE_LEFT: {
|
2014-06-29 23:00:11 -07:00
|
|
|
player.body.x -= (STEAL_DISTANCE + 8);
|
2014-06-29 12:13:02 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case STATE_FACE_RIGHT: {
|
2014-07-06 15:05:05 -07:00
|
|
|
player.body.width += (STEAL_DISTANCE + 8);
|
2014-06-29 12:13:02 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case STATE_FACE_DOWN: {
|
2014-07-06 15:05:05 -07:00
|
|
|
player.body.height += STEAL_DISTANCE;
|
2014-06-29 12:13:02 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case STATE_FACE_UP: {
|
2014-06-29 23:00:11 -07:00
|
|
|
player.body.y -= (STEAL_DISTANCE * 2);
|
2014-06-29 12:13:02 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-05 12:20:33 -07:00
|
|
|
if ( this.physics.arcade.overlap(x, player) == true ) {
|
2014-06-29 19:36:10 -07:00
|
|
|
delState(player, STATE_STEALING);
|
2014-06-29 12:13:02 -07:00
|
|
|
x.sprite_has_treasure = false;
|
2014-06-29 19:36:10 -07:00
|
|
|
var stolen = moonlightTreasures[x.sprite_treasure];
|
2014-07-05 12:30:25 -07:00
|
|
|
if ( typeof stolen == 'undefined' ) {
|
|
|
|
|
// You should put a trap here.
|
|
|
|
|
console.log("Tried to steal undefined : " + x.sprite_treasure);
|
|
|
|
|
} else {
|
|
|
|
|
player.score += stolen['value'];
|
|
|
|
|
}
|
2014-06-29 12:13:02 -07:00
|
|
|
x.sprite_treasure = null;
|
2014-06-29 19:36:10 -07:00
|
|
|
if ( this.recentlyStolenGroup.total >= RECENTLYSTOLEN_MAX ) {
|
|
|
|
|
this.recentlyStolenGroup.remove(
|
|
|
|
|
this.recentlyStolenGroup.getBottom(),
|
|
|
|
|
true);
|
|
|
|
|
}
|
2014-07-11 19:53:38 -07:00
|
|
|
this.recentlyStolenGroup.addAll('cameraOffset.x', 36);
|
2014-06-29 19:36:10 -07:00
|
|
|
var rs = game.add.sprite(
|
|
|
|
|
SCREEN_OFFSET_RECENTLYSTOLEN.x + 12,
|
|
|
|
|
SCREEN_OFFSET_RECENTLYSTOLEN.y + 12,
|
|
|
|
|
'treasure',
|
|
|
|
|
(stolen['y'] * TREASURE_SHEET_WIDTH) + stolen['x'],
|
|
|
|
|
this.recentlyStolenGroup);
|
|
|
|
|
rs.anchor.setTo(0.5, 0.5);
|
|
|
|
|
rs.scale.x = 3;
|
|
|
|
|
rs.scale.y = 3;
|
|
|
|
|
rs.angle = 0;
|
|
|
|
|
tween = game.add.tween(rs);
|
|
|
|
|
tween.to({angle: 360}, 1000, null);
|
2014-07-01 22:49:23 -07:00
|
|
|
tween.onComplete.add(function(){this.angle=0;}, rs);
|
2014-06-29 19:36:10 -07:00
|
|
|
tween.start();
|
|
|
|
|
tween = game.add.tween(rs.scale);
|
|
|
|
|
tween.to({x: 1, y: 1}, 1000, null);
|
|
|
|
|
tween.start();
|
|
|
|
|
rs.fixedToCamera = true;
|
2014-06-29 12:13:02 -07:00
|
|
|
}
|
|
|
|
|
player.body.position = prevpos;
|
2014-07-06 15:48:27 -07:00
|
|
|
player.body.width = prevwidth;
|
|
|
|
|
player.body.height = prevheight;
|
2014-06-29 12:13:02 -07:00
|
|
|
}
|
2014-06-22 09:58:25 -07:00
|
|
|
}
|
|
|
|
|
|
2014-07-09 22:14:20 -07:00
|
|
|
// this.effectSprites.forEach(_player_collide, this);
|
2014-06-22 09:58:25 -07:00
|
|
|
|
2014-07-11 08:10:42 -07:00
|
|
|
function _AI_collide(o1, o2)
|
|
|
|
|
{
|
|
|
|
|
o1.collide_with_AI(o2);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-09 22:14:20 -07:00
|
|
|
this.aiSprites.forEach(_player_collide, this);
|
2014-07-11 08:10:42 -07:00
|
|
|
game.physics.arcade.overlap(this.aiSprites, this.aiSprites,
|
|
|
|
|
_AI_collide);
|
2014-06-22 09:58:25 -07:00
|
|
|
this.updateShadowTexture();
|
|
|
|
|
|
2014-06-27 18:04:34 -07:00
|
|
|
if ( this.aiSprites.debug == false ) {
|
2014-06-22 09:58:25 -07:00
|
|
|
function _draw_viewrect(x) {
|
|
|
|
|
var r = x.viewRectangle();
|
2014-06-26 23:39:32 -07:00
|
|
|
if ( isSet(r) == false )
|
2014-06-22 09:58:25 -07:00
|
|
|
return;
|
2014-06-26 23:39:32 -07:00
|
|
|
this.shadowTexture.context.fillStyle = 'rgb(128, 128, 255)';
|
2014-06-22 09:58:25 -07:00
|
|
|
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;
|
2014-06-26 23:39:32 -07:00
|
|
|
if ( isSet(p) == false)
|
2014-06-22 09:58:25 -07:00
|
|
|
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-07-11 23:49:20 -07:00
|
|
|
var clockhour = this.clock.getHours();
|
|
|
|
|
if ( this.clock.getHours() > 12 )
|
|
|
|
|
clockhour -= 12;
|
|
|
|
|
this.hud_hourhand.frame = parseInt((5 * clockhour) + (0.083 * this.clock.getMinutes()));
|
|
|
|
|
this.hud_minutehand.frame = this.clock.getMinutes();
|
2014-07-13 23:39:37 -07:00
|
|
|
this.scoreTextBitmap.setText("$ " + player.score);
|
2014-06-22 09:58:25 -07:00
|
|
|
}
|
|
|
|
|
|
2014-07-12 23:33:24 -07:00
|
|
|
GameState.prototype.shutdown = function()
|
|
|
|
|
{
|
|
|
|
|
this.aiSprites.setAll('ready_to_update', false);
|
2014-07-12 23:57:46 -07:00
|
|
|
this.aiSprites.forEach(function(x) {
|
|
|
|
|
if ( isSet(x.awareness_timer) == true )
|
|
|
|
|
x.awareness_timer.stop();
|
|
|
|
|
if ( isSet(x.glint_timer) == true )
|
|
|
|
|
x.glint_timer.stop();
|
|
|
|
|
if ( isSet(x.conversation_timer) == true )
|
|
|
|
|
x.conversation_timer.stop();
|
|
|
|
|
if ( isSet(x.rotation_timer) == true )
|
|
|
|
|
x.rotation_timer.stop();
|
|
|
|
|
if ( isSet(x.timer) == true )
|
|
|
|
|
x.timer.stop();
|
|
|
|
|
}, this);
|
2014-07-12 23:33:24 -07:00
|
|
|
this.aiSprites.destroy();
|
|
|
|
|
this.aiSprites = null;
|
|
|
|
|
this.uigroup.destroy();
|
|
|
|
|
this.uigroup = null;
|
|
|
|
|
this.recentlyStolenGroup.destroy();
|
|
|
|
|
this.clock = null;
|
|
|
|
|
this.clockTimer.stop();
|
|
|
|
|
this.bubble_group.destroy();
|
|
|
|
|
this.effectSprites.destroy();
|
|
|
|
|
this.shadowTextureColor = null;
|
|
|
|
|
this.staticSounds.forEach(function(x) {
|
|
|
|
|
x.sound.stop();
|
|
|
|
|
game.sound.remove(x);
|
|
|
|
|
}, this);
|
|
|
|
|
this.map_collision_layers.forEach(function(x) {
|
|
|
|
|
x.destroy();
|
|
|
|
|
}, this);
|
|
|
|
|
this.map.destroy();
|
|
|
|
|
pathfinder_grid = null;
|
|
|
|
|
pathfinder = null;
|
|
|
|
|
this.shadowSprite.destroy();
|
|
|
|
|
this.staticLights.destroy();
|
|
|
|
|
this.staticSounds.destroy();
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-22 09:58:25 -07:00
|
|
|
var Boot = function(game) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Boot.prototype.preload = function()
|
|
|
|
|
{
|
2014-07-13 22:25:50 -07:00
|
|
|
game.load.image('background', 'gfx/ui/background.png');
|
|
|
|
|
game.load.image('font-16px', 'gfx/ui/font-16px.png');
|
|
|
|
|
game.load.image('font-8px', 'gfx/ui/font-8px.png');
|
|
|
|
|
game.load.image('lightbar', 'gfx/ui/lightbar.png');
|
|
|
|
|
game.load.image('loadingtube', 'gfx/ui/loadingtube.png');
|
|
|
|
|
game.load.spritesheet('gears', 'gfx/ui/gears.png', 128, 128, 10);
|
2014-06-22 09:58:25 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Boot.prototype.create = function()
|
|
|
|
|
{
|
|
|
|
|
this.input.maxPointers = 1;
|
|
|
|
|
this.stage.disableVisibilityChange = false;
|
|
|
|
|
this.stage.scale.pageAlignHoritzontally = true;
|
|
|
|
|
game.state.start('preloader', true, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var Preloader = function(game) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Preloader.prototype.preload = function()
|
|
|
|
|
{
|
2014-07-13 22:25:50 -07:00
|
|
|
this.background = game.add.image(0, 0, 'background');
|
|
|
|
|
this.loadingText = textImage(game.world.centerX,
|
|
|
|
|
game.world.centerY,
|
|
|
|
|
"Loading...",
|
|
|
|
|
FONTSIZE_MEDIUM);
|
|
|
|
|
this.loadingText.anchor.setTo(0.5, 0.5);
|
|
|
|
|
this.creditText = textImage(game.world.centerX,
|
|
|
|
|
480 - 16,
|
|
|
|
|
"Featuring Art by Peter Hann (www.peter-hann.com)",
|
|
|
|
|
FONTSIZE_SMALL);
|
|
|
|
|
this.creditText.anchor.setTo(0.5, 0.5);
|
|
|
|
|
this.preloadTube = game.add.image(game.world.centerX, 280, 'loadingtube');
|
|
|
|
|
this.preloadTube.anchor.setTo(0.5, 0.5);
|
|
|
|
|
this.loadingGears = game.add.sprite(game.world.centerX - (193/2) - 72,
|
|
|
|
|
game.world.centerY - 112,
|
|
|
|
|
'gears');
|
|
|
|
|
addAnimation(this.loadingGears, 'spingears');
|
|
|
|
|
this.loadingGears.animations.play('spingears');
|
|
|
|
|
this.lightbar = game.add.image(game.world.centerX - (193/2) + 32,
|
|
|
|
|
280 - 18,
|
|
|
|
|
'lightbar');
|
|
|
|
|
game.load.setPreloadSprite(this.lightbar, 0);
|
2014-06-22 09:58:25 -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']);
|
|
|
|
|
}
|
|
|
|
|
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() {
|
2014-07-13 22:25:50 -07:00
|
|
|
this.lightbar.destroy();
|
|
|
|
|
this.background.destroy();
|
|
|
|
|
this.preloadTube.destroy();
|
|
|
|
|
this.loadingText.destroy();
|
|
|
|
|
this.loadingGears.destroy();
|
2014-07-12 22:02:30 -07:00
|
|
|
game.state.start('startscreen', true, false);
|
2014-06-22 09:58:25 -07:00
|
|
|
}
|
|
|
|
|
|
2014-07-13 22:25:50 -07:00
|
|
|
var tween = this.add.tween(this.lightbar).to({ alpha: 0 }, 5000, Phaser.Easing.Linear.None, true);
|
|
|
|
|
tween = this.add.tween(this.preloadTube).to({ alpha: 0 }, 4500, Phaser.Easing.Linear.None, true);
|
|
|
|
|
tween = this.add.tween(this.loadingText).to({ alpha: 0 }, 4000, Phaser.Easing.Linear.None, true);
|
|
|
|
|
tween = this.add.tween(this.creditText).to({ alpha: 0 }, 4000, Phaser.Easing.Linear.None, true);
|
|
|
|
|
tween = this.add.tween(this.loadingGears).to({ alpha: 0 }, 4000, Phaser.Easing.Linear.None, true);
|
|
|
|
|
tween = this.add.tween(this.background).to({ alpha: 0 }, 3500, Phaser.Easing.Linear.None, true);
|
2014-06-22 09:58:25 -07:00
|
|
|
tween.onComplete.add(goalready, this);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-12 22:02:30 -07:00
|
|
|
var StartScreen = function(game) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StartScreen.prototype.create = function()
|
|
|
|
|
{
|
2014-07-13 22:25:50 -07:00
|
|
|
this.background = game.add.image(0, 0, 'background');
|
2014-07-13 21:37:51 -07:00
|
|
|
this.labeltext = bitmapText("(C) 2014 Andrew Kesterson - http://akesterson.itch.io/",
|
|
|
|
|
FONTSIZE_SMALL);
|
|
|
|
|
this.linkButton = game.add.button(game.world.centerX,
|
|
|
|
|
460,
|
|
|
|
|
this.labeltext,
|
|
|
|
|
this.linkClicked,
|
|
|
|
|
this);
|
|
|
|
|
this.linkButton.anchor.setTo(0.5, 0.5);
|
|
|
|
|
|
|
|
|
|
this.startGameButton = game.add.button(game.world.centerX,
|
|
|
|
|
100,
|
|
|
|
|
'newgamebtn',
|
|
|
|
|
this.startGameClicked,
|
|
|
|
|
this,
|
|
|
|
|
1,
|
|
|
|
|
0);
|
|
|
|
|
this.startGameButton.anchor.setTo(0.5, 0.5);
|
|
|
|
|
this.creditsButton = game.add.button(game.world.centerX,
|
|
|
|
|
200,
|
|
|
|
|
'creditsbtn',
|
|
|
|
|
this.creditsClicked,
|
|
|
|
|
this,
|
|
|
|
|
1,
|
|
|
|
|
0);
|
|
|
|
|
this.creditsButton.anchor.setTo(0.5, 0.5);
|
2014-07-13 22:25:50 -07:00
|
|
|
this.startGameButton.alpha = 0;
|
|
|
|
|
this.creditsButton.alpha = 0;
|
|
|
|
|
this.linkButton.alpha = 0;
|
|
|
|
|
|
|
|
|
|
var tween = this.add.tween(this.startGameButton).to({ alpha: 1.0 }, 3000, Phaser.Easing.Linear.None, true);
|
|
|
|
|
tween = this.add.tween(this.creditsButton).to({ alpha: 1.0 }, 3000, Phaser.Easing.Linear.None, true);
|
|
|
|
|
tween = this.add.tween(this.linkButton).to({ alpha: 1.0 }, 3000, Phaser.Easing.Linear.None, true);
|
|
|
|
|
tween = this.add.tween(this.background).to({ alpha: 1.0 }, 3000, Phaser.Easing.Linear.None, true);
|
2014-07-13 21:37:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StartScreen.prototype.linkClicked = function()
|
|
|
|
|
{
|
|
|
|
|
window.open("http://akesterson.itch.io/");
|
2014-07-12 22:02:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StartScreen.prototype.startGameClicked = function()
|
|
|
|
|
{
|
|
|
|
|
this.startGameButton.destroy();
|
|
|
|
|
this.creditsButton.destroy();
|
2014-07-13 22:25:50 -07:00
|
|
|
this.background.destroy();
|
|
|
|
|
this.linkButton.destroy();
|
|
|
|
|
this.labeltext.destroy();
|
2014-07-12 22:02:30 -07:00
|
|
|
game.state.start('game', true, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StartScreen.prototype.creditsClicked = function()
|
|
|
|
|
{
|
|
|
|
|
console.log("Roll the credits dumbass");
|
|
|
|
|
}
|
2014-06-22 09:58:25 -07:00
|
|
|
|
2014-07-12 22:02:30 -07:00
|
|
|
var EndScreen = function(game) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EndScreen.prototype.create = function()
|
|
|
|
|
{
|
2014-07-12 23:33:24 -07:00
|
|
|
this.gameOverText = game.add.image((640/2),
|
2014-07-12 23:57:46 -07:00
|
|
|
100,
|
2014-07-12 23:33:24 -07:00
|
|
|
'gameover');
|
|
|
|
|
this.gameOverText.anchor.setTo(0.5, 0.5);
|
2014-07-12 23:57:46 -07:00
|
|
|
this.startGameButton = game.add.button((640 / 2),
|
|
|
|
|
200,
|
|
|
|
|
'newgamebtn',
|
|
|
|
|
this.startGameClicked,
|
|
|
|
|
this,
|
|
|
|
|
1,
|
|
|
|
|
0);
|
|
|
|
|
this.startGameButton.anchor.setTo(0.5, 0.5);
|
|
|
|
|
this.creditsButton = game.add.button((640 / 2),
|
|
|
|
|
300,
|
|
|
|
|
'creditsbtn',
|
|
|
|
|
this.creditsClicked,
|
|
|
|
|
this,
|
|
|
|
|
1,
|
|
|
|
|
0);
|
|
|
|
|
this.creditsButton.anchor.setTo(0.5, 0.5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EndScreen.prototype.startGameClicked = function()
|
|
|
|
|
{
|
|
|
|
|
this.startGameButton.destroy();
|
|
|
|
|
this.creditsButton.destroy();
|
|
|
|
|
this.gameOverText.destroy();
|
|
|
|
|
game.state.start('game', true, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EndScreen.prototype.creditsClicked = function()
|
|
|
|
|
{
|
|
|
|
|
console.log("Roll the credits dumbass");
|
2014-07-12 22:02:30 -07:00
|
|
|
}
|