Hello !
I'd like to design a little game in which, a little ship (a Triangle) would move on the screen.
The problem is that I'd like to make the ship rotate when multiple keys are pressed (see below).
But the compiler refuses :
make all (in directory: /home//Desktop/C++)
g++ -c main.cpp Game.cpp Ship.cpp
Game.cpp: In member function ‘void Game::run()’:
Game.cpp:56:6: error: duplicate case value
case((sf::Keyboard::Down) && (sf::Keyboard::Right)):
^~~~
Game.cpp:53:6: note: previously used here
case((sf::Keyboard::Up) && (sf::Keyboard::Left)):
^~~~
Makefile:8: recipe for target 'all' failed
make: *** [all] Error 1
Compilation failed.
void Game::run()
{
window.create(sf::VideoMode(800,600), "Test", sf::Style::Default);
window.setVerticalSyncEnabled(true);
std::unique_ptr<Ship> player = std::make_unique<Ship>(10,10,40);
while(window.isOpen() == true)
{
sf::Event ev;
while(window.pollEvent(ev) == true)
{
if(ev.type == sf::Event::Closed)
{
window.close();
}
if(ev.type == sf::Event::KeyPressed)
{
switch(ev.key.code)
{
case(sf::Keyboard::Escape):
window.close();
break;
case(sf::Keyboard::Up):
player->move_y(-10);
break;
case(sf::Keyboard::Down):
player->move_y(10);
break;
case(sf::Keyboard::Left):
player->move_x(-10);
break;
case(sf::Keyboard::Right):
player->move_x(10);
break;
case((sf::Keyboard::Up) && (sf::Keyboard::Left)):
player->rotate(10);
break;
case((sf::Keyboard::Down) && (sf::Keyboard::Right)):
player->rotate(-10);
break;
default:
break;
}
}
}
window.clear(sf::Color::Black);
player->drawOn(&window);
window.display();
}
}
Regards