package sk.neuromancer.sphaera.rewrite; import sk.neuromancer.sphaera.interf.Tickable; import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; public class SphaeraGame extends Game implements Tickable{ private Splash splash = null; private Menu menu = null; private World world = null; private SoundPlayer soundPlayer; public static final int DEFAULT_WIDTH = 900; public static final int DEFAULT_HEIGHT = 650; public static final int TPS = 30; public static final int FOV = 75; private long lastTickTime; private long ticks, frames; @Override public void create(){ Gdx.graphics.setTitle("Sphaera"); splash = new Splash(); setScreen(splash); Gdx.input.setInputProcessor(splash); soundPlayer = new SoundPlayer(); soundPlayer.load(); //soundPlayer.play(); ticks = frames = 0; lastTickTime = System.currentTimeMillis(); } @Override public void resize(int width, int height) { super.resize(width, height); } @Override public void render() { long now = System.currentTimeMillis(); if(now - lastTickTime > (1/TPS) * 1000){ tick(ticks); lastTickTime = now; } draw(); } @Override public void tick(long tickCount) { ticks++; GameState state = getScreen(); state.tick(tickCount); soundPlayer.tick(tickCount); if(ticks % 30 == 0){ System.out.println(Gdx.graphics.getFramesPerSecond()); } if(state.isFinished()){ if(state instanceof World){ soundPlayer.playExplosion(); } state = state.next(); Gdx.input.setInputProcessor(state); setScreen(state); if(state instanceof Menu){ menu = (Menu) state; }else if(state instanceof World){ world = (World) state; }else if(state instanceof Exit){ this.dispose(); state.dispose(); Gdx.app.exit(); } } } public void draw(){ frames++; super.render(); } @Override public void pause() { super.pause(); } @Override public void resume() { super.resume(); } @Override public void dispose() { if(splash != null) splash.dispose(); if(menu != null) menu.dispose(); if(world != null) world.dispose(); if(soundPlayer != null) soundPlayer.dispose(); } @Override public GameState getScreen() { return (GameState) super.getScreen(); } }