Basic Files

This commit is contained in:
Ash Reynolds 2016-02-08 18:08:43 +00:00
parent 447fbed207
commit 6edb84511f
18 changed files with 717 additions and 0 deletions

View file

@ -0,0 +1,65 @@
package com.game;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.game.Misc.Vars;
import com.game.States.StateManager;
public class Game extends ApplicationAdapter {
private float accum;
private SpriteBatch sb;
private OrthographicCamera cam;
private OrthographicCamera hudCam;
private StateManager sm;
@Override
public void create () {
sb = new SpriteBatch();
cam = new OrthographicCamera();
cam.setToOrtho(false, Vars.SCREEN_WIDTH, Vars.SCREEN_HEIGHT);
hudCam = new OrthographicCamera();
hudCam.setToOrtho(false, Vars.SCREEN_WIDTH, Vars.SCREEN_HEIGHT);
sm = new StateManager(this);
}
@Override
public void resize (int width, int height) {
}
@Override
public void render () {
accum += Gdx.graphics.getDeltaTime();
while (accum >= Vars.STEP) {
accum -= Vars.STEP;
sm.update(Vars.STEP);
sm.render();
}
}
@Override
public void pause () {
}
@Override
public void resume () {
}
@Override
public void dispose () {
sm.dispose();
}
public SpriteBatch getSpriteBatch() { return sb; }
public OrthographicCamera getCam() { return cam; }
public OrthographicCamera getHudCam() { return hudCam; }
}

View file

@ -0,0 +1,16 @@
package com.game.Misc;
/**
* Created by Ash on 08/02/2016.
*/
public class Vars {
// Application related
public static final String TITLE = "Group Project";
public static final int SCREEN_WIDTH = 1280;
public static final int SCREEN_HEIGHT = 720;
public static final boolean RESIZABLE = false;
public static final float FRAMERATE = 60f;
// Physics related
public static final float STEP = 1 / FRAMERATE;
}

View file

@ -0,0 +1,36 @@
package com.game.States;
/**
* Created by Ash on 08/02/2016.
*/
public class Menu extends State {
public Menu(StateManager sm) {
super(sm);
}
@Override
public void init() {
}
@Override
public void update(float dt) {
}
@Override
public void render() {
}
@Override
public void handleInput() {
}
@Override
public void dispose() {
}
}

View file

@ -0,0 +1,43 @@
package com.game.States;
import com.badlogic.gdx.graphics.Texture;
/**
* Created by Ash on 08/02/2016.
*/
public class Play extends State {
Texture img;
public Play(StateManager sm) {
super(sm);
}
@Override
public void init() {
img = new Texture("badlogic.jpg");
}
@Override
public void update(float dt) {
}
@Override
public void render() {
sb.setProjectionMatrix(cam.combined);
sb.begin();
sb.draw(img, 0, 0);
sb.end();
}
@Override
public void handleInput() {
}
@Override
public void dispose() {
img.dispose();
}
}

View file

@ -0,0 +1,33 @@
package com.game.States;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.game.Game;
/**
* Created by Ash on 08/02/2016.
*/
public abstract class State {
protected StateManager sm;
protected Game game;
protected SpriteBatch sb;
protected OrthographicCamera cam;
protected OrthographicCamera hudCam;
public State (StateManager sm)
{
this.sm = sm;
game = sm.game();
sb = game.getSpriteBatch();
cam = game.getCam();
hudCam = game.getHudCam();
}
public abstract void init();
public abstract void update(float dt);
public abstract void render();
public abstract void handleInput();
public abstract void dispose();
}

View file

@ -0,0 +1,63 @@
package com.game.States;
import com.game.Game;
import java.util.HashMap;
import java.util.Stack;
/**
* Created by Ash on 08/02/2016.
*/
public class StateManager {
private Game game;
//private Stack<State> states;
private HashMap<States, State> states = new HashMap<States, State>();
private States currentState;
public enum States
{
MENU,
PAUSE,
PLAY,
}
public StateManager(Game game)
{
this.game = game;
states.put(States.MENU, new Menu(this));
states.put(States.PLAY, new Play(this));
setState(States.PLAY); // TODO, set to MENU
}
public void update(float dt)
{
states.get(currentState).update(dt);
}
public void render()
{
states.get(currentState).render();
}
public void handleInput()
{
states.get(currentState).handleInput();
}
public void dispose()
{
states.get(currentState).dispose();
}
// Accessors
public Game game() { return game; }
// Mutators
public void setState(States state)
{
currentState = state;
System.out.println("Setting state: " + currentState.name());
states.get(currentState).init();
}
}