#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
int main()
{
// Create the main window
sf::RenderWindow window(sf::VideoMode(800, 600), "MTGame");
// Load a sprite to display
sf::Texture texture;
if (!texture.loadFromFile("./data/test.jpg"))
return EXIT_FAILURE;
sf::Sprite sprite(texture);
// Load a music to play
sf::Music music;
if (!music.openFromFile("./data/background.wav"))
return EXIT_FAILURE;
// Play the music
music.play();
// Start the game loop
while (window.isOpen())
{
// Process events
sf::Event event;
while (window.pollEvent(event))
{
// Close window -> exit
if (event.type == sf::Event::Closed)
window.close();
}
//Move-Loop
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
sprite.move(-1, 0);
} else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
sprite.move(1, 0);
} else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
sprite.move(0, 1);
} else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
sprite.move(0, -1);
}
//End-Loop
// Clear screen
window.clear();
// Draw the sprite
window.draw(sprite);
// Update the window
window.display();
}
return EXIT_SUCCESS;
}