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 20:26:44 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <memory>
|
2020-07-03 18:31:17 +00:00
|
|
|
|
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 20:26:44 +00:00
|
|
|
|
|
|
|
class Entity : std::enable_shared_from_this<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;
|
2020-07-03 20:26:44 +00:00
|
|
|
Entity(const Entity& entity) = delete;
|
2020-07-03 03:48:58 +00:00
|
|
|
|
2020-07-04 18:15:56 +00:00
|
|
|
virtual void Move(const float& delta_time, const float& dir_x, const float& dir_y) {};
|
|
|
|
virtual void Move(const float& delta_time, const sf::Vector2f& offset) {};
|
|
|
|
virtual void Move(const sf::Vector2f& offset) {};
|
2020-07-03 03:48:58 +00:00
|
|
|
virtual void Update(const float& delta_time) = 0;
|
2020-07-03 18:34:22 +00:00
|
|
|
virtual void Render(sf::RenderTarget* target) = 0;
|
2020-07-03 18:31:17 +00:00
|
|
|
|
2020-07-03 20:26:44 +00:00
|
|
|
// Called when the entity is about to be destroyed.
|
|
|
|
// Make sure to call this in your extending Entity.
|
|
|
|
virtual void Destroying();
|
2020-07-03 18:31:17 +00:00
|
|
|
|
2020-07-03 20:26:44 +00:00
|
|
|
void DestroyLater(); // In most cases, this will be ran next EntityEvent::Update()
|
|
|
|
const bool& IsGettingDestroyed() const;
|
2020-07-03 18:31:17 +00:00
|
|
|
|
|
|
|
// If your event does not extend from EntityEvent, you will need to execute this yourself inside Event::Update.
|
|
|
|
void UpdateComponents(const float& delta_time);
|
|
|
|
|
2020-07-03 20:26:44 +00:00
|
|
|
void AddComponent(std::unique_ptr<Component> component);
|
|
|
|
|
|
|
|
std::shared_ptr<Entity> GetShared() {
|
|
|
|
return shared_from_this();
|
|
|
|
}
|
2020-07-04 18:55:40 +00:00
|
|
|
protected:
|
2020-07-03 20:26:44 +00:00
|
|
|
std::vector<std::unique_ptr<Component>> components;
|
2020-07-03 18:31:17 +00:00
|
|
|
bool destroying = false;
|
2020-07-03 03:48:58 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //GAMEENGINE_ENTITY_H
|