64 lines
2.1 KiB
Java
Raw Permalink Normal View History

2018-06-18 15:17:56 -07:00
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;}
}