// Base class for all renderable and destructable entitites. #ifndef ENTITY_HPP #define ENTITY_HPP #include "Platform.hpp" #include "Position.hpp" class Level; class DynamicPixelBuffer; float constexpr HIT_TIME = 1.0f; class Entity { protected: Position topleft; int hitpoints = 1; float hittime = 0.0f; Color hitcolor; // Entity-specific step method. This one was already implemented in all // derived classes, which is why [PlayerX] and [PlayerY] are passed like // that. virtual void doStep( float PlayerX, float PlayerY, FloatSeconds const & Frametime, Level &level ); public: /// Constructors and destructors /// ---------------------------- Entity(); Entity(Position const &topleft, int hitpoints = 1); virtual ~Entity(); /// ---------------------------- /// Member retrieval /// ---------------- Position const& getTopLeft() const; float getLeft() const; float getTop() const; int getHitPoints() const; float getHitTime() const; /// ---------------- /// State changes /// ------------- // Handles updates for all generic fields. Returns `false` if this object // is destroyed and should be removed. bool step( Position const &PlayerPos, FloatSeconds const & Frametime, Level &level ); // Removes a single hit point and sets the hit animation color to [color]. // Returns the new number of hit points. int takeDamage(Color color); /// ------------- /// Rendering /// --------- virtual PixelBuffer const& getSprite() = 0; // Renders the entity to [buf]. void blit(DynamicPixelBuffer &buf); /// --------- }; #endif /* ENTITY_HPP */