The Blog of Ryan Foss

It's a start!
xna

Rolling Average Smoothing

At the IGDA Twin Cities meeting in March, the lead developer for Just Jam, Matt Heinzen, mentioned using rolling averages to do animation. This caught my attention, since it was a perfect phrase for a trick I have used a number of times in my programming. I thought I’d take a shot at explaining it here since I did a horrible job on the IGDATC Podcast.

A rolling average is also known as a moving average along with a few other cute names. Wikipedia does a good job explaining it in that Wikipedia way. You know, the equation way with complicated, but accurate, descriptions. I say a rolling average is just a way to take the average of a select part of data set. For example, in the last 7 days, I’ve averaged 0.6 cans of Mt. Dew a day. If, tomorrow, I don’t consume any Mt. Dew, my 7 day average will go down.

So how does this help in programming? For me, its usually a matter of convenience. You may have binary data and you want to smooth it out some for instance. To really smooth it out you may want to be aware of your time step, acceleration/deceleration, velocity, motion time, time into motion. Maybe even more. With a rolling average all you need is a target value.

Lets say you’ve got an arrow and you want to have it point somewhere. You don’t want to have super control over the animation of the arrow like I mention above, you simply want to tell it to point up or point down. However, it would be nice if the arrow rotation had some motion.

Let’s set up this example. There is an arrow pointing up, lets call that 0 degrees. Now at some moment you want to say point down, rotating 180 degrees. If all you do is say at one moment your 0 degrees, and the next moment your 180, there is no animation. Let’s use rolling average to smooth it out. All we need to know is the target rotation angle, which in this example is either 0 or 180, and the current angle. We need to pick a period, which in the Mt. Dew example was 7 days. In a typical game, and in most cases I’ve designed, they end up depending on the frame rate, lets not concern ourselves with that at the moment and pick a period of 10.

rolling average rotation = ((current angle) * 9 + (target angle) * 1) / 10

With that example, the first frame after the target angle is changed from 0 to 180, the rolling average will calculate it to be as follows.

rolling average rotation = ((0 degrees) * 9 + (180 degrees) * 1) / 10
rolling average rotation = 18 degrees

That is to say instead of it immediately snapping to 180 degrees, the first frame after its told to go to 180 degrees it rotates to 18 degrees. The next frame would look like this:

rolling average rotation = ((18 degrees) * 9 + (180 degrees) * 1) / 10
rolling average rotation = 34.2

And continuing on.

To help illustrate this I’ve made a little XNA program.  You can either download it and give it a try (no guarantees), or watch this video.

Zombie Game Prototype

I’m working with Robert Green at Battery Powered Games on another game, this time its a action game. About 4 months ago, Rob and I got together for a meeting to discuss our next efforts and discussed ways to learn from our mistakes on Deadly Chambers. We each came with five game ideas and pitched them to each other, back and forth. At the end we picked one idea and went with it. The idea we picked was mine and goes something like this:

Combine Flight Control with Tower Defense, best described with with humans and zombies. You control the humans and try to get them to a safe house, they may or may not have weapons. The zombies try to eat your humans. I’m not going to go into the details beyond that because, along with a designer we’ve hired, we working on many of the details to make sure the game is fun, engaging and rewarding.

Since the pitch, I’ve been thinking about the game play and I’ve come to many conclusions. This is a problem, since we have yet to see the game in prototype form. Rob (and me to some extent) has been busy on some other projects, one of which is Battery Tech, and another is an android game that will be hitting the market within the month (fingers crossed). (My friend Bill and I did the art for this soon to be released game FYI so look for future blog posts about it). Rob hasn’t had the time to make a prototype as he’s also executing some other business ventures and contracts.

As I said we hired a designer but he has become confused about the game which is primarily my fault. With so much time thinking about the game play its hard to keep an open mind, to be flexible. It’s hard to explain things well and succinctly, at the same time to not seem contradictory to previous statements. We’ve gotten buried in communication issues and semantics. It has been interesting to see the designer’s interpretations and opinions, and his designs given our flawed descriptions and requirements. Its also been problematic because we each have our ideas we’re pretty adamant about, but no way to see them in action, get a feel for what works and further the discussion. I was contemplating making some level drawings and animating them to show how I expect game play to work, but then I decided I should just program a prototype.

This is what I love about programming. I started at about 9pm and fired up some XNA sample and just had at it. 6 hours later the clock reads 3am and I reluctantly call it quits. But at the end is a partial prototype allowing for human path drawing, basic zombie AI seeking/attack, a safe house, turning (human becomes zombie), weapon pickup, and human AI targeting.

¬†Ryan’s Zombie Prototype Version 1

In the above picture, the grey blue lines are paths for the humans. The purple diamonds are zombies. You can also see some of the humans are armed with little guns. The lines from humans to zombies show that the humans are targeting and within range of a zombie. I’ll be adding some code to do shooting next as well as see what Rob and the designer say.

Needless to say, I’m excited to program again and wonder why I never really get into it when its so much fun. I’m excited to build up some momentum on this project as well. I’m art lead with two artists on my team, so I’m anxious to get them working.

Senior Design, GSP-490

Last week I finished my senior design class in my Game and Simulation Programming (GSP) degree, class GSP-490. I was worried because I was very busy with Deadly Chambers I had made the bad decision of doing a senior project alone instead of in a group/team as advised. This meant everything was on me. Documentation, design, programming. At the decision point I was too consumed otherwise to commit to anything but what I thought I could handle myself.

The good news is it went well. Grades are in and I got a 90.04%, just eeking out the A. This was a wonderful surprise since I had accepted the fact I was probably going to get a B. Luckily everything with my game fell into place at the last minute and I completed the game (for the most part).

PING! is an action game where you control a ball. You decide which direction the ball should turn when it hits something. Concept was by Bill Nagel and me. It was programmed in XNA Game studio 3.1 (C# FYI). I did all the art assets, programming, source control (using SVN), etc. myself.

Here are some screen shots of my game.

Start Menu

Dynamic Camera Fly at Level Start

Countdown to Start

Game Play Example

Win Condition, PING!

Menu Integration

Apocalypse Update

The team has been working along quite well. He have the starts of a basic menu system in place and a leveling system that shows the concept. The art is in the middle of states unfortunately, I’m trying to get some normal mapping to work, which isn’t as easy as I was hoping. Good stuff to learn.

I was hoping to get into shaders a bit to do the shields but I went with a sprite approach. I simply draw 50+ sprites in a circle around the planet. It works, and I can control their vertical size to reflect the shield capacity. Worked like a charm.

Asteroids and Relfection


I added an asteroids class to the game and got them working. You can shoot them now too and they disappear and your bullets bounce away. I’m having some problems with the reflection vector, where the reflection appears to be mirrored. It’s late though, and I just want to post a picture.

Asteroid Apocalypse Template


I spent the better part of the evening yesterday getting this project running. It’s an empty shell really, but it has some art assets from Blender (via a slightly modified FBX python exporter), rotating earth and asteroids too. It allowed me to get the scene setup with a configuration I like. I’m using a tight FOV (XNA uses the horizontal to define their FOV setting which is new to me) so the 3D models are subtle and feel smaller.

Combine Dodge, aka Henry Rain


I took the modified RockRain XNA game project I’ve been working on and deployed it on my Xbox 360. Pretty neat. Henry made me change it from Aidan’s face to his face. Plenty fun though none the less.

XN-Yay!

Well, it isn’t the best but the basics are there to demonstrate the concept.
Essentially you are looking at XNAMentor’s Space Invaders project modified with our game concept in mind. I also got the Blender to XNA FBX pipeline working so I’m feeling pretty confident we can pull this off.

Additionally, I’ve been reading Beginning XNA 3.0 Game Programming and I’ve got one of the “games” working. It’s originally a meteor dodger game where meteors fall and you have to avoid them. I modified the art so instead of a spaceship, you are combine harvester that dodges my son Aidan’s face. This was a big hit with my son Nate.

GSP, XNA, and SVN Oh My

I bet I’m not going to get any readers based on that title, but I don’t know a better way to sum this up.

My first week of GSP-360, Applied Development Project, ended Sunday and it was a roller coaster ride. First off, the class is more focused on documentation than development and strongly suggested we do a “mod” instead of a “from scratch” project. I was very disappointment but with the professors approval, I recruited a team to make a game from scratch using the XNA Game Studio framework.

The week started off rough, being that our communication needed to be ironed out. That, and I was somewhat stressed because I’m new to C# (the programming language) and XNA (Microsoft’s branding for game related software and development stuff). I didn’t really know what I was getting into. However, after we got together and chatted using Google Talk, we settled on a concept.


I suggested a game and the team was willing and eager. The concept is a simple arcade style shooter, similar to asteroids in design but instead of trying to blow up asteroids, you shoot them to change their course and steer them away. I put the concept art above together to help communicate the idea and I think that helped.

Additionally, I set up a SVN repository for us to work in. This is especially important for programmers. For those who don’t know, SVN (aka, Subversion) is a Version Control System and that means that we can work on projects together, but a master repository holds all our stuff. If we make changes to something, we check it in and others will get the changes. It should help us work together easier because it mandates document control. An easy way to imagine it is if your team had to work on a letter together. Most teams divide out the sections and then put it together, which can work fine. But having one document that we all work in and change, almost like a shared file system, makes it so we all can contribute to every section.

I plan on writing up an SVN tutorial in the next couple days to explain what I did and how.

Onward to Education

I got my grade for GSP-410 (Software Engineering for Game Programming) today. Was excited to see I got an A.

I’m a week into my other classes now and things are going well. I’m taking a career development class, CARD 405. That is a real snooze so far. All about interviewing and the job market. Which would be good, if I didn’t have a job.

The other class is GSP-360, Applied Development Project. The intent of the class to my dismay isn’t to develop in the sense of software, its to develop a mod with focus on the documentation. The concept, game design, technical design, project design, etc. documentation. They suggested using Torque, which I was not a fan of modding to. We had to form teams, so I recruited 3 others to work an XNA project. I’m the lead. We’ll see where we go.

Our first assignment, the Concept Document, is due on Sunday and we haven’t decided what we are going to make yet.

XNA C# Gotcha #1

Thought I would post a problem I encountered and the solution I figured out.

Given:

A class, mySpriteClass, with method:

public Vector2 position { get; set; } // Sprite position on screen

And trying to update position in the game update loop with the following line:

mySprite1.position.X += 1;

Gives the error:

Cannot modify the return value of ‘mySpriteClass.position’ because it is not a variable

Change

mySprite1.position.X += 1;

to

Vector2 Position = new Vector2(mySprite1.position.X + 1, mySprite1.position.Y);
mySprite1.position = Position;

I thought I knew what is going on here, but when I tried to explain it, it got out of hand. Its something to do with value types vs. reference types.

XNA W00T!

Got to play with some XNA today at work. I whipped this quick generic gun model up to prove out the content pipeline (Blender and textures). This is a modification to the BasicModel project, but with my parts and textures.

It was a lot of fun, and whoa a lot of learning. I see I have my work cut out for me, bot as a programmer, but as an artist.

XNA coolness

A coworker and I went to the local XNA MN user group meeting last Wednesday. I have to say I’m pretty impressed. Sounds like it could be fun so we’re getting into it. Homebrew 360 games sound like it could be a lot of fun too. Me, I’m just itching to start making a game.

The Zune news was also just released at GDC which is also pretty neat. Makes me want a Zune. Too bad the DRM crap sucks. I don’t know if I want the thing if all it can play is WMVs. That sucks.