Skip to content

Instantly share code, notes, and snippets.

@tdgroot
Last active December 28, 2016 18:17
Show Gist options
  • Save tdgroot/6355265 to your computer and use it in GitHub Desktop.
Save tdgroot/6355265 to your computer and use it in GitHub Desktop.
public class Camera {
private final Player player;
private final Vector2f size;
private final Level level;
private final Rectangle bounds;
public Camera(Player player, Level level, Vector2f size, Rectangle bounds) {
this.player = player;
this.level = level;
this.size = size;
this.bounds = bounds;
}
public float getX() {
float x = player.getPosition().getCenterX() - size.getX() / 2;
if (x < bounds.getX())
x = bounds.getX();
if (x > bounds.getWidth() / 2)
x = bounds.getWidth() / 2;
return x;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment