summary refs log tree commit diff stats
path: root/src/transform_system.h
blob: eb1a95b78a4cd1cb41564eb4138f73f7bd8b41cb (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
#ifndef TRANSFORM_SYSTEM_H_BA2633BC
#define TRANSFORM_SYSTEM_H_BA2633BC

#include <range/v3/all.hpp>
#include <set>
#include <tuple>
#include "direction.h"
#include "system.h"
#include "vector.h"

class Game;

struct AxisResult {
  Direction dir;
  bool blocked = false;
};

struct CollisionResult {
  AxisResult horiz;
  AxisResult vert;
};

class TransformSystem : public System {
public:

  static constexpr SystemKey Key = SystemKey::Transform;

  TransformSystem(Game& game) : game_(game) {}

  void initSprite(int spriteId, vec2i loc);

  void moveSprite(int spriteId, vec2i newLoc);

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

  CollisionResult checkCollision(int spriteId, vec2i newLoc, Direction dir);

private:

  Game& game_;
  std::set<std::tuple<int, int>> spritesByY_;
};

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