From 7f0e8c7ef70c62814c274f110367db92f01cbb26 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 10 Mar 2015 00:41:59 -0400 Subject: C++11'd everything! Also moved location information from physics components into entity. --- src/entity.h | 81 +++++++++++++++++++++++++----------------------------------- 1 file changed, 34 insertions(+), 47 deletions(-) (limited to 'src/entity.h') diff --git a/src/entity.h b/src/entity.h index 5a37147..803a9b8 100644 --- a/src/entity.h +++ b/src/entity.h @@ -3,42 +3,45 @@ class Entity; class Component; -class Locatable; -class Collidable; #include #include "renderer.h" -#include "world.h" +#include "game.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 +class Message { + public: + enum class Type { + walkLeft, + walkRight, + stopWalking, + stopMovingHorizontally, + stopMovingVertically, + collision, + jump, + stopJump, + drop, + canDrop, + cantDrop + }; + + Message(Type type) : type(type) {} + + Type type; + Entity* collisionEntity; + int dropAxis; }; -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); + void send(Game& game, Message& msg); + void tick(Game& game); + void input(Game& game, int key, int action); + void render(Game& game, Texture& buffer); + void detectCollision(Game& game, Entity& collider, std::pair old_position); - World* world; + std::pair position; + std::pair size; private: std::list> components; @@ -46,27 +49,11 @@ class Entity { 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; + virtual void receive(Game&, Entity&, Message&) {} + virtual void render(Game&, Entity&, Texture&) {} + virtual void tick(Game&, Entity&) {} + virtual void input(Game&, Entity&, int, int) {} + virtual void detectCollision(Game&, Entity&, Entity&, std::pair) {} }; #endif -- cgit 1.4.1