NON-PROGRAMMERS READ THIS
Download this silly physics toy:
Controls: Keyboard, mouse, F1, F4, ESC
PROGRAMMERS READ THIS
When I started writing Jumpman, something that frustrated me was that there are a couple of seemingly basic things that SDL/OpenGL doesn’t actually provide out of the box, and that I couldn’t seem to find a really good source for sample code for– things like drawing text, or creating a simple GUI, or building a crossplatform binary. So once the game was done I decided to clean up my code a little, strip out the “Jumpman” parts and release the basic skeleton as open source sample code. Below is that code, and a small tutorial on setting up Mac OS X such that it can build Windows and Linux executables. The hope is to make an overall package that would allow someone starting an SDL/OpenGL game to just sit down and start writing, rather than having to spend time downloading and fiddling with libraries.
The Jumpcore package comes in two versions. A minimal version that includes only:
And a more fully featured version that also comes packaged with:
The included libraries were picked in an attempt to include all the basic stuff a game needs, while still making the package as easy as possible to port and reuse in weird situations: all the libraries are self-contained and except for SDL itself can be built from the package as source where necessary; nothing depends on anything more complicated than the STL– I avoided heavyweight dependencies like Ogre or libpng; and everything is under a BSD-like license. The biggest limitation of the package at the moment is that it’s a bit mac-centric (I have not tested it with Visual Studio or Dev-C++).
Basically, here’s a box full of Legos and half a robot. Have fun.
DOWNLOAD
HOW TO BUILD
Included is a Jumpcore.xcodeproj for compiling on mac, which can be compiled with XCode; windows makefile and support files are in a folder named win/, and can be compiled with mingw; Linux makefile and support files are in a folder named lin/, and can be compiled with gcc. More detailed instructions for all three platforms follow:
To build a mac executable, from a mac: Included is a Jumpcore.xcodeproj for use with XCode; just build that in Release mode and it should produce a 10.3.9-compatible universal binary (though note, I’ve not specifically tested it with 10.3.9).
Here’s the best way I’ve found to do this:
Once you’ve done this, run “sudo make cross” and it will install the SDL headers into your mingw directory.
A directory named “Jumpcore” will be created with a Jumpcore.exe and all the support files necessary.
Just distribute source. No, really. Building Linux binaries for distribution is tricky, and binaries aren’t what people want anyway. However if you want to do what I did and chicken out, what I recommend is installing Virtual Box or Q (probably Virtual Box, though Q is what I used) and loading up an Ubuntu install CD. This is quicker and easier than trying to set up a cross compile. Then go into the “lin/” directory and type “make”.
I was able to successfully compile Jumpcore on Windows by doing the following:
This will create an install directory named “Jumpcore”. If you want to compile for debugging, in that last step type: make WINDOWS=1 DEBUG=1
Install Freetype and SDL. Go into the directory lin/ and run make. This will create an install directory named “Jumpcore”. If you want to compile for debugging, instead type: make DEBUG=1
GETTING STARTED
Once you get the thing built, you’re going to want to start focusing on swapping out the Typewriter code for your own code. Jumpcore consists of a main.cpp that does basic bringup/teardown and event loop work hopefully good enough for most games, and makes callbacks as appropriate into a display.cpp (display logic) and a program.cpp (game logic) you provide. You’ll want to implement the following methods:
In display.cpp
display() - This is called when it is time to draw a new frame.
audio_callback() - This is set up as the SDL audio callback.
drawButton (”full version” only) - This is a cpSpaceEach callback which the default display() calls on each interface item. If you want to change the appearance of the ControlBase controls this is a good place to do that.
In program.cpp
program_update() - The default display() calls this once per framedraw.
program_eventkey() - This is called when SDL gets a key event.
program_eventjoy() - This is called when SDL gets a joystick event.
program_eventmouse() - This is called when SDL gets a mouse event.
program_interface() - This is called after the event system finishes dispatching events to ControlBase controls, to give the interface a chance to redraw itself.
BackOut() - Called when ESC is hit (quits).
AboutToQuit() - Called right before the program quits.
Documentation for the individual libraries and functions included with Jumpcore can be found on these separate pages:
LIMITATIONS AND POSSIBLE FUTURE IMPROVEMENTS
I’m not really sure if this is ultimately going to be useful to anyone, and I don’t intend to maintain it unless there are people actually using it. However if there turns out to be any interest in this there are a few things I’d like to improve in a future release:
Finally, there have actually been a number of interesting-looking SDL “game engines” released lately, so you should be aware of those in case one fits your needs better than Jumpcore does. Two I’m aware of are 2D Boy’s Boy engine and Mattias Gustavsson’s Pixie engine.
- Andrew McClure
mcc@grumpybumpers.com
http://runhello.com