-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
47 lines (34 loc) · 1020 Bytes
/
main.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
#include <SFML/Graphics.hpp>
int main() {
sf::RenderWindow window(sf::VideoMode(640, 540),
"SFML works!", sf::Style::Default);
//Circle
sf::CircleShape circle(50.0f);
circle.setFillColor(sf::Color::Green);
//Rectangle
sf::RectangleShape rectangle(sf::Vector2f(100, 50));
rectangle.setPosition(30,30);
rectangle.setFillColor(sf::Color::Cyan);
float speed = 5.0f;
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();
}
// Keyboard Input
if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
circle.move(0, -speed);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
circle.move(0, speed);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
circle.move(-speed, 0);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
circle.move(speed, 0);
window.clear();
window.draw(circle);
window.draw(rectangle);
window.display();
}
return 0;
}