108 lines
3.2 KiB
Java
108 lines
3.2 KiB
Java
|
package com.jalenwinslow.game;
|
||
|
|
||
|
import com.badlogic.gdx.Gdx;
|
||
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||
|
import com.jalenwinslow.game.gameobjects.GameObject;
|
||
|
import com.jalenwinslow.game.gameobjects.GameObjectHandler;
|
||
|
import com.jalenwinslow.game.gameobjects.Player;
|
||
|
import com.jalenwinslow.game.states.*;
|
||
|
import com.jalenwinslow.game.ui.UIDebug;
|
||
|
import com.jalenwinslow.game.ui.UIPointer;
|
||
|
import com.jalenwinslow.game.ui.UITimer;
|
||
|
import com.jalenwinslow.game.utils.Assets;
|
||
|
import com.jalenwinslow.game.utils.CamHandler;
|
||
|
import com.jalenwinslow.game.utils.Controls;
|
||
|
import java.util.Scanner;
|
||
|
|
||
|
import java.util.Random;
|
||
|
|
||
|
/**
|
||
|
* Created by jalen on --/--/----.
|
||
|
*/
|
||
|
|
||
|
public class Handler {
|
||
|
|
||
|
private Main main;
|
||
|
private State menuState;
|
||
|
private State gameState;
|
||
|
private GameObjectHandler goHandler;
|
||
|
private CamHandler cam;
|
||
|
public Random rand;
|
||
|
public Scanner sc;
|
||
|
private int time;
|
||
|
private float elapsedTime;
|
||
|
|
||
|
public UIDebug debugger;
|
||
|
public UIPointer pointer;
|
||
|
public UITimer timer;
|
||
|
|
||
|
public Handler(Main main) {
|
||
|
this.main = main;
|
||
|
}
|
||
|
|
||
|
public void init() {
|
||
|
Assets.init();
|
||
|
goHandler = new GameObjectHandler(this);
|
||
|
cam = new CamHandler(this, main.getCam(), null);
|
||
|
rand = new Random();
|
||
|
sc = new Scanner(System.in);
|
||
|
|
||
|
debugger = new UIDebug(this, null, 16, 64, true);
|
||
|
pointer = new UIPointer(this, 0, 0, Assets.pointer1, true);
|
||
|
timer = new UITimer(this, Assets.timerBG, true);
|
||
|
main.getStage().addActor(debugger);
|
||
|
main.getStage().addActor(pointer);
|
||
|
main.getStage().addActor(timer);
|
||
|
|
||
|
menuState = new MenuState(this);
|
||
|
gameState = new GameState(this);
|
||
|
State.setCurrentState(gameState);
|
||
|
State.getCurrentState().init(0);
|
||
|
}
|
||
|
|
||
|
public void update(float dt) {
|
||
|
elapsedTime += dt;
|
||
|
if (elapsedTime >= 1) {
|
||
|
time++;
|
||
|
elapsedTime--;
|
||
|
}
|
||
|
|
||
|
Controls.update(dt);
|
||
|
if (State.getCurrentState() != null) State.getCurrentState().update(dt);
|
||
|
if (goHandler != null) goHandler.update(dt);
|
||
|
if (cam != null) cam.update(dt);
|
||
|
|
||
|
debugger.update(dt);
|
||
|
timer.update(dt);
|
||
|
}
|
||
|
|
||
|
public void render(SpriteBatch batch) {
|
||
|
if (State.getCurrentState() != null) State.getCurrentState().render(batch);
|
||
|
if (goHandler != null) goHandler.render(batch);
|
||
|
}
|
||
|
|
||
|
public void dispose() {
|
||
|
if (menuState != null) menuState.dispose(); menuState = null;
|
||
|
if (gameState != null) gameState.dispose(); gameState = null;
|
||
|
if (goHandler != null) goHandler.dispose(); goHandler = null;
|
||
|
Assets.dispose();
|
||
|
}
|
||
|
|
||
|
//Other methods
|
||
|
public void addPlayer(Player player) {
|
||
|
goHandler.addPlayer(player);
|
||
|
}
|
||
|
public void addGameObject(GameObject gameObject) { goHandler.addGameObject(gameObject); }
|
||
|
|
||
|
//Getters and Setters
|
||
|
public Main getMain() {return main;}
|
||
|
public MenuState getMenuState() {return (MenuState) menuState;}
|
||
|
public GameState getGameState() {return (GameState) gameState;}
|
||
|
public GameObjectHandler getGoHandler() {return goHandler;}
|
||
|
public CamHandler getCam() {return cam;}
|
||
|
public int getTime() {return time;}
|
||
|
|
||
|
public void setTime(int time) {this.time = time;}
|
||
|
|
||
|
}
|