123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
#include <SFML/Graphics.hpp>
void viewControls()
{
sf::RenderWindow window(sf::VideoMode(800, 450), "Lester");
sf::View gameView;
gameView.reset(sf::FloatRect(200, 200, 300, 200));
sf::View minimapView;
minimapView.setCenter(sf::Vector2f(350, 300));
minimapView.setSize(sf::Vector2f(200, 200));
gameView.setViewport(sf::FloatRect(0, 0, 1, 1));
minimapView.setViewport(sf::FloatRect(0.75f, 0, 0.25f, 0.25f));
}
void gametextures()
{
//Game Textures
sf::Texture grass;
sf::Texture stone;
sf::Texture flower_Yellow;
sf::Texture flower_Red;
sf::Texture sand;
//Player Textures
sf::Texture player_left;
sf::Texture player_right;
sf::Texture player_down;
sf::Texture player_up;
//Load All Textures
if (grass.loadFromFile("grass.png"))
if (stone.loadFromFile("stone.png"))
if (flower_Yellow.loadFromFile("flower_yellow.png"))
if (sand.loadFromFile("sand.png"))
//Player Load
if (player_up.loadFromFile("char_u.png"))
if (player_right.loadFromFile("char_r.png"))
if (player_left.loadFromFile("char_l.png"))
if (player_down.loadFromFile("char_d.png"))
//Set Textures to a Sprite
sf::Sprite Grass(grass);
sf::Sprite Stone(stone);
sf::Sprite FlowerY(flower_Yellow);
sf::Sprite Sand(sand);
//Set Player Sprite
sf::Sprite Player(player_up);
grass.setRepeated(true);
}
void playermovement()
{
float playerSpeed = 2.0f;
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
Player.setTexture(player_left);
Player.move(playerSpeed - 0.1, 0);
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
Player.setTexture(player_right);
Player.move(playerSpeed + 0.1, 0);
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
Player.setTexture(player_up);
Player.move(0, playerSpeed - 0.1);
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
Player.setTexture(player_down);
Player.move(0, playerSpeed + 0.1);
}
}
int main()
{
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
viewControls();
gametexutres();
playermovment();
window.clear(sf::Color::Black);
window.draw(Player);
window.display();
}
return 0;
}