portfolio past work
resumehire me
lifeabout me
  • News
  • Dev Blog
Technology+1 | Sun 29 Aug 2010

OUCH! I just lost like 20 minutes of typing. Ah well. Guess I'll give you the short version then.

A new game idea has floated into my head. And its inspired me to start working on the Engine again. I plan on writing about the game details once I flesh it out a bit more. Which reminds me about the title of this entry. So, why technology+1? Well, I've added another major opensource library to the Engine.

Which library you ask? This one TiledLib and its addition has been monumental. Being able to place a GameObject inside the editor and edit its properties? Priceless. A Map Editor is a great investment and huge timesaver. Finally, the days of reloading the game too see if an object is in the right position are over!

Here's a short video of the state of the Engine with the TiledLib addition. The map being demo'ed has the following setup:

  • (ObjectLayer) Effects: the 5 glow sprites.
  • (ObjectLayer) Mechanics: timed trigger to create orbs every 5 seconds.
  • (ObjectLayer) Items: collectable stars.
  • (ObjectLayer) Boundary: walls to prevent the player from walking through the mountains/trees.
  • (ObjectLayer) Enemies: not used just yet.
  • (TileLayer) Tiles: defines the map using the tileset.
Map Editor ObjectLayers are coloured.

The next step is taking the data from the map and importing it into the engine. Luckily TiledLib does all the heavy lifting. Awesome right? All you have todo is link the MapObjects to your GameObjects. Here, I'll show you how I did it.

The map is loaded into a WorldObject which is responsible for drawing the tile layer, and loading all the objects into the engine. Each ObjectLayer calls this routine:

    private void setupGameObjects(MapObjectLayer m_layer) {
        foreach (MapObject m_obj in m_layer.Objects)
        {
            // Import all the information from the map object
            // type, name, start position, and properties
            string w_type = (string)m_obj.Type;
            string w_name = (string)m_obj.Name;
            Vector2 w_position = new Vector2(m_obj.Bounds.X + m_obj.Bounds.Width / 2,
            m_obj.Bounds.Y + m_obj.Bounds.Height / 2);
            Dictionary<string, string> w_properties = new Dictionary<string, string>();

            w_properties.Add("width", m_obj.Bounds.Width.ToString());
            w_properties.Add("height", m_obj.Bounds.Height.ToString());

            w_properties.Add("start_x", w_position.X.ToString());
            w_properties.Add("start_y", w_position.Y.ToString());

            foreach (Property m_property in m_obj.Properties)
            {
                w_properties.Add(m_property.Name,(String) m_property);
            }

            // Find the right WorldObject factory function based on the type
            // of the mapobject.
            BaseObject w_obj;
            w_obj = WorldFactory.LookupCreateFunction(w_type)(Engine.level1,w_properties);
        }
  }

See, Easy right? This may not be the best way, but it works for now. Thanks Nick!

Oh and here's that video

New Project

KyleRead More
bostelk@gmail.ca
give me a call. skim 140 characters. waste some time watching videos. look at some fancy drawings.