-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDot.cpp
More file actions
97 lines (89 loc) · 2.61 KB
/
Dot.cpp
File metadata and controls
97 lines (89 loc) · 2.61 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
#include "Dot.h"
Dot::Dot(float _x, float _y) : x(_x), y(_y) {
circle.setRadius(10);
circle.setPointCount(30);
circle.setPosition(_x, _y);
circle.setOrigin(10, 10);
circle.setFillColor(Color::White);
circle.setOutlineThickness(3);
circle.setOutlineColor(Color::Black);
hitbox.setSize(Vector2f(20, 20));
hitbox.setOrigin(10, 10);
hitbox.setPosition(_x, _y);
selection = noOne;
}
Dot::~Dot() {}
void Dot::checkHover(RenderWindow& window) {
if (selection == noOne) {
Vector2i mousePos = Mouse::getPosition(window);
if (mousePos.x > hitbox.getPosition().x - hitbox.getSize().x / 2 && mousePos.x < hitbox.getPosition().x + hitbox.getSize().x / 2
&&
mousePos.y > hitbox.getPosition().y - hitbox.getSize().y / 2 && mousePos.y < hitbox.getPosition().y + hitbox.getSize().y / 2)
{
circle.setRadius(14);
circle.setOrigin(14, 14);
hitbox.setSize(Vector2f(28, 28));
}
else {
circle.setRadius(10);
circle.setOrigin(10, 10);
}
}
}
bool Dot::checkClick(RenderWindow& window, int playerNum, bool& lockClick)
{
Vector2i mousePos = Mouse::getPosition(window);
if (Mouse::isButtonPressed(Mouse::Left) && !lockClick &&
mousePos.x > hitbox.getPosition().x - hitbox.getSize().x / 2 && mousePos.x < hitbox.getPosition().x + hitbox.getSize().x / 2 &&
mousePos.y > hitbox.getPosition().y - hitbox.getSize().y / 2 && mousePos.y < hitbox.getPosition().y + hitbox.getSize().y / 2)
{
if (selection == noOne) {
circle.setRadius(14);
circle.setOrigin(14, 14);
hitbox.setSize(Vector2f(28, 28));
if (playerNum == 1) {
selection = player1;
circle.setOutlineColor(Color::Red);
}
else {
selection = player2;
circle.setOutlineColor(Color::Blue);
}
}
else {
selection = noOne;
circle.setRadius(10);
circle.setOrigin(10, 10);
hitbox.setSize(Vector2f(20, 20));
circle.setOutlineColor(Color::Black);
}
lockClick = true;
return true;
}
return false;
}
void Dot::setSelection(int selector)
{
if (!(selector == 0 && selection == noOne || selector == 1 && selection == player1 || selector == 2 && selection == player2)) {
if (selector == 0) {
selection = noOne;
circle.setRadius(10);
circle.setOrigin(10, 10);
hitbox.setSize(Vector2f(20, 20));
circle.setOutlineColor(Color::Black);
}
else {
circle.setRadius(14);
circle.setOrigin(14, 14);
hitbox.setSize(Vector2f(28, 28));
if (selector == 1) {
selection = player1;
circle.setOutlineColor(Color::Red);
}
else {
selection = player2;
circle.setOutlineColor(Color::Blue);
}
}
}
}