2016-02-08 18:08:43 +00:00
|
|
|
package com.game;
|
|
|
|
|
|
|
|
import com.badlogic.gdx.ApplicationAdapter;
|
|
|
|
import com.badlogic.gdx.Gdx;
|
2016-02-10 18:21:32 +00:00
|
|
|
import com.badlogic.gdx.Input;
|
2016-02-08 18:08:43 +00:00
|
|
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
|
|
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
2016-02-10 18:21:32 +00:00
|
|
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
2016-02-08 18:08:43 +00:00
|
|
|
import com.game.Misc.Vars;
|
2016-02-10 18:21:32 +00:00
|
|
|
import com.game.Managers.StateManager;
|
2016-02-08 18:08:43 +00:00
|
|
|
|
2016-02-10 18:21:32 +00:00
|
|
|
public class App extends ApplicationAdapter {
|
2016-02-08 18:08:43 +00:00
|
|
|
|
|
|
|
private float accum;
|
|
|
|
|
2016-02-10 18:21:32 +00:00
|
|
|
// Batches
|
2016-02-08 18:08:43 +00:00
|
|
|
private SpriteBatch sb;
|
2016-02-10 18:21:32 +00:00
|
|
|
private ShapeRenderer sr;
|
|
|
|
|
|
|
|
// Cameras
|
2016-02-08 18:08:43 +00:00
|
|
|
private OrthographicCamera cam;
|
|
|
|
private OrthographicCamera hudCam;
|
|
|
|
|
2016-02-10 18:21:32 +00:00
|
|
|
// Managers
|
2016-02-08 18:08:43 +00:00
|
|
|
private StateManager sm;
|
|
|
|
|
|
|
|
@Override
|
2016-02-09 13:12:43 +00:00
|
|
|
public void create() {
|
2016-02-10 18:21:32 +00:00
|
|
|
|
|
|
|
// Create batches
|
2016-02-08 18:08:43 +00:00
|
|
|
sb = new SpriteBatch();
|
2016-02-10 18:21:32 +00:00
|
|
|
sr = new ShapeRenderer();
|
2016-02-08 18:08:43 +00:00
|
|
|
|
2016-02-10 18:21:32 +00:00
|
|
|
// Create Main + HUD cameras
|
2016-02-08 18:08:43 +00:00
|
|
|
cam = new OrthographicCamera();
|
|
|
|
cam.setToOrtho(false, Vars.SCREEN_WIDTH, Vars.SCREEN_HEIGHT);
|
|
|
|
hudCam = new OrthographicCamera();
|
|
|
|
hudCam.setToOrtho(false, Vars.SCREEN_WIDTH, Vars.SCREEN_HEIGHT);
|
2016-02-10 18:21:32 +00:00
|
|
|
|
|
|
|
// Create statemanager (Should always happen last)
|
2016-02-08 18:08:43 +00:00
|
|
|
sm = new StateManager(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void resize (int width, int height) {
|
2016-02-10 18:21:32 +00:00
|
|
|
|
2016-02-08 18:08:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void render () {
|
2016-02-10 18:21:32 +00:00
|
|
|
super.render();
|
2016-02-08 18:08:43 +00:00
|
|
|
accum += Gdx.graphics.getDeltaTime();
|
|
|
|
while (accum >= Vars.STEP) {
|
|
|
|
accum -= Vars.STEP;
|
2016-02-09 00:05:48 +00:00
|
|
|
sm.handleInput();
|
2016-02-08 18:08:43 +00:00
|
|
|
sm.update(Vars.STEP);
|
|
|
|
sm.render();
|
|
|
|
}
|
|
|
|
|
2016-02-10 18:21:32 +00:00
|
|
|
if(Gdx.input.isKeyPressed(Input.Keys.ESCAPE)) { Gdx.app.exit(); }
|
2016-02-08 18:08:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void dispose () {
|
|
|
|
sm.dispose();
|
2016-02-10 18:21:32 +00:00
|
|
|
sb.dispose();
|
|
|
|
sr.dispose();
|
2016-02-08 18:08:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public SpriteBatch getSpriteBatch() { return sb; }
|
2016-02-10 18:21:32 +00:00
|
|
|
public ShapeRenderer getSr() { return sr; }
|
|
|
|
public StateManager getSm() { return sm; }
|
2016-02-08 18:08:43 +00:00
|
|
|
public OrthographicCamera getCam() { return cam; }
|
|
|
|
public OrthographicCamera getHudCam() { return hudCam; }
|
|
|
|
}
|