Final Year – Team Project

Armed ‘n’ Cuddly was a game project that I was involved in for 8-9 months of the final year. The game idea is a mix between the collection elements of Pokemon and the platform action of games like Mario 64 and Rayman.

The UML class diagram above shows the initial architecture myself and the other programmers put together. Designing the UML diagrams early on allowed us to build a very powerful and robust system. This system uses advanced techniques like dynamic binding, class registration, events, generics and threading demonstrated in the code samples below.

Code Listing 1. Shows the Class Registration system, helping to keep the project loosely coupled.

   1: // Load all content
   2: protected override void LoadContent()
   3: {
   4:     splash.LoadContent();
   5:  
   6:     loadScreen.LoadContent();
   7:  
   8:     // Starts a new thread to perform a task
   9:     ThreadStart ThreadStarter = delegate
  10:     {
  11:         if (editorMode)
  12:         {
  13:             // Place the code to be run by this thread here
  14:             Engine.GUI.GUIManager.AddToBuildScripts("Panel", Engine.GUI.GUIPanel.CreatePanelWithScript);
  15:             Engine.GUI.GUIManager.AddToBuildScripts("Button", Engine.GUI.GUIButton.CreateButtonWithScript);
  16:             Engine.GUI.GUIManager.AddToBuildScripts("Textbox", Engine.GUI.GUITextbox.CreateTextboxWithScript);
  17:             Engine.GUI.GUIManager.AddToBuildScripts("Listbox", Engine.GUI.GUIListbox.CreateListboxWithScript);
  18:             Engine.GUI.GUIManager.AddToBuildScripts("Object_Dialog", ToolDialogs.Object_Dialog.CreateDialogWithScript);
  19:             Engine.GUI.GUIManager.AddToBuildScripts("Texture_Effect_Dialog", ToolDialogs.Texture_Effect_Dialog.CreateDialogWithScript);
  20:             Engine.GUI.GUIManager.AddToBuildScripts("BumpMap_Effect_Dialog", ToolDialogs.BumpMap_Effect_Dialog.CreateDialogWithScript);
  21:             Engine.GUI.GUIManager.AddToBuildScripts("Particle_Dialog", ToolDialogs.Particle_Dialog.CreateDialogWithScript);
  22:             Engine.GUI.GUIManager.BuildFromScripts("NonContentPipeline_Assets/Scripts/toolGUI.xml", ref loadedObjects);
  23:             renderBoxes = true;
  24:         }
  25:  
  26:         Engine._3D.SceneManager.AddToBuildScripts("Project_Strafe.SceneObjects.StatObject", StatObject.BuildFromScript);
  27:         Engine._3D.SceneManager.AddToBuildScripts("Project_Strafe.SceneObjects.Player", SceneObjects.Player.BuildFromScript);
  28:         Engine._3D.SceneManager.AddToBuildScripts("Project_Strafe.SceneObjects.Enemy", SceneObjects.Enemy.BuildFromScript);
  29:         Engine._3D.SceneManager.AddToBuildScripts("Engine._3D.Particles.SmokePlumeParticleSystem", SmokePlumeParticleSystem.BuildFromScript);
  30:  
  31:         Engine._3D.SceneManager.BuildFromScripts(fileName, ref loadedObjects);
  32:     };
  33:  
  34:     contentLoader = new Thread(ThreadStarter);
  35: }

 

Code Listing 2. Shows the dynamic binding used by SetMaterialValues to allow this rendering method to accept any Effect type regardless of the implementing class.

   1: /// <summary>
   2: /// Draws the model
   3: /// </summary>
   4: /// <param name="transforms">The object space transforms of the model to be rendered</param>
   5: virtual protected void RenderModel(Matrix[] transforms)
   6: {
   7:     foreach (ModelMesh mesh in model_object.Meshes)
   8:     {
   9:         // Note: matWorldTransform multiplies the object space co-ordinates defined in the
  10:         // model file with the world-view-projection co-ords.
  11:         // Might need changing depending on how we create the models
  12:         // and there associated effects.                
  13:         matWorldTransform = transforms[mesh.ParentBone.Index] * worldViewProj;
  14:         foreach (ModelMeshPart part in mesh.MeshParts)
  15:         {
  16:             // As this is a virtual method it will call the parent
  17:             // SetMaterialValues method if it exists else it will call
  18:             // SetMaterialValues defined here!
  19:             SetMaterialValues();
  20:             part.Effect = material.GetEffect();
  21:         }
  22:         mesh.Draw(SaveStateMode.SaveState);
  23:     }
  24: }

 

All this came together to give us a scalable game environment that the design team and programmers could build around.

 

Source Code

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: