Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@schosin
Last active August 13, 2020 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schosin/8c6e5463c1380b5afa77d0a797968dfe to your computer and use it in GitHub Desktop.
Save schosin/8c6e5463c1380b5afa77d0a797968dfe to your computer and use it in GitHub Desktop.
Example "factory" class WallLibrary
public class WallLibrary extends PassiveSystem {
// Systems
private PolygonLibrary polygonLibrary;
// Component mappers
private ComponentMapper<Groups> groupsM;
private ComponentMapper<Position> posM;
private ComponentMapper<Blocking> blockingM;
private ComponentMapper<Renderable> renderableM;
private ComponentMapper<Shape> shapeM;
private ComponentMapper<Tint> tintM;
public int createTile(float x, float y, Color color, boolean blocking) {
return createRectangle(x, y, G.tileSize, G.tileSize, color, blocking);
}
public int createRectangle(float x, float y, float width, float height, Color color, boolean blocking) {
var entity = world.create();
groupsM.create(entity).add(Group.Walls);
posM.create(entity).set(x, y);
renderableM.create(entity).layer(20);
tintM.create(entity).color(color);
shapeM.create(entity).shapeType(ShapeType.Filled).polygon(polygonLibrary.rectangle(width, height));
if (blocking) {
blockingM.create(entity);
}
return entity;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment