Ping Pong - Using C++

 

"Ping-Pong" is a graphic based multiplayer console game. Simply, it is a table tennis game. In this game, the main role to be played it to volley the pong (ball) so that it do not hit the vertical boundary. Failing to do so, score increases for opponent player. With the integration of a simple menu and options, it is an interactive game with simple graphics. The three levels are included, which are classified as easy, moderate and hard and can be chosen by the user manually. As the players continue on volleying the ball with the movable paddles, the speed gets on increasing. The speed of balls, for making players emphasized on the game, gets increased after the interval of every ten consecutive volleys by paddles. Once the ball hits the boundary, the speed of the balls is restored to normal. The player scoring 5 at first wins the game.  For representing the score scored, square bars are shown behind each paddle. The player scoring total score of five firstly wins the game. The guide has been added so that new players can learn about how to play.


How to download code?

  • Click here for source code.
  • New window will open where there is a source code of this project. Download all the files.
  • Remember that this project runs in Dev C++.


Demo of this game :


  

For more source code and tutorial, SUBSCRBE to my YouTube channel. 


Development platform

Computer programming language has been used to develop this project.

 

Compiler

Dev C++ has been used as compiler in this project whose version is 5.11.


Header files used

The header files used in this project are as follows :

  1. Graphics
  2. Iostream
  3. Windows


Library functions

The following library functions has been used :

  1. Under graphics header file
    1. Bar
    2. Circle
    3. Closegraph
    4. Delay
    5. Floodfill
    6. Initwindow
    7. Outtextstyle
    8. Outtextxy
    9. Rectangle
    10. Setcolor
    11. Setfillstyle
    12. Settextstyle
  2. Under iostream header file
    1. Clrscr
    2. Getch
    3. Strcpy
  3. Under windows header file
    1. Getasynckeystate

 

Concepts used

Topics/ concepts of this language that you need to know for making this type of game :

  1. Array
  2. Class and object
  3. Function
  4. For looping statement
  5. If else conditional statement
  6. Inheritance
  7. While looping statement
  8. Graphics 


Logic description

On the startup of the game, menu is shown which can be navigated using up and down arrow keys. 


Since this is a multiplayer game, two paddles are present, and for  their movement tab, left-control, up-arrow and down-arrow keys can be used. The paddles can be moved only in vertical direction. 


Talking about the direction of ball movement, here, includes four directions. Let us consider movement-1 : down-right, movement-2 : up-right, movement-3 : up-left and movement-4 : down-left. When ball gets hit on the paddles, if the ball is in movement-1, ball direction changes to movement-4, form movement-2 to movement-3, movement-3 to movement-2 and movement-4 to movement-1.


But this protocol do not get applied when ball collide on the top and bottom boundaries. Here, movement-1 changes to movement-2, movement-2 changes to movement-1, movement-3 changes to movement-4 and movement-4 changes to movement-3.


The score pattern is simple. Whenever the ball gets hit on the vertical boundaries score for opponent player gets increases. The player scoring total score of 5 at first wins the game.


Realizing the mistakes that I did in "Ping-Pong using C", I have developed similar game in C++ platform, with features of multiple levels and score visualizations. Total of three levels has been included : namely, Easy, Moderate and Hard. The alignment of obstacle has been used for the differentiation of levels.


For the score visualization, instead of numeric representation, bar-function has been used. Scores are displayed on the vertical boundaries of respective players' side.


The most important function in this project is "GetAsyncKeyState". This function simply has been used to determine the different keys pressed.   


Some screenshots

No comments:

Post a Comment

Article Ad1