Tuesday, 23 October 2012

Update Under Way!

The update of Commando Ghost is being worked on and it is definitely something to look forward to, with its all new graphically stunning backgrounds and epic battle vibrations! The features that I added like vibrations and completely randomized backgrounds are not simple but I will explain them to you.  

To program a randomizer it is not very hard! First you have to say:

Random r = new Random(); // Create an instance of the Random class and call it “r”

Then to get a random number “x” between 1 and 6 you would code:

x = r.Next(1, 6); 

In Commando Ghost, I use this type of code to choose a random starting background visual.  Then using the randomly selected background number in my Draw() function I display the correct background using code something like:

switch (CurrentBackground)
                    case 1:
                        spriteBatch.Draw(background, Vector2.Zero, Color.White);
                    case 2:
                        spriteBatch.Draw(background2, Vector2.Zero, Color.White);
                    case 3:
                        spriteBatch.Draw(background3, Vector2.Zero, Color.White);
                    case 4:
                        spriteBatch.Draw(background4, Vector2.Zero, Color.White);
                    case 5:
                        spriteBatch.Draw(background5, Vector2.Zero, Color.White);
                    case 6:
                        spriteBatch.Draw(background6, Vector2.Zero, Color.White);

The code above gets the int “CurrentBackground” and finds which number is in it. It then displays a different background depending on the randomized number.

To have the Windows Phone vibrate is normally a way to show that the user touched or hit something in a game. The only hard part programming it was trying to find the code for it and also trying to find what class to use. Here is how to do it.
First add this at the top:

using Microsoft.Devices;

Then write:

VibrateController.Default.Start(new TimeSpan(0, 0, 0, 1, 0));

The code above tells the Windows Phone to vibrate for 1 second! Normally for button presses you want to keep vibrations short and for deaths they can be a bit longer!
These are just two of the areas I recently worked on for the update!

Thank you for all the support with Commando Ghost and my blog and I hope you like the update for Commando Ghost and continue reading about me, the eleven year old programmer!


  1. Hello,

    First, awesome your such a young programmer.
    Second, when I was reading this post I wondered why you haven't created an array with images or named the variables after your random number (ex: int num = r.Next(0, 5); spritebatch.Draw(imagearray[num]...(etc.);)

    If you need some help, feel free to contact me on twitter or something. :)

  2. Good for you Logan. I have played the game and I really like it! Keep up the good work and KEEP PROGRAMMING! You're good at it.

    From A