Advertisement
Felanpro

something random I just found

Aug 24th, 2019
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.53 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <SFML/Graphics.hpp>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     sf::RenderWindow window(sf::VideoMode(500, 500), "Self-made views");
  10.     window.setVerticalSyncEnabled(true);
  11.  
  12.     sf::RectangleShape player(sf::Vector2f(20, 20));
  13.     player.setFillColor(sf::Color::Magenta);
  14.     player.setPosition(240, 240);
  15.  
  16.     sf::RectangleShape ground(sf::Vector2f(50, 50));
  17.     ground.setFillColor(sf::Color::Green);
  18.  
  19.     sf::RectangleShape sky(sf::Vector2f(50, 50));
  20.     sky.setFillColor(sf::Color::Blue);
  21.  
  22.     int direction = 0;
  23.     int up = 1;
  24.     int right = 2;
  25.     int down = 3;
  26.     int left = 4;
  27.     int x_direction_view = 0;
  28.     int y_direction_view = 0;
  29.  
  30.     int map[10][10]
  31.     {
  32.         {1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  33.         {1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  34.         {1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  35.         {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  36.         {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  37.         {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  38.         {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  39.         {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  40.         {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  41.         {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  42.     };
  43.  
  44.     while (window.isOpen())
  45.     {
  46.         sf::Event event;
  47.         while (window.pollEvent(event))
  48.         {
  49.             if (event.type == sf::Event::Closed)
  50.                 window.close();
  51.  
  52.             if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
  53.                 direction = up;
  54.             else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
  55.                 direction = right;
  56.             else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
  57.                 direction = down;
  58.             else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
  59.                 direction = left;
  60.             else
  61.                 direction = 0;
  62.         }
  63.  
  64.         if (direction == up)
  65.         {
  66.             //player.move(0, -2);
  67.             y_direction_view += 4;
  68.         }
  69.         else if (direction == right)
  70.         {
  71.             //player.move(2, 0);
  72.             x_direction_view -= 4;
  73.         }
  74.         else if (direction == down)
  75.         {
  76.             //player.move(0, 2);
  77.             y_direction_view -= 4;
  78.         }
  79.         else if (direction == left)
  80.         {
  81.             //player.move(-2, 0);
  82.             x_direction_view += 4;
  83.         }
  84.         else
  85.             ;
  86.  
  87.  
  88.         window.clear(sf::Color::White);
  89.  
  90.         for (int y = 0; y < 10; y++)
  91.         {
  92.             for (int x = 0; x < 10; x++)
  93.             {
  94.                 if (map[y][x] == 0)
  95.                 {
  96.                     ground.setPosition(x * 50, y * 50);
  97.                     ground.move(x_direction_view, y_direction_view);
  98.                     window.draw(ground);
  99.                 }
  100.                 else if (map[y][x] == 1)
  101.                 {
  102.                     sky.setPosition(x * 50, y * 50);
  103.                     sky.move(x_direction_view, y_direction_view);
  104.                     window.draw(sky);
  105.                 }
  106.             }
  107.         }
  108.  
  109.         window.draw(player);
  110.  
  111.         cout << x_direction_view << endl;
  112.         cout << y_direction_view << endl;
  113.         window.display();
  114.     }
  115.  
  116.     int pause; cin >> pause; //Pause the program
  117.     return 0;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement