package com.lucasdnd.ags.system;
import org.newdawn.slick.GameContainer;
import com.lucasdnd.ags.map.Map;
public class Camera {
private float xOffset = 0; // X Offset
private float yOffset = 0; // Y Offset
private int xMin; // View Limit
private int xMax;
private int yMin;
private int yMax;
private float cameraSpeed = 1f; // The speed at which the camera moves
private int cameraMovingDirection = -1; // The direction the camera is moving torwards
public final static int UP = 0;
public final static int DOWN = 1;
public final static int LEFT = 2;
public final static int RIGHT = 3;
public Camera(Map map, int containerWidth, int containerHeight) {
// Update the starting Offset based on the Map's x and y Offsets
xOffset = map.getxOffset();
yOffset = map.getyOffset();
// Set the max and min Camera movement limit
// Small Map
// Right X limit (negative X)
xMin = 28;
// Left X limit (positive X)
xMax = 400;
// Bot Y limit (negative Y)
yMin = -170;
// Top Y limit (positive Y)
yMax = 50;
}
/**
* Moves the camera around
* @param container
* @param map
* @param xMovement --> 1 if you want to move the camera x+, -1 if you want to move the camera x-
* @param yMovement --> same as above but for y
*/
public void updateOffset(GameContainer container, Map map, int delta, int xMovement, int yMovement) {
// Updates the Offset
xOffset = xOffset + ((xMovement * cameraSpeed) / GameSystem.globalScale);
yOffset = yOffset + ((yMovement * cameraSpeed) / GameSystem.globalScale);
// Limit the Camera movement
if(xOffset > xMax) {
xOffset = xMax;
} else if(xOffset < xMin) {
xOffset = xMin;
}
if(yOffset > yMax) {
yOffset = yMax;
} else if(yOffset < yMin) {
yOffset = yMin;
}
}
public float getxOffset() {
return xOffset;
}
public void setxOffset(float xOffset) {
this.xOffset = xOffset;
}
public float getyOffset() {
return yOffset;
}
public void setyOffset(float yOffset) {
this.yOffset = yOffset;
}
public int getCameraMovingDirection() {
return cameraMovingDirection;
}
public void setCameraMovingDirection(int cameraMovingDirection) {
this.cameraMovingDirection = cameraMovingDirection;
}
public float getCameraSpeed() {
return cameraSpeed;
}
public void setCameraSpeed(float cameraSpeed) {
this.cameraSpeed = cameraSpeed;
}
public int getxMin() {
return xMin;
}
public void setxMin(int xMin) {
this.xMin = xMin;
}
public int getxMax() {
return xMax;
}
public void setxMax(int xMax) {
this.xMax = xMax;
}
public int getyMin() {
return yMin;
}
public void setyMin(int yMin) {
this.yMin = yMin;
}
public int getyMax() {
return yMax;
}
public void setyMax(int yMax) {
this.yMax = yMax;
}
}