summary refs log tree commit diff stats
path: root/src/game.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/game.cpp b/src/game.cpp index ccca10f..ebb792e 100644 --- a/src/game.cpp +++ b/src/game.cpp
@@ -17,4 +17,26 @@ void Game::moveSprite(int id, vec2i newLoc) {
17 if (changedY) { 17 if (changedY) {
18 spritesByY_.emplace(newLoc.y(), id); 18 spritesByY_.emplace(newLoc.y(), id);
19 } 19 }
20} \ No newline at end of file 20}
21
22void Game::tick() {
23 if (!cameraLocked_) {
24 const Sprite& follow = getSprite(followingSprite_);
25 vec2i mapBounds = map_->getMapSize() * map_->getTileSize();
26
27 cameraPos_ = follow.loc() - (cameraFov_ / 2);
28
29 if (cameraPos_.x() < 0) {
30 cameraPos_.x() = 0;
31 }
32 if (cameraPos_.y() < 0) {
33 cameraPos_.y() = 0;
34 }
35 if (cameraPos_.x() + cameraFov_.w() >= mapBounds.w()) {
36 cameraPos_.x() = mapBounds.w() - cameraFov_.w() - 1;
37 }
38 if (cameraPos_.y() + cameraFov_.h() >= mapBounds.h()) {
39 cameraPos_.y() = mapBounds.h() - cameraFov_.h() - 1;
40 }
41 }
42}