summary refs log tree commit diff stats
path: root/src/collision.h
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-04-29 16:45:55 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-04-29 16:45:55 -0400
commitc00668c58b26325203cb6815bc3dedf1e7d7ac5e (patch)
treef03d9b420779f365a51285c9a2b675a5e7e965c5 /src/collision.h
parent36cceabfc5ddd22d9ae0d6c4dee9d4041bf2e348 (diff)
downloadtherapy-c00668c58b26325203cb6815bc3dedf1e7d7ac5e.tar.gz
therapy-c00668c58b26325203cb6815bc3dedf1e7d7ac5e.tar.bz2
therapy-c00668c58b26325203cb6815bc3dedf1e7d7ac5e.zip
Added map object collision
Collision checking in PonderingSystem was rewritten to work as follows: horizontal movement is step first, then vertical. In each step, the closest environmental boundary to the body is found on the axis of movement in the space traversed by the body. Then, if any map objects fall in the region between the body's old position and the environmental boundary (or body new position if no boundary was found), process collision with those bodies in increasing distance order, stopping if a collision stops movement short of where the next collision would take place. After this, process collision with all of the environmental boundaries at the axis distance found earlier, as long as movement hasn't stopped short.

This is not the most optimal implementation, and there is a lot of code repetition, but it is a start and it works.

All map objects currently function as walls.

This fixes the bug where you could, with pixel-perfect precision, jump into the corner of a wall tile.

The top of the hitbox for the spike tile was lowered by one pixel. This fixes a problem where if the player is halfway on a floor tile and halfway over a spike tile, the floor tile would not stop the spike tile from being processed, and the player would die.
Diffstat (limited to 'src/collision.h')
-rw-r--r--src/collision.h81
1 files changed, 0 insertions, 81 deletions
diff --git a/src/collision.h b/src/collision.h deleted file mode 100644 index e5371f8..0000000 --- a/src/collision.h +++ /dev/null
@@ -1,81 +0,0 @@
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 */