Archive for May, 2009

The Zune HD: a new hope for Microsoft? – Ars Technica

I want one god damn it! When will they start selling these here in the UK, answer never, because Americans don’t buy them.

The Zune HD: a new hope for Microsoft? – Ars Technica.

I want it, I need it, If I had one I’d go back to using my old Nokia 3310, as a phone, and the zune for everything else. I don’t want 3G it costs far to much.

Bank Holiday XNA Project

This weekend I thought I’d try making a complete game. The quickest way to do this was to use one of the starter kits and tweak it up. I picked the Platformer Starter Kit that comes with XNA 3.0. There’s lots missing from the starter kit this is just a short list of things I want to add in :-

  • A menu system
  • More levels using all the enemies
  • lives
  • better scoring
  • a high score table
  • power ups
  • scrolling levels
  • hazards
  • shooting enemies
  • enemies with different abilities

It’s rather a long list and one I could keep adding to that’s the whole point of the starter kit it’s just to get you started.  I’ve also started writing a how-to guide to accompany the game which has slowed progress a bit, but I’ve started writing XNA code again so that can only be a good thing, more soon ;-)

FloatUnion.approxSqrt By Frank Savage (Development Manager – XNA Tools Team)

I was listening to the GDC09 talks and Mr Savage did his performance talk he mentioned a FloatUnion struct for approximate square root, but I could never find it until now…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System.Runtime.InteropServices;
 
[StructLayout(LayoutKind.Explicit)]
public struct FloatUnion
{
	[FieldOffset(0)]
	public float x;
 
	[FieldOffset(0)]
	public int n;
 
	public float approxSqrt()
	{
		n -= 1 << 23;
		n = n >> 1;
		n += 1 << 29;
		return x;
	}
}

This was more for me, but it’s here if you ever need it :-)

My Current Dev-Env

I just thought I’d point out that you don’t need an oober System set up the write Games/Apps/Web sites, and here is my current development environment:-

  • Pentium 4ht 3.20Ghz
  • 2Gb DDR2 233Mhz
  • ATI X1950 Pro
  • Maxtor 233Gb Hdd
  • 2x 19″ 1440×700 Monitors
  • Windows 7 RC
  • VS 2008 Express
  • Google Chrome
  • TortoiseSVN
  • Gimp 2
  • Paint.Net

I also have my Xbox360 Elite hooked up through a VGA switcher to one of my monitors.  I’ll see about posting some pictures at some point :-)

Any Questions?

Wolfram|Alpha = geography FAIL

Go here to see that it’s not just Facebook that is geographicly challenged -> 

Yes  and if you just search wolfram on wales you are told it’s a TOWN in the north of England but it will offer you four aternatives in AMERICA!

For thems that don’t understand Americans how this is another fail check out the Wales wiki entry.

I’ll answer my own question shall I?

Last night I asked this question on Twitter :-

#xna #Csharp Question – Anyone know if bit shifting is still faster than multiply/divide in .NET? E.G. (y<<8)+(y<<6) is faster than (y*320)

But no one answered :-( . So I wrote this quick test.

using System;
 
namespace Multiply_Test
{
    class Program
    {
        static void Main(string[] args)
        {
            int c;
 
            Console.Write("Test 1 - ");
            DateTime StartTimeTest1 = DateTime.Now;
            for (int y = 0; y &lt; int.MaxValue; y++)
                c = (y / 2);
            DateTime EndTimeTest1 = DateTime.Now;
 
            TimeSpan taken1 = new TimeSpan((EndTimeTest1.Subtract(StartTimeTest1)).Ticks);
            Console.WriteLine(string.Format("{0} Seconds",taken1.TotalSeconds));
 
            Console.Write("Test 2 - ");
            DateTime StartTimeTest2 = DateTime.Now;
            for (int y = 0; y &lt; int.MaxValue; y++)
                c = (y &gt;&gt; 1);
            DateTime EndTimeTest2 = DateTime.Now;
 
            TimeSpan taken2 = new TimeSpan((EndTimeTest2.Subtract(StartTimeTest2)).Ticks);
            Console.WriteLine(string.Format("{0} Seconds",taken2.TotalSeconds));
 
            Console.WriteLine("\n\nPress Any Key...");
            Console.ReadKey(true);
        }
    }
}

And this was the result :-

Multiply Test Results

Multiply Test Results

Yep still faster.

Finaly some XNA.

OK I was doing my usual potter around the net tonight when I found “Draw Horizontally Centered Text in XNA” and thought I have to tweak this…

///
/// Take a string and draw it centered horizontally on the screen.
///
public static void DrawCentered(String myText, int ScreenWidth, int yPosition, Color drawColor, SpriteFont spriteFont, SpriteBatch spriteBatch)
{
    // Get the size the spritefont will be drawn on the screen.
    Vector2 textSize = spriteFont.MeasureString(myText);
 
    // Get the position we need to draw the text at for it to be centered.
    int centerXPosition = (ScreenWidth / 2) - ((int)textSize.X / 2);
 
    // Draw the centered text.
    spriteBatch.DrawString(spriteFont, myText, new Vector2(centerXPosition, yPosition), drawColor);
}

I hate passing parameters i don’t need and you should strive to avoid magic numbers so I moved the int ScreenWidth to be a local variable and pulled the required value in from the SpriteBatch with the following line :-

            // pick up the screen width.
            int ScreenWidth = spriteBatch.GraphicsDevice.Viewport.Width;

And as a sort of old school codey kick removed the division from the int centerXPosition calculation and replaced it with some bit shifts to bring us to

            // Get the position we need to draw the text at for it to be centered.
            int centerXPosition = (ScreenWidth &gt;&gt; 1) - ((int)textSize.X &gt;&gt; 1);

so in all my replacement method is :-

        ///
        /// Take a string and draw it centered horizontally on the screen.
        ///
        public static void DrawCentered(String myText, int yPosition, Color drawColor, SpriteFont spriteFont, SpriteBatch spriteBatch)
        {
            // pick up the screen width.
            int ScreenWidth = spriteBatch.GraphicsDevice.Viewport.Width;
 
            // Get the size the spritefont will be drawn on the screen.
            Vector2 textSize = spriteFont.MeasureString(myText);
 
            // Get the position we need to draw the text at for it to be centered.
            int centerXPosition = (ScreenWidth &gt;&gt; 1) - ((int)textSize.X &gt;&gt; 1);
 
            // Draw the centered text.
            spriteBatch.DrawString(spriteFont, myText, new Vector2(centerXPosition, yPosition), drawColor);
        }

Have fun with that, and thanks to Kris Steele for the original article ;-)

The geek shall inherit the Earth!

http://geekadvancement.com/

Someone stole my game idea!


Hot New Video Game Consists Solely Of Shooting People Point-Blank In The Face