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:
spriteBatch.Draw(background, Vector2.Zero, Color.White);
spriteBatch.Draw(background2, Vector2.Zero, Color.White);
spriteBatch.Draw(background3, Vector2.Zero, Color.White);
spriteBatch.Draw(background4, Vector2.Zero, Color.White);
spriteBatch.Draw(background5, Vector2.Zero, Color.White);
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:
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!