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:
SeanOMik 2020-07-12 22:35:11 -05:00
parent 63b2d506ba
commit 6e76cc0175
No known key found for this signature in database
GPG Key ID: FA4D55AC05268A88
2 changed files with 21 additions and 4 deletions

View File

@ -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;
};

View File

@ -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);
}