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 main()
- {
- sf::RenderWindow window(sf::VideoMode(500, 500), "Self-made views");
- window.setVerticalSyncEnabled(true);
- sf::RectangleShape player(sf::Vector2f(20, 20));
- player.setFillColor(sf::Color::Magenta);
- player.setPosition(240, 240);
- sf::RectangleShape ground(sf::Vector2f(50, 50));
- ground.setFillColor(sf::Color::Green);
- sf::RectangleShape sky(sf::Vector2f(50, 50));
- sky.setFillColor(sf::Color::Blue);
- int direction = 0;
- int up = 1;
- int right = 2;
- int down = 3;
- int left = 4;
- int x_direction_view = 0;
- int y_direction_view = 0;
- int map[10][10]
- {
- {1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
- {1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
- {1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
- {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
- };
- while (window.isOpen())
- {
- sf::Event event;
- while (window.pollEvent(event))
- {
- if (event.type == sf::Event::Closed)
- window.close();
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
- direction = up;
- else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
- direction = right;
- else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
- direction = down;
- else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
- direction = left;
- else
- direction = 0;
- }
- if (direction == up)
- {
- //player.move(0, -2);
- y_direction_view += 4;
- }
- else if (direction == right)
- {
- //player.move(2, 0);
- x_direction_view -= 4;
- }
- else if (direction == down)
- {
- //player.move(0, 2);
- y_direction_view -= 4;
- }
- else if (direction == left)
- {
- //player.move(-2, 0);
- x_direction_view += 4;
- }
- else
- ;
- window.clear(sf::Color::White);
- for (int y = 0; y < 10; y++)
- {
- for (int x = 0; x < 10; x++)
- {
- if (map[y][x] == 0)
- {
- ground.setPosition(x * 50, y * 50);
- ground.move(x_direction_view, y_direction_view);
- window.draw(ground);
- }
- else if (map[y][x] == 1)
- {
- sky.setPosition(x * 50, y * 50);
- sky.move(x_direction_view, y_direction_view);
- window.draw(sky);
- }
- }
- }
- window.draw(player);
- cout << x_direction_view << endl;
- cout << y_direction_view << endl;
- window.display();
- }
- int pause; cin >> pause; //Pause the program
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement