Game Engine 2D Platformer
GameEntity.hpp
Go to the documentation of this file.
1 /*
2  * @file GameEntity.hpp
3  * @brief GameEntity class interface
4  * @date 2021-03-12
5  ***********************************************/
6 #ifndef GAMEENTITY_HPP
7 #define GAMEENTITY_HPP
8 
9 #include "TinyMath.hpp"
10 #include "Component.hpp"
11 #include "Constants.hpp"
12 #include "EntityManager.hpp"
13 #include <memory>
14 #include <vector>
15 #include <SDL2/SDL.h>
16 
17 class Component; // forward declaration
18 class EntityManager; // forward
22 {
23 
24 public:
29 
32  ~GameEntity();
39  void StartUp(Vector2D position, Vector2D velocity, int width, int height);
42  void ShutDown();
45  void Update();
48  void Render();
52  SDL_Rect* GetRectangle();
56  SDL_Event GetEvent();
60  int GetWidth();
64  int GetHeight();
68  void AddComponent(std::shared_ptr<Component> component);
72  void SetEvent(SDL_Event& e);
79  void Reset();
82  SDL_RendererFlip flip = SDL_FLIP_NONE;
83  SDL_Rect rect;
84  SDL_Rect src, dest;
85  SDL_Texture* m_texture;
86  bool win = false;
87  bool lose = false;
88  int lives = 3;
89  int score = 0;
90  bool eatSound = false;
91  bool deathSound = false;
92  bool collectItemSound = false;
93  bool jumpSound = false;
94  bool cameraFlag = false;
95  int xPosTile = 0;
96  std::vector<int> collectablesAvailable;
97 
98  int arrayPos = 0;
99  bool collectable = false;
100 
102  bool jumping = false;
103  bool isGrounded = false;
107 
108 private:
109  SDL_Event event;
110 
111  int width;
112  int height;
113  std::vector<std::shared_ptr<Component>> components;
114 };
115 
116 #endif
entityType
Definition: Constants.hpp:54
The interface class for different components to inherit.
Definition: Component.hpp:16
EntityManager class that stores all entities within the game.
Definition: EntityManager.hpp:24
Represents an interactable entity in the game that includes Main Character, NPC, Tiles ,...
Definition: GameEntity.hpp:22
void StartUp(Vector2D position, Vector2D velocity, int width, int height)
Initializes attributes for the GameEntity object.
Definition: GameEntity.cpp:21
int GetWidth()
Returns the Width of GameEntity.
Definition: GameEntity.cpp:76
Vector2D velocity
Definition: GameEntity.hpp:81
GameEntity(entityType eType)
Constructor of GameEntity.
Definition: GameEntity.cpp:8
SDL_Rect dest
Definition: GameEntity.hpp:84
Vector2D initialPosition
Definition: GameEntity.hpp:105
~GameEntity()
Destructor of GameEntity.
Definition: GameEntity.cpp:13
bool collectItemSound
Definition: GameEntity.hpp:92
int GetHeight()
Returns the Height of GameEntity.
Definition: GameEntity.cpp:84
void Reset()
Resets the GameEntity.
Definition: GameEntity.cpp:114
SDL_Rect src
Definition: GameEntity.hpp:84
bool isGrounded
Definition: GameEntity.hpp:103
SDL_Rect * GetRectangle()
Returns the Rectangle for GameEntity.
Definition: GameEntity.cpp:60
SDL_RendererFlip flip
Definition: GameEntity.hpp:82
bool win
Definition: GameEntity.hpp:86
bool deathSound
Definition: GameEntity.hpp:91
void ShutDown()
Destrotys and free attributes of the GameEntity Class.
std::vector< int > collectablesAvailable
Definition: GameEntity.hpp:96
void Render()
Renders the object on screen for the GameEntity Class.
Definition: GameEntity.cpp:49
int score
Definition: GameEntity.hpp:89
int xPosTile
Definition: GameEntity.hpp:95
Vector2D initialVelocity
Definition: GameEntity.hpp:106
entityType eType
Definition: GameEntity.hpp:101
void AddComponent(std::shared_ptr< Component > component)
Adds different components to the GameEntity.
Definition: GameEntity.cpp:92
SDL_Event GetEvent()
Returns the Event for GameEntity.
Definition: GameEntity.cpp:68
bool eatSound
Definition: GameEntity.hpp:90
EntityManager * entityManager
Definition: GameEntity.hpp:104
bool lose
Definition: GameEntity.hpp:87
void SetEvent(SDL_Event &e)
Sets the SDL_Event for GameEntity class.
Definition: GameEntity.cpp:100
bool collectable
Definition: GameEntity.hpp:99
bool jumpSound
Definition: GameEntity.hpp:93
SDL_Rect rect
Definition: GameEntity.hpp:83
void SetManager(EntityManager *entityManager)
Sets EntityManager for GameEntity.
Definition: GameEntity.cpp:109
SDL_Texture * m_texture
Definition: GameEntity.hpp:85
void Update()
Updates the position of the game entity.
Definition: GameEntity.cpp:38
int lives
Definition: GameEntity.hpp:88
int arrayPos
Definition: GameEntity.hpp:98
bool jumping
Definition: GameEntity.hpp:102
Vector2D position
Definition: GameEntity.hpp:80
bool cameraFlag
Definition: GameEntity.hpp:94
Definition: TinyMath.hpp:18