2020-07-03 03:48:58 +00:00
|
|
|
//
|
|
|
|
// Created by SeanOMik on 7/2/2020.
|
|
|
|
// Github: https://github.com/SeanOMik
|
|
|
|
// Email: seanomik@gmail.com
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef SIMPLEENGINE_ENTITY_H
|
|
|
|
#define SIMPLEENGINE_ENTITY_H
|
|
|
|
|
|
|
|
#include <SFML/Graphics.hpp>
|
|
|
|
|
2020-07-03 18:31:17 +00:00
|
|
|
#include <stack>
|
|
|
|
|
2020-07-03 03:48:58 +00:00
|
|
|
namespace simpleengine {
|
2020-07-03 18:31:17 +00:00
|
|
|
class Component;
|
|
|
|
class Game;
|
|
|
|
class Event;
|
2020-07-03 03:48:58 +00:00
|
|
|
class Entity {
|
2020-07-03 18:31:17 +00:00
|
|
|
friend class Game;
|
|
|
|
friend class Event;
|
2020-07-03 03:48:58 +00:00
|
|
|
public:
|
|
|
|
Entity() = default;
|
|
|
|
virtual ~Entity() = default;
|
|
|
|
|
|
|
|
virtual void Move(const float& delta_time, const float& x, const float& y) {};
|
|
|
|
virtual void Update(const float& delta_time) = 0;
|
|
|
|
virtual void Render(sf::RenderTarget* target = nullptr) = 0;
|
2020-07-03 18:31:17 +00:00
|
|
|
virtual void Destroying() {}; // Called when the entity is about to be destroyed.
|
|
|
|
|
|
|
|
void DestroyEntity() {
|
|
|
|
destroying = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool& IsGettingDestroyed() const {
|
|
|
|
return destroying;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If your event does not extend from EntityEvent, you will need to execute this yourself inside Event::Update.
|
|
|
|
void UpdateComponents(const float& delta_time);
|
|
|
|
|
|
|
|
void AddComponent(Component* component);
|
|
|
|
private:
|
|
|
|
// This is ran from class `Game` and `Event`. It runs the `UpdateComponents` method and then the `Update` method.
|
|
|
|
void UpdateEntity(const float& delta_time) {
|
|
|
|
UpdateComponents(delta_time);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<Component*> components;
|
|
|
|
bool destroying = false;
|
2020-07-03 03:48:58 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //GAMEENGINE_ENTITY_H
|