-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntity.cpp
More file actions
73 lines (57 loc) · 1.19 KB
/
Copy pathEntity.cpp
File metadata and controls
73 lines (57 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "Entity.h"
#include "Global.h"
Entity::Entity(const std::string& text, const sf::Vector2f& pos, const sf::Vector2f& speed)
: m_sprite(&Global::textureManager), m_position(pos), m_speed(speed), m_isActive(true)
{
m_sprite.setTexture(text);
m_sprite.setPosition(m_position);
}
void Entity::draw()
{
Global::window.draw(m_sprite);
}
void Entity::update(float elapsed)
{
if (!m_isActive) { return; }
auto initPosition = m_position;
m_position.x += m_speed.x * elapsed;
m_position.y += m_speed.y * elapsed;
auto positionDelta = m_position - initPosition;
for (auto& collider : m_colliders)
{
collider->move(positionDelta);
}
m_sprite.setPosition(m_position);
}
void Entity::setActive(bool active)
{
m_isActive = active;
}
void Entity::setPosition(const sf::Vector2f& pos)
{
m_position = pos;
}
void Entity::setSpeed(const sf::Vector2f& speed)
{
m_speed = speed;
}
bool Entity::getActive() const
{
return m_isActive;
}
Sprite& Entity::getSprite()
{
return m_sprite;
}
sf::Vector2f Entity::getPosition() const
{
return m_position;
}
sf::Vector2f Entity::getSpeed() const
{
return m_speed;
}
const std::vector<sf::Shape*>& Entity::getColliders() const
{
return m_colliders;
}