use of com.b3dgs.lionengine.game.feature.tile.Tile in project lionengine by b3dgs.
the class Minimap method prepare.
/**
* Fill minimap surface with tile color configuration.
*
* @throws LionEngineException If surface has not been loaded ({@link #load()} may have not been called).
*/
@Override
public void prepare() {
if (surface == null) {
throw new LionEngineException(ERROR_SURFACE);
}
final Graphic g = surface.createGraphic();
final int v = map.getInTileHeight();
final int h = map.getInTileWidth();
for (int ty = 0; ty < v; ty++) {
for (int tx = 0; tx < h; tx++) {
final Tile tile = map.getTile(tx, ty);
final ColorRgba color = getTileColor(tile);
if (!NO_TILE.equals(color)) {
g.setColor(color);
g.drawRect(tx, v - ty - 1, 0, 0, false);
}
}
}
g.dispose();
}
use of com.b3dgs.lionengine.game.feature.tile.Tile 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.Tile in project lionengine by b3dgs.
the class MapTileCircuitModelTest method testTransitive.
/**
* Test the map circuit resolution with transitive.
*/
@Test
void testTransitive() {
final MapTile map = createMap(TILE_WATER);
final MapTileGroup mapGroup = map.getFeature(MapTileGroup.class);
final MapTileCircuit mapCircuit = map.getFeature(MapTileCircuitModel.class);
map.setTile(5, 5, TILE_ROAD);
final Tile newTile = map.getTile(5, 5);
mapCircuit.resolve(newTile);
assertEquals(ROAD, mapGroup.getGroup(map.getTile(5, 5)));
assertEquals(TRANSITION, mapGroup.getGroup(map.getTile(4, 4)));
assertEquals(TRANSITION, mapGroup.getGroup(map.getTile(5, 4)));
assertEquals(TRANSITION, mapGroup.getGroup(map.getTile(6, 4)));
assertEquals(TRANSITION, mapGroup.getGroup(map.getTile(4, 5)));
assertEquals(TRANSITION, mapGroup.getGroup(map.getTile(6, 5)));
assertEquals(TRANSITION, mapGroup.getGroup(map.getTile(4, 6)));
assertEquals(TRANSITION, mapGroup.getGroup(map.getTile(5, 6)));
assertEquals(TRANSITION, mapGroup.getGroup(map.getTile(6, 6)));
}
use of com.b3dgs.lionengine.game.feature.tile.Tile in project lionengine by b3dgs.
the class TileCollidableModelTest method testFromBottom.
/**
* Test the collidable from bottom.
*/
@Test
void testFromBottom() {
final Transformable transformable = createObject(new FeaturableModel(services, setup));
final AtomicReference<Tile> collided = new AtomicReference<>();
final TileCollidableListener listener = createListener(collided);
collidable.addListener(listener);
transformable.teleport(0.0, -1.0);
transformable.moveLocation(1.0, 0.0, 3.0);
collidable.update(1.0);
assertEquals(map.getTile(0, 0), collided.get());
}
use of com.b3dgs.lionengine.game.feature.tile.Tile in project lionengine by b3dgs.
the class TileCollidableModelTest method testFromLeft.
/**
* Test the collidable from left.
*/
@Test
void testFromLeft() {
final Transformable transformable = createObject(new FeaturableModel(services, setup));
final AtomicReference<Tile> collided = new AtomicReference<>();
final TileCollidableListener listener = createListener(collided);
collidable.addListener(listener);
transformable.teleport(-1.0, 0.0);
transformable.moveLocation(1.0, 2.0, 0.0);
collidable.update(1.0);
assertEquals(map.getTile(0, 0), collided.get());
}
Aggregations