QUICK! You have 48 hours to make game… but you don’t really know game engines that well and you don’t want to spend half your time learning one.
What if there was a way to rapidly prototype 2D games in XNA without having to actually know the details of collision systems, graphics rendering, etc? And it used Ogmo Editor as the basis for designing levels, so you can very quickly put together and experiment with level design separate from the code base?
Molyjam 2012 was actually my first game jam that I participated in, so I found myself in the odd position of having to make a game in 48 hours but not having anything to actually rapidly prototype with. So after Molyjam was over, I got the source code from Old Man Baby, stripped out the game-specific parts and put together Protogame. It’s been sitting on my hard drive for quite a while, so after being reminded on Twitter about game engines I thought I should probably, you know, actually release it.
Download
First up, you can download Protogame from Redpoint Code. It’s set up as a Visual Studio 2010 solution w/ .NET 4. You will also need to install XNA if you don’t have that.
EDIT: Protogame is licensed under MIT (open source).
Basics
I’m only going to cover the basics in this blog post (there isn’t all that much to Protogame anyway; it’s meant to be simple by design). So in the example you can see that we define ExampleGame:
|
1 |
public class ExampleGame : PlatformerGame<ExampleWorld> |
which inherits from PlatformerGame<ExampleWorld>. This says that we’re going to make a platformer game and that ExampleWorld will be controlling the main game flow (world != level). So let’s look at ExampleWorld with all of the functional code stripped out:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
public class ExampleWorld : PlayerWorld { // .. variables here .. public override void DrawBelow(GameContext context) { base.DrawBelow(context); // Executed before everything is drawn. } public override void DrawAbove(GameContext context) { // Executed after everything is drawn. base.DrawAbove(context); } public override bool Update(GameContext context) { // Get our base class to update; if this says we should // stop processing, then we propagate this result. bool handle = base.Update(context); if (!handle) return false; // Called every cycle (step). // // Things to do here are: // * Update player positions (like in the actual example code). // * Handle generic keyboard / mouse events, etc. // // Return true to update entities; false to not. return true; } } |
For those of you used to Game Maker, this might look pretty familiar, only instead of in an object these events apply globally throughout the entire game’s execution. But where do we actually load and design levels? The key is in the LoadLevel() method. It can be used like so:
|
1 2 |
// Load our initial level. this.World.LoadLevel("Level0"); |
This loads the Ogmo Editor level from the file “Resources\Level0.oel”, and handles clearing out all the entities in the existing level, transitioning between levels and loading all of the entities in from the level data. It’s all done for you.
The example comes with a project and example level in the Resources folder which you can use as a starting point for creating levels that are loadable by Protogame.
Tiles, Entities and TileEntities
Here’s a quick table to map the terms in Ogmo Editor with the terms / classes used inside Protogame:
| Ogmo Editor | Protogame |
|---|---|
| Solids | SolidTile (provided automatically) |
| Tiles | Tile |
| Entities | EntityTile |
and a comparison of each of the classes:
| Class | Created when | Drawing | Updating | Collidable | Animated | Alignable |
|---|---|---|---|---|---|---|
| Tile | Level Load | Done for you | N/A | N/A | No | Implicit |
| EntityTile | Level Load | Draw() method | Update() method | Provided | No | Implicit |
| Entity | Runtime | Draw() method | Update() method | Provided | Yes | Provided |
So from this we can see that entities are the most powerful; they’re collidable, can be animated, automatically aligned and can have their Draw and Update methods overridden. Unlike tiles or entity tiles, they are also intended to change position as the game plays, where as the tiles and entity tiles are not.
But entities can’t be specified inside Ogmo Editor; they have to be created during the game. So how do we solve this? We use spawners. A spawner is an EntityTile that does nothing but read in attributes from the Ogmo Editor level and then as it’s first Update() cycle, creates the desired entity. Each type of entity that you want to specify inside the Ogmo Editor will have it’s own spawner class and you can see this in the example code in the form of SpawnPlayerTile. Let’s look at that class now:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
[TileName("spawn", TilesetXmlLoader.XmlLoadMode.Entities)] public class SpawnPlayerTile : EntityTile { private bool m_HasSpawned = false; public SpawnPlayerTile(Dictionary<string , string> attributes) { this.Image = null; this.X = Convert.ToInt32(attributes["x"]); this.Y = Convert.ToInt32(attributes["y"]); this.Width = 32; this.Height = 32; } public override void Update(World rawWorld) { ExampleWorld world = rawWorld as ExampleWorld; if (!this.m_HasSpawned) { world.SpawnPlayer<Player>(this.X, this.Y); world.Player.Y -= 16 + world.Player.PlayerYOffset; this.m_HasSpawned = true; } base.Update(world); } } |
There’s a few important elements here. First is the attribute attached to the class, TileName. This tells the level loader the name of this tile inside Ogmo Editor levels so that it can automatically create instances of this class where ever it sees “spawn” appear in the Ogmo Editor. All Tile and EntityTile classes have a public constructor with a dictionary mapping XML attributes which can be retrieved and used (this is how you read in custom attributes specified in the Ogmo Editor).
We can also see the use of world.SpawnPlayer>Player<. In the cases of worlds derived from PlayerWorld (which the PlatformerGame requires), you can spawn a class derived from Player which contains pre-existing functions for moving left, right, jumping and action keys. It also handles automatically smoothly aligning players to the grid and player animations.
For every other kind of spawner, you will want to simply do world.Entities.Add(entity) to add it to a list of the entities that the world will update and draw for you.
Other Notes
These are the basics that you need to know in order to build games with Protogame. There’s extra features in there like some basic particle systems (derive from ParticleEntity), level transitions (see FadingWorld) and audio entities for playing and panning audio as needed (derive from AudioEntity or PannedAudioEntity). Also if you’re working with a different grid or room size, you should change the constants in the Tileset class.
If you ever need super quick support (like when you’re in a game jam) on how to do something in Protogame, reach out to me on Twitter (@hachque) and I’ll respond as soon as I get the message!



What is the difference between this Ogmo editor and Tiled ( http://www.mapeditor.org )?
And how fine Ogmo runs on Linux?
I’ve never used Tiled, but there’s nothing in the engine that specifically ties it to Ogmo Editor (that’s just what we used during the jam). You can easily replace it by creating another class with equivalent functionality to TilesetXmlLoader and switching out the usage of TilesetXmlLoader with your new class (the only reference to it is in the World class as far as I can remember).