Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- #include <bits/stdc++.h>
- using namespace sf;
- using namespace std;
- int main(){
- RenderWindow renderWindow(sf::VideoMode(800, 500), "SFML works!");
- Event event;
- Color color(Color::White);
- srand(time(NULL));
- Font font;
- if(!font.loadFromFile("fonts/try.otf")){
- cout<<"not found"<<endl;
- return 0;
- }
- Text text;
- text.setFont(font);
- text.setString("Dead Nine!");
- text.setCharacterSize(48);
- Texture texture;
- text.setColor(Color::Black);
- if(!texture.loadFromFile("tmp/try.gif")){
- cout<<"not found"<<endl;
- return 0;
- }
- Sprite s;
- s.setTexture(texture);
- s.setPosition(300,120);
- s.setScale(1.5,1.5);
- srand(time(NULL));
- while(renderWindow.isOpen()){
- while(renderWindow.pollEvent(event)){
- if(event.type == Event::Closed) renderWindow.close();
- if(Keyboard::isKeyPressed(Keyboard::Up)){
- s.move(0,-3);
- }
- if(Keyboard::isKeyPressed(Keyboard::Right)){
- s.move(3,0);
- }
- if(Keyboard::isKeyPressed(Keyboard::Down)){
- s.move(0,3);
- }
- if(Keyboard::isKeyPressed(Keyboard::Left)){
- s.move(-3,0);
- }
- if(Keyboard::isKeyPressed(Keyboard::W)){
- s.rotate(3);
- }
- if(Keyboard::isKeyPressed(Keyboard::S)){
- s.rotate(-3);
- }
- if(Keyboard::isKeyPressed(Keyboard::Num1)){
- text.setFillColor(Color(rand()%255,rand()%255,rand()%255));
- }
- if(Keyboard::isKeyPressed(Keyboard::Num2)){
- color = Color(rand()%255,rand()%255,rand()%255);
- }
- }
- renderWindow.clear(color);
- renderWindow.draw(s);
- renderWindow.draw(text);
- renderWindow.display();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement