summary refs log tree commit diff stats
path: root/src/camera_system.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/camera_system.cpp')
-rw-r--r--src/camera_system.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/camera_system.cpp b/src/camera_system.cpp new file mode 100644 index 0000000..abeba86 --- /dev/null +++ b/src/camera_system.cpp
@@ -0,0 +1,27 @@
1#include "camera_system.h"
2#include "sprite.h"
3#include "game.h"
4#include "map.h"
5
6void CameraSystem::tick(double dt) {
7 if (!locked_) {
8 const Sprite& follow = game_.getSprite(followingSprite_);
9 const Map& map = game_.getMap();
10 vec2i mapBounds = map.getMapSize() * map.getTileSize();
11
12 pos_ = follow.loc() - (fov_ / 2);
13
14 if (pos_.x() < 0) {
15 pos_.x() = 0;
16 }
17 if (pos_.y() < 0) {
18 pos_.y() = 0;
19 }
20 if (pos_.x() + fov_.w() >= mapBounds.w()) {
21 pos_.x() = mapBounds.w() - fov_.w() - 1;
22 }
23 if (pos_.y() + fov_.h() >= mapBounds.h()) {
24 pos_.y() = mapBounds.h() - fov_.h() - 1;
25 }
26 }
27}