Using the Bat class and coding the main function
Switch to the main.cpp
file that was automatically generated when we created the project. If you had a file called Pong.cpp
automatically created, you can leave it as it is or right-click it in the Solution Explorer to rename it main.cpp
. The only thing that matters is that it has the main
function in it so that is where execution will begin. Delete all its auto-generated code and add the code that follows.
Code the Pong.cpp
file as follows:
#include "Bat.h"
#include <sstream>
#include <cstdlib>
#include <SFML/Graphics.hpp>
int main()
{
// Create a video mode object
VideoMode vm(1920, 1080);
// Create and open a window for the game
RenderWindow window(vm, "Pong", Style::Fullscreen);
int score = 0;
int lives = 3;
// Create a bat at the bottom center of the screen
Bat bat(1920 / 2, 1080 - 20);
// We will add a ball in the next chapter
// Create a...