I currently have a libGDX game where I have an entity manager class which is called in the gamescreen. Instead, I would like to utilise it in a gameworld class and a gamerenderer class, but I cannot figure out how to split it up (if that makes sense). I want to do this so that I can manipulate my player class separately and not as a part of the entity manager. Previous attempts have failed because taking 'player' away meant that checkCollisions stopped working (hence why I want to use gameworld and gamerenderer classes instead). Does anyone have any ideas on how to achieve this?
Here is my entity manager class:
public class EntityManager {
private final Array<Entity> entities = new Array<Entity>();
private final Player player;
public EntityManager(int amount) {
player = new Player(new Vector2(110, 15), new Vector2(0, 35));
for (int i = 0; i < amount; i++) {
float x = MathUtils.random(0, ManicMeltdowns.WIDTH - TextureManager.DROPS.getWidth());
float y = MathUtils.random(ManicMeltdowns.HEIGHT, ManicMeltdowns.HEIGHT * 3);
float speed = 2;
addEntity(new Drops(new Vector2 (x, y), new Vector2(0, -speed)));
}
}
public void update() {
for (Entity e : entities)
e.update();
player.update();
checkCollisions();
}
public void render(SpriteBatch sb) {
for (Entity e : entities)
e.render(sb);
player.render(sb);
}
private void checkCollisions() {
for (Drops e : getDrops()) {
if (e.getBounds().overlaps(player.rectangle)) {
ScreenManager.setScreen(new GameOverScreen());
}
}
}
public void addEntity(Entity entity) {
entities.add(entity);
}
private Array<Drops> getDrops() {
Array<Drops> ret = new Array<Drops>();
for (Entity e : entities)
if (e instanceof Drops)
ret.add((Drops)e);
return ret;
}
}
Thanks.