-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTile.cpp
More file actions
120 lines (92 loc) · 2.14 KB
/
Tile.cpp
File metadata and controls
120 lines (92 loc) · 2.14 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "stdafx.h"
#include "Tile.h"
//Constructors and Destructor:
Tile::Tile()
{
this->type = 0;
this->collision = false;
this->captured = false;
this->showCaptured = false;
this->available = false;
this->showAvailable = false;
}
Tile::Tile
(
int type,
int grid_x, int grid_y, float grid_size_f,
const sf::Texture& texture, const sf::IntRect& texture_rect,
const bool collision
)
{
this->type = type;
this->collision = collision;
this->captured = false;
this->showCaptured = false;
this->available = false;
this->showAvailable = false;
this->shape.setPosition(static_cast<float>(grid_x) * grid_size_f, static_cast<float>(grid_y) * grid_size_f);
this->shape.setTexture(texture);
this->shape.setTextureRect(texture_rect);
}
Tile::~Tile()
{
}
// Accessors:
const bool& Tile::isAvailable() const
{
return this->available;
}
const bool& Tile::isCaptured() const
{
return this->captured;
}
const int& Tile::getType() const
{
return this->type;
}
const bool& Tile::getCollision() const
{
return this->collision;
}
const sf::Vector2f Tile::getPosition() const
{
return this->shape.getPosition();
}
const sf::Vector2f Tile::getCenter() const
{
return sf::Vector2f
(
this->shape.getPosition().x + this->shape.getGlobalBounds().width / 2.f,
this->shape.getPosition().y + this->shape.getGlobalBounds().height / 2.f
);
}
const sf::FloatRect Tile::getGlobalBounds() const
{
return this->shape.getGlobalBounds();
}
const float Tile::getDistance(const Entity* entity) const
{
return static_cast<float>(std::sqrt(std::pow((this->getCenter().x - entity->getCenter().x), 2) + std::pow((this->getCenter().y - entity->getCenter().y), 2)));
}
// Modifires:
void Tile::setCaptured(const bool captured)
{
this->captured = captured;
}
void Tile::setShowCaptured(const bool show_captured)
{
this->showCaptured = show_captured;
}
void Tile::setAvailable(const bool available)
{
this->available = available;
}
void Tile::setShowAvailable(const bool show_availability)
{
this->showAvailable = show_availability;
}
// Functions:
const bool Tile::intersects(const sf::FloatRect bounds) const
{
return this->shape.getGlobalBounds().intersects(bounds);
}