#include <Iostream>
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Lethn 2D Engine");
sf::Texture texturebackground;
if (!texturebackground.loadFromFile( "background.png" ) )
return EXIT_FAILURE;
sf::Sprite spritebackground(texturebackground);
sf::Texture player;
if ( !player.loadFromFile( "player.png" ) )
return EXIT_FAILURE;
sf::Sprite playersprite ( player );
sf::View TopDownCamera;
TopDownCamera.reset ( sf::FloatRect ( 0, 0, 800, 600 ) );
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
if ( sf::Keyboard::isKeyPressed( sf::Keyboard:: W ) )
{
playersprite.move ( 0, -20 );
}
else if ( sf::Keyboard::isKeyPressed( sf::Keyboard:: A ) )
{
playersprite.move ( -20, 0 );
}
else if ( sf::Keyboard::isKeyPressed( sf::Keyboard:: D ) )
{
playersprite.move ( 20, 0 );
}
else if ( sf::Keyboard::isKeyPressed( sf::Keyboard:: S ) )
{
playersprite.move ( 0, 20 );
}
else if ( sf::Keyboard::isKeyPressed( sf::Keyboard:: Up ) )
{
TopDownCamera.move ( 0, -10 );
}
else if ( sf::Keyboard::isKeyPressed( sf::Keyboard:: Down ))
{
TopDownCamera.move( 0, 10 );
}
else if ( sf::Keyboard::isKeyPressed( sf::Keyboard:: Left ) )
{
TopDownCamera.move ( -10, 0 );
}
else if ( sf::Keyboard::isKeyPressed( sf::Keyboard:: Right ) )
{
TopDownCamera.move ( 10, 0 );
}
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.setView( TopDownCamera );
window.draw ( spritebackground );
window.draw( playersprite );
window.display();
}
return 0;
}