summary refs log tree commit diff stats
path: root/src/camera_system.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-02-03 01:11:31 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-02-03 01:11:31 -0500
commit24918837c3ff9026d228657d14852c9cf39a5644 (patch)
treebe131a43eb30f164bd70f542cfcaec688fbc3d51 /src/camera_system.cpp
parentf449345e3aeb599eb497dfeeac7027cf4d1de515 (diff)
downloadtanetane-24918837c3ff9026d228657d14852c9cf39a5644.tar.gz
tanetane-24918837c3ff9026d228657d14852c9cf39a5644.tar.bz2
tanetane-24918837c3ff9026d228657d14852c9cf39a5644.zip
Added camera system
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}