From c87b8b569e5c0293ab2e10a71c6b47612a593590 Mon Sep 17 00:00:00 2001 From: Andrew Kesterson Date: Sat, 14 Jun 2014 16:46:50 -0700 Subject: [PATCH] Making AI able to 'see' the player --- moonlight/js/moonlight-skulk.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/moonlight/js/moonlight-skulk.js b/moonlight/js/moonlight-skulk.js index b98686d..ad11510 100644 --- a/moonlight/js/moonlight-skulk.js +++ b/moonlight/js/moonlight-skulk.js @@ -64,8 +64,8 @@ Light.prototype.constructor = Light; Light.prototype.update_new_values = function() { this.radius = parseInt(this.radius); this.fade = this.radius * Number(this.fade); - this.flicker = (this.flicker == 'true'); - this.always_render = (this.always_render == 'true') + this.flicker = parseBoolean(this.flicker); + this.always_render = parseBoolean(this.always_render); this.rect = new Phaser.Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2) } @@ -102,9 +102,9 @@ SoundSprite.prototype.update_new_values = function() { } this.sound_position = parseInt(this.sound_position); this.sound_volume = Number(this.sound_volume); - this.sound_loop = (this.sound_loop == 'true'); - this.sound_forcerestart = (this.sound_forcerestart == 'true'); - this.sound_nofade = (this.sound_nofade == 'true'); + this.sound_loop = parseBoolean(this.sound_loop); + this.sound_forcerestart = parseBoolean(this.sound_forcerestart); + this.sound_nofade = parseBoolean(this.sound_nofade); this.sound = game.add.audio(this.sound_key); this.sound.play( @@ -755,10 +755,10 @@ var AISprite = function(game, x, y, key, frame) { this.animations.destroy(); this.clearWordBubble(); this.state = STATE_UNAWARE; - this.can_move = (this.can_move == 'true'); - this.collide_with_player = (this.collide_with_player == 'true'); - this.collide_with_map = (this.collide_with_map == 'true'); - this.carries_light = (this.carries_light == 'true'); + this.can_move = parseBoolean(this.can_move); + 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); this.loadTexture(this.sprite_name, 0); addAnimation(this, 'bipedwalkleft'); @@ -1010,6 +1010,11 @@ function spriteFacing(spr) return "up"; } +function parseBoolean(val) +{ + return ( val == 'true' || val == true ); +} + function setSpriteMovement(spr) { var x = 0;