Wednesday, March 31, 2010

Reading and Writing XNA Game Data on the xbox

This is something that you think would be simple and straightforward but is actually a bit tricky. I found it tricky anyways, because I could not find adequate information on the subject from Microsoft's XNA and MSDN web sites. Surely, I could be missing something somewhere, but it wasn't apparent to me where I could find what I was looking for. After reading about a dozen or so blogs, forum posts, and MSDN pages, and struggling with my game for a few hours, I finally figured it out. This is what you need to know:


1. You need to use the XNA Storage API, which conveniently will automatically work with PC and xbox without having to code separately for each.


2. There are two separate file locations to work with, the TitleLocation and user-specific folders. The TitleLocation is read-only and stores all game related data that ships with the game. In my case, this is where my map and character data files are kept and read from. I simply place the files in the root folder of the project and add them to the project with properties set to "Copy if Newer" and "No Processing Required". The user-specific folders are read/write and this is where you can save/load games, store high-scores, etc. and it is per user (xbox or windows user).


3. When opening a stream to read data from your TitleLocation, be sure the access flag is set to read-only. It will crash if you open it any other way, even if you only plan to read from it.


I'm not going into all the details with code examples, because there's a lot to find on the internet already. I just wanted to point out some of the facts that I thought were missing from what I read in my research.

Tuesday, March 30, 2010

Turrets!

Originally, we had decided that we wanted to make the game single player, with possible multiplayer and coop additions in the future. However, last week we reversed this decision and opted to go for a multiplayer only game first and then possibly follow it up with a single player and/or coop campaign mode. This would make it easier for us to release the game sooner as less content is required. We started thinking of different types of online games we enjoy playing and although we don't have a definite plan yet, we're leaning towards a sort of 2D Starsiege: Tribes inspired game. There would be two teams, each defending a base where they can deploy turrets, defensive walls, generators, etc. and would heavily rely on setting up cameras and motion sensors to detect and track enemy movement on the map. The map would be divided into many screens to make a big playable arena, so it's not just about combat, but strategy and communication. These are just ideas right now, and we're not sure how well it work out just yet, but that's where all the fun will be trying out different ideas. So this week, we had two major accomplishments: adding the turret, and getting the game to run on xbox. Getting the game to run on xbox was harder than it probably sounds and took me a few hours to figure out. I'm going to post a separate entry on that process for future reference and in case anyone else gets stuck like I did and stumbles across this blog. Anyways, check out the cool turret:


Tuesday, March 23, 2010

Rock n' Roll Arm

The main addition in this update is what I call the "rock n' roll arm". Last update, I added the ability to aim your shots in any direction, 360 degrees, using a crosshair. Unfortunately, this didn't look very good when shooting in any direction except straight ahead because the animation for the hero just has him aiming straight ahead. I fixed this by replacing his shooting arm from the defined animation with a special arm that will rotate to aim wherever you are aiming. This looks much better, and when you circle his arm around it looks like he's rockin out really hard. Aside from this, I also added character-to-character collision and a hollywood style slow motion effect which can be scripted. The new collision allows for characters to push each other around. The slow motion effect is simply to add some style, and to show it off, I added it as part of the attack combo animation I created a few weeks ago.


Monday, March 15, 2010

AI and the Crosshair

I've done a lot of updates since the last post, so the title doesn't do it all justice. I implemented some simple artificial intelligence for the bad guys. I bought this book on game AI years ago that was written for C++ and shows how to create a state machine for managing character AI states. It's pretty robust allowing for you to have functions that execute when entering and exiting a state, and a global function that executes along with each state. Right now, I just have one state that each enemy type uses called "stroll" which basically has them wandering aimlessly with a 5% chance every half second to either jump or change direction. They are also smart enough not to fall off ledges or to run into walls endlessly.


Besides AI, I spent a lot of time polishing up collision; giving characters, melee attacks, and projectiles their own collision rectangles. The projectiles and melee attacks now collide with characters not on their "team". The team concept will be useful for co-op and multiplayer further down the road.


I also added the crosshair from my previous game attempt. While holding down the left trigger on the gamepad, a crosshair is drawn at your head. You can use the right thumbstick to move the crosshair within a certain radius of your head. This crosshair can be used to aim most weapons in any direction and I'm thinking of incorporating it into combo moves in the future.


The last, and coolest looking, update was to the standard shot. Chris came up with some much nicer looking graphics for the standard shot. One is in motion with a tail, and the other is a ball used for when its revving up to be fired and when it collides. When I saw the ball, I thought it would look awesome as part of a particle system and quickly derived a new one based on the explosion particle system with some tweaks. I set it up so the regular graphic will be used alone for a quick shot, and if you charge it up for more than 2 seconds, you get the cool energy trails.

Tuesday, March 9, 2010

Projectiles and destructible tiles

We have projectiles! Not fully implemented yet, but I took my old abstract projectile class and derived "standard shot" class from my previous game attempt and fit them into the new game with map collision. The character editor really helps out here because, with my new updates to it, I am able to specify a starting location for the projectile relative to the character animation. In my previous game, I had to hard code that per character which is annoying and messy. With a few updates to the hero's run and fire animations, he is able to shoot while standing idle or while running now. The other nifty update is destructible tiles. In my previous game, I hard coded the destruction animation so every time you blew up a tile, it crumbled the same exact way. That was ok, but this time around I decided to kick it up a notch and create a particle system for destructible tiles. Now whenever a tile is destroyed, the image is broken into 16 smaller pieces that are randomly blasted away from the center in varying directions, speed, and rotation, with gravity acting on all of them. For demoing and testing purposes, I added functionality for me to add destructible tiles to the map while I'm playing so I'll always have something to blow up =) Check out the video below:



Thursday, March 4, 2010

The Bargle Collective


After boring myself to tears making map segments for a week I decided to switch things up and make a new enemy. This little guy is tentatively being called a Bargle. They are going to serve as our games version of the koopa troopa, in that we'll have different versions of them doing different things. Some ideas we've been throwing around so far are mech operation and manning gun turrets. They're going to be adorably ferocious.

Tuesday, March 2, 2010

Game state management, particle systems, and segment painting

Since I last checked in, I decided to add two things to the game that I already had working in my previous game attempt: particle systems and game state management. Both of these systems I borrowed from samples available from the official XNA web site. I like the way they are done and they are easy to expand from to fit the needs of the game. I built a simple but effective cutscene system off of the game state manager where you simply put the art and sound files in a folder with a name that is a number (like 0, 1, 2, etc.) and you can reference it that way to load and run it in the game. It simply displays the art and plays the sound file one at a time as the user hits the continue button. The video doesn't have sound but you get the idea. In the future I might expand this further to include a script file to make things more robust. The last, and most difficult, feature I added was to the map editor. I had come to realize that it is very difficult and annoying to keep having to line the segments up perfectly and repeatedly when I want to use them repeatedly for a scene. I decided to create a paintbrush like functionality where if I click and drag a segment, it will paint it repeatedly, side by side, or one on top of another, depending on which way I move the cursor. Implementing this functionality caused all sorts of bugs due to the simple way I implemented segment adding and manipulation. I went through and reworked the whole system to be more usable and work in harmony with the new painting feature.



This video shows off the segment painting functionality where I create a new sample map to test the new features with.








I script 3 tiles. The first scripted tile will cause an explosion as long as I stand on it. The second will trigger a cutscene that is just some stock images that come with Windows XP, then removes the scripts from itself so it wont play the cutscene again. The third causes an explosion and shoots the player into the air.