ColorRunner/core/src/de/samdev/colorrunner/game/world/CRGameWorld.java

82 lines
1.6 KiB
Java
Raw Normal View History

2014-08-10 17:19:40 +02:00
package de.samdev.colorrunner.game.world;
2017-04-13 23:30:38 +02:00
import com.badlogic.gdx.Game;
2014-08-11 02:32:28 +02:00
import com.badlogic.gdx.Gdx;
2014-08-11 13:51:41 +02:00
import com.badlogic.gdx.math.Rectangle;
2017-04-14 01:06:53 +02:00
import java.util.ArrayList;
import java.util.List;
2014-08-10 17:19:40 +02:00
import de.samdev.colorrunner.game.world.entities.CRGameEntity;
2014-08-10 20:59:50 +02:00
import de.samdev.colorrunner.game.world.entities.gameentities.PlayerEntity;
2017-04-14 00:13:20 +02:00
import de.samdev.colorrunner.game.world.map.provider.MapProvider;
2014-08-10 19:41:06 +02:00
import de.samdev.colorrunner.input.GameInputListener;
2014-08-10 17:19:40 +02:00
2014-08-10 19:41:06 +02:00
public class CRGameWorld implements GameInputListener {
public PlayerEntity player;
2014-08-11 21:36:01 +02:00
public List<CRGameEntity> entities;
2014-08-11 00:24:55 +02:00
2014-08-10 17:19:40 +02:00
public FPSCounter fps = new FPSCounter();
2014-08-11 13:51:41 +02:00
public Rectangle camViewBoundaries = new Rectangle();
2017-04-14 00:13:20 +02:00
public MapProvider mapprovider;
2017-04-14 01:06:53 +02:00
public CRGameWorld(MapProvider prov) {
mapprovider = prov;
2014-08-11 21:36:01 +02:00
reinitialize();
}
private void reinitialize() {
entities = new ArrayList<CRGameEntity>();
2017-04-14 01:06:53 +02:00
2014-08-10 19:41:06 +02:00
addEntity(player = new PlayerEntity(this, 40, 290));
2014-08-11 00:24:55 +02:00
2017-04-14 00:13:20 +02:00
mapprovider.init(this);
2014-08-10 17:19:40 +02:00
}
public void update(float delta) {
fps.Inc();
2014-08-11 00:24:55 +02:00
2014-08-11 13:51:41 +02:00
for (int i = entities.size()-1; i >= 0; i--) {
CRGameEntity ent = entities.get(i);
if (ent.active)
ent.update(delta);
else
entities.remove(i);
2014-08-10 17:19:40 +02:00
}
2017-04-13 23:30:38 +02:00
if(player.getPosition().y < - 10)
{
2017-04-14 01:11:39 +02:00
((Game) Gdx.app.getApplicationListener()).setScreen(new GameScreen());
2017-04-13 23:30:38 +02:00
}
2014-08-11 02:32:28 +02:00
2017-04-14 00:13:20 +02:00
mapprovider.update(this, player.bounds);
2014-08-10 17:19:40 +02:00
}
2014-08-10 19:41:06 +02:00
public CRGameEntity addEntity(CRGameEntity ent) {
2014-08-10 17:19:40 +02:00
entities.add(ent);
2014-08-11 00:24:55 +02:00
2014-08-10 19:41:06 +02:00
return ent;
}
2014-08-11 21:21:52 +02:00
2014-08-10 19:41:06 +02:00
@Override
public void doJump() {
player.jump();
}
@Override
public void switchColor(SwipeDirection sd) {
player.switchPhase(sd);
}
@Override
public void doFly() {
player.fly();
2014-08-10 17:19:40 +02:00
}
2014-08-11 21:36:01 +02:00
@Override
public void reset() {
reinitialize();
}
2014-08-10 17:19:40 +02:00
}