82 lines
1.6 KiB
Java
82 lines
1.6 KiB
Java
package de.samdev.colorrunner.game.world;
|
|
|
|
import com.badlogic.gdx.Game;
|
|
import com.badlogic.gdx.Gdx;
|
|
import com.badlogic.gdx.math.Rectangle;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import de.samdev.colorrunner.game.world.entities.CRGameEntity;
|
|
import de.samdev.colorrunner.game.world.entities.gameentities.PlayerEntity;
|
|
import de.samdev.colorrunner.game.world.map.provider.MapProvider;
|
|
import de.samdev.colorrunner.input.GameInputListener;
|
|
|
|
public class CRGameWorld implements GameInputListener {
|
|
public PlayerEntity player;
|
|
public List<CRGameEntity> entities;
|
|
|
|
public FPSCounter fps = new FPSCounter();
|
|
public Rectangle camViewBoundaries = new Rectangle();
|
|
|
|
public MapProvider mapprovider;
|
|
|
|
public CRGameWorld(MapProvider prov) {
|
|
mapprovider = prov;
|
|
|
|
reinitialize();
|
|
}
|
|
|
|
private void reinitialize() {
|
|
entities = new ArrayList<CRGameEntity>();
|
|
|
|
addEntity(player = new PlayerEntity(this, 40, 290));
|
|
|
|
mapprovider.init(this);
|
|
}
|
|
|
|
public void update(float delta) {
|
|
fps.Inc();
|
|
|
|
for (int i = entities.size()-1; i >= 0; i--) {
|
|
CRGameEntity ent = entities.get(i);
|
|
|
|
if (ent.active)
|
|
ent.update(delta);
|
|
else
|
|
entities.remove(i);
|
|
}
|
|
|
|
if(player.getPosition().y < - 10)
|
|
{
|
|
((Game) Gdx.app.getApplicationListener()).setScreen(new GameScreen());
|
|
}
|
|
|
|
mapprovider.update(this, player.bounds);
|
|
}
|
|
|
|
public CRGameEntity addEntity(CRGameEntity ent) {
|
|
entities.add(ent);
|
|
|
|
return ent;
|
|
}
|
|
|
|
@Override
|
|
public void doJump() {
|
|
player.jump();
|
|
}
|
|
|
|
@Override
|
|
public void switchColor(SwipeDirection sd) {
|
|
player.switchPhase(sd);
|
|
}
|
|
|
|
@Override
|
|
public void doFly() {
|
|
player.fly();
|
|
}
|
|
|
|
@Override
|
|
public void reset() {
|
|
reinitialize();
|
|
}
|
|
}
|