Close #51 : Set 'blocksvision = false' on a tile's properties to make it see through on a collision layer
This commit is contained in:
@@ -344,7 +344,7 @@
|
|||||||
{
|
{
|
||||||
"sprite_can_see_lightmeter":"0.15",
|
"sprite_can_see_lightmeter":"0.15",
|
||||||
"sprite_canmove":"false",
|
"sprite_canmove":"false",
|
||||||
"sprite_facing":"up",
|
"sprite_facing":"down",
|
||||||
"sprite_group":"townsfolk-guard",
|
"sprite_group":"townsfolk-guard",
|
||||||
"sprite_has_treasure":"true",
|
"sprite_has_treasure":"true",
|
||||||
"sprite_name":"townsfolk-guard-2"
|
"sprite_name":"townsfolk-guard-2"
|
||||||
@@ -352,8 +352,8 @@
|
|||||||
"type":"AI",
|
"type":"AI",
|
||||||
"visible":true,
|
"visible":true,
|
||||||
"width":0,
|
"width":0,
|
||||||
"x":320,
|
"x":672,
|
||||||
"y":608
|
"y":384
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"gid":3544,
|
"gid":3544,
|
||||||
@@ -719,6 +719,25 @@
|
|||||||
},
|
},
|
||||||
"spacing":0,
|
"spacing":0,
|
||||||
"tileheight":32,
|
"tileheight":32,
|
||||||
|
"tileproperties":
|
||||||
|
{
|
||||||
|
"107":
|
||||||
|
{
|
||||||
|
"blocksvision":"false"
|
||||||
|
},
|
||||||
|
"109":
|
||||||
|
{
|
||||||
|
"blocksvision":"false"
|
||||||
|
},
|
||||||
|
"110":
|
||||||
|
{
|
||||||
|
"blocksvision":"false"
|
||||||
|
},
|
||||||
|
"111":
|
||||||
|
{
|
||||||
|
"blocksvision":"false"
|
||||||
|
}
|
||||||
|
},
|
||||||
"tilewidth":32
|
"tilewidth":32
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -854,6 +873,13 @@
|
|||||||
},
|
},
|
||||||
"spacing":0,
|
"spacing":0,
|
||||||
"tileheight":32,
|
"tileheight":32,
|
||||||
|
"tileproperties":
|
||||||
|
{
|
||||||
|
"121":
|
||||||
|
{
|
||||||
|
"blocksvision":"false"
|
||||||
|
}
|
||||||
|
},
|
||||||
"tilewidth":32
|
"tilewidth":32
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -27360,6 +27360,9 @@ Phaser.BitmapData = function (game, key, width, height) {
|
|||||||
if (typeof width === 'undefined') { width = 100; }
|
if (typeof width === 'undefined') { width = 100; }
|
||||||
if (typeof height === 'undefined') { height = 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.
|
* @property {Phaser.Game} game - A reference to the currently running game.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -63,8 +63,21 @@ var AISprite = function(game, x, y, key, frame) {
|
|||||||
for ( var ctr = 1; ctr < viewcoords.length ; ctr++ ) {
|
for ( var ctr = 1; ctr < viewcoords.length ; ctr++ ) {
|
||||||
var coord = [parseInt(viewcoords[ctr][0]),
|
var coord = [parseInt(viewcoords[ctr][0]),
|
||||||
parseInt(viewcoords[ctr][1])];
|
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;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -303,10 +303,56 @@ function gridWithAISprites()
|
|||||||
var normx = Math.max(parseInt(spr.x/32), 0);
|
var normx = Math.max(parseInt(spr.x/32), 0);
|
||||||
var normy = Math.max(parseInt(spr.y/32), 0);
|
var normy = Math.max(parseInt(spr.y/32), 0);
|
||||||
grid.nodes[normy][normx].walkable = false;
|
grid.nodes[normy][normx].walkable = false;
|
||||||
|
grid.nodes[normy][normx].isAISprite = true;
|
||||||
}
|
}
|
||||||
return grid;
|
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)
|
function stringifyInt(x)
|
||||||
{
|
{
|
||||||
return ("" + x);
|
return ("" + x);
|
||||||
|
|||||||
Reference in New Issue
Block a user