Since Traveling Europe, I've been focusing mainly on my side project. Specifically, I've been trying to implement a level editor for my prototype game engine:

{gallery}stories/game_editor_pics{/gallery}

I found this stuff such a pleasing distraction.

For a while, I've been creating new levels that are automatically generated. That is, the generation and placement of the level pickups have been random, and the level, which is basically a maze, is automatically created & configured each time. What I needed, was to be able to create a way to design levels more explicitly and creatively.

I decided that I'd start creating a level editor project which would read all the game's assets and use them to define the level and place game objects in the level. The idea is then to be able to save the configuration of the level design in the editor out to a file, like a level file, which would then be loaded into the game.

This is what a designed level gets serialized down to:

<?xml version="1.0" encoding="utf-8"?>
<level cols="10" rows="10" autoPopulatePickups="False">
  <room number="0" top="True" right="True" bottom="False" left="True">
    <object name="GoldPickup" type="Pickup" resourceId="19" assetPath="game/assets/coin_gold.png">
      <property name="value" value="5" />
    </object>
  </room>
  <room number="1" top="True" right="False" bottom="False" left="True">
    <object name="GoldPickup" type="Pickup" resourceId="19" assetPath="game/assets/coin_gold.png">
      <property name="value" value="5" />
    </object>
  </room>
...

As I also wanted an editor to place pickups etc, I needed to define the properties of the pickups like how many points each type of pickup would have and which asset should be used to draw the pickup etc. This allows me to configure the maze by simply clicking on the walls to hide/show them. Also, I can add arbitrary game objects (like pickups) and then configure their properties before adding them to the room. These will then be loaded when the level starts up in the game.

The assets that the game uses are defined in a resource file which specifies the metadata about the asset, like its path, the type of asset and other metadata. I use this file, just like the game does and that's how I can load and manipulate the same assets that the game has access to. This is what the resources.xml file looks like: 

<?xml version="1.0" encoding="utf-8"?>

<!-- List of all asset in the game -->
  <Asset uid="4" scene="0" name="medium.wav" type="fx" filename="Assets/medium.wav"></Asset>
  <Asset uid="5" scene="0" name="low.wav" type="fx" filename="Assets/low.wav"></Asset>  
  <Asset uid="9" scene="3" name="p1.png" type="graphic" filename="Assets/Platformer/Base pack/Player/p1_walk/p1_walk.png" width="256" height="512">
    <sprite>
      <animation>
        <keyframes>
          <keyframe x="0" y="0" w="67" h="92"/>
          <keyframe x="66" y="0" w="66" h="93"/>
          <keyframe x="132" y="0" w="67" h="92"/>
          <keyframe x="0" y="93" w="67" h="93"/>
          <keyframe x="67" y="93" w="66" h="93"/>
          <keyframe x="133" y="93" w="71" h="92"/>
          <keyframe x="0" y="186" w="71" h="93"/>
          <keyframe x="71" y="186" w="71" h="93"/>
          <keyframe x="142" y="186" w="70" h="93"/>
          <keyframe x="0" y="279" w="71" h="93"/>
          <keyframe x="71" y="279" w="67" h="92"/>
        </keyframes>
      </animation> 
    </sprite>  
  </Asset>
  <Asset uid="10" scene="3" name="p2.png" type="graphic" filename="Assets/Platformer/Base pack/Player/p2_walk/p2_walk.png" width="256" height="512">
     <sprite>
      <animation>
        <keyframes>
          <keyframe x="0" y="0" w="67" h="92"/>
          <keyframe x="67" y="0" w="66" h="93"/>
          <keyframe x="133" y="0" w="66" h="91"/>
          <keyframe x="0" y="93" w="67" h="91"/>
          <keyframe x="67" y="93" w="66" h="91"/>
          <keyframe x="133" y="93" w="69" h="90"/>
          <keyframe x="0" y="184" w="69" h="91"/>
          <keyframe x="69" y="184" w="69" h="92"/>
          <keyframe x="138" y="184" w="68" h="92"/>
          <keyframe x="0" y="276" w="69" h="93"/>
          <keyframe x="69" y="276" w="67" h="92"/>
        </keyframes>
      </animation> 
    </sprite>  
  </Asset>
 
</Assets>

It's taken me a while to get to this point because for a long time I've not actually been concerned with not having this ability, as my main concern was working on the actual game engine code. The thing that was taking a lot of my time, was getting the framerate to be consistent and to run at a constant framerate.

Also, now that I've got to a point where the game engine is basically functional, I can focus on introducing elements of a primitive game like characters, AI and stuff like that which really depends on the rest of the system is predictable and working well.

Also, one of the other main reasons why I needed a way to create levels explicitly like this, is so that I can get two network games to load the same level instead of both loading two different randomly generated levels!

The levels are XML and I'm enjoying the process of writing the level generation code in C# and then writing the corresponding level loading routines in C++. I used JSON to define the network protocol for the multi-player network functionality because it's a bit less verbose than XML, but as the XML is used to define the game settings and to specify the game's resources, I've just opted to use XML for defining the levels also.

So far, it works OK...