First Commit
This commit is contained in:
107
com/jalenwinslow/game/Handler.java
Normal file
107
com/jalenwinslow/game/Handler.java
Normal file
@ -0,0 +1,107 @@
|
||||
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;}
|
||||
|
||||
}
|
72
com/jalenwinslow/game/Main.java
Normal file
72
com/jalenwinslow/game/Main.java
Normal file
@ -0,0 +1,72 @@
|
||||
package com.jalenwinslow.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.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||
import com.badlogic.gdx.utils.viewport.ScreenViewport;
|
||||
|
||||
public class Main extends ApplicationAdapter {
|
||||
|
||||
public static int SCREEN_WIDTH, SCREEN_HEIGHT;
|
||||
|
||||
SpriteBatch batch;
|
||||
private Handler handler;
|
||||
private Stage stage;
|
||||
private OrthographicCamera cam;
|
||||
|
||||
@Override
|
||||
public void create () {
|
||||
batch = new SpriteBatch();
|
||||
handler = new Handler(this);
|
||||
|
||||
stage = new Stage(new ScreenViewport(), batch);
|
||||
stage.getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
|
||||
|
||||
SCREEN_WIDTH = Gdx.graphics.getWidth()/12; //Original is divided by 10
|
||||
SCREEN_HEIGHT = Gdx.graphics.getHeight()/12;
|
||||
|
||||
cam = new OrthographicCamera(SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
cam.setToOrtho(false, cam.viewportWidth, cam.viewportHeight);
|
||||
handler.init();
|
||||
|
||||
cam.update();
|
||||
}
|
||||
|
||||
public void resize() {
|
||||
stage.getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
cam.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render () {
|
||||
|
||||
//Update
|
||||
handler.update(Gdx.graphics.getDeltaTime());
|
||||
|
||||
cam.update();
|
||||
batch.setProjectionMatrix(cam.combined);
|
||||
|
||||
//Render
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
batch.begin();
|
||||
handler.render(batch);
|
||||
batch.end();
|
||||
|
||||
//GUI Render (Stage)
|
||||
stage.draw();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose () {
|
||||
handler.dispose();
|
||||
batch.dispose();
|
||||
stage.dispose();
|
||||
}
|
||||
|
||||
//Getters and Setters
|
||||
public Stage getStage() {return stage;}
|
||||
public OrthographicCamera getCam() {return cam;}
|
||||
}
|
52
com/jalenwinslow/game/gameobjects/GameObject.java
Normal file
52
com/jalenwinslow/game/gameobjects/GameObject.java
Normal file
@ -0,0 +1,52 @@
|
||||
package com.jalenwinslow.game.gameobjects;
|
||||
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.jalenwinslow.game.Handler;
|
||||
|
||||
/**
|
||||
* Created by jalen on 2/16/2018.
|
||||
*/
|
||||
|
||||
public abstract class GameObject {
|
||||
|
||||
protected Handler handler;
|
||||
protected Vector2 pos;
|
||||
protected float depth;
|
||||
protected TextureRegion image;
|
||||
protected Rectangle bounds;
|
||||
|
||||
public GameObject(Handler handler, float x, float y, Texture image) {
|
||||
this.handler = handler;
|
||||
this.pos = new Vector2(x, y);
|
||||
this.depth = y;
|
||||
if (image != null) this.image = new TextureRegion(image);
|
||||
else this.image = null;
|
||||
this.bounds = new Rectangle();
|
||||
}
|
||||
|
||||
public abstract void init(int initState);
|
||||
public abstract void update(float dt);
|
||||
public abstract void render(SpriteBatch batch);
|
||||
public abstract void dispose();
|
||||
|
||||
public boolean hasCollided(float x, float y) {
|
||||
return (x < bounds.x + bounds.width && x > bounds.x && y < bounds.y + bounds.height && y > bounds.y);
|
||||
}
|
||||
|
||||
//Getters and Setters
|
||||
public Vector2 getPos() {return pos;}
|
||||
public float getDepth() {return depth;}
|
||||
public TextureRegion getImage() {return image;}
|
||||
public Rectangle getBounds() {return bounds;}
|
||||
|
||||
public void setPos(Vector2 pos) {this.pos = pos;}
|
||||
public void setPos(float x, float y) {this.pos.set(x, y);}
|
||||
public void setDepth(float depth) {this.depth = depth;}
|
||||
public void setImage(TextureRegion image) {this.image = image;}
|
||||
public void setBounds(Rectangle bounds) {this.bounds = bounds;}
|
||||
|
||||
}
|
78
com/jalenwinslow/game/gameobjects/GameObjectHandler.java
Normal file
78
com/jalenwinslow/game/gameobjects/GameObjectHandler.java
Normal file
@ -0,0 +1,78 @@
|
||||
package com.jalenwinslow.game.gameobjects;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.jalenwinslow.game.Handler;
|
||||
|
||||
/**
|
||||
* Created by jalen on 2/16/2018.
|
||||
*/
|
||||
|
||||
public class GameObjectHandler {
|
||||
|
||||
private Handler handler;
|
||||
private Array<GameObject> gameObjects;
|
||||
private Player player;
|
||||
private Maze maze;
|
||||
|
||||
public GameObjectHandler(Handler handler) {
|
||||
this.handler = handler;
|
||||
this.gameObjects = new Array<GameObject>();
|
||||
}
|
||||
|
||||
public void update(float dt) {
|
||||
for (int i = 0; i < gameObjects.size; i++) {
|
||||
gameObjects.get(i).update(dt);
|
||||
}
|
||||
handler.debugger.msg = "gameobjects " + gameObjects.size;
|
||||
}
|
||||
|
||||
public void render(SpriteBatch batch) {
|
||||
sortGameObjects();
|
||||
for (int i = 0; i < gameObjects.size; i++) {
|
||||
gameObjects.get(i).render(batch);
|
||||
batch.setColor(1, 1, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
for (GameObject go: gameObjects) go.dispose();;
|
||||
gameObjects.clear();
|
||||
player = null;
|
||||
}
|
||||
|
||||
private void sortGameObjects() {
|
||||
for (int i = 0; i < gameObjects.size; i++) {
|
||||
if (i+1 < gameObjects.size && gameObjects.get(i+1) != null) {
|
||||
if (gameObjects.get(i).getDepth() < gameObjects.get(i+1).getDepth()) {
|
||||
gameObjects.swap(i, i+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addGameObject(GameObject gameObject) {
|
||||
gameObjects.add(gameObject);
|
||||
}
|
||||
|
||||
public void addPlayer(Player player) {
|
||||
this.player = player;
|
||||
gameObjects.add(player);
|
||||
}
|
||||
|
||||
public void removePlayer(Player player) {
|
||||
gameObjects.removeValue(player, false);
|
||||
this.player = null;
|
||||
}
|
||||
|
||||
public void removeGameObject(GameObject gameObject) {
|
||||
gameObjects.removeValue(gameObject, false);
|
||||
}
|
||||
|
||||
//Getters and Setters
|
||||
public Array<GameObject> getGameObjects() {return gameObjects;}
|
||||
public Player getPlayer() {return player;}
|
||||
public Maze getMaze() {return maze;}
|
||||
|
||||
public void setMaze(Maze maze) {this.maze = maze;}
|
||||
}
|
60
com/jalenwinslow/game/sprite/Sprite.java
Normal file
60
com/jalenwinslow/game/sprite/Sprite.java
Normal file
@ -0,0 +1,60 @@
|
||||
package com.jalenwinslow.game.sprite;
|
||||
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.jalenwinslow.game.Handler;
|
||||
import com.jalenwinslow.game.gameobjects.GameObject;
|
||||
|
||||
/**
|
||||
* Created by jalen on 2/18/2018.
|
||||
*/
|
||||
|
||||
public abstract class Sprite {
|
||||
|
||||
protected Handler handler;
|
||||
protected Rectangle bounds;
|
||||
protected boolean manual;
|
||||
protected GameObject gameObj;
|
||||
|
||||
protected TextureRegion texture;
|
||||
protected TextureRegion[] frames;
|
||||
protected TextureRegion currentFrame;
|
||||
protected int currentFrameIndex;
|
||||
protected float fps;
|
||||
|
||||
public Sprite(Handler handler, TextureRegion texture, float x, float y, float width, float height, boolean manual, GameObject gameObj) {
|
||||
this.handler = handler;
|
||||
this.texture = texture;
|
||||
this.bounds = new Rectangle(x, y, width, height);
|
||||
this.manual = manual;
|
||||
this.gameObj = gameObj;
|
||||
|
||||
currentFrame = new TextureRegion();
|
||||
frames = new TextureRegion[0];
|
||||
currentFrameIndex = 0;
|
||||
fps = 10.0f;
|
||||
}
|
||||
|
||||
public abstract void update(float dt);
|
||||
public abstract void render(SpriteBatch batch);
|
||||
public abstract void dispose();
|
||||
|
||||
//Getters and Setters
|
||||
public Rectangle getBounds() {return bounds;}
|
||||
public boolean isManual() {return manual;}
|
||||
public GameObject getGameObj() {return gameObj;}
|
||||
public TextureRegion getTexture() {return texture;}
|
||||
public TextureRegion getCurrentFrame() {return currentFrame;}
|
||||
public TextureRegion[] getFrames() {return frames;}
|
||||
public int getCurrentFrameIndex() {return currentFrameIndex;}
|
||||
public float getFps() {return fps;}
|
||||
|
||||
public void setManual(boolean manual) {this.manual = manual;}
|
||||
public void setGameObj(GameObject gameObj) {this.gameObj = gameObj;}
|
||||
public void setTexture(TextureRegion image) {this.texture = image;}
|
||||
public void setFrames(TextureRegion[] frames) {this.frames = frames;}
|
||||
public void setCurrentFrameIndex(int index) {this.currentFrameIndex = index;}
|
||||
public void setFps(int fps) {this.fps = fps;}
|
||||
}
|
41
com/jalenwinslow/game/states/GameState.java
Normal file
41
com/jalenwinslow/game/states/GameState.java
Normal file
@ -0,0 +1,41 @@
|
||||
package com.jalenwinslow.game.states;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.jalenwinslow.game.Handler;
|
||||
import com.jalenwinslow.game.gameobjects.MazeGenerator;
|
||||
import com.jalenwinslow.game.gameobjects.Player;
|
||||
import com.jalenwinslow.game.gameobjects.Tile;
|
||||
import com.jalenwinslow.game.utils.Assets;
|
||||
|
||||
/**
|
||||
* Created by jalen on --/--/----.
|
||||
*/
|
||||
|
||||
public class GameState extends State {
|
||||
|
||||
|
||||
public GameState(Handler handler) {
|
||||
super(handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(int initState) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(SpriteBatch batch) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
|
||||
}
|
||||
}
|
36
com/jalenwinslow/game/states/MenuState.java
Normal file
36
com/jalenwinslow/game/states/MenuState.java
Normal file
@ -0,0 +1,36 @@
|
||||
package com.jalenwinslow.game.states;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.jalenwinslow.game.Handler;
|
||||
|
||||
/**
|
||||
* Created by jalen on --/--/----.
|
||||
*/
|
||||
|
||||
public class MenuState extends State {
|
||||
|
||||
|
||||
public MenuState(Handler handler) {
|
||||
super(handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(int initState) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(SpriteBatch batch) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
|
||||
}
|
||||
}
|
32
com/jalenwinslow/game/states/State.java
Normal file
32
com/jalenwinslow/game/states/State.java
Normal file
@ -0,0 +1,32 @@
|
||||
package com.jalenwinslow.game.states;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.jalenwinslow.game.Handler;
|
||||
|
||||
/**
|
||||
* Created by jalen on --/--/--.
|
||||
*/
|
||||
|
||||
public abstract class State {
|
||||
|
||||
protected Handler handler;
|
||||
private static State currentState = null, previousState = null;
|
||||
|
||||
public State(Handler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public abstract void init(int initState);
|
||||
public abstract void update(float dt);
|
||||
public abstract void render(SpriteBatch batch);
|
||||
public abstract void dispose();
|
||||
|
||||
//Getters and Setters
|
||||
public static State getCurrentState() {return currentState;}
|
||||
public static State getPreviousState() {return previousState;}
|
||||
|
||||
public static void setCurrentState(State state) {
|
||||
State.previousState = State.currentState;
|
||||
State.currentState = state;
|
||||
}
|
||||
}
|
43
com/jalenwinslow/game/ui/UIDebug.java
Normal file
43
com/jalenwinslow/game/ui/UIDebug.java
Normal file
@ -0,0 +1,43 @@
|
||||
package com.jalenwinslow.game.ui;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.jalenwinslow.game.Handler;
|
||||
import com.jalenwinslow.game.utils.Assets;
|
||||
|
||||
/**
|
||||
* Created by jalen on --/--/----.
|
||||
*/
|
||||
|
||||
public class UIDebug extends UIObject {
|
||||
|
||||
//private BitmapFont font;
|
||||
public String msg;
|
||||
private String debugMsg;
|
||||
|
||||
public UIDebug(Handler handler, Texture texture, float x, float y, boolean visible) {
|
||||
super(handler, texture, x, y, visible);
|
||||
//font = new BitmapFont(Gdx.files.internal(Assets.customPixelFont1));
|
||||
//font.setColor(1, 0, 0, 1);
|
||||
//font.getData().scale(2f);
|
||||
msg = "";
|
||||
debugMsg = "Debugger: ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
debugMsg = "Debugger(FPS:" + Gdx.graphics.getFramesPerSecond() + "): " + msg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float parentAlpha) {
|
||||
//font.draw(batch, debugMsg, pos.x, pos.y);
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
//font.dispose();
|
||||
remove();
|
||||
}
|
||||
}
|
45
com/jalenwinslow/game/ui/UIObject.java
Normal file
45
com/jalenwinslow/game/ui/UIObject.java
Normal file
@ -0,0 +1,45 @@
|
||||
package com.jalenwinslow.game.ui;
|
||||
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.jalenwinslow.game.Handler;
|
||||
|
||||
/**
|
||||
* Created by jalen on 2/19/2018.
|
||||
*/
|
||||
|
||||
public abstract class UIObject extends Actor {
|
||||
|
||||
protected Handler handler;
|
||||
protected Texture texture;
|
||||
protected Vector2 pos;
|
||||
//protected boolean visible;
|
||||
protected Rectangle bounds;
|
||||
|
||||
public UIObject(Handler handler, Texture texture, float x, float y, boolean visible) {
|
||||
this.handler = handler;
|
||||
this.texture = texture;
|
||||
this.pos = new Vector2(x, y);
|
||||
this.setVisible(visible);
|
||||
this.bounds = new Rectangle();
|
||||
}
|
||||
|
||||
public abstract void update(float dt);
|
||||
@Override
|
||||
public abstract void draw(Batch batch, float parentAlpha);
|
||||
|
||||
//Getters and Setters
|
||||
public Texture getTexture() {return texture;}
|
||||
public Vector2 getPos() {return pos;}
|
||||
public float getPosX() {return pos.x;}
|
||||
public float getPosY() {return pos.y;}
|
||||
public Rectangle getBounds() {return bounds;}
|
||||
|
||||
public void setTexture(Texture texture) {this.texture = texture;}
|
||||
public void setPos(float x, float y) {pos.set(x, y);}
|
||||
public void setBounds(Rectangle bounds) {this.bounds = bounds;}
|
||||
}
|
23
com/jalenwinslow/game/utils/Assets.java
Normal file
23
com/jalenwinslow/game/utils/Assets.java
Normal file
@ -0,0 +1,23 @@
|
||||
package com.jalenwinslow.game.utils;
|
||||
|
||||
import com.badlogic.gdx.Files;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g3d.utils.TextureProvider;
|
||||
|
||||
/**
|
||||
* Created by jalen on --/--/----.
|
||||
*/
|
||||
|
||||
public class Assets {
|
||||
|
||||
|
||||
|
||||
public static void init() {
|
||||
|
||||
}
|
||||
|
||||
public static void dispose() {
|
||||
|
||||
}
|
||||
}
|
63
com/jalenwinslow/game/utils/CamHandler.java
Normal file
63
com/jalenwinslow/game/utils/CamHandler.java
Normal file
@ -0,0 +1,63 @@
|
||||
package com.jalenwinslow.game.utils;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.jalenwinslow.game.Handler;
|
||||
import com.jalenwinslow.game.gameobjects.GameObject;
|
||||
|
||||
/**
|
||||
* Created by jalen on --/--/----.
|
||||
*/
|
||||
|
||||
public class CamHandler {
|
||||
|
||||
private Handler handler;
|
||||
private OrthographicCamera cam;
|
||||
private float x, y;
|
||||
private float speed, acceleration;
|
||||
private GameObject objOfFocus;
|
||||
private boolean manual;
|
||||
|
||||
public CamHandler(Handler handler, OrthographicCamera cam, GameObject objOfFocus) {
|
||||
this.handler = handler;
|
||||
this.cam = cam;
|
||||
speed = 5;
|
||||
acceleration = 0;
|
||||
this.objOfFocus = objOfFocus;
|
||||
manual = false;
|
||||
}
|
||||
|
||||
public void update(float dt) {
|
||||
|
||||
if (objOfFocus != null && !manual) {
|
||||
x = objOfFocus.getPos().x;
|
||||
y = objOfFocus.getPos().y;
|
||||
}
|
||||
|
||||
//check collision out of game area
|
||||
gameSidesCollision();
|
||||
|
||||
//Update camera
|
||||
cam.position.set(x, y, 0);
|
||||
}
|
||||
|
||||
private void gameSidesCollision() {
|
||||
if (x - Gdx.graphics.getWidth()/24 < 0) {x = Gdx.graphics.getWidth()/24;} // check left side of screen
|
||||
if (x + Gdx.graphics.getWidth()/24 > handler.getGoHandler().getMaze().getMazeWidth()) {
|
||||
x = handler.getGoHandler().getMaze().getMazeWidth() - Gdx.graphics.getWidth()/24;
|
||||
}
|
||||
if (y - Gdx.graphics.getHeight()/24 < 0) {y = Gdx.graphics.getHeight()/24;}
|
||||
if (y + Gdx.graphics.getHeight()/24 >= handler.getGoHandler().getMaze().getMazeHeight()) {
|
||||
y = handler.getGoHandler().getMaze().getMazeHeight() - Gdx.graphics.getHeight()/24;
|
||||
}
|
||||
}
|
||||
|
||||
//Getters and Setters
|
||||
public OrthographicCamera getCamera() {return cam;}
|
||||
public GameObject getObjOfFocus() {return objOfFocus;}
|
||||
public boolean isManual() {return manual;}
|
||||
|
||||
public void setCamera(OrthographicCamera cam) {this.cam = cam;}
|
||||
public void setObjOfFocus(GameObject objOfFocus) {this.objOfFocus = objOfFocus;}
|
||||
public void setManual(boolean manual) {this.manual = manual;}
|
||||
}
|
16
com/jalenwinslow/game/utils/Controls.java
Normal file
16
com/jalenwinslow/game/utils/Controls.java
Normal file
@ -0,0 +1,16 @@
|
||||
package com.jalenwinslow.game.utils;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
|
||||
/**
|
||||
* Updated by jalen on 6/17/2018.
|
||||
*/
|
||||
|
||||
public class Controls {
|
||||
|
||||
|
||||
public static void update(float dt) {
|
||||
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user