-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.h
More file actions
28 lines (26 loc) · 973 Bytes
/
helper.h
File metadata and controls
28 lines (26 loc) · 973 Bytes
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
#pragma once
#include <SFML/Graphics.hpp>
#include<vector>
using namespace std;
// get random unoccupied position for the no button
sf::Vector2f getRandomUnoccupiedPosition(int width, int height, sf::Vector2f buttonSize,
vector<sf::FloatRect>& occupiedAreas) {
sf::Vector2f newPos;
bool validPos = false;
while (!validPos) {
float x = static_cast<float>(rand() % (width - static_cast<int>(buttonSize.x)));
float y = static_cast<float>(rand() % (height - static_cast<int>(buttonSize.y)));
sf::FloatRect newRect(x, y, buttonSize.x, buttonSize.y);
validPos = true;
for (int i = 0; i < occupiedAreas.size(); i++) {
if (newRect.intersects(occupiedAreas[i])) {
validPos = false;
break;
}
}
if (validPos) {
newPos = sf::Vector2f(x, y);
}
}
return newPos;
}