Sunday, June 13, 2010

my p0ng haz > brainz thn urs!!!11!!!1222!! : A brief write up and update

If you can't speak noob, then what I mean't to say was "I have completed writing a pong game in SDL, here is my writeup!"

I decided, to start off my summer holidays to re-acquaint myself with C++ and SDL by writing a simple pong game, this now complete pong game (dubbed pong 2010) is simply a no-frills, back to basics pong game (white ball, white paddles, 7-segment display for scores).

I wanted to get back into the swing of things, so I set about making the game straight away, design documentation was pretty light, and things started off well, until I realised that my initial design just wouldn't cut it when I tried to introduce an AI player.

Originally, my design was simple, all objects in the game were independent of each other, and they interact by returning SDL_Rects via accessor methods, and I just checked if the boxes were colliding, sounds like it would work fine doesn't it? well it did, until I realised I wouldn't be able to write player AI very easily, because the Player class has to know certain details about the ball (such as the location, size and proximity to the player), my first design had no chance of Player AI working without a tonne of bugs.

Rather than restarting the project, I opened up my UML diagram tool, entered in everything I already had into a set of class diagrams, and started to move things around, fortunately I was able to find a decent design that meant I could use much of the existing code I wrote, whilst still being able to allow for the new functionality the game required.

The new design was fairly simple, the Player stores a reference (in this case, a pointer) to the ball as a more primitive superclass (called Rectangle, the paddles and the balls are derived from this class), and the 'Player' class became a super class for the 'HumanPlayer' and 'AIPlayer' subclasses.

This new design allowed me to move player input into the HumanPlayer class and out of the main body, and allowed me to move AI into the AIPlayer class, this made things a lot clearer, and aided me in completing the project.

I also added a nifty feature I picked up in A-Level computing, a 7 segment display, (you know, those displays you probably have on a digital watch or alarm clock you own, I used one for the score system), after an hours programming or so, I was able to finish a class called 'Counter', which was able to display the digits '0' to '9' anywhere on the screen, since the display is simply made up of rectangles, I was able to implement scaling, so now the display can be scaled for the needs of any game that requires a specific-sized counter (I may do a 14-segment display in the future to display the alphabet, but that's a little harder, as it requires diagonal shapes, I'll have to work out how to make those look right when I implement scaling)

That is the basic overview of my pong game, I learnt how to implement AI, which was fun (I've implemented very dumb AI in the past, the player in my pong game is at least a little challenging, but beatable all the same), and I feel like I'm back into the swing of things, after a year of ad-hoc programming due to my studies.


Aside from pong, I have been thinking about other projects to work on, one which I'm actively working on is my website, I really want to launch a new website before the end of summer, but I am going to take my time, and I will only release it when I'm happy with it, I want to do some things that will hopefully be really interesting!

I have a few other ideas in the pipeline, which I'll do if I feel daring enough! I also have the GUI library to work on, progress on that is slow at best, since I haven't really looked at it for a while, it's all about getting that crucial design correct, I tell myself that if I don't attempt to complete it, I am only stifling myself, because I need some GUI components for my various games and apps I have planned, which I cannot complete without getting this finished.


I hope this was an enjoyable read, hopefully I will be able to do videos when I get my new equipment and I have access to some fast broadband.

Thanks for reading

ProgrammerInProgress

No comments:

Post a Comment