je vais mettre le code en entier :
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <string>
#include <iostream>
#include <cstdlib>
#include "Header.h"
using namespace std;
/*sf::Window window;*/
sf::RenderWindow window;
sf::Music musique;
sf::RectangleShape rect;
int speed=2;
void gestion_clavier();
int main()
{
//creation de la fenetre 800x600
window.create(sf::VideoMode (800,600),"jeu video");
cout<<"lancement du jeu"<<endl;
window.setFramerateLimit(60);
rect=Rect(10,10,30,30);
//modifier la position
window.setPosition(sf::Vector2i(192,0));
/*window.setSize(sf::Vector2u(200,100));*/
//tant que la fenetre est ouverte
while (window.isOpen())
{
sf::Event event;
//test de evenements
while(window.pollEvent(event))
{
//si on clique pour fermer
if(event.type==sf::Event::Closed)
window.close();//on ferme la fenetre
}
if (!musique.openFromFile("aseri.ogg"))
{
cout<<"musique non chargé"<<endl;
}// erreur
musique.play();
//window.draw(cercle);//
// window.draw(rect);//
window.display();
//sert a effacer le deplacement
window.clear();
}
return 0;
}
plus le header
sf::RectangleShape Rect(int posX,int posY,int witdh,int height)
{
//on creer le rectangle
sf::RectangleShape rect(sf::Vector2f(witdh, height));
rect.setFillColor(sf::Color(100,200,255));
rect.setPosition(posX,posY);
return rect;
}
void gestion_clavier(){
//gestion du clavier
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
rect.move(0,-speed);
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
rect.move(0,speed);
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
rect.move(-speed,0);
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
rect.move(speed,0);
}
}