From e16fb5be90c889c371cbb0ca2444735c2e12073c Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 18 Feb 2018 12:35:45 -0500 Subject: 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. --- src/collision.h | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/collision.h (limited to 'src/collision.h') 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 @@ +#ifndef COLLISION_H_53D84877 +#define COLLISION_H_53D84877 + +#include "entity_manager.h" +#include "direction.h" + +class Collision { +public: + + using id_type = EntityManager::id_type; + + // Types are defined in descending priority order + enum class Type { + wall, + platform, + adjacency, + warp, + danger + }; + + Collision( + id_type collider, + Direction dir, + Type type, + int axis, + double lower, + double upper) : + collider_(collider), + dir_(dir), + type_(type), + axis_(axis), + lower_(lower), + upper_(upper) + { + } + + inline id_type getCollider() const + { + return collider_; + } + + inline Direction getDirection() const + { + return dir_; + } + + inline Type getType() const + { + return type_; + } + + inline int getAxis() const + { + return axis_; + } + + inline double getLower() const + { + return lower_; + } + + inline double getUpper() const + { + return upper_; + } + + bool operator<(const Collision& other) const; + + bool isColliding(double x, double y, int w, int h) const; + +private: + + id_type collider_; + Direction dir_; + Type type_; + int axis_; + double lower_; + double upper_; +}; + +#endif /* end of include guard: COLLISION_H_53D84877 */ -- cgit 1.4.1