diff options
Diffstat (limited to 'src/game.cpp')
-rw-r--r-- | src/game.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/game.cpp b/src/game.cpp new file mode 100644 index 0000000..ccca10f --- /dev/null +++ b/src/game.cpp | |||
@@ -0,0 +1,20 @@ | |||
1 | #include "game.h" | ||
2 | |||
3 | int Game::addSprite(Sprite sprite) { | ||
4 | int id = sprites_.size(); | ||
5 | sprites_.push_back(std::move(sprite)); | ||
6 | spritesByY_.emplace(sprite.loc().y(), id); | ||
7 | return id; | ||
8 | } | ||
9 | |||
10 | void Game::moveSprite(int id, vec2i newLoc) { | ||
11 | Sprite& sprite = sprites_.at(id); | ||
12 | bool changedY = (sprite.loc().y() != newLoc.y()); | ||
13 | if (changedY) { | ||
14 | spritesByY_.erase(std::make_tuple(sprite.loc().y(), id)); | ||
15 | } | ||
16 | sprite.loc() = newLoc; | ||
17 | if (changedY) { | ||
18 | spritesByY_.emplace(newLoc.y(), id); | ||
19 | } | ||
20 | } \ No newline at end of file | ||