Add a sprite field to entity.
I did this because I don't see why an entity would not have a sprite.
This commit is contained in:
parent
63b2d506ba
commit
6e76cc0175
|
@ -22,13 +22,13 @@ namespace simpleengine {
|
|||
friend class Game;
|
||||
friend class Event;
|
||||
public:
|
||||
Entity() = default;
|
||||
explicit Entity(sf::Sprite& sprite);
|
||||
virtual ~Entity() = default;
|
||||
Entity(const Entity& entity) = delete;
|
||||
|
||||
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) {};
|
||||
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);
|
||||
|
||||
virtual void Render(sf::RenderTarget* target);
|
||||
virtual void Update(const float& delta_time);
|
||||
|
@ -54,6 +54,7 @@ namespace simpleengine {
|
|||
void RenderComponents(sf::RenderTarget* target);
|
||||
void AddComponent(std::unique_ptr<Component> component);
|
||||
protected:
|
||||
sf::Sprite& sprite;
|
||||
std::vector<std::unique_ptr<Component>> components;
|
||||
bool destroying = false;
|
||||
};
|
||||
|
|
|
@ -7,6 +7,22 @@
|
|||
#include "entity.h"
|
||||
#include "component.h"
|
||||
|
||||
simpleengine::Entity::Entity(sf::Sprite &sprite) : sprite(sprite) {
|
||||
|
||||
}
|
||||
|
||||
void simpleengine::Entity::Move(const float &delta_time, const float &dir_x, const float &dir_y) {
|
||||
sprite.setPosition(dir_x * delta_time, dir_y * delta_time);
|
||||
}
|
||||
|
||||
void simpleengine::Entity::Move(const float &delta_time, const sf::Vector2f &offset) {
|
||||
sprite.move(offset * delta_time);
|
||||
}
|
||||
|
||||
void simpleengine::Entity::Move(const sf::Vector2f &offset) {
|
||||
sprite.move(offset);
|
||||
}
|
||||
|
||||
void simpleengine::Entity::Render(sf::RenderTarget *target) {
|
||||
RenderComponents(target);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue