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/components.h | 76 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 37 deletions(-) (limited to 'src/components.h') diff --git a/src/components.h b/src/components.h index 687eab1..f9b6e1e 100644 --- a/src/components.h +++ b/src/components.h @@ -5,48 +5,50 @@ #include #include #include "map.h" +#include class UserMovementComponent : public Component { public: - UserMovementComponent(Entity& parent) : Component(parent) {}; - void input(int key, int action); + void input(Game& game, Entity& entity, int key, int action); private: bool holdingLeft = false; bool holdingRight = false; }; -class PhysicsBodyComponent : public Component, public Collidable, public Locatable { +class PhysicsBodyComponent : public Component { public: - PhysicsBodyComponent(Entity& parent) : Component(parent) {}; - void receive(message_t msg); - void tick(); - void detectCollision(Entity& player, Locatable& physics, std::pair old_position); + void receive(Game& game, Entity& entity, Message& msg); + void tick(Game& game, Entity& entity); + void detectCollision(Game& game, Entity& entity, Entity& collider, std::pair old_position); + + private: + std::pair velocity; + std::pair accel; }; class PlayerSpriteComponent : public Component { public: - PlayerSpriteComponent(Entity& parent, Locatable& physics); - ~PlayerSpriteComponent(); - void render(Texture* buffer); - void receive(message_t msg); - void tick(); + void render(Game& game, Entity& entity, Texture& buffer); + void receive(Game& game, Entity& entity, Message& msg); + void tick(Game& game, Entity& entity); private: - Locatable& physics; - Texture* sprite; + Texture sprite{"../res/Starla.png"}; int animFrame = 0; bool facingLeft = false; bool isMoving = false; }; -class PlayerPhysicsComponent : public Component, public Locatable { +class PlayerPhysicsComponent : public Component { public: - PlayerPhysicsComponent(Entity& parent); - void tick(); - void receive(message_t msg); + PlayerPhysicsComponent(); + void tick(Game& game, Entity& entity); + void receive(Game& game, Entity& entity, Message& msg); private: + std::pair velocity; + std::pair accel; double jump_velocity; double jump_gravity; double jump_gravity_short; @@ -56,38 +58,38 @@ class PlayerPhysicsComponent : public Component, public Locatable { class MapRenderComponent : public Component { public: - MapRenderComponent(Entity& parent, Map* map); - ~MapRenderComponent(); - void render(Texture* buffer); + MapRenderComponent(Map& map); + void render(Game& game, Entity& entity, Texture& buffer); private: - Texture* screen; -}; - -enum direction_t { - up, left, down, right + Texture screen{GAME_WIDTH, GAME_HEIGHT}; }; -typedef struct { - int axis; - int lower; - int upper; - int type; -} collision_t; - -class MapCollisionComponent : public Component, public Collidable { +class MapCollisionComponent : public Component { public: - MapCollisionComponent(Entity& parent, Map* map); - void detectCollision(Entity& player, Locatable& physics, std::pair old_position); + MapCollisionComponent(Map& map); + void detectCollision(Game& game, Entity& entity, Entity& collider, std::pair old_position); private: + enum direction_t { + up, left, down, right + }; + + typedef struct { + int axis; + int lower; + int upper; + int type; + } collision_t; + 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; + Map* leftMap; + Map* rightMap; }; #endif -- cgit 1.4.1