From b53826079429939cdfbda073608cb85be8ba0738 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 7 Mar 2015 11:29:57 -0500 Subject: Created entity-component system Also tweaked the bloom flicker, tweaked the scanline texture, created a second test map, and created some currently unused sound effects. --- src/components.h | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/components.h (limited to 'src/components.h') diff --git a/src/components.h b/src/components.h new file mode 100644 index 0000000..687eab1 --- /dev/null +++ b/src/components.h @@ -0,0 +1,93 @@ +#ifndef COMPONENTS_H +#define COMPONENTS_H + +#include "entity.h" +#include +#include +#include "map.h" + +class UserMovementComponent : public Component { + public: + UserMovementComponent(Entity& parent) : Component(parent) {}; + void input(int key, int action); + + private: + bool holdingLeft = false; + bool holdingRight = false; +}; + +class PhysicsBodyComponent : public Component, public Collidable, public Locatable { + public: + PhysicsBodyComponent(Entity& parent) : Component(parent) {}; + void receive(message_t msg); + void tick(); + void detectCollision(Entity& player, Locatable& physics, std::pair old_position); +}; + +class PlayerSpriteComponent : public Component { + public: + PlayerSpriteComponent(Entity& parent, Locatable& physics); + ~PlayerSpriteComponent(); + void render(Texture* buffer); + void receive(message_t msg); + void tick(); + + private: + Locatable& physics; + Texture* sprite; + int animFrame = 0; + bool facingLeft = false; + bool isMoving = false; +}; + +class PlayerPhysicsComponent : public Component, public Locatable { + public: + PlayerPhysicsComponent(Entity& parent); + void tick(); + void receive(message_t msg); + + private: + double jump_velocity; + double jump_gravity; + double jump_gravity_short; + int direction = 0; + bool canDrop = false; +}; + +class MapRenderComponent : public Component { + public: + MapRenderComponent(Entity& parent, Map* map); + ~MapRenderComponent(); + void render(Texture* buffer); + + private: + Texture* screen; +}; + +enum direction_t { + up, left, down, right +}; + +typedef struct { + int axis; + int lower; + int upper; + int type; +} collision_t; + +class MapCollisionComponent : public Component, public Collidable { + public: + MapCollisionComponent(Entity& parent, Map* map); + void detectCollision(Entity& player, Locatable& physics, std::pair old_position); + + private: + void add_collision(int axis, int lower, int upper, direction_t dir, int type); + + std::list left_collisions; + std::list right_collisions; + std::list up_collisions; + std::list down_collisions; + Map* map; +}; + +#endif -- cgit 1.4.1