o2d -- a two-dimensional game engine

This engine was my senior thesis in school, and a hobby before that. It started out with me wondering if I could reimplement RPG Maker XP in Java, using open-source libraries. Turns out I can, and I did enough of that to satisfy me. Java was too slow (or, more appropriately, I didn’t know enough to write it efficiently in Java), so I ported it to C++. The C++ port done, and a variety of scripting languages embedded and removed, I got bored and starting reimplementing it in a variety of languages as a learning tool. I did Python, Ruby, and later C#/XNA.

When I got my first Flash job offer, I decided I needed a portfolio piece, and this engine seemed a good enough choice.

Anyway, as to why this is cool…

This thing is very complex, especially for Flash. It handles two different layering mechanisms simultaneously — one for human convenience and one for CPU convenience. In the editor, you get three layers upon which to “paint” tiles from your tile palette. When you create the palette, you identify which tiles are logically “higher”, in a z-axis sort of way, than the other tiles. For example, the tree pieces have a height of 1, 2, 3, or 4 (depending on which part of the tree we’re talking about), whereas the grass, water, etc. all have heights of 0. You can paint grass and then a tree piece on a higher layer, and everything just works.

Especially complex is the dead tree coming out of the sunken terrain on the east side of the sample map. This situation requires no special instruction to be interpreted correctly by the renderer. Also notice that tile boundaries are interpreted correctly regardless of complex height scenarios.

Animation and fluid tile transitions are pretty cool within this engine as well. The water, the dirt path, and the sunken terrain are actually only three images total — the transition tiles between each of them, based upon how they’re painted, are built dynamically. In fact, the engine goes one step further, and pre-processes every possible tile, dynamic and static, and builds a single huge bitmap in memory, which it then exclusively uses for all its blitting.

This allows the engine to be pretty fast, considering its complexity. Running at full-tilt (max frame rate allowed in Flash) on my machine uses only about 20% of the CPU.

Have a look and a walk around. Arrow keys or WSAD move.

You are missing some Flash content that should appear here! Perhaps your browser cannot display it, or maybe it did not initialise correctly.

Update November 06:
This now uses Flash 10, and all Array objects have been replaced with Vectors. This has not provided any apparent performance increase, but it makes my code look a lot better. :)
Update November 07:
It now pulls button scripting (which is just movement at this point) from this file on the server, using the custom o2s scripting language.
Update August 16 (2009):
File formats rewritten to binary, file system layout replaced with a single zip file.

Really nice work Cory! You

Really nice work Cory! You never fail to impress! :-)

I updated this to use Flash

I updated this to use Flash 10. You’ll have to install the new plugin if you want to see it now. I’m working on integrating SWFObject or something to simplify both my posting code and the upgrade path.

Have U ever Used Green foot

Have U ever Used Green foot Software to make 2 Dimension Game ?? I think this software make you easier to create 2 dimension game

Hey there Noze Games. :)

Hey there Noze Games. :) Greenfoot is a cool piece of software, thanks for pointing me to it!

Most of the games I build are in Flash, because frankly they sell better than Java games in most circumstances (unless you’re huge like Runescape or Puzzle Pirates). Still, Greenfoot is a totally cool tool, I’m going to have to throw it out next time I teach a programming class. Seems to have a shallower learning curve than most any other graphical programming kit.

o2d was originally intended to be a similar teaching tool — let people build custom-scripted project to learn how to code and structure projects — but that inspiration has waned with time.

Post new comment

The content of this field is kept private and will not be shown publicly.