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/entity.h | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/entity.h (limited to 'src/entity.h') diff --git a/src/entity.h b/src/entity.h new file mode 100644 index 0000000..5a37147 --- /dev/null +++ b/src/entity.h @@ -0,0 +1,72 @@ +#ifndef ENTITY_H +#define ENTITY_H + +class Entity; +class Component; +class Locatable; +class Collidable; + +#include +#include "renderer.h" +#include "world.h" + +enum message_type { + CM_WALK_LEFT, + CM_WALK_RIGHT, + CM_STOP_WALKING, + CM_COLLISION, + CM_JUMP, + CM_STOP_JUMP, + CM_DROP, + CM_CAN_DROP, + CM_CANT_DROP +}; + +typedef struct { + message_type type; + Entity* collisionEntity; + int dropAxis; +} message_t; + +class Entity { + public: + Entity(World* world) : world(world) {} + ~Entity() {}; + void addComponent(std::shared_ptr c); + void send(message_t msg); + void tick(); + void input(int key, int action); + void render(Texture* buffer); + + World* world; + + private: + std::list> components; +}; + +class Component { + public: + Component(Entity& entity) : entity(entity) {} + virtual ~Component() {}; + virtual void receive(message_t msg) {(void)msg;} + virtual void render(Texture* tex) {(void)tex;} + virtual void tick() {} + virtual void input(int key, int action) {(void)key; (void)action;} + + Entity& entity; +}; + +class Locatable { + public: + std::pair position; + std::pair size; + std::pair velocity; + std::pair accel; +}; + +class Collidable { + public: + virtual void detectCollision(Entity& player, Locatable& physics, std::pair old_position) = 0; +}; + +#endif -- cgit 1.4.1