fissh

termios terminal aquarium. demo at ssh://fish@kloet.net
Download | Log | Files | Refs

Entity.h (1275B)


      1 #pragma once
      2 #include <memory>
      3 #include <string>
      4 #include <vector>
      5 
      6 struct AssetPair {
      7   std::vector<std::string> image;
      8   std::vector<std::string> mask;
      9 };
     10 
     11 class Entity {
     12 protected:
     13   const bool moving_right;
     14   float x;
     15   float y;
     16   static inline size_t next_id = 0;
     17   const size_t entity_id;
     18   virtual const std::vector<std::string> &getImage() const = 0;
     19   virtual const std::vector<std::string> &getMask() const = 0;
     20   virtual char getDefaultColor() const noexcept = 0;
     21 
     22 public:
     23   Entity() : moving_right(false), x(0.0f), y(0.0f), entity_id(++next_id) {}
     24   Entity(bool moving_right)
     25       : moving_right(moving_right), x(0.0f), y(0.0f), entity_id(++next_id) {}
     26   Entity(float init_x, float init_y)
     27       : moving_right(false), x(init_x), y(init_y), entity_id(++next_id) {}
     28   virtual ~Entity() = default;
     29 
     30   float getX() const noexcept { return x; }
     31   float getY() const noexcept { return y; }
     32   virtual int getWidth() const noexcept { return getImage()[0].length(); }
     33   size_t getId() const noexcept { return entity_id; }
     34 
     35   virtual void update() noexcept = 0;
     36 
     37   virtual bool shouldBeRemoved() const noexcept;
     38   virtual std::unique_ptr<Entity> createReplacement() const { return nullptr; }
     39   virtual int getPreferredLayer() const noexcept = 0;
     40 
     41   void draw() const;
     42 };