-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrackPrototypeTester.cpp
96 lines (77 loc) · 2.85 KB
/
TrackPrototypeTester.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
87
88
89
90
91
92
93
94
95
96
#include <SFML/Graphics.hpp>
#include "Position.h"
#include "Squircle.h"
#include "Fonts.h"
#include "MouseEvents.h"
#include <iostream>
#include "Clock.h"
int main()
{
srand(time(0));
sf::Vector2u windowSize({2000,1125});
sf::RenderWindow window({windowSize.x,windowSize.y}, "SFML Tutorial");
window.setFramerateLimit(60);
Clock clock;
sf::Text timer;
timer.setFont(Fonts::getFont(OPEN_SANS));
timer.setPosition(20,20);
timer.setCharacterSize(50);
// clock.start();
Squircle seek({10, 100},5);
Squircle track({1000,120},10);
Squircle button({100,100}, 20);
std::vector<Squircle> nodes;
button.setPosition(500,500);
track.setFillColor({36,41,46});
track.setPosition(100,100);
Position::center(seek,track);
Position::alignLeft(seek,track);
float seconds = 10;
float velocity = track.getSize().x/(seconds);
bool draw = false;
while(window.isOpen()){
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::P)
clock.toggle();
else if (event.key.code == sf::Keyboard::Right)
clock.forward(1);
else if (event.key.code == sf::Keyboard::Left)
clock.rewind(1);
}
else if (!draw && MouseEvents::isClick(button.getGlobalBounds(), window)) {
button.setFillColor(sf::Color::Red);
nodes.emplace_back();
nodes.back().setSize(10, 100);
nodes.back().setRadius(1);
nodes.back().setFillColor(sf::Color((int)(rand() % 255 + 1) ,(int)(rand() % 255 + 1),(int)(rand() % 255 + 1)));
Position::center(nodes.back(), seek);
draw = true;
} else if (draw && !MouseEvents::isClick(button.getGlobalBounds(),window)){
draw = false;
button.setFillColor(sf::Color::White);
}
}
if (draw && !nodes.empty()){
nodes.back().setSize(sf::Vector2f((float) seek.getPosition().x - nodes.back().getPosition().x,
nodes.back().getSize().y));
}
timer.setString(std::to_string(clock.getElapsedTimeAsSeconds()));
seek.setPosition(track.getPosition().x + (velocity * clock.getElapsedTimeAsSeconds()), seek.getPosition().y);
if (seek.getPosition().x >= track.getPosition().x + track.getSize().x)
clock.stop();
window.clear();
window.draw(button);
window.draw(timer);
window.draw(track);
for (auto &b : nodes) {
window.draw(b);
}
window.draw(seek);
window.display();
}
return 0;
}