<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Spinneret Design</title>
	<atom:link href="http://spinneretdesign.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://spinneretdesign.com</link>
	<description>The Keyboard Cowboys</description>
	<lastBuildDate>Mon, 09 Jan 2012 18:43:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Part 7: Camera class</title>
		<link>http://spinneretdesign.com/2012/01/07/part-7-camera-class/</link>
		<comments>http://spinneretdesign.com/2012/01/07/part-7-camera-class/#comments</comments>
		<pubDate>Sat, 07 Jan 2012 22:04:45 +0000</pubDate>
		<dc:creator>Jardeth56</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Xna Game Engine]]></category>

		<guid isPermaLink="false">http://spinneretdesign.com/?p=795</guid>
		<description><![CDATA[So this section of my tutorials we are going to cover Cameras, we will be creating two classes our main Camera class and our First Person Camera, later we will be adding a Third Person Camera(Chase Camera). So let&#8217;s look at the code for our main Class that our First Person will inherit from. using [...]]]></description>
			<content:encoded><![CDATA[<p>So this section of my tutorials we are going to cover Cameras, we will be creating two classes our main Camera class and our First Person Camera, later we will be adding a Third Person Camera(Chase Camera).</p>
<p>So let&#8217;s look at the code for our main Class that our First Person will inherit from.</p>
<pre class="brush:csharp">using System;

using Microsoft.Xna.Framework;

using GameEngine;
using GameEngine.Utilities;

using GameEngine.Components;

namespace GameEngine.Cameras

{

  public class Camera : Component, I3DComponent
    {

  Vector3 position = Vector3.Zero;
  Matrix rotationMatrix = Matrix.Identity;
  Vector3 target = new Vector3(0, 0, -1);
  Vector3 up = Vector3.Up;
        Matrix view;

        Matrix projection;

        /// &lt;summary&gt;

        /// Gets or sets the target.

        /// &lt;/summary&gt;

        /// &lt;value&gt;

        /// The target.

        /// &lt;/value&gt;

  public virtual Vector3 Target
        { get { return target; } set { target = value; } }

        /// &lt;summary&gt;

        /// Gets or sets the view.

        /// &lt;/summary&gt;

        /// &lt;value&gt;

        /// The view.

        /// &lt;/value&gt;

        public virtual Matrix View

        { get { return view; } set { view = value; } }

        /// &lt;summary&gt;

        /// Gets or sets the projection.

        /// &lt;/summary&gt;

        /// &lt;value&gt;

        /// The projection.

        /// &lt;/value&gt;

        public virtual Matrix Projection

        { get { return projection; } set { projection = value; } }

        /// &lt;summary&gt;

        /// Gets or sets up.

        /// &lt;/summary&gt;

        /// &lt;value&gt;

        /// Up.

        /// &lt;/value&gt;

  public virtual Vector3 Up
        { get { return up; } set { up = value; } }

        /// &lt;summary&gt;

  /// Gets or sets the position.
        /// &lt;/summary&gt;

        /// &lt;value&gt;

  /// The position.
        /// &lt;/value&gt;

  public virtual Vector3 Position { get { return position; } set { position = value; } } 

        /// &lt;summary&gt;

        /// Gets or sets the scale.

        /// &lt;/summary&gt;

        /// &lt;value&gt;

        /// The scale.

        /// &lt;/value&gt;

  public virtual Vector3 Scale { get { return Vector3.One; } set { } } 

        /// &lt;summary&gt;

        /// Gets or sets the rotation.

        /// &lt;/summary&gt;

        /// &lt;value&gt;

        /// The rotation.

        /// &lt;/value&gt;

        public virtual Matrix Rotation

        {

  get { return rotationMatrix;}
  set{rotationMatrix = value;}
        }

        /// &lt;summary&gt;

  /// Gets or sets the euler rotation.
        /// &lt;/summary&gt;

        /// &lt;value&gt;

  /// The euler rotation.
        /// &lt;/value&gt;

  public Vector3 EulerRotation
        {

            get{return MathUtil.MatrixToVector3(Rotation);}

            set { rotationMatrix = MathUtil.Vector3ToMatrix(value);}

        }

        /// &lt;summary&gt;

        /// Gets the bounding box.

        /// &lt;/summary&gt;

  public virtual BoundingBox BoundingBox
  {get {return new BoundingBox(Position - Vector3.One, Position + Vector3.One);}} 

        /// &lt;summary&gt;

  /// Initializes a new instance of the class.
        /// &lt;/summary&gt;

        /// &lt;param name="Parent"&gt;The parent.&lt;/param&gt;

  public Camera(GameScreen Parent) : base(Parent) { }
        /// &lt;summary&gt;

  /// Initializes a new instance of the class.
        /// &lt;/summary&gt;

        public Camera() : base() { }

        /// &lt;summary&gt;

        /// Updates this instance.

        /// &lt;/summary&gt;

        public override void Update()

        {

  Vector3 newForward = Target - Position;
            newForward.Normalize();

  Matrix rotationMatrixCopy = this.Rotation;
            rotationMatrixCopy.Forward = newForward;

  Vector3 referenceVector = Vector3.Up;
  if (rotationMatrixCopy.Forward.Y == referenceVector.Y || rotationMatrixCopy.Forward.Y == -referenceVector.Y)
  referenceVector = Vector3.Backward; 

            rotationMatrixCopy.Right = Vector3.Cross(this.Rotation.Forward, referenceVector);

            rotationMatrixCopy.Up = Vector3.Cross(this.Rotation.Right, this.Rotation.Forward);

            this.Rotation = rotationMatrixCopy;

            Up = Rotation.Up;

            View = Matrix.CreateLookAt(Position, Target, Up);

            Projection = MathUtil.CreateProjectionMatrix();

        }

    }

}</pre>
<p>So next lets look at our First Person Camera this class is very simple really as most of the work is done in the Camera Class.</p>
<pre class="brush:csharp">using Microsoft.Xna.Framework;

using System;

using GameEngine.Components;

using GameEngine.Utilities;

namespace GameEngine.Cameras{

    // A simple first person camera. Accepts rotation and translation

  public class FPSCamera : Camera
    {

        // Keeps track of the rotation and translation that have been

  // added via RotateTranslate()
        Vector3 rotation;        

        Vector3 translation;  

  public FPSCamera(GameScreen Parent) : base(Parent) { }
  public FPSCamera() : base() { } 

        // This adds to rotation and translation to change the camera view

  public void RotateTranslate(Vector3 Rotation, Vector3 Translation)
        {

            translation += Translation;

            rotation += Rotation;

        }

        public override void Update()

        {

            // Update the rotation matrix using the rotation vector

            Rotation = MathUtil.Vector3ToMatrix(rotation);

  // Update the position in the direction of rotation
            translation = Vector3.Transform(translation, Rotation);

            Position += translation;

            // Reset translation

            translation = Vector3.Zero;

            // Calculate the new target

            Target = Vector3.Add(Position, Rotation.Forward);

            // Have the base Camera update all the matrices, etc.

            base.Update();

        }

    }

}</pre>
<p>So that our Main camera class and our First Person Camera created<br />
Will try and get the next post up a bit sooner that this one.</p>
]]></content:encoded>
			<wfw:commentRss>http://spinneretdesign.com/2012/01/07/part-7-camera-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Part 6: Utilities</title>
		<link>http://spinneretdesign.com/2012/01/05/part-6-utilities/</link>
		<comments>http://spinneretdesign.com/2012/01/05/part-6-utilities/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 12:54:39 +0000</pubDate>
		<dc:creator>Jardeth56</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Xna Game Engine]]></category>

		<guid isPermaLink="false">http://spinneretdesign.com/?p=788</guid>
		<description><![CDATA[So in this post we are going to cover some utilities that will make out life&#8217;s allot easier going forward. So Lets have a look at out first new class it&#8217;s called MathUtil. The Class will have the following function, CreateProjectionMatrix  - Generates a projection matrix for a draw call CreateWorldMatrix &#8211; Creates a world matrix Vector3ToMatrix [...]]]></description>
			<content:encoded><![CDATA[<p>So in this post we are going to cover some utilities that will make out life&#8217;s allot easier going forward.</p>
<p>So Lets have a look at out first new class it&#8217;s called MathUtil.</p>
<p>The Class will have the following function,</p>
<ul>
<li>CreateProjectionMatrix  - Generates a projection matrix for a draw call</li>
<li>CreateWorldMatrix &#8211; Creates a world matrix</li>
<li>Vector3ToMatrix &#8211; Converts a rotation vector into a rotation matrix</li>
<li>MatrixToVector3 &#8211; Converts a rotation matrix into a rotation vector</li>
</ul>
<p>So here the code for our MathUtil class.</p>
<pre class="brush:csharp">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using GameEngine;

namespace GameEngine.Utilities
{
    public static class MathUtil
    {

        /// &lt;summary&gt;
        /// Creates the projection matrix.
        /// &lt;/summary&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public static Matrix CreateProjectionMatrix()
        {
            return Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                (float)Engine.GraphicsDevice.Viewport.Width / (float)Engine.GraphicsDevice.Viewport.Height,
                .01f,
                1000000);
        }

        /// &lt;summary&gt;
        /// Creates the world matrix.
        /// &lt;/summary&gt;
        /// &lt;param name="Translation"&gt;The translation.&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public static Matrix CreateWorldMatrix(Vector3 Translation)
        {
            return CreateWorldMatrix(Translation, Matrix.Identity);
        }

        /// &lt;summary&gt;
        /// Creates the world matrix.
        /// &lt;/summary&gt;
        /// &lt;param name="Translation"&gt;The translation.&lt;/param&gt;
        /// &lt;param name="Rotation"&gt;The rotation.&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public static Matrix CreateWorldMatrix(Vector3 Translation, Matrix Rotation)
        {
            return CreateWorldMatrix(Translation, Rotation, Vector3.One);
        }

        /// &lt;summary&gt;
        /// Creates the world matrix.
        /// &lt;/summary&gt;
        /// &lt;param name="Translation"&gt;The translation.&lt;/param&gt;
        /// &lt;param name="Rotation"&gt;The rotation.&lt;/param&gt;
        /// &lt;param name="Scale"&gt;The scale.&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public static Matrix CreateWorldMatrix(Vector3 Translation, Matrix Rotation, Vector3 Scale)
        {
            return Matrix.CreateScale(Scale) * Rotation * Matrix.CreateTranslation(Translation);
        }

        /// &lt;summary&gt;
        /// Vector3s to matrix.
        /// &lt;/summary&gt;
        /// &lt;param name="Rotation"&gt;The rotation.&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public static Matrix Vector3ToMatrix(Vector3 Rotation)
        {
            return Matrix.CreateFromYawPitchRoll(Rotation.Y, Rotation.X, Rotation.Z);
        }

        /// &lt;summary&gt;
        /// Matrixes to vector3.
        /// &lt;/summary&gt;
        /// &lt;param name="Rotation"&gt;The rotation.&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public static Vector3 MatrixToVector3(Matrix Rotation)
        {
            Quaternion q = Quaternion.CreateFromRotationMatrix(Rotation);
            return new Vector3(q.X, q.Y, q.Z);
        }
    }
}</pre>
<p>Next we are going to Add a Class to help with some graphic stuff, can you guess what we are going to call it? thats right GraphicsUtil</p>
<p>The Class will have the following function,</p>
<ul>
<li>CreateRenderTarget &#8211; This function is going to have multiple signatures within out Class</li>
</ul>
<p>So here&#8217;s the code.</p>
<pre class="brush:csharp">using Microsoft.Xna.Framework.Graphics;
using GameEngine;

namespace GameEngine.Utilities
{
    public static class GraphicsUtil
    {

        /// &lt;summary&gt;
        /// Creates the render target.
        /// &lt;/summary&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public static RenderTarget2D CreateRenderTarget()
        {
            return CreateRenderTarget(Engine.GraphicsDevice.Viewport.Width,
                Engine.GraphicsDevice.Viewport.Height);
        }

        /// &lt;summary&gt;
        /// Creates the render target.
        /// &lt;/summary&gt;
        /// &lt;param name="Width"&gt;The width.&lt;/param&gt;
        /// &lt;param name="Height"&gt;The height.&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public static RenderTarget2D CreateRenderTarget(int Width, int Height)
        {
            return CreateRenderTarget(Width, Height,
                Engine.GraphicsDevice.DisplayMode.Format);
        }

        /// &lt;summary&gt;
        /// Creates the render target.
        /// &lt;/summary&gt;
        /// &lt;param name="Width"&gt;The width.&lt;/param&gt;
        /// &lt;param name="Height"&gt;The height.&lt;/param&gt;
        /// &lt;param name="Format"&gt;The format.&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public static RenderTarget2D CreateRenderTarget(int Width, int Height,
            SurfaceFormat Format)
        {
            return CreateRenderTarget(Width, Height, Format,
                Engine.GraphicsDevice.PresentationParameters.MultiSampleCount,
                Engine.GraphicsDevice.PresentationParameters.DepthStencilFormat);
        }

        /// &lt;summary&gt;
        /// Creates the render target.
        /// &lt;/summary&gt;
        /// &lt;param name="Width"&gt;The width.&lt;/param&gt;
        /// &lt;param name="Height"&gt;The height.&lt;/param&gt;
        /// &lt;param name="Format"&gt;The format.&lt;/param&gt;
        /// &lt;param name="MultiSampleQuality"&gt;The multi sample quality.&lt;/param&gt;
        /// &lt;param name="SampleType"&gt;Type of the sample.&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public static RenderTarget2D CreateRenderTarget(int Width, int Height,
            SurfaceFormat Format, int MultiSampleQuality, DepthFormat SampleType)
        {
            return new RenderTarget2D(Engine.GraphicsDevice, Width,
                Height, false, Format, SampleType, MultiSampleQuality,
                RenderTargetUsage.DiscardContents);
        }

        /// &lt;summary&gt;
        /// Creates the resolve texture.
        /// &lt;/summary&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public static RenderTarget2D CreateResolveTexture()
        {
            return new RenderTarget2D(Engine.GraphicsDevice,
                Engine.GraphicsDevice.Viewport.Width,
                Engine.GraphicsDevice.Viewport.Height, false,
                Engine.GraphicsDevice.DisplayMode.Format,
                Engine.GraphicsDevice.PresentationParameters.DepthStencilFormat,
                Engine.GraphicsDevice.PresentationParameters.MultiSampleCount,
                RenderTargetUsage.DiscardContents);
        }
    }
}</pre>
<p>That&#8217;s it for this post.</p>
]]></content:encoded>
			<wfw:commentRss>http://spinneretdesign.com/2012/01/05/part-6-utilities/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New year</title>
		<link>http://spinneretdesign.com/2012/01/03/new-year/</link>
		<comments>http://spinneretdesign.com/2012/01/03/new-year/#comments</comments>
		<pubDate>Tue, 03 Jan 2012 10:37:18 +0000</pubDate>
		<dc:creator>Jardeth56</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://spinneretdesign.com/?p=784</guid>
		<description><![CDATA[So its a new year!! I have my engine 90% complete now after a hard push over the holidays, so am hoping to get some more posts written this week and get them up.]]></description>
			<content:encoded><![CDATA[<p>So its a new year!!</p>
<p><span id="more-784"></span></p>
<p>I have my engine 90% complete now after a hard push over the holidays, so am hoping to get some more posts written this week and get them up.</p>
]]></content:encoded>
			<wfw:commentRss>http://spinneretdesign.com/2012/01/03/new-year/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Finite-state machine</title>
		<link>http://spinneretdesign.com/2011/12/13/finite-state-machine/</link>
		<comments>http://spinneretdesign.com/2011/12/13/finite-state-machine/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 19:49:01 +0000</pubDate>
		<dc:creator>Jardeth56</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Finite-state machine]]></category>
		<category><![CDATA[FSM]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://spinneretdesign.com/?p=758</guid>
		<description><![CDATA[I know I promised the post last week, but it&#8217;s the run up to xmas and I have had so much work to do its unreal. &#160; Well let&#8217;s jump right in, Finite State Machines or FSMs have for many years been the AI coder&#8217;s first choice to create the illusion of intelligence but FSMs [...]]]></description>
			<content:encoded><![CDATA[<p>I know I promised the post last week, but it&#8217;s the run up to xmas and I have had so much work to do its unreal.</p>
<p>&nbsp;</p>
<p>Well let&#8217;s jump right in, Finite State Machines or FSMs have for many years been the AI coder&#8217;s first choice to create the illusion of intelligence but FSMs are not just used in games AI I have even found then in database APIs.</p>
<p>Here is the best description of a FSM I have found.</p>
<div><center></p>
<table style="border-collapse: collapse; background: #d9d9d9;" border="0">
<colgroup>
<col style="width: 638px;" /></colgroup>
<tbody valign="top">
<tr style="height: 90px;">
<td style="padding-left: 7px; padding-right: 7px;">
<p style="text-align: center;"><em>A finite state machine is a device, or a model of a model of a device, which has a finite number of states it can be in at any given time and can operate on input to either make transitions from one state to another or to cause an output or action to take place. A finite state machine can only be in one state at any moment in time.<br />
</em></p>
</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p></center></div>
<p>&nbsp;</p>
<p>If you looking for more information on FMS then I really recommend the book Programming Game AI by Example, this book is based on C++ but the code can easily be transferred to C#.</p>
<p>&nbsp;</p>
<p>So let&#8217;s start writing some code in Visual Studio creates two projects one Console Application called OrcTest and one Class Library called Ai.</p>
<p>So we are going to start by creating a class called StateTransitionTable.cs in the Ai project.</p>
<pre class="brush:csharp">using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;

namespace Ai
{
    abstract public class StateTransitionTable
    {
        protected Dictionary&lt;object, IState&gt; table = new Dictionary&lt;object, IState&gt;();

        public void SetState(object evt, IState state)
        {
            table.Add(evt, state);
        }

        public IState GetState(object evt)
        {
            Ai.IState i = null;

            try
            {
                i = table[evt];

            }
            catch (KeyNotFoundException)
            {
                return null;
            }

            return i;
        }
    }
}</pre>
<p>Next we are going to create a new class file with our Interface code that each state will inherit from and I called the file IState.cs</p>
<pre class="brush:csharp">using System;
using System.Collections.Generic;
using System.Text;

namespace Ai
{
    public interface IState
    {
         void Enter(Entity e);
         void Execute(Entity e);
         void Exit(Entity e);
    }
}</pre>
<p>And last but not least we will create one more file called Entity.</p>
<pre class="brush:csharp">using System;
using System.Collections.Generic;
using System.Text;

namespace Ai
{
    abstract public class Entity
    {
        protected static Ai.StateTransitionTable transitionTable = null;
        protected IState currentState = null;

        public void UpdateState()
        {
            if (currentState != null)
                currentState.Execute(this);
            else
                System.Diagnostics.Trace.WriteLine("zero state");
        }

        public object Event
        {
            set
            {
                if (value == null)
                {
                    currentState.Exit(this);
                    currentState = null;
                    return;
                }

                IState i = transitionTable.GetState(value);

                if (i != null)
                {
                    if (currentState != null)
                        currentState.Exit(this);

                    currentState = i;
                    currentState.Enter(this);
                }
            }
        }
    }
}</pre>
<p>&nbsp;</p>
<p>Now we have our base code it&#8217;s time to write our State, in this system am going to create 4 states.</p>
<ul>
<li>AttackState</li>
<li>FleeState</li>
<li>IdleState</li>
<li>PatrolState</li>
</ul>
<p>I am only going to show you one state file as all 4 States are the same.</p>
<pre class="brush:csharp">using System;
using System.Collections.Generic;
using System.Text;

namespace Ai
{
    public class AttackState : Ai.IState
    {
        public virtual void Enter(Entity e)
        {
            throw new NotImplementedException();
        }

        public virtual void Execute(Entity e)
        {
            throw new NotImplementedException();
        }

        public virtual void Exit(Entity e)
        {
            throw new NotImplementedException();
        }
    }
}</pre>
<p>So that&#8217;s our FSM setup next we are going to use is it in our OrcTest application.</p>
<p>So we will start by creating a class call Orc.css and add this code</p>
<pre class="brush:csharp">using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using Ai;

namespace OrcTest
{
    enum OrcEvent
    {
        Idle,
        Patrol,
        Attack,
        Flee,
    }

    class OrcTransitionTable : Ai.StateTransitionTable
    {
        public OrcTransitionTable()
        {
            base.table.Add(OrcEvent.Idle, new IdleState());
            base.table.Add(OrcEvent.Patrol, new PatrolState());
            base.table.Add(OrcEvent.Attack, new AttackState());
            base.table.Add(OrcEvent.Flee, new FleeState());
        }
    }

    class Orc : Ai.Entity
    {
        private int _piss;

        public int Piss
        {
            get { return _piss; }
            set { _piss = value; }
        }
        static Orc()
        {
            transitionTable = new OrcTransitionTable();
        }
    }
}</pre>
<p>Next we will modify the Program.cs file with the following code.</p>
<pre class="brush:csharp">using System;
using System.Collections.Generic;
using System.Text;

namespace OrcTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Orc o = new Orc();

            o.Event = OrcEvent.Idle;
            o.UpdateState();

            o.Event = OrcEvent.Patrol;
            o.UpdateState();

            o.Event = OrcEvent.Attack;
            o.UpdateState();

            o.Event = OrcEvent.Flee;
            o.UpdateState();

            o.Event = null;
            o.UpdateState();

            Console.ReadLine();
        }
    }

}</pre>
<p>So next we are going to override the states we created earlier will Orc states</p>
<p>Again I will just show you one as they are all basically the same.</p>
<p>&nbsp;</p>
<pre class="brush:csharp">using System;
using System.Collections.Generic;
using System.Text;
using Ai;

namespace OrcTest
{
    class AttackState: Ai.AttackState
    {
            public override void Enter(Ai.Entity e)
            {
                Console.WriteLine("Enter Attack State");
            }

            public override void Execute(Ai.Entity e)
            {
                Console.WriteLine("In Attack State");
            }

            public override void Exit(Ai.Entity e)
            {
                Console.WriteLine("Exit Attack State");
            }
        }
    }</pre>
<p>And that&#8217;s it we have a basic FSM.</p>
<p>&nbsp;</p>
<p>Hope you liked to post feel free to comment</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://spinneretdesign.com/2011/12/13/finite-state-machine/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Over a week</title>
		<link>http://spinneretdesign.com/2011/12/06/over-a-week/</link>
		<comments>http://spinneretdesign.com/2011/12/06/over-a-week/#comments</comments>
		<pubDate>Tue, 06 Dec 2011 08:39:23 +0000</pubDate>
		<dc:creator>Jardeth56</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://spinneretdesign.com/?p=756</guid>
		<description><![CDATA[I know its been over a week since my last post on my Xna game engine just my work has been very busy. But dont fear I have a Part 6  in the pipeline and a mini tutorial on Finite-state machine coming up this week.]]></description>
			<content:encoded><![CDATA[<p>I know its been over a week since my last post on my Xna game engine just my work has been very busy.</p>
<p>But dont fear I have a Part 6  in the pipeline and a mini tutorial on Finite-state machine coming up this week.</p>
]]></content:encoded>
			<wfw:commentRss>http://spinneretdesign.com/2011/12/06/over-a-week/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Part 5: Adding Unit tests</title>
		<link>http://spinneretdesign.com/2011/11/26/part-5-adding-unit-tests/</link>
		<comments>http://spinneretdesign.com/2011/11/26/part-5-adding-unit-tests/#comments</comments>
		<pubDate>Sat, 26 Nov 2011 20:00:00 +0000</pubDate>
		<dc:creator>Jardeth56</dc:creator>
				<category><![CDATA[Xna Game Engine]]></category>
		<category><![CDATA[xna games engine tutorial]]></category>

		<guid isPermaLink="false">http://spinneretdesign.com/?p=700</guid>
		<description><![CDATA[I tutorial is completly optional and not needed for our engine but I thought it would be worth while to add some Unit Tests. I am using mstest that comes built into visual studio 2010, you could also use nunit if you wished or any unit test framework that works with .net. Am normally very [...]]]></description>
			<content:encoded><![CDATA[<p>I tutorial is completly optional and not needed for our engine but I thought it would be worth while to add some Unit Tests.</p>
<p>I am using mstest that comes built into visual studio 2010, you could also use nunit if you wished or any unit test framework that works with .net.</p>
<p>Am normally very lazy with it comes to unit tests at work I never write them unless I am made to which is really bad of me I know this and every other programmer know it as well that we should be using unit test to make our coding better but its hard to fit them in when your working to a deadline.</p>
<p>So I thought  I would include some in this.</p>
<p>Lets Start by creating a new unit test project and calling it EngineTests</p>
<p>Lest remane the Class UnitTest1.cs to EngineTest.cs and add the following code.</p>
<pre class="brush:csharp">using Engine;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Microsoft.Xna.Framework;
using Engine.Components;
using Microsoft.Xna.Framework.Graphics;

namespace EngineTests
{

    /// &lt;summary&gt;
    ///This is a test class for EngineTest and is intended
    ///to contain all EngineTest Unit Tests
    ///&lt;/summary&gt;
    [TestClass()]
    public class EngineTest : Game
    {

        private TestContext testContextInstance;

        /// &lt;summary&gt;
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///&lt;/summary&gt;
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }
        Game game = new Game();
        GraphicsDeviceManager graphics;
        GraphicsDevice device;

        //Use TestInitialize to run code before running each test
        [TestInitialize()]
        public void EngineSetup()
        {
            graphics = new GraphicsDeviceManager(game);
            graphics.PreferredBackBufferWidth = 500;
            graphics.PreferredBackBufferHeight = 500;
            graphics.IsFullScreen = false;
            graphics.ApplyChanges();
            device = graphics.GraphicsDevice;
            device.Clear(Color.CornflowerBlue);
            Engine.Engine.SetupEngine(graphics);
        }
    }
}</pre>
<p>&nbsp;</p>
<p>So this will set up a new engine that the rest of our test will use to run.</p>
<p>Next we will add some tests for the GameScreen class.</p>
<pre class="brush:csharp">using Engine.GameScreens;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Engine.Components;

namespace EngineTests
{

    /// &lt;summary&gt;
    ///This is a test class for GameScreenTest and is intended
    ///to contain all GameScreenTest Unit Tests
    ///&lt;/summary&gt;
    [TestClass()]
    public class GameScreenTest
    {

        private TestContext testContextInstance;

        /// &lt;summary&gt;
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///&lt;/summary&gt;
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        /// &lt;summary&gt;
        ///A test for GameScreen Constructor
        ///&lt;/summary&gt;
        [TestMethod()]
        public void GameScreenConstructorTest()
        {
            string Name = "TESTSCREEN";
            GameScreen target = new GameScreen(Name);
            Assert.IsNotNull(target);
        }

        /// &lt;summary&gt;
        ///A test for Disable
        ///&lt;/summary&gt;
        [TestMethod()]
        public void DisableTest()
        {
            string Name = "TESTSCREEN1";
            GameScreen target = new GameScreen(Name);
            target.Disable();
            Assert.IsNotNull(target);
        }

        /// &lt;summary&gt;
        ///A test for Initialize
        ///&lt;/summary&gt;
        [TestMethod()]
        public void InitializeTest()
        {
            string Name = "TESTSCREEN3";
            GameScreen target = new GameScreen(Name);
            target.Initialize();
            Assert.AreEqual(target.Initialized, true);
        }

        /// &lt;summary&gt;
        ///A test for ToString
        ///&lt;/summary&gt;
        [TestMethod()]
        public void ToStringTest()
        {
            string Name = "TESTSCREEN4";
            GameScreen target = new GameScreen(Name);
            string expected = "TESTSCREEN4";
            string actual;
            actual = target.ToString();
            Assert.AreEqual(expected, actual);
        }

        /// &lt;summary&gt;
        ///A test for Initialized
        ///&lt;/summary&gt;
        [TestMethod()]
        public void InitializedTest()
        {
            string Name = "TESTSCREEN6";
            GameScreen target = new GameScreen(Name);
            bool expected = true;
            bool actual;
            target.Initialized = expected;
            actual = target.Initialized;
            Assert.AreEqual(expected, actual);
        }
    }
}</pre>
<p>Next some test for the GameSceenCollection</p>
<pre class="brush:csharp">using Engine.GameScreens;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace EngineTests
{

    /// &lt;summary&gt;
    ///This is a test class for GameScreenCollectionTest and is intended
    ///to contain all GameScreenCollectionTest Unit Tests
    ///&lt;/summary&gt;
    [TestClass()]
    public class GameScreenCollectionTest
    {

        private TestContext testContextInstance;

        /// &lt;summary&gt;
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///&lt;/summary&gt;
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        /// &lt;summary&gt;
        ///A test for GameScreenCollection Constructor
        ///&lt;/summary&gt;
        [TestMethod()]
        public void GameScreenCollectionConstructorTest()
        {
            GameScreenCollection target = new GameScreenCollection();
            Assert.IsNotNull(target);
        }

        /// &lt;summary&gt;
        ///A test for GetKeyForItem
        ///&lt;/summary&gt;
        [TestMethod()]
        [DeploymentItem("Engine.dll")]
        public void GetKeyForItemTest()
        {
            GameScreenCollection_Accessor target = new GameScreenCollection_Accessor();
            GameScreen item = new GameScreen("TESTSCREEN7");
            string expected = "TESTSCREEN7";
            string actual;
            actual = target.GetKeyForItem(item);
            Assert.AreEqual(expected, actual);
        }
    }
}</pre>
<p>And finally our Component class tests</p>
<pre class="brush:csharp">using Engine.Components;<br />
using Microsoft.VisualStudio.TestTools.UnitTesting;<br />
using System;<br />
using Engine.GameScreens;<br />
using Microsoft.Xna.Framework;<br />
using Microsoft.Xna.Framework.Graphics;</p>
<p>namespace EngineTests<br />
{<br />
    /// &lt;summary&gt;<br />
    ///This is a test class for ComponentTest and is intended<br />
    ///to contain all ComponentTest Unit Tests<br />
    ///&lt;/summary&gt;<br />
    [TestClass()]<br />
    public class ComponentTest<br />
    {</p>
<p>        private TestContext testContextInstance;</p>
<p>        /// &lt;summary&gt;<br />
        ///Gets or sets the test context which provides<br />
        ///information about and functionality for the current test run.<br />
        ///&lt;/summary&gt;<br />
        public TestContext TestContext<br />
        {<br />
            get<br />
            {<br />
                return testContextInstance;<br />
            }<br />
            set<br />
            {<br />
                testContextInstance = value;<br />
            }<br />
        }</p>
<p>        Game game = new Game();<br />
        GraphicsDeviceManager graphics;<br />
        GraphicsDevice device;</p>
<p>        //Use TestInitialize to run code before running each test<br />
        [TestInitialize()]<br />
        public void MyTestInitialize()<br />
        {<br />
            graphics = new GraphicsDeviceManager(game);<br />
            graphics.PreferredBackBufferWidth = 500;<br />
            graphics.PreferredBackBufferHeight = 500;<br />
            graphics.IsFullScreen = false;<br />
            graphics.ApplyChanges();<br />
            device = graphics.GraphicsDevice;<br />
            device.Clear(Color.CornflowerBlue);<br />
            Engine.Engine.SetupEngine(graphics);<br />
        }</p>
<p>        /// &lt;summary&gt;<br />
        ///A test for InitializeComponent<br />
        ///&lt;/summary&gt;<br />
        [TestMethod()]<br />
        [DeploymentItem("Engine.dll")]<br />
        public void InitializeComponentTest()<br />
        {<br />
            Component_Accessor target = new Component_Accessor(new GameScreen("TESTSCREEN8"));<br />
            GameScreen Parent = new GameScreen("TESTSCREEN9");</p>
]]></content:encoded>
			<wfw:commentRss>http://spinneretdesign.com/2011/11/26/part-5-adding-unit-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Part 4: The Engine</title>
		<link>http://spinneretdesign.com/2011/11/26/part-4-the-engine/</link>
		<comments>http://spinneretdesign.com/2011/11/26/part-4-the-engine/#comments</comments>
		<pubDate>Sat, 26 Nov 2011 18:16:00 +0000</pubDate>
		<dc:creator>Jardeth56</dc:creator>
				<category><![CDATA[Xna Game Engine]]></category>
		<category><![CDATA[xna games engine tutorial]]></category>

		<guid isPermaLink="false">http://spinneretdesign.com/?p=688</guid>
		<description><![CDATA[Well I know its only been a couple of hours since my last post but since we haven&#8217;t really got anything working yet and there is errors in the code due to missing classes, I thought I would get this one up as soon as&#160;possible. &#160; So lets get started. The Engine Class this is [...]]]></description>
			<content:encoded><![CDATA[<p>Well I know its only been a couple of hours since my last post but since we haven&#8217;t really got anything working yet and there is errors in the code due to missing classes, I thought I would get this one up as soon as&nbsp;possible.</p>
<p>&nbsp;</p>
<p>So lets get started.</p>
<p>The Engine Class this is the main class of the engine so I have named it Engine as I thought that was the most logical name.</p>
<p>Lets start by adding a new class called engine to the root of our folder structure.</p>
<p>Here is the starting code</p>
<pre class="brush:csharp">using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Engine.Components;
using Engine.Services;
using Engine.GameScreens;

namespace Engine
{
    public static class Engine
    {

        public static GraphicsDevice GraphicsDevice;
        public static SpriteBatch SpriteBatch;
        public static GameScreenCollection GameScreens = new GameScreenCollection();
        public static GameTime GameTime;
        public static bool IsInitialized = false;
        public static IEServiceContainer Services;
        public static IEContentManager Content;
        public static GameScreen BackgroundScreen;
        public static GameScreen DefaultScreen;

        /// &lt;summary&gt;
        /// Setups the engine.
        /// &lt;/summary&gt;
        /// &lt;param name="GraphicsDeviceService"&gt;The graphics device service.&lt;/param&gt;
        public static void SetupEngine(IGraphicsDeviceService GraphicsDeviceService)
        {

            Engine.GraphicsDevice = GraphicsDeviceService.GraphicsDevice;
            Engine.SpriteBatch = new SpriteBatch(GraphicsDeviceService.GraphicsDevice);

            Engine.IsInitialized = true;

            Engine.Services = new IEServiceContainer();
            Engine.Services.AddService(typeof(IGraphicsDeviceService), GraphicsDeviceService);

            Engine.Content = new IEContentManager(Services);

            BackgroundScreen = new GameScreen("Engine.BackgroundScreen");
            BackgroundScreen.OverrideUpdateBlocked = true;
            BackgroundScreen.OverrideDrawBlocked = true;
            BackgroundScreen.OverrideInputBlocked = true;

            DefaultScreen = BackgroundScreen;
        }

        /// &lt;summary&gt;
        /// Updates the specified game time.
        /// &lt;/summary&gt;
        /// &lt;param name="gameTime"&gt;The game time.&lt;/param&gt;
        public static void Update(GameTime gameTime)
        {
            Engine.GameTime = gameTime;
            List&lt;GameScreen&gt; updating = new List&lt;GameScreen&gt;();
            foreach (GameScreen screen in GameScreens)
                updating.Add(screen);
            for (int i = GameScreens.Count - 1; i &gt;= 0; i--)
                if (GameScreens[i].BlocksUpdate)
                {
                    if (i &gt; 0)
                        for (int j = i - 1; j &gt;= 0; j--)
                            if (!GameScreens[j].OverrideUpdateBlocked)
                                updating.Remove(GameScreens[j]);

                    break;
                }

            foreach (GameScreen screen in updating)
                if (screen.Initialized)
                    screen.Update();

            updating.Clear();

            foreach (GameScreen screen in GameScreens)
                updating.Add(screen);

            for (int i = GameScreens.Count - 1; i &gt;= 0; i--)
                if (GameScreens[i].BlocksInput)
                {
                    if (i &gt; 0)
                        for (int j = i - 1; j &gt;= 0; j--)
                            if (!GameScreens[j].OverrideInputBlocked)
                                updating.Remove(GameScreens[j]);

                    break;
                }

            foreach (GameScreen screen in GameScreens)
                if (!screen.InputDisabled)
                    screen.IsInputAllowed = updating.Contains(screen);
                else
                    screen.IsInputAllowed = false;
        }

        /// &lt;summary&gt;
        /// Draws the specified game time.
        /// &lt;/summary&gt;
        /// &lt;param name="gameTime"&gt;The game time.&lt;/param&gt;
        /// &lt;param name="RenderType"&gt;Type of the render.&lt;/param&gt;
        public static void Draw(GameTime gameTime, ComponentType RenderType)
        {
            Engine.GameTime = gameTime;
            List&lt;GameScreen&gt; drawing = new List&lt;GameScreen&gt;();

            GraphicsDevice.Clear(Color.CornflowerBlue);

            foreach (GameScreen screen in GameScreens)
                if (screen.Visible)
                    drawing.Add(screen);

            for (int i = GameScreens.Count - 1; i &gt;= 0; i--)
                if (GameScreens[i].BlocksDraw)
                {
                    if (i &gt; 0)
                        for (int j = i - 1; j &gt;= 0; j--)
                        {
                            if (!GameScreens[j].OverrideDrawBlocked)
                                drawing.Remove(GameScreens[j]);
                        }

                    break;
                }

            foreach (GameScreen screen in drawing)
                if (screen.Initialized)
                    screen.Draw(RenderType);
        }
    }
}</pre>
<p>So by adding this code to our engine we have got ride of all our error and got 8 new ones but&nbsp;that&#8217;s&nbsp;ok we will get rid of then by the end of this tutorial.<br />
The main&nbsp;difference&nbsp; between this class and the other class we have created so far is that we don&#8217;t have to instantiate it,&nbsp;instead we can get its members using Engine.MemberName.<br />
Next we will add a new class that Implements <a title="MSDN Link" href="http://msdn.microsoft.com/en-us/library/system.iserviceprovider.aspx" target="_blank">IServiceProvider</a>. This is a object that will keep track Service providers by&nbsp;inheriting&nbsp;from IServiceProvider.</p>
<p>So with in the Services folder in our solution add a new class called IEServiceContainer.</p>
<p>So here is the code</p>
<pre class="brush:csharp">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Engine.Services
{
    public class IEServiceContainer : IServiceProvider
    {

        Dictionary&lt;Type, object&gt; services = new Dictionary&lt;Type, object&gt;();

        /// &lt;summary&gt;
        /// Adds the service.
        /// &lt;/summary&gt;
        /// &lt;param name="Service"&gt;The service.&lt;/param&gt;
        /// &lt;param name="Provider"&gt;The provider.&lt;/param&gt;
        public void AddService(Type Service, object Provider)
        {
            if (services.ContainsKey(Service))
                throw new Exception("The service container already has a service provider of type " + Service.Name);
            this.services.Add(Service, Provider);
        }

        /// &lt;summary&gt;
        /// Gets the service.
        /// &lt;/summary&gt;
        /// &lt;param name="Service"&gt;The service.&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public object GetService(Type Service)
        {
            foreach (Type type in services.Keys)
                if (type == Service)
                    return services[type];

            throw new Exception("The service container does not contain "
            + "a service provider of type " + Service.Name);
        }

        /// &lt;summary&gt;
        /// Gets the service.
        /// &lt;/summary&gt;
        /// &lt;typeparam name="T"&gt;&lt;/typeparam&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public T GetService&lt;T&gt;()
        {
            object result = GetService(typeof(T));

            if (result != null)
                return (T)result;

            return default(T);
        }

        /// &lt;summary&gt;
        /// Removes the service.
        /// &lt;/summary&gt;
        /// &lt;param name="Service"&gt;The service.&lt;/param&gt;
        public void RemoveService(Type Service)
        {
            if (services.ContainsKey(Service))
                services.Remove(Service);
        }

        /// &lt;summary&gt;
        /// Determines whether the specified service contains service.
        /// &lt;/summary&gt;
        /// &lt;param name="Service"&gt;The service.&lt;/param&gt;
        /// &lt;returns&gt;
        ///   &lt;c&gt;true&lt;/c&gt; if the specified service contains service; otherwise, &lt;c&gt;false&lt;/c&gt;.
        /// &lt;/returns&gt;
        public bool ContainsService(Type Service)
        {
            return services.ContainsKey(Service);
        }
    }
}</pre>
<p>Next we are going to create a custom content&nbsp;manager&nbsp;expanding on the XNA&#8217;s base content&nbsp;manager, the main reason for this is so we can use cached&nbsp;content&nbsp;and also allow us to unload content insted of unloading&nbsp;everything.</p>
<p>So add a new class to services folder and call it IEContentManager</p>
<pre class="brush:csharp">using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Content;

namespace Engine.Services
{
    public class IEContentManager : ContentManager
    {

        public IEContentManager(IServiceProvider serviceProvider)
            : base(serviceProvider) { }

        public bool PreserveAssets = true;

        List&lt;IDisposable&gt; disposable = new List&lt;IDisposable&gt;();
        Dictionary&lt;string, object&gt; loaded = new Dictionary&lt;string, object&gt;();

       public override T Load&lt;T&gt;(string assetName)
        {

            T r = this.ReadAsset&lt;T&gt;(assetName, RecordIDisposable);
            if (PreserveAssets &amp;&amp; !loaded.ContainsKey(assetName))
                loaded.Add(assetName, r);
            return r;
        }

        void RecordIDisposable(IDisposable asset)
        {
            if (PreserveAssets)
                disposable.Add(asset);
        }

        public override void Unload()
        {
            foreach (IDisposable disp in disposable)
                disp.Dispose();
            loaded.Clear();
            disposable.Clear();
        }

        public void Unload(string assetName)
        {
            if (loaded.ContainsKey(assetName))
            {

                if (loaded[assetName] is IDisposable &amp;&amp; disposable.Contains((IDisposable)loaded[assetName]))
                {
                    IDisposable obj = disposable[disposable.IndexOf((IDisposable)loaded[assetName])];
                    obj.Dispose();
                    disposable.Remove(obj);
                }
                loaded.Remove(assetName);
            }
        }
    }
}</pre>
<p>Last but not least we are going to add a game screen&nbsp;collection&nbsp;class so we can have&nbsp;multiple&nbsp;game screens in our engine.</p>
<p>So we need to add a new class to our GameScreen folder and call it can you guess that&#8217;s right GameScreenCollection</p>
<pre class="brush:csharp">using System.Collections.ObjectModel;

namespace Engine.GameScreens
{
    public class GameScreenCollection : KeyedCollection&lt;string, GameScreen&gt;
    {

        /// &lt;summary&gt;
        /// When implemented in a derived class, extracts the key from the specified element.
        /// &lt;/summary&gt;
        /// &lt;param name="item"&gt;The element from which to extract the key.&lt;/param&gt;
        /// &lt;returns&gt;
        /// The key for the specified element.
        /// &lt;/returns&gt;
        protected override string GetKeyForItem(GameScreen item)
        {
            return item.Name;
        }

        /// &lt;summary&gt;
        /// Removes the element at the specified index of the &lt;see cref="T:System.Collections.ObjectModel.KeyedCollection`2"/&gt;.
        /// &lt;/summary&gt;
        /// &lt;param name="index"&gt;The index of the element to remove.&lt;/param&gt;
        protected override void RemoveItem(int index)
        {
            GameScreen screen = Items[index];
            if (Engine.DefaultScreen == screen)
                Engine.DefaultScreen = Engine.BackgroundScreen;

            base.RemoveItem(index);
        }
    }
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://spinneretdesign.com/2011/11/26/part-4-the-engine/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Part 3: Starting Coding the Engine</title>
		<link>http://spinneretdesign.com/2011/11/25/part-3-starting-coding-the-engine/</link>
		<comments>http://spinneretdesign.com/2011/11/25/part-3-starting-coding-the-engine/#comments</comments>
		<pubDate>Fri, 25 Nov 2011 17:28:00 +0000</pubDate>
		<dc:creator>Jardeth56</dc:creator>
				<category><![CDATA[Xna Game Engine]]></category>
		<category><![CDATA[xna games engine tutorial]]></category>

		<guid isPermaLink="false">https://jardeth56.wordpress.com/?p=643</guid>
		<description><![CDATA[So in this tutorial we are going start our engine, we will be making 3 classes and a interface, Component Class Component Interface GameScreen Class Component Collection Class So we are going to start with our component class this is the basis for all objects managed by the engine. using Microsoft.Xna.Framework; using System; using Engine.GameScreens; [...]]]></description>
			<content:encoded><![CDATA[<p>So in this tutorial we are going start our engine, we will be making 3 classes and a interface,</p>
<ul>
<li>Component Class</li>
<li>Component Interface</li>
<li>GameScreen Class</li>
<li>Component Collection Class</li>
</ul>
<p>So we are going to start with our component class this is the basis for all objects managed by the engine.</p>
<pre class="brush:csharp">using Microsoft.Xna.Framework;
using System;
using Engine.GameScreens;

namespace Engine.Components
{
    public class Component
    {
        public GameScreen Parent;
        public bool Initialized = false;
        public bool Visible = true;

        /// &lt;summary&gt;
        /// Initializes a new instance of the  class.
        /// &lt;/summary&gt;
        /// &lt;param name="Parent"&gt;The parent.&lt;/param&gt;
        public Component(GameScreen Parent)
        {
            InitializeComponent(Parent);
        }

        /// &lt;summary&gt;
        /// Initializes a new instance of the  class.
        /// &lt;/summary&gt;
        public Component()
        {
            InitializeComponent(Engine.DefaultScreen);
        }

        /// &lt;summary&gt;
        /// Initializes the component.
        /// &lt;/summary&gt;
        /// &lt;param name="Parent"&gt;The parent.&lt;/param&gt;
        protected virtual void InitializeComponent(GameScreen Parent)
        {
            if (!Engine.IsInitialized)
                throw new Exception("Engine must be initialized with SetupEngine() before components can be initialized");

            Parent.Components.Add(this);
            Initialized = true;
        }

        /// &lt;summary&gt;
        /// Updates this instance.
        /// &lt;/summary&gt;
        public virtual void Update()
        {
        }

        /// &lt;summary&gt;
        /// Draws this instance.
        /// &lt;/summary&gt;
        public virtual void Draw()
        {
        }

        /// &lt;summary&gt;
        /// Disables the component.
        /// &lt;/summary&gt;
        public virtual void DisableComponent()
        {
            Parent.Components.Remove(this);
        }
    }
}</pre>
<p>This should be pretty self explantory.</p>
<p>The main think to note is that the component is owned by a Game Screen who calls the component&#8217;s update and draw methods every frame.</p>
<p>If you engine is made up of a lot of differently formatted classes, then you will have problems when it comes to updating and drawing objects, having a base class means that all we have to do is inherit from it, change the update adn draw a little and the engine will do everything for us.</p>
<p>The next thing we are going to do is define some inferfaces for out components.</p>
<pre class="brush:csharp">using System;
using Microsoft.Xna.Framework;

namespace Engine.Components
{

    public interface I3DComponent
    {

        ///
<summary> /// Gets or sets the position. /// </summary>

        ///
        /// The position.
        ///
        Vector3 Position { get; set; }

        ///
<summary> /// Gets or sets the euler rotation. /// </summary>

        ///
        /// The euler rotation.
        ///
        Vector3 EulerRotation { get; set; }

        ///
<summary> /// Gets or sets the rotation. /// </summary>

        ///
        /// The rotation.
        ///
        Matrix Rotation { get; set; }

        ///
<summary> /// Gets or sets the scale. /// </summary>

        ///
        /// The scale.
        ///
        Vector3 Scale { get; set; }

        ///
<summary> /// Gets the bounding box. /// </summary>

        BoundingBox BoundingBox { get; }
    }

    public interface I2DComponent
    {
        Rectangle Rectangle { get; set; }
    }

    public enum ComponentType
    {
        Component2D,
        Component3D,
        Both,
        All
    }
}</pre>
<p>Over time we will expand on this adding additional functioality but this gives us a good starting place.</p>
<p>Next we will move on to the GameScreen class, The GameScreen class contains a goup of components, and heandles thier update, draw and input.<br />
We will add the ability to block drawing, update and input this is great is we are making a pause screen or such like.<br />
The bast way to think about this is a stack where if the top screen is paused then all other screens under it are paused.</p>
<p>While this kind of state management could be inculded the final game and not managed by the engine, we are trying to make our engine as flexible as possable.</p>
<p>So heres the code</p>
<pre class="brush:csharp">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Engine.Components;
using Engine.GameScreens;

namespace Engine.GameScreens
{
    public class GameScreen
    {
        public ComponentCollection Components;

        public bool Visible = true;

        public bool BlocksUpdate = false;

        public bool OverrideUpdateBlocked = false;

        public bool BlocksDraw = false;

        public bool OverrideDrawBlocked = false;

        public bool BlocksInput = false;

        public bool OverrideInputBlocked = false;

        public bool InputDisabled = false;

        public bool IsInputAllowed = true;

        public string Name;

        /// &lt;summary&gt;
        /// Occurs when [on initialized].
        /// &lt;/summary&gt;
        public event EventHandler OnInitialized;

        bool inititalized = false;
        /// &lt;summary&gt;
        /// Gets or sets a value indicating whether this GameScreen"/&gt; is initialized.
        /// &lt;/summary&gt;
        /// &lt;value&gt;
        ///   &lt;c&gt;true&lt;/c&gt; if initialized; otherwise, &lt;c&gt;false&lt;/c&gt;.
        /// &lt;/value&gt;
        public bool Initialized
        {
            get { return inititalized; }
            set
            {
                inititalized = value;
                if (OnInitialized != null)
                {
                    OnInitialized(this, new EventArgs());
                }
            }
        }

        /// &lt;summary&gt;
        /// Initializes a new instance of the  class.
        /// &lt;/summary&gt;
        /// &lt;param name="Name"&gt;The name.&lt;/param&gt;
        public GameScreen(string Name)
        {
            Components = new ComponentCollection(this);

            this.Name = Name;
            Engine.GameScreens.Add(this);

            if (!Initialized)
                Initialize();
        }

        /// &lt;summary&gt;
        /// Initializes this instance.
        /// &lt;/summary&gt;
        public virtual void Initialize()
        {
            this.Initialized = true;
        }

        /// &lt;summary&gt;
        /// Updates this instance.
        /// &lt;/summary&gt;
        public virtual void Update()
        {
            List&lt;Component&gt; updating = new List&lt;Component&gt;();

            foreach (Component c in Components)
                updating.Add(c);

            foreach (Component Component in updating)
                if (Component.Initialized)
                    Component.Update();
        }

        /// &lt;summary&gt;
        /// Draws the specified render type.
        /// &lt;/summary&gt;
        ///RenderType"&gt;Type of the render.
        public virtual void Draw(ComponentType RenderType)
        {
            List&lt;Component&gt; drawing = new List&lt;Component&gt;();

            foreach (Component component in Components)
            {
                if (RenderType == ComponentType.Both)
                {
                    if (component is I2DComponent || component is I3DComponent)
                        drawing.Add(component);
                }
                else if (RenderType == ComponentType.Component2D)
                {
                    if (component is I2DComponent)
                        drawing.Add(component);
                }
                else if (RenderType == ComponentType.Component3D)
                {
                    if (component is I3DComponent)
                        drawing.Add(component);
                }
                else
                {
                    drawing.Add(component);
                }
            }

            List defer2D = new List();

            foreach (Component component in drawing)
                if (component.Visible &amp;&amp; component.Initialized)
                {
                    if (component is I2DComponent)
                    {
                        defer2D.Add(component);
                    }
                    else
                    {
                        component.Draw();
                    }
                }
            foreach (Component component in defer2D)
                component.Draw();
        }

        /// &lt;summary&gt;
        /// Disables this instance.
        /// &lt;/summary&gt;
        public virtual void Disable()
        {
            Components.Clear();
            Engine.GameScreens.Remove(this);
            if (Engine.DefaultScreen == this)
                Engine.DefaultScreen = Engine.BackgroundScreen;
        }

        /// &lt;summary&gt;
        /// Returns a &lt;see cref="System.String"/&gt; that represents this instance.
        /// &lt;/summary&gt;
        /// &lt;returns&gt;
        /// A &lt;see cref="System.String"/&gt; that represents this instance.
        /// &lt;/returns&gt;
        public override string ToString()
        {
            return Name;
        }
    }
}</pre>
<p><em>Note: We don&#8217;t want to limit our input by forcing it all into one function on the GameScreen, because we want to take advantage fo things like key press events, mouse events, and gamepad events.</em></p>
<p>Next we need to set up our ComponentCollection. This is a custom collection that handles the management of the Parent value for components when it is moved around various screens.</p>
<pre class="brush:csharp">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using Engine.GameScreens;

namespace Engine.Components
{
    public class ComponentCollection : Collection
    {
        GameScreen owner;

        /// &lt;summary&gt;
        /// Initializes a new instance of the  class.
        /// &lt;/summary&gt;
        /// &lt;param name="Owner"&gt;The owner.&lt;/param&gt;
        public ComponentCollection(GameScreen Owner)
        {
            owner = Owner;
        }

        /// &lt;summary&gt;
        /// Inserts an element into the &lt;see cref="T:System.Collections.ObjectModel.Collection`1"/&gt; at the specified index.
        /// &lt;/summary&gt;
        ///The zero-based index at which &lt;paramref name="item"/&gt; should be inserted.
        ///The object to insert. The value can be null for reference types.
        /// &lt;paramref name="index"/&gt; is less than zero.-or- is greater than .
        protected override void InsertItem(int index, Component item)
        {
            if (item.Parent != null &amp;&amp; item.Parent != owner)
                item.Parent.Components.Remove(item);

            item.Parent = owner;

            base.InsertItem(index, item);
        }

        /// &lt;summary&gt;
        /// Removes the element at the specified index of the &lt;see cref="T:System.Collections.ObjectModel.Collection`1"/&gt;.
        /// &lt;/summary&gt;
        /// &lt;param name="index"&gt;The zero-based index of the element to remove.&lt;/param&gt;
        /// &lt;paramref name="index"/&gt; is less than zero.-or- is equal to or greater than .
        protected override void RemoveItem(int index)
        {
            Items[index].Parent = null;

            base.RemoveItem(index);
        }
    }
}</pre>
<p>Well that&#8217;s it for this post we will be covering more next time.</p>
]]></content:encoded>
			<wfw:commentRss>http://spinneretdesign.com/2011/11/25/part-3-starting-coding-the-engine/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Part 2: Engine Design</title>
		<link>http://spinneretdesign.com/2011/11/25/part-2-engine-design/</link>
		<comments>http://spinneretdesign.com/2011/11/25/part-2-engine-design/#comments</comments>
		<pubDate>Fri, 25 Nov 2011 12:56:49 +0000</pubDate>
		<dc:creator>Jardeth56</dc:creator>
				<category><![CDATA[Xna Game Engine]]></category>
		<category><![CDATA[xna game engine]]></category>
		<category><![CDATA[xna games engine tutorial]]></category>

		<guid isPermaLink="false">http://jardeth56.wordpress.com/?p=633</guid>
		<description><![CDATA[So in this part of my tutorials we are going to talk about the engines design and structure. The image below shows how we are going to layout the basic folder structure for our engine. As we work thought this series we will build up the engine so it is a good idea to build [...]]]></description>
			<content:encoded><![CDATA[<p>So in this part of my tutorials we are going to talk about the engines design and structure.</p>
<p>The image below shows how we are going to layout the basic folder structure for our engine.<br />
<span id="more-633"></span></p>
<p style="text-align: center;"><a href="http://jardeth56.files.wordpress.com/2011/11/engine-layout.jpg"><img class=" wp-image-634 aligncenter" title="Engine Layout" src="http://jardeth56.files.wordpress.com/2011/11/engine-layout.jpg?w=274" alt="Engine Layout" width="274" height="299" /></a></p>
<p>As we work thought this series we will build up the engine so it is a good idea to build the folder  structure to start will.</p>
<p>Defining the folder structure right off the bat will allow us to keep our engine as clean as possible.</p>
<p>So to get started launch Visual Studio (Am using 2010), we need to create tow projects in our solution, one for the engine its self and one as a demo project.</p>
<p>Am assuming you already have Xna 4.0 installed on your computer.</p>
<p>Am not going to talk you thought all the stages of setting up you projects in VS, just know we need an Xna Windows Games Library and a Xna Windows Game.</p>
<p>Hit F5 and make sure you new project runs and you should see a blue screen, very interesting.</p>
<p>So Create a new Class file and call it Engine, this is the main class  for the engine and create the folder structure about note that the Engine  in the Folder structure about is not a folder its the class we have just created.</p>
<p>So now we have all that it place its time to start building our engine, so in my next post I will cover some of the basic elements of our engine and we can start writing code.</p>
]]></content:encoded>
			<wfw:commentRss>http://spinneretdesign.com/2011/11/25/part-2-engine-design/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Part 1: What is a Games Engine?</title>
		<link>http://spinneretdesign.com/2011/11/22/part-1-what-is-a-games-engine/</link>
		<comments>http://spinneretdesign.com/2011/11/22/part-1-what-is-a-games-engine/#comments</comments>
		<pubDate>Tue, 22 Nov 2011 17:40:32 +0000</pubDate>
		<dc:creator>Jardeth56</dc:creator>
				<category><![CDATA[Xna Game Engine]]></category>
		<category><![CDATA[xna game engine]]></category>
		<category><![CDATA[xna games engine tutorial]]></category>

		<guid isPermaLink="false">https://jardeth56.wordpress.com/?p=515</guid>
		<description><![CDATA[Well this blog will document me creating a game engine using Microsoft xna framework. So lets start with a little background, Wikipedia defines a game engine as &#8220;a system designed for creation and development of video games&#8221; thanks Wikipedia that it in a nut shell. All games have an engine in one form or another, [...]]]></description>
			<content:encoded><![CDATA[<p>Well this blog will document me creating a game engine using Microsoft xna framework.</p>
<p>So lets start with a little background, Wikipedia defines a game engine as &#8220;a system designed for creation and development of video games&#8221; thanks Wikipedia that it in a nut shell.<br />
<span id="more-515"></span><br />
All games have an engine in one form or another, look at batman arkham city this is built on the unreal engine.</p>
<p>GTA 4 had a custom-made engine just for Rockstar.</p>
<p>So in this blog we are going to cover how to make our own engine, if your only interested in making games then I recommend that you look online of an engine that meets you needs this is more designed for developers wanting to understand how games work.</p>
<p>So that&#8217;s some information about engine now to cover the Microsoft Xna framework.</p>
<p>Microsoft XNA is a set of tools with a managed runtime environment  provided by Microsoft that facilitates video game development and management. XNA attempts to free game developers from writing &#8220;repetitive boilerplate code&#8221; and to bring different aspects of game production into a single system.</p>
<p>Thanks again Wikipedia!</p>
<p>One of my main reasons for using Xna is its cross-platform ability with minimum effort the same code can run on window and xbox 360.</p>
<p>Well thats the background covered in my next post I will be covering designing our engine.</p>
]]></content:encoded>
			<wfw:commentRss>http://spinneretdesign.com/2011/11/22/part-1-what-is-a-games-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

