Код: Выделить всё
#include
#include
#include
#include
std::random_device rd;
std::mt19937 gen(rd());
std::vector circles;
std::vector colors = {
sf::Color::Red,
sf::Color::Green,
sf::Color::Blue,
sf::Color::Yellow,
sf::Color::Magenta,
sf::Color::Cyan,
};
unsigned int width;
unsigned int height;
sf::CircleShape circle(50.0f);
bool overlap_circles(const sf::CircleShape& current, const std::vector& list, const float radius);
void generate_circles();
bool check_for_space();
int main() {
SetProcessDPIAware();
width = GetSystemMetrics(SM_CXSCREEN);
height = GetSystemMetrics(SM_CYSCREEN);
sf::RenderWindow window(sf::VideoMode({width, height}), "First Game", sf::State::Fullscreen);
circle.setOrigin(circle.getGeometricCenter());
window.setVerticalSyncEnabled(true);
window.setMouseCursorGrabbed(true);
generate_circles();
sf::Clock holdTimer;
bool isHolding = false;
while (window.isOpen()) {
while (const std::optional event = window.pollEvent()) {
if (event->is()) {
window.close();
}
if (const auto* mouse_pressed = event->getIf()) {
if (mouse_pressed->button == sf::Mouse::Button::Right) {
circles.clear();
}
if (mouse_pressed->button == sf::Mouse::Button::Left) {
isHolding = true;
generate_circles();
holdTimer.restart();
}
}
if (const auto* mouse_released = event->getIf()) {
if (mouse_released->button == sf::Mouse::Button::Left) {
isHolding = false;
}
}
}
if (isHolding && holdTimer.getElapsedTime().asSeconds() >= 0.5f) {
generate_circles();
}
window.clear(sf::Color::Black);
for (const sf::CircleShape& temp : circles) window.draw(temp);
window.display();
}
return 0;
}
void generate_circles() {
std::shuffle(colors.begin(), colors.end(), gen);
for (int i = 1; i x + radius*range) continue;
if (current_y < y - radius*range || current_y > y + radius*range) continue;
return true;
}
return false;
}
< /code>
Так что это код. Проблема заключается в том, что overpap_circles Код: Выделить всё
bool check_for_space() {
sf::CircleShape circle_test = circle;
const float step = circle.getRadius()*2;
constexpr float boundaries = 25.0f;
for (float x = boundaries; x
Подробнее здесь: [url]https://stackoverflow.com/questions/79716934/how-do-i-solve-my-program-crashing-c[/url]
Мобильная версия