Mixing the Game State Management and Platformer XNA Recipes
- Posted: Mar 18, 2011 at 7:00 AM
- 12,173 Views
- 7 Comments
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
Just about every application needs some kind of state management, games more so than most. From basic menus, to options, to "life" management. A game without options, lives, etc. is only half a game.
The App Hub provides two, among many others, interesting recipes. One for a basic game, Platformer "... is a self-contained game solution for Windows, Xbox 360, and Windows Phone 7 that includes both game code and game assets. The game is a standard 2D platformer with levels, enemies, and collectable gems." and one for Game State Management, "...shows how to manage the transitions among menus and gameplay states." While each is useful by themselves, alone they only tell part of a complete game story.
Aaron Stebner via his Link to samples that merge the XNA Game Studio 4.0 platformer starter kit with the game state management sample post has pointed us to just that.
"... I added a couple of versions to the merged Platformer/Gamestate Management sample that I did as a result of a question on the AppHub forums. Here are all the relevant links:
Bare bones merged version
+ scrolling level
+ moving tiles"
(Please click through to the post to get the downloads... I didn't want to leach all his traffic...)
So what's so the big deal about menus?
The issue is XNA development isn't your WinForm/WPF/SilverLight kind of development. In XNA you are responsible for drawing everything, in code. There's no GUI designer. There's no draggy and droppy. Code, code, code, everything is in code.
This means some things that are simple in a form based world become harder in a game loop world. Like option screens, etc.
Enough chatting, lets look at the some code. Here's a snap of what it takes to draw a a Level
Lets looks at the before and after, to see just how much we're getting. Here's the original Platformer
Note: If you download the Platformer code and you see this when running it;
Try changing the Game Profile property to "Reach" (via the Project Properties)
Here's a snap of the solution for the mega merged version ( Bare bones merged + lives + scrolling level + power-ups + moving tiles) which shows off the Main Menu, lives and side scrolling.
To give you a feel for the project, here's a snap of the Visual Studio Solution
So how's the Main Menu done?
It's the mixing in of the Game State Management that makes this fairly easy, much easier than you having to re-invent this wheel and code it all from scratch yourself.
Something I found pretty cool in the Platformer is how the Levels are mapped. Each level map is actually just a text file.
Here's the original first level;
Hopefully this has wet your appetite a little and give you something to play with this weekend...