use of com.b3dgs.lionengine.game.feature.tile.TileGame in project lionengine by b3dgs.
the class MapTileFog method create.
/**
* Create a fog of war from a map.
*
* @param map The map reference.
* @param config The fog configuration.
* @param sheet The sheet used (can be <code>null</code>).
*/
public void create(MapTile map, Media config, SpriteTiled sheet) {
this.map.create(map.getTileWidth(), map.getTileHeight(), map.getInTileWidth(), map.getInTileHeight());
if (sheet != null) {
this.map.loadSheets(Arrays.asList(sheet));
}
for (int i = 0; i < NO_FOG; i++) {
final String group;
if (i == FOG) {
group = FOG_GROUP;
} else {
group = TRANSITION_GROUP;
}
mapGroup.changeGroup(new TileGame(i, 0, 0, map.getTileWidth(), map.getTileHeight()), group);
}
mapGroup.changeGroup(new TileGame(NO_FOG, 0, 0, map.getTileWidth(), map.getTileHeight()), MapTileGroupModel.NO_GROUP_NAME);
transition.loadTransitions(config);
for (int tx = 0; tx < map.getInTileWidth(); tx++) {
for (int ty = 0; ty < map.getInTileHeight(); ty++) {
this.map.setTile(tx, ty, FOG);
}
}
}
use of com.b3dgs.lionengine.game.feature.tile.TileGame in project lionengine by b3dgs.
the class PrefMapRegion method apply.
/*
* Preference
*/
@Override
public void apply(MapTile map) {
final MapTileTransition mapTransition = map.getFeature(MapTileTransition.class);
final int sx = area.getInTileX();
final int sy = area.getInTileY();
final int ex = UtilMath.clamp(area.getInTileWidth(), 0, map.getInTileWidth() - 1);
final int ey = UtilMath.clamp(area.getInTileHeight(), 0, map.getInTileHeight() - 1);
int remaining = count;
while (remaining > 0) {
final int tx = UtilRandom.getRandomInteger(sx, ex);
final int ty = UtilRandom.getRandomInteger(sy, ey);
final int size = UtilRandom.getRandomInteger(maxSize);
final int halfBottom = (int) Math.floor(size / 2.0);
final int halfTop = (int) Math.ceil(size / 2.0);
for (int ox = -halfBottom; ox < halfTop; ox++) {
for (int oy = -halfBottom; oy < halfTop; oy++) {
final int ntx = UtilMath.clamp(tx + ox, sx, ex);
final int nty = UtilMath.clamp(ty + oy, sy, ey);
final Tile tile = new TileGame(number, ntx, nty, map.getTileWidth(), map.getTileHeight());
map.setTile(tile.getInTileX(), tile.getInTileY(), number);
mapTransition.resolve(tile);
}
}
remaining--;
}
}
use of com.b3dgs.lionengine.game.feature.tile.TileGame in project lionengine by b3dgs.
the class CollisionResultTest method testResult.
/**
* Test the collision result.
*/
@Test
void testResult() {
final Double x = Double.valueOf(1.0);
final Double y = Double.valueOf(2.0);
final Tile tile = new TileGame(1, 3, 4, 1, 1);
final CollisionResult result = new CollisionResult(x, y, tile, formulaX, formulaY);
assertEquals(x, result.getX());
assertEquals(y, result.getY());
assertEquals(tile, result.getTile());
assertTrue(result.startWithX("formula"));
assertFalse(result.startWithY("formulaZ"));
assertTrue(result.endWithX("X"));
assertFalse(result.endWithY("Z"));
assertTrue(result.contains("formula"));
assertFalse(result.contains("formulaZ"));
assertTrue(result.containsX("formulaX"));
assertFalse(result.containsY("formulaZ"));
}
use of com.b3dgs.lionengine.game.feature.tile.TileGame in project lionengine by b3dgs.
the class MapTileCircuitModel method updateTransitiveTile.
/**
* Update tile.
*
* @param tile The tile reference.
*/
private void updateTransitiveTile(Tile tile) {
final Circuit circuit = extractor.getCircuit(tile);
if (circuit == null || !circuits.containsKey(circuit)) {
final String group = getTransitiveGroup(circuit, tile);
if (group != null) {
final int old = tile.getNumber();
final Integer ref = mapTransition.getTiles(new Transition(TransitionType.CENTER, group, group)).iterator().next();
final Tile newTile = new TileGame(ref.intValue(), tile.getInTileX(), tile.getInTileY(), tile.getWidth(), tile.getHeight());
map.setTile(newTile.getInTileX(), newTile.getInTileY(), newTile.getNumber());
mapTransition.resolve(newTile);
map.setTile(newTile.getInTileX(), newTile.getInTileY(), old);
}
}
}
use of com.b3dgs.lionengine.game.feature.tile.TileGame in project lionengine by b3dgs.
the class MapTileFog method reset.
/**
* Reset the revealed tiles to fogged.
*/
public void reset() {
for (final Tile tile : revealed) {
final Tile reset = new TileGame(tile.getSheet(), FOG, tile.getX(), tile.getY(), tile.getWidth(), tile.getHeight());
map.setTile(reset);
}
revealed.clear();
}
Aggregations