Click here to Skip to main content
13,897,352 members
Click here to Skip to main content
Add your own
alternative version


20 bookmarked
Posted 14 Jul 2010
Licenced CPOL

Pong in a Win32 Console

, 15 Jul 2010
Rate this:
Please Sign up or sign in to vote.
Pong in a Win32 Console


Pong is one of the earliest arcade video games and a two-dimensional sports game which simulates table tennis and was the first game developed by Atari Inc in June 1972. The player controls an in-game paddle by moving it vertically across the left side of the screen, and can compete against either a computer controlled opponent or another player controlling a second paddle on the opposing side. Players use the paddles to hit a ball back and forth. The aim is for a player to earn more points than the opponent; points are earned when one fails to return the ball to the other.

Pong is a simple game to code. The game involves a ball and two pads. The ball moves around on its own in the game world, and the player moves the pad. If the ball hits the wall or lands on the pad, change the ball's general direction. But if the ball misses the pad, then display the message - you missed - to the player.

The controls are:

UPmove pad up
DOWNmove pad down
TABtoggle Cheat on/off
F1display help

Writing code for the core logic of a Pong game is as follows. First update the position of the pong ball:

//update ball's x location
//update ball's y location

Then test or check the ball's y location in the game's world positions using a series of "if" statements. If the ball hits the top or bottom wall, then change the ball's general direction.

/* check if ball's location at top or bottom of screen,if true reverse ball's y heading */
if( (ball.y<pong_screen_top) />PONG_SCREEN_BOTTOM-2) ) ball.headingY=-ball.headingY;

Now check if the ball has landed on the pad, if it has then make the ball bounce back.

/* check if ball lands on pad, if true bounce back */
if ( (ball.y>= PlayersPad.LEFT) && 
	(ball.y<= PlayersPad.RIGHT) && (ball.x==PlayersPad.x))

But if the ball misses the pad, then display the message - you missed - to the player.

if ( ball.x < PONG_SCREEN_LEFT)	displayYouMissed();

That's it. Download the source and check it out. Thanks for reading.


  • 15th July, 2010: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

About me:
I attended programming college and I have a degree in three most famous and successful programming languages. C/C++, Visual Basic and Java. So i know i can code. And there is a diploma hanging on my wall to prove it.
I am a professional, I am paid tons of cash to teach or do software development. I am roughly 30 years old .

I hold lectures in programming. I have also coached students in C++, Java and Visual basic.

In my spare time i do enjoy developing computer games, and i am developing a rather simple flight simulator game
in the c++ programming language using the openGL graphics libray.

I've written hundreds of thousands of code syntax lines for small simple applications and games.

You may also be interested in...

Comments and Discussions

GeneralMy vote of 1 Pin
danielsage10-Nov-10 14:10
memberdanielsage10-Nov-10 14:10 
GeneralOld stuff Pin
CDMTJX20-Jul-10 9:14
memberCDMTJX20-Jul-10 9:14 
GeneralMy vote of 4 Pin
KentuckyEnglishman20-Jul-10 3:09
memberKentuckyEnglishman20-Jul-10 3:09 
GeneralMy vote of 2 Pin
Dave Kreskowiak15-Jul-10 4:34
mveDave Kreskowiak15-Jul-10 4:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.190306.1 | Last Updated 15 Jul 2010
Article Copyright 2010 by Software_Developer
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid