Close #51 : Set 'blocksvision = false' on a tile's properties to make it see through on a collision layer

This commit is contained in:
2014-07-12 10:31:07 -07:00
parent a62f30ba5c
commit e530233cde
4 changed files with 93 additions and 5 deletions

View File

@@ -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
},
{

View File

@@ -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.
*/

View File

@@ -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 )
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;
}

View File

@@ -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);