102 lines
2.1 KiB
Java
102 lines
2.1 KiB
Java
package de.samdev.colorrunner.game.world;
|
|
|
|
import com.badlogic.gdx.Game;
|
|
import com.badlogic.gdx.Gdx;
|
|
import com.badlogic.gdx.audio.Music;
|
|
import com.badlogic.gdx.math.Rectangle;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import de.samdev.colorrunner.CRGame;
|
|
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;
|
|
import de.samdev.colorrunner.screens.gameScreen.GameScreen;
|
|
import de.samdev.colorrunner.screens.menu.MainMenu;
|
|
|
|
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;
|
|
private Music music;
|
|
public int scoreMeter = 0;
|
|
|
|
|
|
public CRGameWorld(MapProvider prov) {
|
|
mapprovider = prov;
|
|
|
|
|
|
music = CRGame.manager.get("sound/mainsound.mp3", Music.class);
|
|
music.setLooping(true);
|
|
music.play();
|
|
|
|
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);
|
|
}
|
|
|
|
float posi = player.getPosition().x;
|
|
if((posi / 75) >= (float)scoreMeter)
|
|
{
|
|
scoreMeter++;
|
|
}
|
|
if(player.getPosition().y < - 10)
|
|
{
|
|
((Game) Gdx.app.getApplicationListener()).setScreen(new MainMenu());
|
|
music.stop();
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|