diff --git a/CPPLINT.cfg b/CPPLINT.cfg new file mode 100644 index 0000000..79a6a5f --- /dev/null +++ b/CPPLINT.cfg @@ -0,0 +1,3 @@ +set noparent +linelength=80 +filter=-build/header_guard,-readability/alt_tokens \ No newline at end of file diff --git a/src/Thing.h b/src/Thing.h index 6a80445..9fcd3fa 100644 --- a/src/Thing.h +++ b/src/Thing.h @@ -2,16 +2,43 @@ #define THING_CPP_USLBKY9A #include -#include "Qor/TileMap.h" +#include "Qor/TileMap.h" #include "Qor/BasicPartitioner.h" class Game; class Sprite; -class Thing: - public Node -{ +class Thing : public Node { public: + enum Type { + INVALID_THING = 0, + + MONSTERS, + MOUSE = MONSTERS, + SNAIL, + WIZARD, + ROBOT, + DUCK, + MONSTERS_END, + + ITEMS = MONSTERS_END, + BATTERY = ITEMS, + HEART, + STAR, + KEY, + ITEMS_END, + + OBJECTS = ITEMS_END, + SPRING = OBJECTS, + DOOR, + OBJECTS_END, + + MARKERS = OBJECTS_END, + LIGHT = MARKERS, + MARKERS_END + }; + + // Constructor Thing( const std::shared_ptr& config, MapTile* placeholder, @@ -21,132 +48,106 @@ class Thing: Freq::Timeline* timeline, Cache* resources ); - virtual ~Thing() {} - void init_thing(); - - void setup_player(const std::shared_ptr& player); - void setup_map(const std::shared_ptr& map); - void setup_other(const std::shared_ptr& thing); + // Destructor + virtual ~Thing() {} - static unsigned get_id(const std::shared_ptr& config); - static bool is_thing(std::string name); - enum Type - { - INVALID_THING = 0, + // Static Variables + const static std::vector s_TypeNames; - MONSTERS, - MOUSE = MONSTERS, - SNAIL, - WIZARD, - ROBOT, - DUCK, - MONSTERS_END, - ITEMS = MONSTERS_END, - BATTERY = ITEMS, - HEART, - STAR, - KEY, - ITEMS_END, + // Getters + unsigned id() const { return m_ThingID; } + Game* game() { return m_pGame; } + MapTile* placeholder() { return m_pPlaceholder; } + Sprite* sprite() { return m_pSprite.get(); } + static unsigned get_id(const std::shared_ptr& config); + float hp_fraction() { return m_HP * 1.0f / m_MaxHP; } - OBJECTS = ITEMS_END, - SPRING = OBJECTS, - DOOR, - OBJECTS_END, - - MARKERS = OBJECTS_END, - LIGHT = MARKERS, - MARKERS_END - }; - - const static std::vector s_TypeNames; + // Properties + static bool is_thing(std::string name); + bool solid() const { return m_Solid; } + bool alive() const { return not m_Dead and not m_Dying; } bool is_monster() const { - return m_ThingID >= MONSTERS && m_ThingID < MONSTERS_END; - } + return m_ThingID >= MONSTERS && m_ThingID < MONSTERS_END; } bool is_item() const { - return m_ThingID >= ITEMS && m_ThingID < ITEMS_END; - } + return m_ThingID >= ITEMS && m_ThingID < ITEMS_END; } bool is_object() const { - return m_ThingID >= OBJECTS && m_ThingID < OBJECTS_END; - } + return m_ThingID >= OBJECTS && m_ThingID < OBJECTS_END; } bool is_marker() const { - return m_ThingID >= MARKERS && m_ThingID < MARKERS_END; - } + return m_ThingID >= MARKERS && m_ThingID < MARKERS_END; } + // bool is_weapon() const { + // return m_ThingID >= WEAPONS && m_ThingID < WEAPONS_END; } - //bool is_weapon() const { - // return m_ThingID >= WEAPONS && m_ThingID < WEAPONS_END; - //} - bool alive() const { return not m_Dead and not m_Dying; } + // Methods + void init_thing(); + + void register_player(Sprite* p); + void setup_player(const std::shared_ptr& player); + void setup_map(const std::shared_ptr& map); + void setup_other(const std::shared_ptr& thing); + void stun(); + void origin(); + void shoot(Sprite* origin); + void activate(); + void gib(Node* bullet); + void sound(const std::string& fn); bool damage(int dmg); - - bool solid() const { return m_Solid; } - unsigned id() const { return m_ThingID; } static std::shared_ptr find_thing(Node* n); - Game* game() { return m_pGame; } - Sprite* sprite() { return m_pSprite.get(); } - - static void cb_to_bullet(Node* thing_node, Node* bullet); - static void cb_to_static(Node* thing_node, Node* static_node); - static void cb_to_player(Node* player_node, Node* thing_node); - - void sound(const std::string& fn); - MapTile* placeholder() { return m_pPlaceholder; } + // Virtual Functions virtual void lazy_logic_self(Freq::Time t) override; virtual void logic_self(Freq::Time t) override; - void gib(Node* bullet); - float hp_fraction() { return m_HP * 1.0f / m_MaxHP; } - - void stun(); - void origin(); - void shoot(Sprite* origin); - void activate(); + // Callbacks + static void cb_to_bullet(Node* thing_node, Node* bullet); + static void cb_to_static(Node* thing_node, Node* static_node); + static void cb_to_player(Node* player_node, Node* thing_node); + - void register_player(Sprite* p); - private: - + // Member Properties + unsigned m_ThingID = 0; int m_HP = 1; int m_MaxHP = 1; float m_StartSpeed = 0.0f; float m_Speed = 0.0f; + bool m_Dying = false; bool m_Dead = false; - Cache* m_pResources = nullptr; bool m_bActive = false; + bool m_Solid = false; + + std::string m_Identity; + glm::vec3 m_Impulse; + std::vector m_Players; + boost::signals2::scoped_connection m_ResetCon; + + // Pointers MapTile* m_pPlaceholder = nullptr; BasicPartitioner* m_pPartitioner = nullptr; Game* m_pGame = nullptr; TileMap* m_pMap = nullptr; - bool m_Solid = false; - - // sprite is optional for thing type, not attached - std::shared_ptr m_pSprite; - std::string m_Identity; - unsigned m_ThingID = 0; - - boost::signals2::scoped_connection m_ResetCon; - - // ground detection for monsters + // Pointers - Ground Detection (Monsters) std::shared_ptr m_pLeft; std::shared_ptr m_pRight; - glm::vec3 m_Impulse; + // sprite is optional for thing type, not attached + std::shared_ptr m_pSprite; + Freq::Alarm m_StunTimer; Freq::Timeline* m_pTimeline; - std::vector m_Players; + // Cache + Cache* m_pResources = nullptr; }; #endif -