Advertisement
Guest User

main.cpp

a guest
Apr 26th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <SFML\Graphics.hpp>
  2. #include "CRed.h"
  3. #include "CBlue.h"
  4.  
  5. int main()
  6. {
  7.     //ustawienie okna
  8.     sf::RenderWindow window({ 1366, 720 }, "Bumper Cars", sf::Style::Fullscreen);
  9.     window.setFramerateLimit(60);
  10.  
  11.     //pobranie tekstur z pliku
  12.     sf::Texture texture1;
  13.     texture1.loadFromFile("B_plansza.bmp");
  14.     sf::Sprite map1;
  15.     map1.setTexture(texture1);
  16.  
  17.     sf::Texture texture2;
  18.     texture2.loadFromFile("B_car_red.png");
  19.     CRed red1;
  20.     red1.setTexture(texture2);
  21.  
  22.     sf::Texture texture3;
  23.     texture3.loadFromFile("B_car_blue.png");
  24.     CBlue blue1;
  25.     blue1.setTexture(texture3);
  26.  
  27.     //ustawienie pozycji tekstur
  28.     map1.setPosition(0, 0);
  29.     red1.setPosition(300, 500);
  30.     blue1.setPosition(800, 200);
  31.  
  32.     //główna pętla
  33.     while (window.isOpen())
  34.     {
  35.         sf::Event event;
  36.         while (window.pollEvent(event))
  37.         {
  38.             if (event.type == sf::Event::Closed)
  39.                 window.close();
  40.             if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
  41.                 window.close();
  42.  
  43.         }
  44.  
  45.         red1.move_left(red1.velocity, red1.acceleration, red1, blue1, map1);
  46.         red1.move_right(red1.velocity, red1.acceleration, red1, blue1, map1);
  47.         red1.move_up(red1.velocity, red1.acceleration, red1, blue1, map1);
  48.         red1.move_down(red1.velocity, red1.acceleration, red1, blue1, map1);
  49.  
  50.         window.clear();
  51.         window.draw(map1);
  52.         window.draw(red1);
  53.         window.draw(blue1);
  54.         window.display();
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement