Home

Tutorials
Game Engine
Documentation
Papers
Alt. Projects
Audio Projects
The Team
Contributors
Places
Things
DarkWynter
Game Object Tutorial

 

GameObject Abstraction

 The GameObject class provides all functionality required by a 3D world object in our engine.
 
 GameObject is  an abstract, generic, three-dimensional object used by ObjectLibrary.
 It is used as an abstract handle for all 3D world objects by ObjectLibrary, Renderer, and Collision.
 
 GameObject contains the following data-types:
   load     - A xmlNode which includes object instance-specific data such as textures, models, and starting positions.  
  mass     - A collection of physical statistics defining the object in space and physical motion.
  draw     - A collection of content assets defining the way the model should be animated and drawn.
 
 GameObject allows child objects to override the following methods:
   
   Load()
   Update()
   Draw()
   PostDraw()
   ObjectCollisionResponse()
   TerrainCollisionResponse()
 
 The user-defined GameObject may choose which methods it wishes to override.
 In each overridden method, functionality can be supplamented by calling base.Method(), or replaced by not calling base.

 

Pre-defined GameObjects

 Current Engine Layer GameObjects are:
   Terrain
   Player
   Bullet
   Particle
 
 Current Game Layer GameObjects are:
   Human     (extends Player)
   AI        (extends Player)
   Portal    (extends GameObject)
   Skysphere (extends GameObject)

 

How to override GameObject

1) Open one of the level files in "/Content/LevelEdit/".
 
2) Copy one of the existing <GameObject> xml tags and modifying it's fields to suit your GameObject.
 
   <GameObject id="4" x="0.1" z="0.4" grid="unit" typeID="Cera" model="Content/_models/mouse"
               texture="Content/_textures/mouseTex" bumpTexture="Content/_textures/septasoulTexture_bump"
               maxScale="120.0" animated ="true"/>
 
3) In the Game Layer, add the GameObject's Type and Xml-name to UserDefinedTypes.cs.
 
           // Get the Object Type
           string type = gameObject.load.node.LocalName;
 
           // Create the GameObject based on type
           switch (type)
           {
               case "GameObject":
                   if (gameObject.load.node.Attributes["typeID"].Value == "Cera")
                   {
                       gameObject = new CeraAI(gameObject.load);
                       return true;
                   }
                   if (gameObject.load.node.Attributes["typeID"].Value == "Sky")
                   {
                       gameObject = new SkySphere(gameObject.load);
                       return true;
                   } 
                   break;
               default:
                   Console.WriteLine("Error Loading XML Object: " + type);
                   break;
           }
 
4) Add a new class (*.cs) file to the Game layer project in the GameObjects folder. 
 
5) Override the GameObject class.  
Use public override functions including Load(), Update(), and Draw() to modify your GameObject's behavior. 
 
     public class MyObject : GameObject
     {
       public override bool Load(ObjectLibrary objectLibrary)
       {
       }
       public override void Update(ref ObjectLibrary objectLibrary)
       {
       }
       public override Draw Draw()
       {
       }
       public override bool ObjectCollisionResponse(GameObject collidedObject, Vector3 resultantForce, ObjectLibrary objectLibrary)
       {
       }
       public override void TerrainCollisionResponse(Terrain terrain)
       {
       }      
     }