diff --git a/moonlight/gfx/map.json b/moonlight/gfx/map.json index 1d142fe..811883b 100644 --- a/moonlight/gfx/map.json +++ b/moonlight/gfx/map.json @@ -344,7 +344,7 @@ { "sprite_can_see_lightmeter":"0.15", "sprite_canmove":"false", - "sprite_facing":"up", + "sprite_facing":"down", "sprite_group":"townsfolk-guard", "sprite_has_treasure":"true", "sprite_name":"townsfolk-guard-2" @@ -352,8 +352,8 @@ "type":"AI", "visible":true, "width":0, - "x":320, - "y":608 + "x":672, + "y":384 }, { "gid":3544, @@ -719,6 +719,25 @@ }, "spacing":0, "tileheight":32, + "tileproperties": + { + "107": + { + "blocksvision":"false" + }, + "109": + { + "blocksvision":"false" + }, + "110": + { + "blocksvision":"false" + }, + "111": + { + "blocksvision":"false" + } + }, "tilewidth":32 }, { @@ -854,6 +873,13 @@ }, "spacing":0, "tileheight":32, + "tileproperties": + { + "121": + { + "blocksvision":"false" + } + }, "tilewidth":32 }, { diff --git a/moonlight/js/#phaser.js# b/moonlight/js/#phaser.js# index c82aa5a..7afa7d0 100644 --- a/moonlight/js/#phaser.js# +++ b/moonlight/js/#phaser.js# @@ -27360,6 +27360,9 @@ Phaser.BitmapData = function (game, key, width, height) { if (typeof width === 'undefined') { width = 100; } if (typeof height === 'undefined') { height = 100; } + console.log(typeof width); + console.log(typeof height); + /** * @property {Phaser.Game} game - A reference to the currently running game. */ diff --git a/moonlight/src/AISprite.js b/moonlight/src/AISprite.js index fb7785d..cfa6871 100644 --- a/moonlight/src/AISprite.js +++ b/moonlight/src/AISprite.js @@ -63,8 +63,21 @@ var AISprite = function(game, x, y, key, frame) { for ( var ctr = 1; ctr < viewcoords.length ; ctr++ ) { var coord = [parseInt(viewcoords[ctr][0]), parseInt(viewcoords[ctr][1])]; - if ( grid.nodes[coord[1]][coord[0]].walkable == false ) - return false; + if ( grid.nodes[coord[1]][coord[0]].walkable == false ) { + if ( grid.nodes[coord[1]][coord[0]].isAISprite == true ) + return false; + + tiles = tilesFromCollisionLayers(coord[0] * TILE_WIDTH, + coord[1] * TILE_HEIGHT); + for ( var i = 0; i < tiles.length ; i++ ) { + // Default behavior is for all colliding tiles to block vision, + // they have to set property 'blocksvision' == false to prevent it + if ( (tiles[i].index != -1 && + isSet(tiles[i].properties['blocksvision']) == false) || + parseBoolean(tiles[i].properties['blocksvision']) == true ) + return false; + } + } } return true; } diff --git a/moonlight/src/Util.js b/moonlight/src/Util.js index d499a89..6846339 100644 --- a/moonlight/src/Util.js +++ b/moonlight/src/Util.js @@ -303,10 +303,56 @@ function gridWithAISprites() var normx = Math.max(parseInt(spr.x/32), 0); var normy = Math.max(parseInt(spr.y/32), 0); grid.nodes[normy][normx].walkable = false; + grid.nodes[normy][normx].isAISprite = true; } return grid; } +function getTileTileset(tile) +{ + var last = null; + game.state.states.game.map.tilesets.forEach(function(ts) { + if ( isSet(last) == false && ts.firstgid < tile.index ) { + last = ts; + return; + } else if ( isSet(last) == true && + ts.firstgid < tile.index && + ts.firstgid > last.firstgid ) { + last = ts; + return; + } + }, this); + return last; +} + +function setTileProperties(tile) +{ + tile.properties = {}; + if ( tile.index == -1 ) { + return; + } + var tileset = getTileTileset(tile); + // Great, our tileset doesn't have any properties. + if ( isSet(tileset.tileProperties) == false) { + return; + } + tile.properties = tileset.tileProperties[tile.index - tileset.firstgid]; + if ( isSet(tile.properties) == false ) + tile.properties = {}; +} + +function tilesFromCollisionLayers(x, y) +{ + layers = game.state.states.game.map_collision_layers; + var res = []; + layers.forEach(function(layer) { + var tile = layer.getTiles(x, y, 1, 1)[0]; + setTileProperties(tile); + res.push(tile); + }, this); + return res; +} + function stringifyInt(x) { return ("" + x);