use of com.b3dgs.lionengine.game.feature.tile.TileGame in project lionengine by b3dgs.
the class MapTileFog method updateFov.
/**
* Update fovable field of view (fog of war).
*
* @param fovable The fovable reference.
*/
private void updateFov(Fovable fovable) {
final int tx = fovable.getInTileX();
final int ty = fovable.getInTileY();
final int tw = fovable.getInTileWidth();
final int th = fovable.getInTileHeight();
final int ray = fovable.getInTileFov();
final int sx = UtilMath.clamp(tx - ray - tw / 2, 0, map.getInTileWidth() - 1);
final int ex = UtilMath.clamp(tx + ray + tw / 2, 0, map.getInTileWidth() - 1);
final int sy = UtilMath.clamp(ty - ray - th / 2, 0, map.getInTileHeight() - 1);
final int ey = UtilMath.clamp(ty + ray + th / 2, 0, map.getInTileHeight() - 1);
for (int x = sx + 1; x < ex; x++) {
for (int y = sy + 1; y < ey; y++) {
final Tile tile = new TileGame(Integer.valueOf(0), NO_FOG, x * map.getTileWidth(), y * map.getTileHeight(), map.getTileWidth(), map.getTileHeight());
map.setTile(tile);
transition.resolve(getTile(x, y));
}
}
for (int x = sx; x < ex + 1; x++) {
for (int y = sy; y < ey + 1; y++) {
final Tile tile = map.getTile(x, y);
revealed.add(tile);
}
}
}
use of com.b3dgs.lionengine.game.feature.tile.TileGame in project lionengine by b3dgs.
the class MapTileGameTest method testAppendCollectionCreatedDifferentTileWidth.
/**
* Test the map collection append when map is created with different tile width.
*/
@Test(expected = LionEngineException.class)
public void testAppendCollectionCreatedDifferentTileWidth() {
map.create(1, 1, 1, 1);
final MapTile map1 = new MapTileGame();
map1.create(1, 1, 1, 1);
map1.setTile(new TileGame(Integer.valueOf(0), 0, 0, 0, 1, 1));
final MapTile map2 = new MapTileGame();
map2.create(2, 1, 1, 1);
map.append(Arrays.asList(map1, map2), 0, 0, 0, 0);
}
use of com.b3dgs.lionengine.game.feature.tile.TileGame in project lionengine by b3dgs.
the class MapTileGameTest method testAppendCollectionCreatedDifferentTileHeight.
/**
* Test the map collection append when map is created with different tile height.
*/
@Test(expected = LionEngineException.class)
public void testAppendCollectionCreatedDifferentTileHeight() {
map.create(1, 1, 1, 1);
final MapTile map1 = new MapTileGame();
map1.create(1, 1, 1, 1);
map1.setTile(new TileGame(Integer.valueOf(0), 0, 0, 0, 1, 1));
final MapTile map2 = new MapTileGame();
map2.create(1, 2, 1, 1);
map.append(Arrays.asList(map1, map2), 0, 0, 0, 0);
}
use of com.b3dgs.lionengine.game.feature.tile.TileGame in project lionengine by b3dgs.
the class MapTileGameTest method testAppendCollectionNotCreated.
/**
* Test the map collection append when map is not created.
*/
@Test
public void testAppendCollectionNotCreated() {
final MapTile map1 = new MapTileGame();
map1.create(1, 1, 1, 1);
map1.setTile(new TileGame(Integer.valueOf(0), 0, 0, 0, 1, 1));
Assert.assertEquals(0, map.getInTileWidth());
Assert.assertEquals(0, map.getInTileHeight());
Assert.assertEquals(0, map.getTilesNumber());
map.append(Arrays.asList(map1, map1), 0, 0, 0, 0);
Assert.assertEquals(2, map.getInTileWidth());
Assert.assertEquals(2, map.getInTileHeight());
Assert.assertEquals(1, map.getTilesNumber());
}
use of com.b3dgs.lionengine.game.feature.tile.TileGame in project lionengine by b3dgs.
the class MapTileSurfaceModel method setTile.
@Override
public void setTile(int tx, int ty, int number) {
Check.superiorStrict(tx, -1);
Check.superiorStrict(ty, -1);
Check.inferiorStrict(tx, getInTileWidth());
Check.inferiorStrict(ty, getInTileHeight());
TileGame tile = tiles.get(ty).get(tx);
final int oldNum;
if (tile == null) {
tile = new TileGame(number, tx, ty, tileWidth, tileHeight);
tiles.get(ty).set(tx, tile);
oldNum = -1;
} else {
oldNum = tile.getNumber();
}
if (number != oldNum) {
tile.set(number);
if (tilesPerSheet > 0) {
tile.setSheet((int) Math.floor(number / (double) tilesPerSheet));
}
for (int i = 0; i < listenable.size(); i++) {
listenable.get(i).onTileSet(tile);
}
}
}
Aggregations