-
Notifications
You must be signed in to change notification settings - Fork 0
/
NodeShape.cpp
86 lines (75 loc) · 2.14 KB
/
NodeShape.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
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
#include "NodeShape.h"
NodeShape::NodeShape()
{
mTextureManager.load("walkableSquare", "img/walkableSquare.png");
mTextureManager.load("obstacleSquare", "img/obstacleSquare.png");
mTextureManager.load("startSquare", "img/startSquare.png");
mTextureManager.load("endSquare", "img/endSquare.png");
mTextureManager.load("pathSquare", "img/pathSquare.png");
mNodeState = walkable;
mShape.setTexture(mTextureManager.get("walkableSquare"));
mPosition = sf::Vector2f(0.0f, 0.0f);
mShape.setPosition(mPosition);
}
void NodeShape::draw(sf::RenderWindow& window)
{
window.draw(mShape);
}
void NodeShape::captureMouseClick(sf::RenderWindow& window, int selectType)
{
/*selectType values
0 = walkable, 1 = osbtacle, 2 = start, 3 = end*/
if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
sf::Vector2f mouse = window.mapPixelToCoords(sf::Mouse::getPosition(window));
sf::FloatRect bounds = mShape.getGlobalBounds();
if (bounds.contains(mouse))
{
if (selectType == 0)
{
mShape.setTexture(mTextureManager.get("walkableSquare"));
mNodeState = walkable;
}
else if (selectType == 1)
{
mShape.setTexture(mTextureManager.get("obstacleSquare"));
mNodeState = obstacle;
}
else if (selectType == 2)
{
mShape.setTexture(mTextureManager.get("startSquare"));
mNodeState = start;
}
else if (selectType == 3)
{
mShape.setTexture(mTextureManager.get("endSquare"));
mNodeState = end;
}
}
}
}
void NodeShape::setPosition(sf::Vector2f position)
{
mPosition = position;
mShape.setPosition(mPosition);
}
sf::FloatRect NodeShape::getGlobalBounds()
{
return mShape.getGlobalBounds();
}
void NodeShape::setTexture(std::string texture)
{
mShape.setTexture(mTextureManager.get(texture));
if (texture == "walkableSquare")
mNodeState = walkable;
else if (texture == "obstacleSquare")
mNodeState = obstacle;
else if (texture == "startSquare")
mNodeState = start;
else if (texture == "endSquare")
mNodeState = end;
}
sf::Vector2f NodeShape::getPosition()
{
return mShape.getPosition();
}