Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- #include <conio.h>
- #include <string>
- #include <iostream>
- using namespace sf;
- using namespace std;
- int main()
- {
- string s="SFML works!";
- RenderWindow window(VideoMode(520, 520), s);
- RectangleShape player(Vector2f(100.0f,100.0f));
- player.setFillColor(Color::Red);
- while (window.isOpen())
- {
- Event ev1;
- while (window.pollEvent(ev1))
- {
- switch (ev1.type) {
- case Event::Closed:
- window.close();break;
- case Event::Resized:
- cout<<ev1.size.width<<endl<<ev1.size.height<<endl;break;
- case Event::TextEntered:
- if (ev1.text.unicode<128)
- cout<<ev1.text.unicode;
- }
- }
- if (Keyboard::isKeyPressed(Keyboard::Key::A))
- player.move(-0.1f,0.0f);
- else
- if (Keyboard::isKeyPressed(Keyboard::Key::D))
- player.move(0.1f,0.0f);
- else
- if (Keyboard::isKeyPressed(Keyboard::Key::W))
- player.move(0.0f,-0.1f);
- else
- if (Keyboard::isKeyPressed(Keyboard::Key::S))
- player.move(0.0f,0.1f);
- window.draw(player);
- window.display();
- window.clear();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement