The following steps will show you how to finish the Gameloop and add scoring to the game code:
- Add two new variables to the source.cpp file: one of the int type, called score, and one of the bool type, called gameover. Initialize the score to 0 and gameover to true:
std::vector<Enemy*> enemies; std::vector<Rocket*> rockets; float currentTime; float prevTime = 0.0f; int score = 0; bool gameover = true;
- Create a new function called reset(). We will use this to reset the variables. Create a prototype for the reset function at the top of the source.cpp file:
bool checkCollision(sf::Sprite sprite1, sf::Sprite sprite2); void reset();
At the bottom of the source.cpp file, after where we created the checkCollision function, add the reset function itself so that when the game resets, all the values are also reset. To...