Allegro.cc - Online Community

Allegro.cc Forums » The Depot » GRIM and Game Demo SOURCE

This thread is locked; no one can reply to it. rss feed Print
GRIM and Game Demo SOURCE
Matt Weir
Member #7,476
July 2006
avatar

(warning, long post but hopefully informative!)

Source Code (0.1 Mb)
Data (5.2 Mb)

Hi there all!

As promised earlier here is the source code for:

GRIM (2D skeletal animation editor)
Game Demo (that uses GRIM).

There's also a 'usable' level editor for the game demo included. See the link for screenshots and more info on the specific projects.

All this was put together for my Game Programming portfolio which got me the job I was after (and they looked through a large part of the source so it can't be too bad ;) ). :)

Basically I'm releasing this source as a learning resource for anyone that's interested. There's quite a lot to it (10,000 lines if I remember) so I'll try and point out some parts that people might find interesting. It might be a bit confusing because the the game, the GRIM editor, and the level editor all share the same code base but they're all split up pretty well. If you have MSVC8 you can load the project file which has everything split up nicely into folders.

You'll find some of the code commented well and some not at all. All kinda depended how I felt on the day or how tricky I found something. If you see anything weird chances are it's just a placeholder until that certain part of the system is developed properly. I don't think this will compile straight away with another compilier (ie. not MSCV8) but it shouldn't take much work at all to change this. (I didn't realise 'strcpy_s' was MS only etc.)

Libs you'll need to compile are Allegro (4.2), OpenLayer (a semi recent SVN probably, rather than the precompiled binary you can find around the net), and FMOD. I could prob post the DLL's if really needed.

The CODE rar contains all the source code and the MSVC8 projects files.
The DATA rar contains all the graphics/levels/skeletons/sound etc needed to run the game.

Here's a quick rundown of some of the more interesting files/classes:

------------------
Animation.h/c

All the animation classes for loading groups of files as animations and displaying them. The 'Anygraphics' class is the main wrapper around a bitmap and is used even for things that aren't animations (ie. static backgrounds etc). Animations are made up of a group of 'FrameSets' that contain individual 'Frames'. If you had a magic donut for example, you could have a seperate frameset for each coloured donut or one with equally magic sprinkles. (Mmmm donut....)

------------------
Anything starting with 'GRIM'

Files specific to the GRIM editor.

------------------
MattLog.h/c

This is the logging class I wrote for debugging. It just dumps strings and numbers to a file basically. I could be much better but it works so I never really improved it.

------------------
Level.h/c

The data structure for the game level. Basically just a simple array of tiles. There are two layers in the game demo, one in front of all the Entities and one behind. Eventually I'll make each element of the array a linked list of tiles so you can have infinite layers but for the moment you can do plenty with 2 so it's not a huge priority. That and the more layers, the slower the framerate will be. Please note no Entity data is stored in the level at all. (see Entity explanation)

------------------
OL_GUI.h/c

This is my Openlayer GUI I made that works on top of the Allegro gui. I basically rewrote all the different things though (Menu system, File loader/saver etc), they're a little less complete than the Allegro ones but a bit more 'modern' in use. It was written in 24 hours and hacks were the order of the day (we are talking about the Allegro GUI here).

------------------
M_Entity.h/c

An Entity is any object in the game such as the player, enemies, magic cupcakes, cameras, triggers, particle trees (see later) etc. EntityList is just a big linked list of Entities that manages them. To make a new Entity you just write a class that inherits it and you overload the inmportant methods.
These are:

MoveMe - This is called every frame, here you increase the entities position by it's velocities * deltaTime and do whatever else you want.

DrawMe - Called every frame to draw the Entity.

UpdateLogic - Called at a constant interval (20-25 msecs, can't remember). This is where all the main logic goes such as changing direction, AI, and anything that needs timing really.

Entites are loaded from the level file and instantiated at runtime by an Object Factory, EntityFactory.

------------------
MParticle.h/c

The basic stuff for Particles and Particle Tree's (a collection of particles, also an entity). Particle tree should be inherited and the functions more drawing, moving, and logic overloaded. Check out the 'Particles' folder for examples of different particle factories (rain, explosions).

------------------
Skeleton.h/c

The main class to hold all the Skeletal Animation data. This is the real guts of what GRIM is built around and contains everything to do with loading, saving, buiding, interpolation, etc. Uses the 'Animation' class to hold all the skins. (so they can be animated independantly easily)

------------------
Resource Manager (folder)

All the code for the Resource Manager. You use this to load any data you may need and it caches it so that if you try and load, for instance, an image multiple times then it will just give you a pointer to the first time it was loaded. This means if you have 100 cupcakes in your game 'cupcake.png' will only be loaded into memory once. It also has garbage collection to quickly unload everything or things can be individually unloaded. To add functionality for different types of data you create a plugin class that tells the Resource Manager how to load/unload the data. (eg. Graphics, Sound etc.)

Very useful. ;)

Note for the nerdy: I know it should use a hash table rather than a stl map (for speed) but that will be fixed at some point. It already works reasonably fast so it's not a high priority.

------------------
Entities (folder)

All the entities used in the game demo. Prob a good place to look if your interested in how Entites work.

------------------

Feel free to ask any questions regarding the code and program design and layout. I will try and answer as best I can. Please note that this is all quite unoptimised, I program things to work well first and then to work quickly after that if actually needed. It is the best way, I find, to actually make progress on your projects.

In terms of license, basically this is all just for education, NOT free or OpenSource. If you really want to use any of the code then ask, I'm pretty resonable ;). For now the graphics, sound, music, and code are ONLY TO BE USED WITH THIS PROJECT. If you want to add features or help out then contact me, I'd be glad for the help or suggestions. The main reason for this is that I'm still working on this, just a bit slower now that I have a job. (this was all done in 4 1/2 months but other commitments were few)

Sorry for the long post but learning is fun! Really....

Matt Weir.

GullRaDriel
Member #3,861
September 2003
avatar

Matt said:

Note for the nerdy: I know it should use a hash table rather than a stl map (for speed) but that will be fixed at some point. It already works reasonably fast so it's not a high priority.

Use the GLIB !

Anyway, thanks for releasing the source, it will be helpfull for me because I was searching ( some few days ago ) some ressource about skeleton animation :-)

Keep up the good work, Matt !

PS: I hope this work will help you to have the job you aim !

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

LennyLen
Member #5,313
December 2004
avatar

Quote:

PS: I hope this work will help you to have the job you aim !

Pssssst

GullRaDriel
Member #3,861
September 2003
avatar

Heh thanks.Anyway the source looks nice :)

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Matt Weir
Member #7,476
July 2006
avatar

Yeah, the portfolio did help me to get the job I was after which is awesome.

For the skeletal animation stuff definately check out the 'skeleton.c/h' files. Basically all the major stuff is in there. Of course it's only how it works, creating the models is a completely different story. There's probably more to this than actually implementing the models themselves. This was probably the hardest thing about making the skeletal animation system, it would be easy to implement a new feature but hard to make it actually usable in the editor.

Cheers for having a look, hopefully it helps!

Matt.

Albin Engström
Member #8,110
December 2006
avatar

sweet :P. decided to write my own after all so I'll definitely take a look at it.
gratz to the job btw.

Go to: