-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntity.cpp
More file actions
103 lines (87 loc) · 2.02 KB
/
Copy pathEntity.cpp
File metadata and controls
103 lines (87 loc) · 2.02 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "Entity.h"
const Vector2f &Entity::getpos() const
{
return this->sprite.getPosition();
}
const FloatRect Entity::getbounds() const
{
return this->sprite.getGlobalBounds();
}
void Entity::setpos(const float x, const float y)
{
this->sprite.setPosition(x,y);
}
void Entity::updateWindowBoundColision(RenderTarget* target)
{
//Left
if (this->getbounds().left < 0.f)
{
this->setpos(0.f, this->getbounds().top);
}
//Right
else if (this->getbounds().left + this->getbounds().width > target->getSize().x)
{
this->setpos(target->getSize().x - this->getbounds().width, this->getbounds().top);
}
//Top
if (this->getbounds().top < 0.f)
{
this->setpos(this->getbounds().left, 0.f);
}
//Bottom
else if (this->getbounds().top + this->getbounds().height > target->getSize().y)
{
this->setpos(this->getbounds().left, target->getSize().y - this->getbounds().height);
}
}
void Entity::movement(const float& dt, float dir_x, float dir_y)
{
this->movementcomponent->move(dir_x, dir_y, dt);
this->sprite.setTextureRect(this->animation->uvRect);
}
void Entity::updateAnimation(const float& dt,int row)
{
if(this->animation)
{
this->animation->update(dt,row);
}
}
void Entity::update(const float& dt)
{
if (this->movementcomponent)
{
this->movementcomponent->update(dt);
}
}
void Entity::render(RenderTarget& target)
{
target.draw(this->sprite);
}
void Entity::initvariables()
{
this->animation = nullptr;
this->texture = nullptr;
this->points = 0;
}
Entity::Entity()
{
this->initvariables();
}
Entity::~Entity()
{
delete this->animation;
delete this->movementcomponent;
}
void Entity::setTexture(Texture& texture)
{
this->animation = new Animation(&texture, Vector2u(4, 4), 0.2f);
this->texture = &texture;
this->sprite.setTexture(texture);
this->sprite.scale(0.15f, 0.15f);
this->sprite.setPosition(0.f, 0.f);
this->sprite.setTextureRect(IntRect(0, 0, 480, 270));
}
void Entity::createMovementComponent(const float maxVelocity)
{
this->movementcomponent = new MovementComponent(this->sprite, maxVelocity);
}