Gamedev Framework (gf)  0.12.0
A C++14 framework for 2D games
Entity.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2019 Julien Bernard
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 #ifndef GF_ENTITY_H
22 #define GF_ENTITY_H
23 
24 #include "Portability.h"
25 #include "Time.h"
26 
27 namespace gf {
28 #ifndef DOXYGEN_SHOULD_SKIP_THIS
29 inline namespace v1 {
30 #endif
31 
32  struct RenderStates;
33  class RenderTarget;
34 
53  class GF_API Entity {
54  public:
62  Entity(int priority = 0)
63  : m_priority(priority)
64  , m_liveness(Liveness::ALIVE)
65  {
66  }
67 
71  virtual ~Entity();
72 
78  void setPriority(int priority) {
79  m_priority = priority;
80  }
81 
87  int getPriority() const {
88  return m_priority;
89  }
90 
102  bool isAlive() const {
103  return m_liveness == Liveness::ALIVE;
104  }
105 
111  void setAlive() {
112  m_liveness = Liveness::ALIVE;
113  }
114 
121  void kill() {
122  m_liveness = Liveness::DEAD;
123  }
124 
137  virtual void update(Time time);
138 
146  virtual void render(RenderTarget& target, const RenderStates& states);
147 
148  private:
149  enum class Liveness : int {
150  ALIVE,
151  DEAD,
152  };
153 
154  int m_priority;
155  Liveness m_liveness;
156  };
157 
158 #ifndef DOXYGEN_SHOULD_SKIP_THIS
159 }
160 #endif
161 }
162 
163 #endif // GF_ENTITY_H
Base class for all render targets (window, texture, ...)
Definition: RenderTarget.h:66
Define the states used for drawing to a RenderTarget.
Definition: RenderStates.h:82
Represents a time value.
Definition: Time.h:74
Entity(int priority=0)
Contructor.
Definition: Entity.h:62
A game entity.
Definition: Entity.h:53
The namespace for gf classes.
Definition: Action.h:35
void setAlive()
Set the entity alive (again)
Definition: Entity.h:111
void setPriority(int priority)
Set the priority of the entity.
Definition: Entity.h:78
int getPriority() const
Get the priority of the entity.
Definition: Entity.h:87
void kill()
Kill an entity.
Definition: Entity.h:121
bool isAlive() const
Check if the entity is alive.
Definition: Entity.h:102