Gamedev Framework (gf)  0.8.0
A C++14 framework for 2D games
Entity.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2018 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  int getPriority() const {
79  return m_priority;
80  }
81 
93  bool isAlive() const {
94  return m_liveness == Liveness::ALIVE;
95  }
96 
102  void setAlive() {
103  m_liveness = Liveness::ALIVE;
104  }
105 
112  void kill() {
113  m_liveness = Liveness::DEAD;
114  }
115 
128  virtual void update(Time time);
129 
137  virtual void render(RenderTarget& target, const RenderStates& states);
138 
139  private:
140  enum class Liveness : int {
141  ALIVE,
142  DEAD,
143  };
144 
145  int m_priority;
146  Liveness m_liveness;
147  };
148 
149 #ifndef DOXYGEN_SHOULD_SKIP_THIS
150 }
151 #endif
152 }
153 
154 #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:73
Entity(int priority=0)
Contructor.
Definition: Entity.h:62
A game entity.
Definition: Entity.h:53
The namespace for gf classes.
Definition: Action.h:34
void setAlive()
Set the entity alive (again)
Definition: Entity.h:102
int getPriority() const
Get the priority of the entity.
Definition: Entity.h:78
void kill()
Kill an entity.
Definition: Entity.h:112
bool isAlive() const
Check if the entity is alive.
Definition: Entity.h:93