Zum Hauptinhalt springen

Description

Coong was the first game that I wrote from scratch only in C++ and without the help of a game engine. 

The name Coong is a combination of the words "Pong" and "Coop". Coong is a spin-off of the old "Pong" classic and offers the possibility to play together with a friend against the computer.

Player 1 has only the upper half to cover with his paddle and player 2 only the lower half. The tricky part is that the paddles can disappear at irregular intervals and the players have to remember the location of their paddles. On top of that, the ball speeds up every time it hits the paddle. Once the players or the computer reach four points, the game is over and ends automatically.

Gameplay

Controls

Button   Movement
W   Player 1 Movement UP
S   Player 1 Movement DOWN
O   Player 2 Movement UP
L   Player 2 Movement DOWN

UML Chart

This UML chart visualizes the dependencies of the individual classes and structures.

Figure 1

Check Collision

Since Coong does not run in a game engine and therefore there are no automated colliders, the collision has to be calculated by yourself. Fortunately, there is a library called "Simple DirectMedia Layer", which creates rectangles. In Figure 2 you can see the function that returns a boolean if a point of one rectangle touches or overlaps the other.

Figure 2

To make the function understandable, I have shown in Figure 3 a visual representation of the two rectangles, which can be for example the player's paddle (R1) and the ball (R2). The function checks if one of the four points (circled in red) touches or overlaps with the paddle.

Figure 3

As mentioned before, this function calculates if there is a collision between the ball and the player's paddle. This function can then update the speed of the ball by calculating the position between the player's paddle and the ball (Figure 4). However, since there are problems if the ball moves too fast I have defined a maximum value for the speed in the function.

Figure 4
  • What I have learned
      • Since it was my first project in C++, I was able to learn a lot in the programming language.

      • Memory managements is particularly important in C++. Unlike C#, you have to be careful not to program memory leaks.

      • How SDL (Simple DirectMedia Layer) is implemented and used in a project.

       

    • Since it was my first project in C++, I was able to learn a lot in the programming language.

    • Memory managements is particularly important in C++. Unlike C#, you have to be careful not to program memory leaks.

    • How SDL (Simple DirectMedia Layer) is implemented and used in a project.

     

Repository & Build

Link to the repository: ​https://christian-brueckl.de:8443/svn/Coong/​​​​​​​​​​​​​

_________________________

Username: showcase
Password: showcase