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
|
#ifndef MAP_COLLISION_H
#define MAP_COLLISION_H
#include "entity.h"
#include <list>
class Map;
class Game;
class MapCollisionComponent : public Component {
public:
MapCollisionComponent(const Map& map);
void detectCollision(Game& game, Entity& entity, Entity& collider, std::pair<double, double> old_position);
private:
enum class Direction {
up, left, down, right
};
struct Collision {
enum class Type {
wall,
wrap,
teleport,
reverse,
platform,
danger
};
double axis;
double lower;
double upper;
Type type;
};
void addCollision(double axis, double lower, double upper, Direction dir, Collision::Type type);
void processCollision(Game& game, Entity& collider, Collision collision, Direction dir, std::pair<double, double> old_position);
std::list<Collision> left_collisions;
std::list<Collision> right_collisions;
std::list<Collision> up_collisions;
std::list<Collision> down_collisions;
const Map& map;
};
#endif
|