use of com.badlogic.ashley.core.Entity in project Catacomb-Snatch by Catacomb-Snatch.
the class Entities method createWithPosition.
public static Entity createWithPosition(Level level, int x, int y) {
final Entity tile = level.createEntity();
tile.add(level.createComponent(Position.class).set(x, y));
return tile;
}
use of com.badlogic.ashley.core.Entity in project Catacomb-Snatch by Catacomb-Snatch.
the class Entities method createTile.
public static Entity createTile(Level level, int x, int y, Color color, TextureRegion texture, boolean isWall) {
final Entity tile = createBaseTile(level, x, y, color, isWall);
tile.add(level.createComponent(Sprite.class).set(texture));
return tile;
}
use of com.badlogic.ashley.core.Entity in project Catacomb-Snatch by Catacomb-Snatch.
the class Entities method createPlayer.
// The following are factory methods to create new entities with component presets
public static Entity createPlayer(Level level, TextureRegion[][] spriteSheet) {
final Entity player = level.createEntity();
// TODO: This can return null!
player.add(level.createComponent(Position.class).set(level.getNextSpawnLocation()));
player.add(level.createComponent(Velocity.class).reset());
// TODO change default based on selected character
player.add(level.createComponent(Health.class).reset(20));
player.add(level.createComponent(Sprite.class).set(spriteSheet[0][0]));
return player;
}
use of com.badlogic.ashley.core.Entity in project Catacomb-Snatch by Catacomb-Snatch.
the class Level method setTile.
/**
* Sets a tile at the given x and y coordinate.
* If x and / or y are out of the level boundaries, nothing is being set.
*
* This should only be used for tiles that do not move,
* any tiles that have a {@link net.catacombsnatch.game.entity.components.Velocity} component on them
* will throw an {@link IllegalArgumentException}.
*
* @param tile The tile object to set
* @param x The x position
* @param y The y position
*/
public void setTile(Entity tile, int x, int y) {
if (x < 0 || y < 0 || x >= width || y >= height)
return;
if (Entities.velocity.get(tile) != null) {
throw new IllegalArgumentException("Trying to add static tile with velocity to level at " + x + ", " + y);
}
try {
final int index = x + y * width;
final Entity previous = tiles[index];
if (previous != null) {
removeEntity(previous);
}
tiles[index] = tile;
addEntity(tile);
} catch (IllegalArgumentException ignored) {
}
}
use of com.badlogic.ashley.core.Entity in project Catacomb-Snatch by Catacomb-Snatch.
the class View method render.
@Override
public void render(Scene scene) {
if (viewport == null)
return;
if (target != null) {
// "Camera" movement
offset.lerp(target, 0.5f);
// Draw tiles
int rendered = 0;
for (float y = (viewport.y - viewport.height - offset.y) / SIZE - 2; y <= -(viewport.y + offset.y) / SIZE + 4; y++) {
for (float x = (viewport.x + offset.x) / SIZE - 2; x < (viewport.x + viewport.width + offset.x) / SIZE + 2; x++) {
Entity tile = level.getTile((int) x, (int) y);
// if (tile != null && tile.shouldRender(this)) {
// tile.render((SpriteBatch) scene.getBatch(), this);
rendered++;
// }
}
}
Monitoring.update(DEBUG_TILES_RENDERED, rendered);
// Render entities
// renderer.setGraphics((SpriteBatch) scene.getBatch());
// renderer.process();
}
// Draw overlays
panel.draw(scene.getBatch());
// miniMap.render(scene);
}
Aggregations