summary refs log tree commit diff stats
path: root/src/game.h
blob: 274ef2e377aac427e3fdb13dca90000c9bf92e34 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef GAME_H_E6F1396E
#define GAME_H_E6F1396E

#include <set>
#include <range/v3/all.hpp>
#include <vector>
#include "sprite.h"

struct Input {
  bool left = false;
  bool right = false;
  bool up = false;
  bool down = false;
};

class Game {
public:

  int addSprite(Sprite sprite);

  const Sprite& getSprite(int id) const {
    return sprites_.at(id);
  }

  const std::vector<Sprite>& getSprites() {
    return sprites_;
  }

  auto spriteView() const {
    return ranges::views::transform([&] (int id) -> const Sprite& {
      return sprites_.at(id);
    });
  }

  auto getSpritesByY() const {
    return spritesByY_ | ranges::views::transform([] (const std::tuple<int, int>& val) {
      return std::get<1>(val);
    });
  }

  void moveSprite(int id, vec2i newLoc);

  void setSpriteState(int id, std::string state) {
    sprites_[id].setState(std::move(state));
  }

  void setSpriteDirection(int id, Direction dir) {
    sprites_[id].setDirection(dir);
  }

  void tickSpriteAnim() {
    for (Sprite& sprite : sprites_) {
      sprite.tickAnim();
    }
  }

private:

  std::vector<Sprite> sprites_;
  std::set<std::tuple<int, int>> spritesByY_;
};

#endif /* end of include guard: GAME_H_E6F1396E */