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

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

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