summary refs log tree commit diff stats
path: root/src/components
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/components
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/components')
-rw-r--r--src/components/mappable.h4
-rw-r--r--src/components/ponderable.h16
2 files changed, 18 insertions, 2 deletions
diff --git a/src/components/mappable.h b/src/components/mappable.h index 6f3d38e..e92074e 100644 --- a/src/components/mappable.h +++ b/src/components/mappable.h
@@ -7,7 +7,7 @@
7#include <list> 7#include <list>
8#include "component.h" 8#include "component.h"
9#include "renderer/texture.h" 9#include "renderer/texture.h"
10#include "collision.h" 10#include "components/ponderable.h"
11#include "entity_manager.h" 11#include "entity_manager.h"
12 12
13class MappableComponent : public Component { 13class MappableComponent : public Component {
@@ -46,7 +46,7 @@ public:
46 class Boundary { 46 class Boundary {
47 public: 47 public:
48 48
49 using Type = Collision::Type; 49 using Type = PonderableComponent::Collision;
50 50
51 Boundary( 51 Boundary(
52 double axis, 52 double axis,
diff --git a/src/components/ponderable.h b/src/components/ponderable.h index fd7e775..5354f87 100644 --- a/src/components/ponderable.h +++ b/src/components/ponderable.h
@@ -21,6 +21,17 @@ public:
21 }; 21 };
22 22
23 /** 23 /**
24 * List of different types of collidable surfaces.
25 */
26 enum class Collision {
27 wall,
28 platform,
29 adjacency,
30 warp,
31 danger
32 };
33
34 /**
24 * Constructor for initializing the body type, which is a constant. 35 * Constructor for initializing the body type, which is a constant.
25 */ 36 */
26 PonderableComponent(Type type) : type(type) 37 PonderableComponent(Type type) : type(type)
@@ -67,6 +78,11 @@ public:
67 bool collidable = true; 78 bool collidable = true;
68 79
69 /** 80 /**
81 * The effect that colliding with this body has.
82 */
83 Collision colliderType = Collision::wall;
84
85 /**
70 * If this flag is disabled, the entity will be ignored by the pondering 86 * If this flag is disabled, the entity will be ignored by the pondering
71 * system. 87 * system.
72 * 88 *