Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <SFML/Graphics.hpp>
- using namespace std;
- int width = 800;
- int height = 600;
- int main()
- {
- int map[5][5] =
- {
- {1, 1, 1, 1, 1},
- {1, 0, 0, 0, 1},
- {1, 0, 1, 1, 1},
- {1, 0, 0, 0, 1},
- {1, 1, 1, 1, 1}
- };
- sf::RenderWindow window(sf::VideoMode(width, height), "In Progress");
- window.setVerticalSyncEnabled(true);
- window.setFramerateLimit(10);
- sf::RectangleShape player(sf::Vector2f(50, 50));
- player.setPosition(0, 0);
- player.setFillColor(sf::Color::Magenta);
- sf::RectangleShape object(sf::Vector2f(50, 50));
- object.setPosition(0, 0);
- object.setFillColor(sf::Color::Black);
- sf::Event event;
- while (window.isOpen())
- {
- while (window.pollEvent(event))
- {
- if (event.type == sf::Event::Closed)
- {
- window.close();
- }
- else if (event.type == sf::Event::KeyPressed)
- {
- if (event.key.code == sf::Keyboard::W)
- {
- player.move(0, -5);
- }
- else if (event.key.code == sf::Keyboard::A)
- {
- player.move(-5, 0);
- }
- else if (event.key.code == sf::Keyboard::S)
- {
- player.move(0, 5);
- }
- else if (event.key.code == sf::Keyboard::D)
- {
- player.move(5, 0);
- }
- }
- }
- //Handle other things
- window.clear(sf::Color::White); //Clear
- //Here we draw everything
- for (int mapY = 0; mapY < 5; mapY++)
- {
- for (int mapX = 0; mapX < 5; mapX++)
- {
- if (map[mapY][mapX] == 1)
- {
- object.setPosition(mapX * 50, mapY * 50);
- window.draw(object);
- }
- }
- }
- window.display(); //Display
- }
- int pause; cin >> pause;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement