Game Development Games Linux Game Development

Can You Make Pong?

Since I’ve decided to start with the basics and create a simple Pong clone, I figured I would do some research. I found quite a few tutorials and other articles, but the following is one I wish I would have found months ago: But Can You Make Pong?

Well, there it is. The good old game Pong can be quite a challenge, and certainly not something you finish in a day or two. And this is exactly the reason I believe Pong is the perfect game to test your skills as an all-round developer and/or studio. It’s not overly ambitious, yet it requires a good amount of discipline. Look at it this way: If you can’t finish a simple game of Pong, do you truly think you are ready for the big games?

I have already worked a couple of hours on my Pong clone, and I can see it taking multiple days, and knowing how I seem to like to underestimate myself, probably a couple of weeks or months. Yeesh, that’s a sobering thought: Pong requiring many, many hours to complete.

I’m not too intimidated. I mean, even with my lack of experience, it is just Pong. It’s not even Massively Multiplayer Pong. I just can’t claim to have made such an “easy” game.

I did a bit of research, thinking I could find some simple tutorials. I found some C# ones, which do me no good, but I did find some general Pong physics tips which might come in handy later: ball physics and Pong “physics” .

The gold mine came from the LinuxDevCenter at O’Reilly: Retro Gaming Hacks, Part 1: Clone Pong, Using Only SDL (and Your Brain) by Josh Glover, a contributer to Retro Gaming Hacks. It’s basically a step-by-step tutorial on writing a Pong clone using SDL. I am not too happy with the example code, but it is called a “hack” for a reason. My goal is to implement Pong, but I will use this tutorial as a guide rather than try to mimic the code very closely.

21 replies on “Can You Make Pong?”

Sorry for being blunt, but how can it take you multiple days to write Pong? It’s really not that hard and you should be able to figure it out without tutorials.

I’d say, start with just a ball that bounces around the screen. Writing the basic SDL code may take an hour or two, but implementing a bouncing ball shouldn’t take more than thirty minutes. In other words, you can write a bouncing ball in a single evening.

Come on, Gianfranco, write that bouncing ball and send me your code. You’ve been talking about developing your own game for over 20 months now, time to deliver some results. I know you can do it.

Don’t make me come over there and kick your butt! (…because the flight would be quite expensive.)

Excellent choice to do this. This one excercise will give you an extremely valuable experience that I’d guess 75% of game-developers have never had.

William.. If it’s so easy, just spend a couple of minutes and go do it. I guarantee you’ll learn something from it. Come back and tell us how many HOURS it took. 🙂

Your pong is written in Kyra, yes?
Perhaps if you keep the code very tight and simple to understand, the Kyra chap will check the finished code into their CVS, as a new example. Maybe some motivation for you?

I use PTK, and it comes with a wonderful Arkanoid clone — in 500 lines of code. I’d be aiming for something around that size for a playable mini game (unless others think that is way off). That example has some nice sprites/backgrounds + a couple of sound FX to polish it up a bit.

William: It will take multiple days, but not 24 hours worth of work each day! I’m referring to the 1-5 hours per week I normally seem to be able to work.

I’ve done the ball bouncing around the screen, and in fact had something in my old engine weeks ago doing just that. It’s the part where it cares about what it is bouncing against that makes it more difficult.

However, you are right about the part about delivering results. It’s why I am writing a Pong clone in the first place. And the tutorials aren’t because I don’t think I could figure it out. They’re to make sure I keep on track with writing JUST a Pong clone as opposed to trying to make a Pong clone that would allow for more than two players or multiple balls or power-ups or bricks or enemies…

Billy: And the sense of accomplishment will be good for me. After 20 or so months, it would be nice to have something a bit more complete than my Game in a Day for last June. B-)

BAZ: Actually, I could definitely submit it as an example for using Kyra to make a game. It’s not a bad idea. But first, I have to finish it!

All of this talk of “days” is strange. Did it really take you guys days? I programmed it in C# in three hours back when C# was shiny and new. It was the second thing I programmed in C#. Of course, I have experience making pong, having made a version in Basic, Pascal, C++, and assembler. It used to be how I tested a new language.

In a decent piece of middleware like TGB or Flash, it’s really fast. Slap down some shapes, hook one of them up to mouse or arrows and the others up to simple algorithms. Make something that iterates every frame to move things and check the ball’s bouncing. In TGB, you can simply set the ball’s world limit and physics to “bouncy” and only check for scores.

The only way I can see this taking days is if you’re totally new to the software you’re using. It can take a day just to figure out how to hook something up to user input, and a day to figure out how to get things to move around right. But if you’re at all familiar with the language?

Why is it such a daunting prospect to you guys? Pong is, speaking from experience, not very hard at all. Solitaire is harder to program. 😛

Craig, it is daunting because I haven’t successfully made a Pong clone before. I always thought it was so easy that I could skip that step and move on to something harder, but I never did manage to get anything done.

And while I can be optimistic and expect to be finished within a week of starting, assuming that I only work a few hours in that week, my experience with my estimates is that I always underestimate how long it would take to do something.

When I wrote a Guess the Numbers game in C++, I wasn’t satisfied that it worked. Anyone could make one that works. I made one that wouldn’t break if you typed something other than a number. It was robust.

I imagine something similar might happen with Pong. I can probably get a game that works fairly easily, but I will likely not be satisfied until I could get the ball to bounce off of paddles in a way that doesn’t look weird.

Yes… Pong shouldn’t take that long. If you can draw graphics and get input in Kyra you’re about 50% of the way there, it should be finished in your 1-5 hours of development.

A lot of your problem seems less how to write graphics or physics code and more “how do I code pong.” This was really a bottleneck for me when I first started to code games (as opposed to graphics demos and random apps), because there are plenty of tutorials on how to code with OpenGL, DirectX, SDL, etc. but not many on how to write gameplay. The problem with this is it changes a lot from game to game, so you need to get in the habit of figuring out what your game rules are and just coding them, which lucky is easy for a well defined game like pong.

You seem to be stuck on collision and perhaps AI. Both of them are dead simple for pong, I won’t tell you how to do it (although Craig has already given some hints), but I’m sure if you think about the requirements you’ll be able to figure them out quickly.

When it comes to coding gameplay I almost advise getting in the habit of anti-design, writing code that’s as agile as possible and embracing hacks, because when you’re prototyping new game ideas your game could completely change from its initial design in an hour or two. Once your design is more solidified you can recode it in a cleaner more optimized fashion.

Even though pong should take a few hours at most something that has a good polished feel could take you a while longer. You might want to look into coding “extras” after you finish the main gameplay, including user profiles, highscores, a nice menu, match summary screens and various graphical effects like particle systems. In theory you might be able to reuse some of it.

I really should turn these long ass GBGames rants into blog entries :).

I wouldn’t say that I am stuck yet. I was basically throwing away a bunch of code and knowledge from the engine project and starting almost from scratch. Luckily I already had some useful pieces of code, such as Kyra and the input system, so now it just a matter of piecing things together. I already have a window that can be closed when I hit Q or ESC, and I’ve started on the paddles and ball. I also think that I will have something up in a matter of hours…it’s just that those hours will be stretched over days.

Maybe it sounds worse than it really is. I think I am in good shape, which I suppose is all that matters.

Yeah pong won’t take that long. Actually the thing that should take the most time is the AI. I’ve never actually made a pong clone myself, i’ve made a sort of wallball game, where you have 3 walls a paddle and a ball though. Very simply you just invert the x or y coordinate depending on when it hit the wall, that’s the sinchy stuff. The tough stuff is making the opponant paddle move convincingly. But I think even with that you can use some simple rules that will turn out more complex behavior.

Hmm maybe I should do a real pong clone — so I can work on AI. I did a tetris as my “first” and tetris is definately a challenge when you’ve never done it before. Even without AI.


I just looked at the article “But can you make Pong” And what he’s proposing might would take more than a few hours or a few days. You don’t need complex physics for pong, or anything complex really. You don’t have to program peer-to-peer, or even have a “proper UI” to call pong done. In fact all you need to know is that you move x and y seperately, and that you reverse it by switching negative to positive or the other way around when bouncing off of walls.

You CAN add a bunch of extra crap to pong, however you want to get it working. Worry about making WonderPong later. Like I said the AI will be the toughest part. But in fact why not make only one kind of AI even if it’s not perfect. Point is you want to make a pong game, not to have the best ai in the world either.

So use the mouse to control the paddle, make sure there is bounds checking on the paddle. Make the ball start from anywhere (other than completely center to the paddle). It does NOT need to bounce differently from different positions on the paddle. Remember you want this to work, not be SuperDuperUltraPongFantastic. The only rule for pong physics you need at this point is. When X hits something (done via normal bounding boxes, you do not need vectors and such to get it working, this will be later when you want to perfect collision) then X becomes -X (negative X) — if it hits anything on the X again it becomes positive again. Do that also for Y. So it bounces off of walls now and the paddle. Make sure you can exit the game. Make sure that when it makes it past the paddle you can score. And that it exits when someone gets 10 points (or whatever you decide).

As far as AI is concerned you’re sort of on your own here. Not sure what I would do myself. I would think “what do I do when I play”. I would probably judge where in “y” (as pong is played horizontal) the ball is, and try to line up my paddle visually. I’m not sure how you would do that with pong AI but you could do something like, if ball is on the top start hovering towards the top, else hover towards the bottom. And I would just have it sort of fakey deduce about where the ball is, it can’t be exact or the player won’t be able to win ever. Another idea is to make the paddle take a position at a certain time increment, and then move the paddle there, rather than moving in sync with the ball, it will just move to the position it sees once. Once it gets there it does it again. There are probably more places to tell you what to do as far as pong ai goes.


I’ve been reading over the “retro gaming hacks” pong articles over at linux dev center — and i’ll have to say that’s a pretty good tutorial. It just goes basic enough and simple enough to get you going. I would follow that one.


Heh, the funny thing is that I was hoping to get Pong to allow two human players. I figured AI would be something to deal with later. Not that I think it would be terribly difficult to get any working AI. It’s just another feature to add once I get the basic game up and playable.

@Billy: I did Pong already and yes, it doesn’t take minutes, it takes hours, but it doesn’t take days. Of course, if you can only spend like an hour a day, it does take days. 🙂

Actually, it might be fun to see how long a Pong game would take me to write. I think I can set aside a day this weekend to see how quickly I can pull it off.

Just remember that there is more to a game than just the core game mechanic. I’d say the core game mechanic for pong is probably only 25% of time to produce the game.

GB, you should make it 2 player. One player just happens to have an AI behind it rather than a human. The interface for the player thing is identical.

That is, if you go OO. I’m not sure what route you’re taking, but I’ve seen it said before multiple times “write it once procedurally so that you understand it, then throw it out completely and rewrite it OO so that it’s right.”

If your goal is to “just get Pong!” then skip the purity stuff and just write loops. 🙂 Take the 5 hours to make Poor Man’s Pong, just something functional. Then, for educational value, study it for a bit and then go back and write it “cleanly”, with OO, AI and multi-player options, pluggable physics (your base one being the dead-trivial one Keith describes), etc. At this level, it’s two different tasks. Do it once to say that you did, and second time to say that you did it well. You’ll learn more that way.

Other tips: Extreme Programming suggests breaking time estimates down to NO MORE than 4 hour chunks. That’s the time “before lunch” and “after lunch”, and besides, most people can’t well-estimate something larger than that anyway. Personally I try not to have anything larger than 2 hours, and many tasks (when my boss lets me take the time to break things down this far) are a mere 15 minutes in my estimate.

What that does is force you to figure out how a problem breaks down BEFORE you start addressing it. “OK, so I need a ball that bounces. I can’t estimate that. So I need a ball that displays at some coordinate, and I need to change that coordinate. OK, I can do display in 30 min, changing, uh, well I need to make it editable and then I need some way to change it. Editable coordinate values, pfft, 15 min. Changing it, well, that’s going to have to be on a time-basis so I’ll need a time loop to update it. Time loop, an hour. Hm, but then there’s that bounce thing…”

So just from that exercise, you now now that you need a ball entity that has intrinsic coordinates that can be edited from the outside, you need a time loop that updates those coordinates, and you think you can write that in about 1.75 hours. And you know the next thing you need to break down is bouncing, which means collision detection, which means two objects, which means a wall object, and then a collision detector between a ball and wall, now you can estimate those separately…

Take 2 hours before you write a single line of code and do that sort of time-based analysis. Very often it will not only give you a much more accurate estimate (it does for me), but it allows you to discover your architecture and data model and algorithms before you code.

Other tip: Credit here goes to the immortal Fred Brooks, who literally wrote the book on software development. Good data structures will make algorithms obvious. Bad data structures will make good algorithms impossible.

I thought Brooks wrote the book on project planning, but I haven’t read The Mythical Man Month in years. Maybe it is next on my list of books to read.

Yep, Brooks of The Mythical Man Month. But he goes into more than just project management, or rather the subjects he talks about have impact beyond it. Definitely get the 20th anniversary edition from the mid-90s, as it has extra material he wrote in the 80s as well as some retrospective material. Even though he was talking about large projects, I’d argue that it applies to any multi-person project and has good take-aways even for one-man projects.

Really, you shouldn’t be allowed to work in software development if you haven’t read Brooks. 🙂

Making a pong game isn’t much work, but making a ‘complete’ pong game is where you can underestimate the time. Granted, it’s not a mamoth task especially if you’ve coded pong or something similar before, but, adding in the menu system, pause option, sound, crude AI for the computer player and secondary input support for a second human player takes time. They may each be individually simple quick tasks, but they still add up.

Pong is also a very simple framework from which you can develop network skills. Allowing you to focus on networking issues rather than worry that the game itself isn’t yet finished or the graphics need work. Instead, add multiplayer internet support. This would add a fair amount of work to the project and could be considered overkill, but the point is, Pong as a “playable” game can be created in an hour, but, pong as a complete game can take a while longer and there is no reason it can’t take quite a large amount of time if you network it especially if it’s your first networked game…

After Pong try your hand at something like cloning Space Invaders or Galaxian/Galaga. Again these games appear deceptivly easy, but if you study the game a little you realise there is a fine line between a Galaxian clone and a Galaxian clone that plays as well as the original.

I’ve often wondered if there are any books that look back at the classics from the early 70’s/80’s and clone them as accuratly as possible using modern methods. I guess copyright issues could be a problem but not something that couldn’t be worked around? Anyone know of such a book?

Guess I need to check out the retro hacks book you linked to, it may just be the book described above 🙂

Comments are closed.