summary refs log tree commit diff stats
path: root/src/collision.h
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-02-18 12:35:45 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-02-18 12:35:45 -0500
commite16fb5be90c889c371cbb0ca2444735c2e12073c (patch)
treecbaa20e14a34c460b6c9886f266c4b4b6f62ae87 /src/collision.h
parented08b673c50b076042d8f0c49501372168142764 (diff)
downloadtherapy-e16fb5be90c889c371cbb0ca2444735c2e12073c.tar.gz
therapy-e16fb5be90c889c371cbb0ca2444735c2e12073c.tar.bz2
therapy-e16fb5be90c889c371cbb0ca2444735c2e12073c.zip
Implemented map adjacency
This brings along with it the ability to move to different maps, for which the PlayingSystem and PlayableComponent were introduced. The PlayingSystem is a general overseer system that handles big picture stuff like initializing the player and changing maps. The PlayableComponent represents the player. While the ControllableComponent is also likely to always only be on the player entity, the two are distinct by separation of concerns.

This also required a refactoring of how collisions are processed, because of a bug where the player can move to a new map when horizontal collisions are checked, and vertical collisions are skipped, causing the player to clip through the ground because the normal force was never handled.
Diffstat (limited to 'src/collision.h')
-rw-r--r--src/collision.h81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/collision.h b/src/collision.h new file mode 100644 index 0000000..e5371f8 --- /dev/null +++ b/src/collision.h
@@ -0,0 +1,81 @@
1#ifndef COLLISION_H_53D84877
2#define COLLISION_H_53D84877
3
4#include "entity_manager.h"
5#include "direction.h"
6
7class Collision {
8public:
9
10 using id_type = EntityManager::id_type;
11
12 // Types are defined in descending priority order
13 enum class Type {
14 wall,
15 platform,
16 adjacency,
17 warp,
18 danger
19 };
20
21 Collision(
22 id_type collider,
23 Direction dir,
24 Type type,
25 int axis,
26 double lower,
27 double upper) :
28 collider_(collider),
29 dir_(dir),
30 type_(type),
31 axis_(axis),
32 lower_(lower),
33 upper_(upper)
34 {
35 }
36
37 inline id_type getCollider() const
38 {
39 return collider_;
40 }
41
42 inline Direction getDirection() const
43 {
44 return dir_;
45 }
46
47 inline Type getType() const
48 {
49 return type_;
50 }
51
52 inline int getAxis() const
53 {
54 return axis_;
55 }
56
57 inline double getLower() const
58 {
59 return lower_;
60 }
61
62 inline double getUpper() const
63 {
64 return upper_;
65 }
66
67 bool operator<(const Collision& other) const;
68
69 bool isColliding(double x, double y, int w, int h) const;
70
71private:
72
73 id_type collider_;
74 Direction dir_;
75 Type type_;
76 int axis_;
77 double lower_;
78 double upper_;
79};
80
81#endif /* end of include guard: COLLISION_H_53D84877 */