-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
66 lines (52 loc) · 2.13 KB
/
Copy pathmain.cpp
File metadata and controls
66 lines (52 loc) · 2.13 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
#include "engine.h"
#include "ui.h"
#include <thread>
void usePanel(const int& maxPanelHeight, const int& minPanelHeight, sf::RectangleShape& panel, sf::Clock& animationClock, bool& isMovingToUp, bool& isPanelMoving);
void closePanel(sf::RectangleShape& panel, sf::Clock& animationClock);
int main() {
sf::Clock clock;
int frameCount = 0;
UI ui;
// Окно
sf::RenderWindow window(sf::VideoMode(WIDTH * CELL_SIZE, HEIGHT * CELL_SIZE + ui.getMinPanelHeight()), "SandBox");
window.setFramerateLimit(140);
SandBoxEngine engine;
unsigned short brushSize = 2;
while (window.isOpen()) {
float frameTime = clock.restart().asSeconds();
float fps = 1.0f / frameTime;
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
}
if (event.type == sf::Event::KeyPressed) {
if (event.key.code == sf::Keyboard::Num1) brushSize = 0; // Точечная кисть
if (event.key.code == sf::Keyboard::Num2) brushSize = 5; // Средняя
if (event.key.code == sf::Keyboard::Num3) brushSize = 8; // Большая
if (event.key.code == sf::Keyboard::Num4) brushSize = 13; // Огромная
}
if (event.type == sf::Event::MouseButtonPressed) {
ui.MouseButtonPressed(engine, window);
}
}
sf::Vector2i mousePos = sf::Mouse::getPosition(window);
if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
ui.isLeftButtonPressed(engine, brushSize, mousePos);
} else if (sf::Mouse::isButtonPressed(sf::Mouse::Right)) {
ui.isRightButtonPressed(engine, brushSize, mousePos);
}
if (frameCount >= 140) {
window.setTitle("SandBox | FPS: " + std::to_string(static_cast<int>(fps)));
frameCount = 0;
}
ui.MovePanel();
frameCount++;
engine.update();
window.clear();
engine.draw(window);
ui.draw(window);
window.display();
}
return 0;
}