Monday, September 11, 2006

F14 XNA Game





The video reflects the latest released version.

full source included:
F14XNA62.zip [mirror] (7.1MB) - Big thanks to Robby_ks for the xbox 360 port.
Updated v0.62 (12/23/06)
Please look near the bottom of this post for update details.

So about a week or so ago microsoft released the beta of XNA. It's a development platform that is based on C# and the .net 2.0 framework. When the final version comes out later this year, you should be able to re-target your project to X360, recompile with little code change, and actually play it on your X360 (that is if you join their $99/year creator's club).

I'm a coder by profession but I've never done any graphics or game programming before. I've glanced at directx and Managed Directx before but both of those still seamed like way too much work to get started. XNA looked like it finally simplified things enough so you can just get right to the game coding. Since I had a few years of C# under my belt I finally decided it was time to try and see if I could write a game.

Overall XNA has been pretty nice to work with but it's definitely a beta product (some missing functionality, bugs, missing or inaccurate documentation, etc).

Disclaimer: This is my first game I have ever wrote. I haven't even read any game programming books. Basically I got most of the help I needed from the excellent official xna forums and the links I list below. I wrote this game basically to get familiar with the new XNA framework.

So here is my rather generic 2D vertical scrolling shooter F14 XNA. Think 1942 or Raiden and you'll get the idea. This first release is really far from done but I thought I had put enough work into it to have something kind of fun to play with some possibly useful code. I have quite a few interesting gameplay mechanics I want to implement in the future. I'm not sure if I'll ever finish it since I really want to dive into the 3d stuff. But everybody says you should write a 2D game first so here it is. Either way it served it's educational purpose.

Installation: The current xna beta doesn't let you create a stand alone package for distribution. You must install .net framework 2.0, c# express, and XNA beta. Then, fire up c# express, open the f14.sln file, click build, rebuild. Then look under bin\release and run the f14.exe. If you want to run it in debug under the IDE just hit F5 in C# express but performance is better if you run the f14.exe directly. It should have no problems runing at a solid 60fps on most machines.

Controls:
Keyboard and X360 wired controller are currently supported.
W,S,A,D, Right analog stick, D-Pad: Movement
space, A button, Right trigger: Fire
Home, start button: restart
esc, back button: exit

Gameplay:
By default you get 3 lives. Fight off a few waves of enemies and make it to the big boss at the end. If you managed to destory it, the level just starts over again. To change the numer of lives look in the Player class and change totalLives. When you die you are invulnerable for the first 2 seconds.

features:
- 1 level of play including 3 enemy types and a boss
- 3 levels of parallax scrolling
- sound
- high score
- animated sprites, rotation, scaling
- basic enemy ai, track the player, movement patterns
- robust scripting engine so making your own levels would be easy.
- "realistic" graphics (ha!)
- keyboard and Xbox 360 wired controller including rumble support.

Project details:
- about 4400 lines of code of which around 3300 I wrote myself.
- 8 days coding on my free time. Can we say a LOT of late nights.
- A pretty complete 2D vertical scrolling shooter engine that should be pretty easy to customize.
- This was my xna learning curve project so I'm sure there are a lot of things I could have done better. Feel free to rip it apart and post any suggestion you might have in the comments.
- The OO design is a bit sloppy. I've got some loose scoping, the constructors are a mess, too much code in the Director class that needs to be pushed out to the other classes. Yeah there is still a lot of cleanup I need to do.
- Heavy use of strongly typed generics collections.
- Most textures cached in a Dictionary
- The scripting engine is pretty flexible. It should make designing levels pretty easy and the ScriptItem class is ready to be serialized. It would be trivial to support outside editing of say a level xml file and then loading it up into the game. Check out Director.GenerateScript(). You can easily generate squadrons of fighters, display text, change background speed, play a sound, etc.
- Spent way too much time on Common\ScrollingBackground.cs. I think I rewrote it 3 times but I like the final result. I can take almost any size textures, piece them together, and loop them. You can scroll in either direction.
- Default resolution is 1024X768 but you can change it to whatever you want or go full screen, and I think the game should handle it. I tried not to hard code anything based on a fixed resolution.
- I take NO credit for any of the art assets (well except maybe for the little puffs of clouds). Most of the stuff I just googled because I can't draw worth a darn. Most sprites I cleaned up in Paint.net making ample use of the magic wand to make the backgrounds transparent.
- For explosions I used Simply Explosion Maker.
- Most sounds are from the spacewars project with some recordings of the voices which were processed through Audacity for some effects (like on Warning!).
- No music until there is something like mp3 support. Otherwise file size would get way large.
- Input I used Dean Johnson's Game component.
- bitmap fonts I used garykac.
- There is a bug where after an enemy dies and the script spawns a new enemy with a different projectile texture, the projectiles for the dead enemy that are still on the screen could possibly change images in mid flight. Basically I'm reusing those Enemy objects too soon. I'll get this fixed up maybe later this week along with some much needed code cleanup.

Well, that's about it. There's still a lot of work to be done but I think I'll take a break for a bit since I've been going at it pretty hard for the last week.

Links:
xna beta:
http://msdn.microsoft.com/directx/xna/gse/

You need to install C# express first (even if you have the full visual studio already installed)
http://msdn.microsoft.com/vstudio/express/support/install/

F14 XNA Discussion:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=716083&SiteID=1

http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=882&SiteID=1
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=690814&SiteID=1&mode=1
http://www.xnaspot.com/
http://www.xnaresources.com/
http://learn-xna.com
http://www.xnadevelopment.com
http://blogs.msdn.com/xna/
http://exdream.no-ip.info/blog/
http://xbox360homebrew.com/blogs/audio/archive/2006/09/01/119.aspx
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=689261&SiteID=1

http://blogs.msdn.com/garykac/archive/2006/08/30/728521.aspx
http://audacity.sourceforge.net/
http://www.getpaint.net/
http://www.xnaspot.com/Sample_SimpleInput.aspx
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5133
http://gpwiki.org/

Previous Videos
Pre-release prototype
v0.50 first release
v0.60 short 1 min version

Version History:
v0.51 (9/12/06)
- added game over voice
- version # prints in the lower left corner
- fixed a build issue with the signing property on the project file thanks to Knight99

v0.60 (9/13/06)
- cleaned up all the code. If you are at all interested in the source please make sure you grab the latest version. OO design is pretty clean now, flattened the class hierarchy a bit, cleaned up the constructors, use of texture cache is now consistent across the entire game. The following classes were removed: bullet, missle, and explosion.
- fixed the above mentioned bug on projectiles.
- Added the ability for any vehicle (enemy or player) to shoot multiple types of projectiles. I've reworked the ufo boss to now shoot 3 different projectiles each with it's own rate of fire, max shots, and speed.
- extended the level a bit with a few more squadron of fighters.
- guided missiles (both enemy and player) should make it in the next release. I've already had some good internal preliminary tests.

v0.61.(12/17/06) (Mirror)
- additional files:
F14 XACT sound project source
F14 WAV files
- ported from beta 1 to XNA Game Studio Express 1.0.
- Sorry no new features in this release.
- It took quite a bit of effort to do (almost a full day).
- Helpful porting pages:
http://letskilldave.com/archive/2006/10/30/Migrating-an-XNA-Application-from-Beta-1-to-Beta-2.aspx
http://blogs.msdn.com/xna/archive/2006/11/01/beta-2-changes-part-i.aspx
- Things that broke that had to be fixed:
- setting window resolution
- no more designer broke a few things especially the use of game components
- GameTime and not being able to get to time elapsed from the Game object was the biggest issue
- had to convert xact project to 2.0 to get sound working
- cue.play sound bug code work around
- spritebatch.draw and depth parameter seems to work a bit different (the order in which the draws are executed critical now)
- Still can't get publishing and stand alone executable installation working but I haven't tried very hard yet.

- XBOX 360 port by Robby_ks, Thanks! Here are some of the changes he had to make
Here is a short ChangeLog to get it working on Xbox 360:
- Added actionSafeArea and titleSafeArea to Director and SceneItem to avoid items outside the visual area
- Changed all bound checks in SceneItem.cs, Player.cs, and Enemy.cs
- Fixed a bug with the ScrollingBackground which was only occurring when using small resolutions (eg. 640x480)
- Use content manager for loading of textures in BitmapFont.cs and TextureCache.cs, since Texture2D.fromFile() is not supported on Xbox 360
- Using #if !XBOX360 to ignore all mouse related stuff in InputManager.cs

v0.62 (12/23/06) [mirror]
- Big thanks to Robby_ks for the xbox 360 port and cleaning up and organizing all my source files/content.
- It is now a single consolidated solution that contains both windows and xbox 360 projects, xact project, and raw wav files. This is now the complete source with all content used to make the game.
- To deploy to xbox 360 you have to first right click properties on the solution, configuration properites, check deploy on F14Xbox.

Post a Comment