-
-
Save schosin/8c6e5463c1380b5afa77d0a797968dfe to your computer and use it in GitHub Desktop.
Example "factory" class WallLibrary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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