itch.io is community of indie game creators and players

Devlogs

Pong - Creating My First Game [Postmortem]

MG Pong
A downloadable game

Pong was the first computer game (that I am aware of) and it feels almost like a rite of passage for an aspiring game developer to make a game of Pong! This postmortem has actually been written several months after finishing the game; I realised that whilst I had record devlog videos at the time of the project, I never really did a proper post mortem after I finished it.

I now write on Substack as it's not easy to find these old posts on Itch, if you'd like to read my other posts you can check out the full archive in that link, and I've put a subscription form at the bottom of this post.

From LUA to C#

The way I started out was to start working through the resources that I mentioned in my previous post. The Harvard GD50 course covered Pong as the very first game and even though that course uses the LUA language, I found it very useful.

I actually found it a useful exercise to see how he wrote the game in LUA and then create my own version of it in C# as it really forced me to read his code and figure out exactly what it was doing without being able to actually copy it.

Basic Mechanics Are Easy

Creating the basic mechanics of a ball bouncing around a screen and moving some paddles up and down was pretty easy. Now I am writing this post 6 months after creating this game but one thing that I have found in just about every game I have built since then or most game tutorials, is that the basic mechanics of the game are quite often fairly easy to implement but the real challenge comes when trying to expand on those basics - do something different.

One thing I have done with all of my games is tried to make them mine in some way. I never wanted to just make a basic copy of an existing game; I always wanted to put my own stamp on it and I will always want to do that. Not only does it make the project a lot more interesting, but I think it’s a good way to really learn.

Collision Troubles

Once I had the basics done I wanted to expand on the game, add some new features and I had two main ideas; one was to allow the paddle to rotate to allow the player more control over the direction of the ball movement but this would have fundamentally changed the way that collision detection works.

MonoGame is a pretty basic framework. I had to implement collision detection myself - write a little algorithm for it. I used simple bounding boxes around my sprites and to detect an overlap is actually pretty simple as you can implement something called AABB collision and I enjoyed the challenge of this.

However, detecting overlap between rectangles is easy but if I rotated the paddle, what looks simple on screen completely changes the collision detection. MonoGame did not have any functionality to handle this and I would have had to write my own clever algorithm for that, and that really wasn’t something I really wanted to to at that point, or at any point really. I wanted to be working at a higher level.

Misunderstanding Game Basics

I abandoned the idea of the rotated paddles and instead focused on trying to implement an extra feature of a “power ball” that would give the player various power ups and here is where I became massively tripped up!

The game was extremely buggy and it was really only in hindsight, some time later that I was able to figure out what the problem was.

You see my extensive experience in application and web development was actually working against me here but I didn’t know it at the time. These three types of software have vastly different paradigms:

  • Applications - Responds to events like button clicks, text input
  • Web software - Uses a Client / Server based architecture
  • Games - Driven by a core game loop which runs continually

All games will be doing something every “frame” and many frames are executed every second - usually 60 FPS. This means that in each frame we’re only doing a tiny fraction of work, such as moving a ball just a few pixels along a trajectory for example.

This took me the longest time to get my head around because when writing application software if I wanted to move a ball across a screen, I’d write some kind of loop for it to be done and then once done, control returns back to the calling code but games don’t work that way! Everything runs in parallel, every single frame, and because of this fundamental misunderstanding of how games work, I got myself in such a muddle with my first implementation of even just a simple game of Pong!

Another misunderstanding that tied into the above problem was understanding the concept of state. These “power balls” changed the behaviour of the game in some way. For example one of them would make the paddle bigger and this was simple as I could create a method which would expand the panel and just call that method.

However when this broke down was when a particular powerup would initiate a change that took place at some point in the future and this is where my misunderstanding of the game loop compounded with misunderstanding of how state machines work just created a massive mess!

So I wanted a powerup that would cause the ball to move way faster on the next hit but of course I couldn’t just call a method to do that because that next hit hadn’t happened yet! What I needed to do (it’s easy to write this in hindsight 6 months later!) was set a state to say “hey this ball is now in fast mode” or something to that effect.

Starting Over!

Sadly, I got myself so mixed up that I ended up just abandoning the first project and creating a new one from scratch. I wrote the code more cleanly and got the basic game working fine but I think I’d been burned a little too hard and honestly, I was a bit too scared to try to re-implement the power balls feature for fear that I might just get it wrong all over again!

Also, by this point I had spent several weeks on the game which was astounding to me! I couldn’t believe that something that seemed very simple in my head was turning out so complicated! Welcome to gamedev eh? 😉

So this time around I made sure that I created a completed game with a title screen, a way to win the game and lose the game, a pause mechanic and basic functionality that worked. I was able to do that and finally, I had a playable first game now released on Itch which was a big milestone for me, but I never expanded on it.

Download MG Pong
Leave a comment