RSS
 

Archive for the ‘XNA’ Category

XNA User Group & Boise Code Camp

27 Feb

Boise Code Camp happened yesterday and we had an excellent turn out.

I decided to give a session on XNA game development which turned out to have more people than I expected. I was also shocked to see so many hands go up when I asked how many people used XNA already, then see almost all those hands drop when I asked if anyone launched any games.

What is it that causes people to stop making their game? There must be some reason games are not being completed. My personal opinion… and thats all it is… is that many give up on development when they get stuck on something, bored of working alone, or see their dream of a game becoming a never ending processes of jumping through hoops.

This being said I think its time for us to start an XNA user group in the Boise, Idaho area. A few of us talked after the session and are putting out feelers to see who may be interested. I would like to have at least 15-20 dedicated folks that wouldn’t mind meeting once ever month or 2. I do not want to lead this alone and feel 2-3 leaders would be best. I am going to send out an email to BSDG (Boise Development Group) and see if we get a positive response.

If you are interested in joining an XNA user group please contact me directly or reply to this post.

Also… the demo game from code camp is available for download

River Rush (Code Camp)

 
1 Comment

Posted in C#, XNA

 

Trials and Tribulations Working with XNA

02 Feb

Wow, getting a game started on your own can be a pain in the ass. The XNA forums are full of information but scattered here and there and everywhere. Building a game is more than writing lines of code. Working with XNA you must deal with Importing objects, positioning them, lighting/shading them, and once you have that figured out you may be able to write some code.

For those of us who fly solo, It’s very time consuming and extremely painful to research, build a little, research more… erase what we have done, start again, build a little, research, build, erase, build, research, research, erase, erase all, Start over… you catch my drift.

Well I am in the start over phase, I had a game going (XNA Tanks) about a year ago that I finally have time to come back to. A year later… I am a much better programmer and a new version of XNA is out so I think its time to do this game correct.

What am I going to do other than build a game? I am going to post all the questions I have and every road block I run into. Then as I solve these riddles I will post how, and why when relevant, that way when the next developer going mano-a-mano with XNA doesn’t get blown away within the first couple days.

 
2 Comments

Posted in C#, XNA

 

Render BoundingSphere in XNA 4.0

26 Jan

There have been some changes in XNA 4.0 that prevent drawing primitives with XNA 3.1 code.
The following is a bounding sphere render class

 /// <summary>
    /// Provides a set of methods for rendering BoundingSpheres.
    /// </summary>
    public static class BoundingSphereRenderer
    {
        static VertexBuffer vertBuffer;
        static VertexDeclaration vertDecl;
        static BasicEffect effect;
        static int sphereResolution;

        /// <summary>
        /// Initializes the graphics objects for rendering the spheres. If this method isn't
        /// run manually, it will be called the first time you render a sphere.
        /// </summary>
        /// <param name="graphicsDevice">The graphics device to use when rendering.</param>
        /// <param name="sphereResolution">The number of line segments
        ///     to use for each of the three circles.</param>
        public static void InitializeGraphics(GraphicsDevice graphicsDevice, int sphereResolution)
        {
            BoundingSphereRenderer.sphereResolution = sphereResolution;

            //vertDecl = new VertexDeclaration(
            effect = new BasicEffect(graphicsDevice);
            effect.LightingEnabled = false;
            effect.VertexColorEnabled = false;

            VertexPositionColor[] verts = new VertexPositionColor[(sphereResolution + 1) * 3];

            int index = 0;

            float step = MathHelper.TwoPi / (float)sphereResolution;

            //create the loop on the XY plane first
            for (float a = 0f; a <= MathHelper.TwoPi; a += step)
            {
                verts[index++] = new VertexPositionColor(
                    new Vector3((float)Math.Cos(a), (float)Math.Sin(a), 0f),
                    Color.White);
            }

            //next on the XZ plane
            for (float a = 0f; a <= MathHelper.TwoPi; a += step)
            {
                verts[index++] = new VertexPositionColor(
                    new Vector3((float)Math.Cos(a), 0f, (float)Math.Sin(a)),
                    Color.White);
            }

            //finally on the YZ plane
            for (float a = 0f; a <= MathHelper.TwoPi; a += step)
            {
                verts[index++] = new VertexPositionColor(
                    new Vector3(0f, (float)Math.Cos(a), (float)Math.Sin(a)),
                    Color.White);
            }

            vertBuffer = new VertexBuffer(graphicsDevice, typeof(VertexPositionColor), verts.Length, BufferUsage.None);
            vertBuffer.SetData(verts);
        }

        /// <summary>
        /// Renders a bounding sphere using different colors for each axis.
        /// </summary>
        /// <param name="sphere">The sphere to render.</param>
        /// <param name="graphicsDevice">The graphics device to use when rendering.</param>
        /// <param name="view">The current view matrix.</param>
        /// <param name="projection">The current projection matrix.</param>
        /// <param name="xyColor">The color for the XY circle.</param>
        /// <param name="xzColor">The color for the XZ circle.</param>
        /// <param name="yzColor">The color for the YZ circle.</param>
        public static void Render(
            BoundingSphere sphere,
            GraphicsDevice graphicsDevice,
            Matrix view,
            Matrix projection,
            Color xyColor,
            Color xzColor,
            Color yzColor)
        {
            if (vertBuffer == null)
                InitializeGraphics(graphicsDevice, 30);

            graphicsDevice.SetVertexBuffer(vertBuffer);

            effect.World =
                Matrix.CreateScale(sphere.Radius) *
                Matrix.CreateTranslation(sphere.Center);
            effect.View = view;
            effect.Projection = projection;
            effect.DiffuseColor = xyColor.ToVector3();

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();

                //render each circle individually
                graphicsDevice.DrawPrimitives(
                      PrimitiveType.LineStrip,
                      0,
                      sphereResolution);
                pass.Apply();
                effect.DiffuseColor = xzColor.ToVector3();
                graphicsDevice.DrawPrimitives(
                      PrimitiveType.LineStrip,
                      sphereResolution + 1,
                      sphereResolution);
                pass.Apply();
                effect.DiffuseColor = yzColor.ToVector3();
                graphicsDevice.DrawPrimitives(
                      PrimitiveType.LineStrip,
                      (sphereResolution + 1) * 2,
                      sphereResolution);
                pass.Apply();

            }

        }

        public static void Render(BoundingSphere[] spheres,
           GraphicsDevice graphicsDevice,
           Matrix view,
           Matrix projection,
           Color xyColor,
            Color xzColor,
            Color yzColor)
        {
            foreach (BoundingSphere sphere in spheres)
            {
                Render(sphere, graphicsDevice, view, projection, xyColor, xzColor, yzColor);
            }
        }

        public static void Render(BoundingSphere[] spheres,
            GraphicsDevice graphicsDevice,
            Matrix view,
            Matrix projection,
            Color color)
        {
            foreach (BoundingSphere sphere in spheres)
            {
                Render(sphere, graphicsDevice, view, projection, color);
            }
        }

        /// <summary>
        /// Renders a bounding sphere using a single color for all three axis.
        /// </summary>
        /// <param name="sphere">The sphere to render.</param>
        /// <param name="graphicsDevice">The graphics device to use when rendering.</param>
        /// <param name="view">The current view matrix.</param>
        /// <param name="projection">The current projection matrix.</param>
        /// <param name="color">The color to use for rendering the circles.</param>
        public static void Render(
            BoundingSphere sphere,
            GraphicsDevice graphicsDevice,
            Matrix view,
            Matrix projection,
            Color color)
        {
            if (vertBuffer == null)
                InitializeGraphics(graphicsDevice, 30);

            graphicsDevice.SetVertexBuffer(vertBuffer);

            effect.World =
                  Matrix.CreateScale(sphere.Radius) *
                  Matrix.CreateTranslation(sphere.Center);
            effect.View = view;
            effect.Projection = projection;
            effect.DiffuseColor = color.ToVector3();

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();

                //render each circle individually
                graphicsDevice.DrawPrimitives(
                      PrimitiveType.LineStrip,
                      0,
                      sphereResolution);
                graphicsDevice.DrawPrimitives(
                      PrimitiveType.LineStrip,
                      sphereResolution + 1,
                      sphereResolution);
                graphicsDevice.DrawPrimitives(
                      PrimitiveType.LineStrip,
                      (sphereResolution + 1) * 2,
                      sphereResolution);

            }

        }
    }
 
3 Comments

Posted in C#, XNA

 

TanksXNA

05 May

The TanksXNA game is good enough for an initial release, I need to add a Bugs board so people can add bugs they find there.

Anyways without further ado here it is

The XNA redistributable is required in order to run the game, a check is coming later for that.

TanksXNA

Redistributable

 
2 Comments

Posted in C#, XNA

 

XNA Orthographic Camera

24 Mar

To test my new site and syntax highlighter I am posting a snippet used inside of the XNA game I am making.

This is a Basic Orthographic Camera Class that is an excellent choice for any 3D game where the view doesn’t really change or any 2.5D game.

    public class Camera
    {
        //View
        Vector3 cameraPosition = new Vector3(-12, 10, 0);
        Vector3 cameraLookAt = Vector3.Zero;

        //Matrix
        public Matrix Projection { get; private set; }

        public Matrix View { get; private set; }

        public Camera(int windowWidth, int windowHeight)
        {
            Projection = Matrix.CreateOrthographic(windowWidth, windowHeight, -1000f, 1000f);
            View = Matrix.CreateLookAt(cameraPosition, cameraLookAt, Vector3.Zero);
        }

        public void HandleInput(KeyboardState currentKeyboardState)
        {
            int x = 2;
             #region camera
            if (currentKeyboardState.IsKeyDown(Keys.Left))
            {
                if (currentKeyboardState.IsKeyDown(Keys.LeftControl))
                    cameraLookAt.X += x;
                else if (currentKeyboardState.IsKeyDown(Keys.LeftShift))
                    cameraLookAt.Z += x;
                else
                    cameraLookAt.Y += x;
            }

            if (currentKeyboardState.IsKeyDown(Keys.Right))
            {
                if (currentKeyboardState.IsKeyDown(Keys.LeftControl))
                    cameraLookAt.X -= x;
                else if (currentKeyboardState.IsKeyDown(Keys.LeftShift))
                    cameraLookAt.Z -= x;
                else
                    cameraLookAt.Y -= x;
            }

            if (currentKeyboardState.IsKeyDown(Keys.Up))
            {
                if (currentKeyboardState.IsKeyDown(Keys.LeftControl))
                    cameraPosition.Y -= x; //Zoom in
                else if (currentKeyboardState.IsKeyDown(Keys.LeftShift))
                    cameraPosition.Z += x;
                else
                    cameraPosition.X += x; //UP
            }

            if (currentKeyboardState.IsKeyDown(Keys.Down))
            {
                if (currentKeyboardState.IsKeyDown(Keys.LeftControl))
                    cameraPosition.Y += x; //Zoom out;
                else if (currentKeyboardState.IsKeyDown(Keys.LeftShift))
                    cameraPosition.Z -= x;
                else
                    cameraPosition.X -= x; //Down

            }

            View = Matrix.CreateLookAt(
                cameraPosition,
                cameraLookAt,
                Vector3.Up);

            #endregion

        }

    }
 
No Comments

Posted in C#, XNA