Featured Posts

Acid Rain: A Hero's Journey --Dream Build Play 2010 Entry

I submitted my game into Microsoft's 2010 Dream Build Play competition today. Deadline is tomorrow March 3rd so i just made it in.

Watch it full screen at Youtube: Acid Rain  

Make sure you switch the video to 720p in the lower right of the video window.  It defaults to 360p which looks fuzzy.

Whew.  I'm going to take a little break from my game and catch up on stuff I have neglected. I hope to do some posts about the tools I used to make my game and I'd like to do a series of tutorials on spritebatch. Oh yeah and I need to get my taxes done. I'm not sure how long the judging lasts but since I know there is no way I'll hear anything back, my plan is to go ahead and playtest for another couple of weeks then submit my game for playtesting with Microsoft (ie. the Creator's Club website). If it passes that I'll submit for review and with any luck get it on the Indie Live Marketplace. The DBP contest gave me a focus point which forced me to cut things off and consolidate/finalize missions etc.

So here is my gameplay video for Acid Rain. It's not a trailer. That will take a lot more work. This is just my submission video for DBP. This is also too long for a trailer which should probably be under a minute.

 

Simple 2D Shadows Tutorial recognized

So this was a pleasant surprise.

My first XNA tutorial that I submitted to Ziggyware.com here and of course posted on this site here was recognized by Microsoft.

I know it's a small thing but it's those small things that encourage us to continue forging ahead.

Here is the link to MS's reference to my tutorial on 2D simple Shadows.  What I really like is I am categorized with other "Space Brains".

http://blogs.msdn.com/xna/archive/2009/03/10/creators-club-communiqu-21.aspx

Allan

Volcano Storm Update - Working on GamePlay

I'm finally posting an update video on my efforts with XNA.

This is about a month and a half of work after my last video.  What have I added/changed?  Pretty much everything.

I completely dumped the Tile System that I was using from Nick Gravelyn's video tutorials series.  I just couldn't stand the look of the repetitive Tiles.  Perhaps it is my lack of artistic knowledge in creating seamless tiles that don't look so repetitive but after trying to create seamless tiles that don't look repetitive for months, I finally gave up.  Once my programming knowledge increased a little I was able to start toying with other terrain generation ideas.  I'm still using a bottom foundation of rocky grass tiles, however since my game structure is not constrained to tile size, there was no reason why I counldn't branch out on the tile concept.  My foundation tiles are now 510 X 510, created in ZBrush, rotated forward at 20 degrees and then screen captured as 510 X 510 Top Down tiles.  I have a bunch of game Objects that litter the foundation base.  All of these are created as 3D objects in ZBrush, tilted 20-45 degrees and randomly placed on my map.  This includes the mountains, Rocks, Trees, downed Trees, Volcano etc.  This helps break the repitition.  I also created a second layer of snowy landscape  Tiles that overlays the rocky grass layer.   I'm still vasilating on the look of the snowy ground layer.  I like the snow but it starts to make things look kind of busy. Perhaps too busy.  Since it's all randomly generated (except for the foundation rocky grass layer) I'm able to adjust the size of my map on the fly and the volume of stuff on the map.

I added a cloud layer that scales as you zoom in and out with the camera.  There are clouds that roll across the mountain range at all times and then there are higher clouds that only appear when you start to zoom out.  As you zoom out, I adjust the clouds transparency and scale so it looks like you are moving through the cloud layers.   My son said, "You need to adjust the sound so when you zoom out and are further away, your rock explosions and AcidRain Bursts are quieter."...so I did that....except for the thunder of course....because that's up where you are.   He said, "You need storm clouds."  So I added stormy clouds with lightning and thunder.  He reminded me that there is a delay between thunder sound and lightning.  OK.  That took a few days.  Then he said, what happens when the volcano rocks hit the trees.  I guess they should burn.  A week later and they burn.  And of course I needed burnt tree textures to replace the regular tree textures.

So now I have a look that I am moderately satisfied with.  Now the hard part....I need to make gameplay.

Thankfully I didn't neglect collision detection in my design so my player collides with the acidrain and the volcano rocks..  He also collides with the mountains and the volcano.  That collsion makes him slow and scale since he is climbing.  And of course I have to keep track of everything's depth.  Since the player walks behind some things and in front of others.  And he collides with certain higher rock formations.

Adding player health is the first step to gameplay once you have collision detection.  So I started working on a HUD.  Since my player is a vacationing mountain climber/hiker, I thought a rope would be appropriate for my health bar.  After several days trying to make a rope in ZBrush....(one that I could rotate and frey into strings and pieces)..in order to capture the frames I needed for a desintigrating rope/health bar, I integrated it into my game.  I added a rope exploding particle effect, code to tie the length of the rope to player health and a temperary text field just so I can make sure the rope length is actually tied to player health.  I showed this to my daughter and I said, "How do you like the health bar?"  She said, "Oh that...it looks ok."  See my guy is a vactioning mountain climber, so I thought a rope would be a good....  She said, "Oh that's a rope?" 

Ouch.  She got a good laugh out of that.
 
Allan

Simple 2D Shadows Extended XNA Tutorial



You can download the source code with lots of comments at the bottom of this tutorial.

2dshadowssimple1



2dshadowssimple21

  public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        private Texture2D canopy;
        private Texture2D trunk;
        private Rectangle canopyRect;
        private byte shadowAlpha;
        private Color color;
        private int shadowOffsetX;
        private int shadowOffsetY;
        private float shadowRotation;
        private bool sunCycle = false;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

canopy145

trunk145


 protected override void Initialize()
        {
            //Set screen dimensions
            graphics.PreferredBackBufferWidth = 1280;
            graphics.PreferredBackBufferHeight = 720;
            graphics.IsFullScreen = false;
            graphics.ApplyChanges();
            Window.Title = "Simple 2D Shadows";
            
 
            //Set Shadow Start values.  These variables are used in the second spritebatch.draw in order to make our shadow.
            shadowAlpha = 40; // set transparency level, Adjust this depending on how dark your background is
            //I use the color variable to define the color of our canopy texture in the second draw of the canopy texture.
            //Using overload number 8 gives us color(byte r, byte g, byte b, byte a)
            //Remember a byte is 0 to 255. These values represent Red, Green, Blue and Alpha(transparency)
            //Setting r,g,b to 0 makes out texture black and then we can play with the alpha level to determine how transparent we
            //want our texture.  Make it darker for a darker background or adjust it based on game design.
            color = new Color(0, 0, 0, shadowAlpha); 
            shadowOffsetX = 0; // Shadow X Position offset, Use this to fine tune shadow position
            shadowOffsetY = 20; // Shadow y position offset, Use this to fine tune shadow position
            shadowRotation = -1f; //Shadow rotation starting position.  Use this to rotate the texture based upon sun position.
            
            base.Initialize();
        }



 protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //Load canopy and trunk
            canopy = Content.Load(@"Canopy145");
            trunk = Content.Load(@"Trunk145");
            //create rectangle for canopy, sized to width and height of canopy texture
            canopyRect = new Rectangle(500, 200, canopy.Width, canopy.Height); 

            // TODO: use this.Content to load your game content here
        }



  protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            //Check if user hits spacebar and set sunCycle to true to start sun cycle
            if (Keyboard.GetState().IsKeyDown(Keys.Space) && sunCycle == false)
            {
                sunCycle = true;
            }

            //if suncycle is true (ie. you hit space bar), increment shadowRotation to rotate shadow texture 
            if (sunCycle)
            { 
                shadowRotation += .005f;

                if (shadowRotation >= 1f)  //stop shadowRotation when it is greater than 1.
                {
                    sunCycle = false;
                }
            }
          
            base.Update(gameTime);
        }






 protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.SkyBlue);

            spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.BackToFront, SaveStateMode.None);

                        spriteBatch.Draw(canopy,
                           canopyRect,
                           null,
                           Color.White,
                           0f,
                           new Vector2(0f, 0f),
                           SpriteEffects.None, 0.2f);
                       
            spriteBatch.Draw(canopy,
                             new Vector2(canopyRect.Center.X + shadowOffsetX,
                             canopyRect.Bottom - shadowOffsetY),
                             null,
                             color,
                             shadowRotation,
                             new Vector2(canopy.Width / 2, canopy.Height),
                             1f,
                             SpriteEffects.None, 0.5f);
            
            spriteBatch.Draw(trunk, 
                            new Vector2(canopyRect.Center.X, canopyRect.Center.Y), 
                            null, 
                            Color.White, 
                            0f,
                            new Vector2(trunk.Width / 2, trunk.Height / 2 - 25), 
                            1f, 
                            SpriteEffects.None, 
                            0.5f);

            spriteBatch.End();

            base.Draw(gameTime);
        }




Download 2D Shadows Extended

Simple 2D Shadows in XNA



notreeshadow1

runleft2



hereZiggywarewinners



this





behindtree1



















private Texture2D treeTop; 



treeTop = content.Load<Texture2D>(@"Tiles/canopy145"); 

You'll need your spriteBatch.Draw statements sandwiched in between spritebatch.begin and spritebatch.end in your main draw method as usual.

spriteBatch.Begin(SpriteBlendMode.AlphaBlend,SpriteSortMode.BackToFront, SaveStateMode.None, camera.Transform);

spriteBatch.Draw.....

spriteBatch.Draw....

spriteBatch.End();

I use a 2dCamera in my little game thus the camera.Transform but you don't need this for this example.

Now if you want to extend this, you could make color a variable and make your shadow x, y positions variables.  Then you could adjust your shadow position and transparency based upon wherever you want your sun.  If you want to go crazy, you could have a day night cycle and alter your shadow positions and transparency based upon the time of day.  That would be cool in an RPG.

In order to make color a variable, one way I have found that you can do it is to make color a Vector4.






Notice how I use the variable color in place of Color.White or New Color() in the second draw statement.  The only thing to keep in mind is when you make color a Vector4, you're now using floats instead of bytes.  So color is from 0 - 1.

You can apply the exact same logic to a player character.  The added benefit is your X, Y offsets for your shadows all stay the same for every direction you draw your character, thus your shadows appear consistant as you turn your character.  Here is a video of my character running and circling.  I increased the alpha to 80 so the video would show the shadow better.  I offset the player rectangle X +10 and Y - 5 on every player animation.  So all player animations have the same offset.  This places my Sun somewhere in the Southwestern sky.  It's easier to see the shadows if you watch the video in HD.

Review Learn Programming Now! XNA Game Studio 2.0 by Rob Miles

Very Silly Games

Rob,

As a new C#/XNA programmer, I've really enjoyed your book, "Learning Programming Now!" If you don't mind I have a few basic coding questions.

My 1st question is, Why do you use an algorithim to scale sprites to the displaywidth and height in your Bread and Cheese game when it seems that you could just use the scale feature built into the SpriteBatch.Draw method. There is an overload for Draw that includes scale. Would it not be simpler to just use that built-in scale feature in Draw and adjust it relative to DisplayWidth and Height?

My 2nd question is, On the XNA Creator's Club Website in the Getting Started section, there is a tutorial teaching you to make a 2D "Shoot the Flying Saucers" game. In this tutorial, the author uses a seperate class to define his sprites. He calls his class GameObjects and in that class assigns the various sprite fields etc. In his main Game class he then refers to those fields by using GameObjects dot field. (GameObjects.field) However in your book in the Bread and Cheese game you use a Structure to hold the sprite information. Is this simply a personnal coding perference or is one way better than the other?

My Final Quesiton is more complicated so please bear with me. I've read a few books that use GameComponents and Game Services to organize their code. (I'm specifically referring to "Beginning XNA 2.0 Game Programming" by Lobao, Evangelista and Faris.) This organizational structure seems bizarrly complicated to me and it seems to me that it breaks the elegance of using the class structure and proper inheritance/parameter passing between classes that you learn in C#. However the game code works and in some regards it's much simpler because is seems that it gets around all of the inheritance problems that become very complicated using multiple classes.

Since you don't address this type of structure in your book, would you be willing to offer your opinion on the use of GameComponents/Services vs. classes as a way to structure game code in C# and XNA?

Thanks so much for your help.

Allan Chaney

Sorry about the delay in getting back to you. Been awfully busy recently. I've put my answers in line...

My 1st question is, Why do you use an algorithim to scale sprites to the displaywidth and height in your Bread and Cheese game when it seems that you could just use the scale feature built into the SpriteBatch

Draw method. There is an overload for Draw that includes scale. Would it not be simpler to just use that built-in scale feature in Draw and adjust it relative to DisplayWidth and Height?

>>> Indeed I could use the scale. The thing is that I wanted to use this to teach about programming and scaling. Perhaps in a future book I could mention that the method is avaiable.

My 2nd question is, On the XNA Creator's Club Website in the Getting Started section, there is a tutorial teaching you to make a 2D "Shoot the Flying Saucers" game. In this tutorial, the author uses a seperate class to define his sprites. He calls his class GameObjects and in that class assigns the various sprite fields etc. In his main Game class he then refers to those fields by using GameObjects dot field. (GameObjects.field) However in your book in the Bread and Cheese game you use a Structure to hold the sprite information. Is this simply a personnal coding perference or is one way better than the other?

>>> I wanted to start with structures and then move into objects later.

My Final Quesiton is more complicated so please bear with me. I've read a few books that use GameComponents and Game Services to organize their code. (I'm specifically referring to "Beginning XNA 2.0 Game Programming" by Lobao, Evangelista and Faris.) This organizational structure seems bizarrly complicated to me and it seems to me that it breaks the elegance of using the class structure and proper inheritance/parameter passing between classes that you learn in C#. However the game code works and in some regards it's much simpler because is seems that it gets around all of the inheritance problems that become very complicated using multiple classes.

Since you don't address this type of structure in your book, would you be willing to offer your opinion on the use of GameComponents/Services vs. classes as a way to structure game code in C# and XNA?

>>> I've not had a chance to look at this book I'm afraid. If you want my philosophy on game structure take a look at my Starlight game for Smartphone. It is not an XNA game, but it has a lot of stuff about game design and sprite management. It also has some stuff about animation that you might find useful.

http://msdn.microsoft.com/en-us/library/aa446569.aspx

I'm immensely impressed anytime an author both supports their work with this kind of dedication and takes the time to communicate with their readers.  His website is amazing.  He has the code for a ton of his games you can download and learn from.

I highly highly recommend this book for any beginning or intermediate XNA developer.

My only recommendation for Mr. Miles is that he please write another book updating the text for XNA version 3.0 and I think he should spend a chapter or two addressing muli-class structured code and the use of Game Components.  Although these are complex topics, they are unavoidable and Rob Miles is the perfectly suited to explain them to you and me.

Allan