int main()
{
sf::RenderWindow window(sf::VideoMode(600, 600), "SFML works!");
sf::Texture texture;
if(!texture.loadFromFile("barbare.png", sf::IntRect(0,0,64,64)))
{
std::cout << "erreur" << std::endl;
window.close();
}
sf::Sprite perso;
perso.setTexture(texture);
sf::Vector2f position(0,0);
sf::RectangleShape mur;
mur.setSize(sf::Vector2f(64,64));
mur.setPosition(300,300);
mur.setFillColor(sf::Color::Red);
while(window.isOpen())
{
sf::Vector2f mouvement(0,0);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
mouvement.y -= 0.1;
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
mouvement.y += 0.1;
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
mouvement.x += 0.1;
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
mouvement.x -= 0.1;
sf::FloatRect virtalSprite(perso.getPosition().x + mouvement.x,
perso.getPosition().y + mouvement.y,
perso.getGlobalBounds().height,
perso.getGlobalBounds().width);
if(!virtalSprite.intersects(mur.getGlobalBounds()))
perso.move(mouvement);
else
std::cout << "collision" << std::endl;
window.clear(sf::Color::Black);
window.draw(mur);
window.draw(perso);
window.display();
}
return 0;
}