Splash is a basic 3D Pacman clone written using C++ and OpenGL. I have tried hard to make the design and the implementation of Splash clean and easy to understand. As such, I think that the source code for Splash will be of use to anyone new to software engineering in C++, and to anyone thinking of writing a videogame in C++ using OpenGL. Splash has no other dependencies apart from the GNU C++ compiler (3.9.5 and above), GLUT, and OpenGL.
Splash source code, game instructions, and resources (zip, 792K)
Screenshots (on PicasaWeb)
A note to all students using Splash for instructional/reference purposes: I have noticed a large number of hits to this page at the end of each academic term. If you’ve found Splash to be useful or unhelpful in any particular way, I would really love it if you could tell me about it so that I can make improvements to the project. Just email me and let me know what you think.
A year or so ago, I took an introductory graphics course. The final assignment was to write an ‘interactive simulation’ (i.e. a video game), using the hierarchical models we’d developed in the first assignment. Our models were of dinosaurs, and I selected a Plesiosaur as my subject. Thus, Splash is a game about with an aquatic dinosaur as the protaganist (and also as the antagonists ![]()
I’d previously tried twice to write a full-fledged video game, and both times I failed because the scope of what I was trying to build was too large. Thus, I decided to keep it simple. So, I built a Pacman clone. The game itself is played in 2D, although the graphics are 3D. This is critical when writing your first game: Start really small. There will be more than enough stuff to occupy your time in a small game to make it a worthwhile exercise.
It took me about 6 days of concerted programming to drum up the engine. There was no unified interface, the game was run by specifying levels at the command line, and basically it was all very unfinished. Also, the code screamed for refactoring. So, over this past Christmas break, I rolled up my sleeves, prettied up the code a bit, and added the little details that every game needs: For instance, a startup screen, a heads-up display, high score lists (well, timed records for each level), and an endgame sequence.
These additions took another 12 days of on-and-off effort. This is because the structure of a game engine is pretty simple, whereas the architecture needed to add all the other navigational stuff is pretty substantial. I decided to do everything without leaning on any other frameworks or libraries (even Boost) because (a) This way, other computer science students could flit through the code and get quite a bit out of it, knowing only C++, and (b) so that I could get an idea of what a good game framework would need to provide in order to make possible the rapid development of a video game. (Boost would definitely be a boon in several places, but it’s a bit much for the newbie to swallow all at once and so I decided to forego it.)
I came to a bunch of conclusions as to what such a framework would need, but the #1 thing that I feel would make things much easier is a good way of abstracting time. When writing Splash, I was usually specifying what would happen between any two frames of animation, and writing code that has to monitor changes in time ‘slices’ like this is no fun. An event model, or some other way of being able to say “do this for 10 seconds and then start doing this” would be invaluable.
I intended to build a level editor at one point (in Python) but I ran out of steam. Perhaps another time. As it stands, Splash has only 4 levels.
I tried to scour the Splash code as much as possible, but when I finally gave up there were a handful of things that were still quite ugly. (Transitioning between game states, in particular, is horrific and should be replaced with an explicit state machine.) Still, I’d encourage anyone thinking about writing their own game, or even anyone new to C++, to take a look at the source. On my home machine I use SCONS to organize my C++ code into packages, but the source distribution of Splash builds using plain old GNU make. I’ve built it successfully on OS/X and Linux: See the README and the makefile for details.
Comments (0)