Dev Stuff
2,266
0
Advertisement
So I figured I might post something that's maybe worth posting.
In Damut Dan there are objects on the screen, that run around, blow things up, and eat babies, and then there are 'templates', that specify common data & parameters for the different types of these on-screen objects.
Templates are loaded from XML files during load time, and the on-screen objects are 'spawned' during game play.
Every object is instantiated with a template, that it accesses when referencing common data. There might be a 'skeleton warrior' template, which specifies that every skeleton warrior object will draw skeletionWarriorLoinCloth.png, and be given a bone-gun as a weapon.
This was done to cut down on the amount of memory used at run-time. Really nothing out of the ordinary here.
All objects in Damut Dan can are one of two things - static background objects (trees in the distance, etc.), or dynamic objects (everything else). Dynamic objects are really the meat of the game. They contain all of the game logic, and the game logic really only refers to them (not to static objects). Any object 'spawned' during game play will be a dynamic object. Also, any type referenced in an XML file will be a dynamic object.
Treating everything as a dynamic object gives us a lot of power.
For instance, the information for dynamic objects relating to 'gibbing' specify objects to spawn like so:
Here you see several 'gib piece templates'. Each ObjectTemplateFile property value is the name of another dynamic object xml file. So, using this system, you could theoretically have an object gib into more instances of the same object, or puppies, or enemies, or chainsaw rockets, or... you get the idea.
I decided to take advantage of .Net's reflection system, and allow us to create instances of classes specified at runtime.
In this template data file, we see two reflection-y parameters: TypeName and GameObjectTypeName. TypeName specifies what C# class the template itself is, and GameObjectTypeName specifies what C# class to instantiate when spawning objects that reference this template.
In this particular example, we see that the user simply specifies the default classes for both the template and the dynamic objects that use it, but we could specify any sub-classes of those classes.
XML Driven Design in Damut Dan
Templates and Objects
In Damut Dan there are objects on the screen, that run around, blow things up, and eat babies, and then there are 'templates', that specify common data & parameters for the different types of these on-screen objects.
Templates are loaded from XML files during load time, and the on-screen objects are 'spawned' during game play.
Every object is instantiated with a template, that it accesses when referencing common data. There might be a 'skeleton warrior' template, which specifies that every skeleton warrior object will draw skeletionWarriorLoinCloth.png, and be given a bone-gun as a weapon.
This was done to cut down on the amount of memory used at run-time. Really nothing out of the ordinary here.
Everything is an Object
All objects in Damut Dan can are one of two things - static background objects (trees in the distance, etc.), or dynamic objects (everything else). Dynamic objects are really the meat of the game. They contain all of the game logic, and the game logic really only refers to them (not to static objects). Any object 'spawned' during game play will be a dynamic object. Also, any type referenced in an XML file will be a dynamic object.
Treating everything as a dynamic object gives us a lot of power.
For instance, the information for dynamic objects relating to 'gibbing' specify objects to spawn like so:
...> <Template ObjectTemplateFile="skaterGib01" Count="10" XRangeMin="-32" XRangeMax="32" YRangeMin="-32" YRangeMax="0"/> <Template ObjectTemplateFile="skaterGib02" Count="10" XRangeMin="-32" XRangeMax="32" YRangeMin="0" YRangeMax="32"/> The Magic of Reflection
I decided to take advantage of .Net's reflection system, and allow us to create instances of classes specified at runtime.
TypeName="DamutDan.DynamicObjectTemplate" GameObjectTypeName="DamutDan.DynamicObject" ...In this template data file, we see two reflection-y parameters: TypeName and GameObjectTypeName. TypeName specifies what C# class the template itself is, and GameObjectTypeName specifies what C# class to instantiate when spawning objects that reference this template.
In this particular example, we see that the user simply specifies the default classes for both the template and the dynamic objects that use it, but we could specify any sub-classes of those classes.
Advertisement
Advertisement
Advertisement
Discussion