Advertisement
Felanpro

cool way to print maps

Apr 22nd, 2019
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <SFML/Graphics.hpp>
  4.  
  5. using namespace std;
  6.  
  7. int width = 800;
  8. int height = 600;
  9.  
  10. int main()
  11. {
  12.     int map[5][5] =
  13.     {
  14.         {1, 1, 1, 1, 1},
  15.         {1, 0, 0, 0, 1},
  16.         {1, 0, 1, 1, 1},
  17.         {1, 0, 0, 0, 1},
  18.         {1, 1, 1, 1, 1}
  19.     };
  20.  
  21.     sf::RenderWindow window(sf::VideoMode(width, height), "In Progress");
  22.     window.setVerticalSyncEnabled(true);
  23.     window.setFramerateLimit(10);
  24.  
  25.     sf::RectangleShape player(sf::Vector2f(50, 50));
  26.     player.setPosition(0, 0);
  27.     player.setFillColor(sf::Color::Magenta);
  28.  
  29.     sf::RectangleShape object(sf::Vector2f(50, 50));
  30.     object.setPosition(0, 0);
  31.     object.setFillColor(sf::Color::Black);
  32.  
  33.     sf::Event event;
  34.     while (window.isOpen())
  35.     {
  36.         while (window.pollEvent(event))
  37.         {
  38.             if (event.type == sf::Event::Closed)
  39.             {
  40.                 window.close();
  41.             }
  42.             else if (event.type == sf::Event::KeyPressed)
  43.             {
  44.                 if (event.key.code == sf::Keyboard::W)
  45.                 {
  46.                     player.move(0, -5);
  47.                 }
  48.                 else if (event.key.code == sf::Keyboard::A)
  49.                 {
  50.                     player.move(-5, 0);
  51.                 }
  52.                 else if (event.key.code == sf::Keyboard::S)
  53.                 {
  54.                     player.move(0, 5);
  55.                 }
  56.                 else if (event.key.code == sf::Keyboard::D)
  57.                 {
  58.                     player.move(5, 0);
  59.                 }
  60.             }
  61.         }
  62.  
  63.         //Handle other things
  64.  
  65.         window.clear(sf::Color::White); //Clear
  66.  
  67.         //Here we draw everything
  68.         for (int mapY = 0; mapY < 5; mapY++)
  69.         {
  70.             for (int mapX = 0; mapX < 5; mapX++)
  71.             {
  72.                 if (map[mapY][mapX] == 1)
  73.                 {
  74.                     object.setPosition(mapX * 50, mapY * 50);
  75.                     window.draw(object);
  76.                 }
  77.             }
  78.         }
  79.  
  80.         window.display(); //Display
  81.     }
  82.  
  83.     int pause; cin >> pause;
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement