-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMovementComponent.cpp
More file actions
62 lines (40 loc) · 1.34 KB
/
Copy pathMovementComponent.cpp
File metadata and controls
62 lines (40 loc) · 1.34 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
#include "headers.h"
#include "MovementComponent.h"
//Constructors / Descructors
MovementComponent::MovementComponent(sf::Vector2f& direction, sf::Vector2f& velocity,
sf::Sprite& sprite, float movementSpeed, bool& isGrounded)
:m_velocity{ velocity }, m_direction{ direction }, m_sprite{ sprite }, m_isGrounded{isGrounded}
{
}
MovementComponent::~MovementComponent()
{
}
//Public functions
void MovementComponent::update(const float& timePerFrame)
{
this->updateMovement(timePerFrame);
}
void MovementComponent::updateMovement(const float& timePerFrame)
{
this->moveSprite(timePerFrame);
}
void MovementComponent::moveSprite(const float& timePerFrame)
{
m_sprite.move(m_velocity.x * timePerFrame,m_velocity.y * timePerFrame);
}
void MovementComponent::setDirectionTowardsPoint(const float& timePerFrame,const sf::Vector2f& point)
{
sf::Vector2f directionVector{
point.x - m_sprite.getPosition().x,
point.y - m_sprite.getPosition().y
};
float vectorLength{ sqrt(directionVector.x * directionVector.x + directionVector.y * directionVector.y) };
float normalizeVector{ 1 / vectorLength };
directionVector *= normalizeVector;
m_direction = directionVector;
}
Tile* MovementComponent::shortestPathFirstTile(std::vector<std::vector<Tile*>>& tileMap,
const sf::Vector2f& startPosition,const sf::Vector2f& endPosition)
{
return nullptr;
}