diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-02-02 16:51:22 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-02-02 16:51:22 -0500 |
commit | b628c80f988c1fb250b94b17dca8e082bc4c1d0b (patch) | |
tree | b4de344e1d8d28a88aa1a1dbc381e07f03707fff /src/game.cpp | |
parent | a475b843e7d37f128ce30140d193f0312aa70c9c (diff) | |
download | tanetane-b628c80f988c1fb250b94b17dca8e082bc4c1d0b.tar.gz tanetane-b628c80f988c1fb250b94b17dca8e082bc4c1d0b.tar.bz2 tanetane-b628c80f988c1fb250b94b17dca8e082bc4c1d0b.zip |
Added moving camera
Diffstat (limited to 'src/game.cpp')
-rw-r--r-- | src/game.cpp | 24 |
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 | |||
22 | void 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 | } | ||