ubergods's profilePat's spaceBlogGuestbookNetwork Tools Help

Pat's space

ubergods

Occupation
Location
December 02

Adding an MP3 Soundtrack To Your XNA Game

Version 3.0 of the XNA framework makes it very easy to import and use MP3 files in their native format within our games.  Earlier versions of the framework required us to convert these files and use XACT to play music.  Below I'll show you how easy it is to add an MP3 soundtrack to your own game.
 
The first step is to add the MP3 file to your project's shared content directory which I will assume anyone at this stage in XNA development knows how to do.  Next we must invoke the XNA Media library in your class which is done by using the following include statement at the top of the .cs file:

using
Microsoft.Xna.Framework.Media;

Next we will need to declare a variable which will represent an instance of our MP3 within the class and then load the content (the MP3) into that variable.  I do this within the LoadContent function of my primary game class.  I have included an example statement below:

Song backgroundSong;
backgroundSong = Content.Load<
Song>("Sounds/background"
);


Now that we have an object representing our MP3 in our class, all we need to do is tell the MediaPlayer which is included with XNA.Framework.Media, to play the MP3.  If you want your MP3 to loop, you simply specify this as well.  I have included examples of these statements below:

MediaPlayer

.IsRepeating = true;
MediaPlayer
.Play(backgroundSong);


We also have the option of pausing the MP3 at its current position and then resuming again where it left off:

MediaPlayer

.Pause();
MediaPlayer
.Resume();
 
Stopping the MP3 is also a simple function call:

MediaPlayer

.Stop();


Below is an example from my PunkBoy game which allows me to pause and resume the background song based off the user pressing the 'S' key.

public

class PunkBoyGame : Microsoft.Xna.Framework.Game
{
    ...

    bool playMusic = true;

    KeyboardState previousState = Keyboard.GetState();

    ...
}

protected override void Update(GameTime gameTime)
{
KeyboardState keyboardState = Keyboard.GetState();

...

    if (keyboardState.IsKeyDown(Keys.S) && !previousState.IsKeyDown(Keys.S))
    {
        if (playMusic)
        {
          playMusic =
false;
          MediaPlayer.Pause();
        }
        else if (!playMusic)
        {
          playMusic =
true;
          MediaPlayer.Resume();
        }
    }

    ...

    previousState = Keyboard.GetState();

    base.Update(gameTime);
}
 
November 30

PunkBoy Official Release

Punkboy has officially been released.  Feel free to download the source and/or the game at http://www.codeplex.com/punkboy
 
The game was written in C# using Microsoft's XNA Game Studio 3.0, and based off of the Platformer starter kit included with XNA.  Much of the starter kit's code remains in place but has been updated, modified and tweaked into its current state.  Following is a list of some of the changes:
  • The graphics in the game have been completely changed to represent the PunkBoy theme.
    • The background art was obtained from the original game poster created for the project by Niles Resch, the poster can be downloaded in PDF format from my skydrive.
    • The PunkBoy sprite was modified to resemble the game poster from an original sprite created by ProgZmax.
    • The Zombified Scene Kid sprite was modified from one of the monster sprites included with the starter kit.
    • All other graphics were created or modified using Adobe Photoshop.
  • New music and sound effects were added.
    • The soundtrack includes: Punk is Dead by Crass, Ashtray Dirt by The Subhumans and Self Destruct by GBH.
    • The "Oi!" sound effect was recorded using Windows Sound Recorder.
  • An improved scoring system was implemented.
    • In the original game, the score would reset for every new level.  The score is now maintained until the game is exited.
    • If a player encounters a monster and dies, 100 points are subtracted from his score.  If his score is less than 100, the score is set to 0.
  • A menu system with informational screens was implemented.
  • The original 3 levels were modified and expanded upon resulting in 5 total levels.
    • The game cycles through the same 5 levels, but offers infinite game play by increasing the speed of the monsters in each subsequent cycle.
  • Every anarchy symbol (gems in the original game) in each level must be collected before moving on to the next level.
    • A counter displaying the remaining symbols to be collected has been added below the score.

 

Professor Samuel Stokes' Blog
ubergods, your source for uber, period.

October 23

XNA RPG Starter Kit Quest Modification

At the bottom of this post I have added a short video that shows how simple it is to modify the XNA RPG Starter Kit and add your own quests and items.  The creators club site has a very basic and helpful tutorial here which will walk you through adding your own quest to the game.  The modification and/or addition of a new item to the game follows the same principles.  Below is an example of the XML file for my Sword of 1000 Truths, I will highlight the key points that I changed in Green.

<?xml version="1.0" encoding="utf-8" ?>
<XnaContent>
    <Asset Type="RolePlayingGameData.Weapon">
       
<Name>Sword of 1000 Truths</Name> The name that appears in the item description window
       
<Description>The Sword of 1000 Truths is a legendary sword that will easily strike down the most powerful of enemies</Description> The item description that appears when viewing the sword in game.
       
<GoldValue>100000</GoldValue> The value of the sword if you were to sell it, this sword is worth a LOT of money.
        <IsDroppable>true</IsDroppable>
       
<MinimumCharacterLevel>1</MinimumCharacterLevel> I allow the player to equip this sword at level 1
        <SupportedClasses>
            <Item>Warrior</Item>
            <Item>Paladin</Item>
        </SupportedClasses>
        <IconTextureName>Sword07a</IconTextureName>
        <TargetDamageRange>
           
<Minimum>1000</Minimum> Minimum damage is 1000HP as opposed to 4HP that the short sword would cause
           
<Maximum>2000</Maximum> Maximum damage is 2000HP as opposed to the 8HP that the short sword would cause
        </TargetDamageRange>
        <SwingCueName>SwordSwing</SwingCueName>
        <HitCueName>SwordHit</HitCueName>
        <BlockCueName>SwordBlock</BlockCueName>
        <Overlay>
            <TextureName>Spells\OverlayMelee</TextureName>
            <FrameDimensions>111 130</FrameDimensions>
            <FramesPerRow>1</FramesPerRow>
            <Animations>
                <Item>
                    <StartingFrame>1</StartingFrame>
                    <EndingFrame>1</EndingFrame>
                    <Interval>200</Interval>
                    <IsLoop>false</IsLoop>
                </Item>&lt;a href="http://video.msn.com/video.aspx?vid=9b9f08ea-719d-486f-8912-024e87f07fe1" target="_new" title="XNA RPG Starter Kit Quest Modification"&gt;Video: XNA RPG Starter Kit Quest Modification&lt;/a&gt;
            </Animations>
        </Overlay>
    </Asset>
</XnaContent>


Thanks,

Professor Samuel Stokes' Blog
ubergods, your source for uber...period




XNA RPG Starter Kit Quest Modification

   
Video: XNA RPG Starter Kit Quest Modification
Higher Quality Downloadable WMV Version of this Video
September 23

Pong With Classes

This is an update on an earlier blog I posted regarding creating a simple pong game using XNA...
 
My professor Samuel Stokes asked us to take our pong game created in XNA and move a large portion of the code to a separate class.  A bit tedious and frustrating at first, but I realized it was just a matter of keeping some of the sprite declarations in the main program and passing them as variables to the methods within the class I had built.  I used one class for all of the methods and variables I moved out so I could declare most of the variables within the class instead of passing them along each time.  You can check out the code on my SkyDrive through the link at the bottom of this entry.
 
- Pat
 
 
 
 
 
 
September 11

Game Idea

So way back in 2001 when flash was first becoming popular, I wrote a short little cartoon called "Punkboy vs. Poserboy."
 
I'm thinking about expanding on this idea for a game using XNA, perhaps it will be titled "Punkboy: Rise of the Scene Kid Army."  The goal of the game will be to save the world from the putrid movement of self-absorbed so called "scene kids."  Perhaps Punkboy will advance through the levels, getting new weapons (doc martins, studded belt, gutterstench, etc) and defeating increasingly pompous Scenesters until the final battle where he must destroy the birthplace and sanctuary of many of these types - MySpace.
 
Just an idea...
 
- Pat
 
 
Thanks for visiting!
Please wait...
Sorry, the comment you entered is too long. Please shorten it.
You didn't enter anything. Please try again.
Sorry, we can't add your comment right now. Please try again later.
To add a comment, you need permission from your parent. Ask for permission
Your parent has turned off comments.
Sorry, we can't delete your comment right now. Please try again later.
You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
Complete the security check below to finish leaving your comment.
The characters you type in the security check must match the characters in the picture or audio.