-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisionComponent.cpp
58 lines (41 loc) · 1.15 KB
/
VisionComponent.cpp
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
#include "stdafx.h"
#include "VisionComponent.h"
// Constructors and Destructor:
VisionComponent::VisionComponent(sf::Vector2f position, const float range, sf::Vector2f direction)
{
this->area = new Area(position, range, sf::Color::Red);
this->range = range;
this->direction = direction;
}
VisionComponent::~VisionComponent()
{
// Deleting area
delete this->area;
}
// Accessors:
const float& VisionComponent::getRange() const
{
return this->area->getRadius();
}
const sf::Vector2f& VisionComponent::getDirection() const
{
return this->direction;
}
// Functions:
void VisionComponent::update(sf::Vector2f position, sf::Vector2f direction, const float& dt)
{
this->area->update(position, dt);
this->direction = direction;
// sf::Vector2f direction_norm = direction / static_cast<float>(std::sqrt(std::pow(direction.x, 2) + (direction.y, 2)));
//
// this->direction = direction_norm * this->range;
}
void VisionComponent::update(sf::Vector2i position, sf::Vector2f direction, const float& dt)
{
this->area->update(position, dt);
this->direction = direction;
}
void VisionComponent::render(sf::RenderTarget& target)
{
this->area->render(target);
}