The Blog of Ryan Foss

It's a start!
programming

Rocket Builder Prototype

This Rocket Builder Prototype is something I’ve been playing with. Inspired by Kerbal Space Program and my kids interest in Bad Piggies’s sandbox mode, I built a quick prototype for testing. When I showed my kids its was a hit, and I’ve never experienced better motivation.

CLICK TO PLAY

This prototype was built in Unity 3.5 and works on Android, PC and web. I used Unity’s built in physics of rigid bodies and joints for the parts which I think works great.  I’m aware of a number of bugs or strange behavior, and the interface needs work, but it is a prototype after all.

There is still a lot I want to do with this, and my kids have more ideas too. Hopefully I can get back to it in the near future.

If you have any ideas or comments, or a cool design you want to share, send me a note!

Fireman Run Menu Development

Over the last week I’ve started implementing the menu and interactive buttons into the Fireman Run game. Rather than describe some of those changes, I recorded a quick video to show how my development is going.

Fireman Run is a game I’m developing with a few friends. It’s made in Unity, using C# and primary testing is on Android devices at the moment.

Project: Fireman Run Reveal

This isn’t much of a post I admit, but I’m so overdue and I have to much to say about it that I’m boiling over. So for now, I just want to say that I’m working on a Android mobile game called Fireman Run. It’s a rooftop running game, but with fire, and you can spray to put out fires if necessary.

Automatic Road Geometry Generation in Unity

I’ve had an awesome project at work developing a simulation in Unity3D that builds a test track, a road essentially, right before your eyes.  Technically, we’re using some pretty hefty data, including OpenCRG and Power Spectral Density data as inputs, but I also added a lower weight random algorithm that can make for some roads more appropriate for game play.

In the image above you can see a long length of track that I generated with a few inputs.  Additionally, it creates road rails to help keep the vehicle on the road.  It also creates a simple ditch on each side of the road from a simple profile. Additional options include material selection, which changes the road appearance.

It’s not often that I get to share stuff from work, but this is only a taste of what it can do. The project will eventually be released to the public. Hopefully some day I can share a video of everything it does.

The vehicles are from the Car Tutorial project provided by Unity.

Global Game Jam

I can’t believe I let this go without mention, but man I’ve been busy!  I have so much to say and reflect on it overwhelms me to think about it.

The Global Game Jam 2012 is one such event.  Way back in January I spent 48 hours making a game and it was awesome.  Of that 48 hours, I slept four!   The result was a game we called “Boogie Fling”.  It was developed in Unity, and you can play the web version here: Boogie Fling

Much credit has to go to Ty Burks for most of the art and Tori Kamal for the hilarious sounds and music.

The Game Jam was awesome and the local IGDA group had an outstanding attendance with over 27 participants on 11 teams!  It was awesome fun to jam with so many cool and interesting people.

 

Hungry Monsters Prototype

While on my recent business trip, I spent my time at the airport and on the plane programming a game concept I’ve been thinking about a lot lately: Hungry Monsters (the first prototype). Fair warning, there is no game play yet, but merely a rapid prototype of the game play elements, specifically the resource management of employees, work stations, ammunition and the actual playing field.

Hungry Monsters is very similar to Plants vs. Zombies, but with my own engineering spin on it. What’s different, at least in my design, is that the player will have to decide how to spend their resources differently by running a bakery to provide the food (the ammunition), as well as place weapons to fend off (feed) the onslaught of hungry monsters. Players will have to decide if they place another muffin shooter, an oven, or another employee for instance.

The prototpye at this stage doesn’t allow the player to do anything yet, but was built to allow me to investigate the idea. Through the Unity Editor I’m able to try different combination of things. Considering this took me about 6 hours (built from scratch in airports and on the flight for a recent business trip) I’m pretty happy with the outcome and excited to move on. Please excuse the Microsoft Paint artwork and simple geometry, it is a first pass prototype!

In the next version I hope to have the basic interactive elements working to allow placement of work stations, workers and weapons. (I need a better word for weapons too!)

Minnetron 10,000 Arcade Viewer

I’ve made a Unity Web Player version of my Arcade Viewer for the Minnetron 10,000 Arcade Cabinet I’ve been building.  My intent was that this would both show how the cabinet goes together (since I built it digitally in Blender first, why not use it?) and to allow others to try out paint job concepts.

To see the “game” click on the image.  You may need to install the Unity Web Player, but it will be worth it!  Or just download the Windows executable.

http://ryanfoss.com/games/prototype/arcadecab/
FYI, the name “Minnetron 10,000″ is a play on the Minnesota nickname “Land of 10,000 Lakes”.

Blocks that Fall in Unity

If you’ve been to the IGDA Twin Cities meetings, or have seen any of the videos (here and here) where I presented the idea of collaborative game developing, you know that the group is off and running.  We’re moving forward with a Mr. Driller inspired climbing game of block destruction.

We’ve done a lot of development over the two months we’ve been at it.  However, at the last meeting a number of bugs showed up during the live demo.  Due to certain circumstances (my laptop fell to ground and quit working) I ran the game demo on a netbook.  Although the game still played well, a number of bugs appeared more often than in my play testing, probably related to framerate and physics calculations.

As a game developer, something I’ve always wanted to do was program a Tetris clone.  Why?  Well, because although its simple, its also a good exercise in programming for a novice game programmer.  Alas, its also one of those things I’ve never done (but always think about).  Given the troubles we’re experiencing with the existing block falling code in the game, I decided it was time to take a crack at it.

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.

I Graduated!

It happened, and I have the bills, and diploma, to prove it!

I now have a second Bachelor of Science degree in Game and Simulation Programming from DeVry University.

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.

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.

Face Detection ala OpenCV


I found this cool tool called OpenCV, which stands for Open source Computer Vision. Its a library for programming computer aided vision stuff, such as with a web cam. I got the face detection algorithms working and as you can see, we’re having a little fun with it.

The little red circle on my forehead is the brightest spot in the image. The software will detect any number of faces, circling each. I’m going to make a “temperature” plot based off a target color to help diagnose finding a green laser dot.

I know that although this may sound simple, I’m going to have a lot of problems with color and balance considering the lighting situations I have.

A Nearest Color Algorithm

I’ve been developing this software at work to take an image from a video stream (a webcam in this case) and detect if a green laser dot is present. After spending most of my day getting a project to compile and a program to recognize my webcam as a stream, and being distracted by numerous other projects and co-workers, I just wasn’t at the top of my algorithm development game to detect the green dot. Combine that with office lighting and you know my dilemma (fluorescent lighting is often green tinted and throws off a white balance.)

I start by stepping through each pixel in the source and check its color. If you take the pixel’s colors from each channel and find the average you’ve essentially got a gray scale value. This doesn’t work so well since some shiny metal might throw off the detection (like a ring). If I wanted to find the brightest spot, this is a good approach, but I needed to emphasize the green. At first I added a weight to the green channel by simply doubling it. So now the average is calculated as (R+G+G+B)/4, counting the green channel twice. This was better, but also prone to problems.

At the end of the day I had a basic project setup and working with some hit or miss detection. I had invested over an hour into multiple approaches and although my algorithms for color matching were working somewhat, and I knew there had to be a better approach.

What dawned on me later was something I should have noted much earlier. I know that the RGB color concept is essentially a three dimensional array, but since it is color I’m used to thinking of it two dimensionally like you see in an image editing program. Once I visualized it as a 3D space, a big cube made of blocks so to speak, I knew my answer.

You know the shortest route from A to B is a straight line right. This is easy to calculate in 2D using the Pythagorean Theorem as you probably recognize:

a² + b² = c²

This also applies in 3D space, which is exactly what RGB color is. An RGB value is a point in a 3D space. The Theorem applies like this:

a² + b² + c² = d²

The obvious solution was in front of me but I didn’t see it. Euclidean distance would give me exactly what I needed. I needed to treat the color difference as a distance.

r² + g² + b² = d²

For instance, say I wanted to find the closest pixel in the supplied source to a target color RGB 128, 255, 128. I check pixels against my target color by finding their channel distance. So imagine I have a black pixel of 0, 0, 0. My distance is calculated as:

r = pixel_color – target_color = 0 – 128 = -128
g = pixel_color – target_color = 0 – 255 = -255
b = pixel_color – target_color = 0 – 128 = -128

d = sqrt(r² + g² + b²) = 312.7

What if I have a pixel with color 0, 0 255, or a pixel with color 0, 255, 0. Which one is closer to my target? If I calculate the average, they are the same. But by distance, the green pixel is closer to my desired.

C++ Wisdom

An object encapsulates state and behavior. Abstraction is the means by which the state and behavior of a class are derived from the many specific instances of things that the class is said to represent.

Object oriented (OO) programming is a tricky devil, especially someone like me who was self taught BASIC when I was 9. Reading the above gave me one of those light bulb moments that helped me break through some of the OO jargon and C++ I’m working with.

Sound Served

At work I played around with our sound server and sound messaging and I was excited to get variable engine sounds working working. When we first started doing sound on the PC, the system couldn’t keep up with the simulation and play the sound at sync. None of us had any sound programming experience and could not get it to work well. We had some balancing issues so we made a sound server that could run on a remote machine where the processor wasn’t consumed. This was good for a lot of reasons, but ultimately is ugly today IMO because it adds complexity and lots of messaging. Hopefully I can integrate sound directly into our simulation this summer. Meanwhile, since we are simulating some boats I added the ability to control volume and pitch and volume on indexed sounds that are attached to vehicles, and send messages with the corresponding values. The code looks something like this.

pitch = 0.75 + 0.5*currentSpeed/maxSpeed;
volume = 0.50 + 0.5*currentSpeed/maxSpeed;

//send message “vehicle index soundname x y z h p r volume pitch”

Its pretty simple and it works quite well. Essentially as the vehicle increases in speed the volume and pitch of the motor sound increases. It proved the concept, which I’m sure is how some games do it. Next I want to add an idling sound and modify it something like this.

if currentSpeed < 0.25*maxSpeed {
volumeIdle = 1.0 – 1.0/0.25*currentSpeed/maxSpeed; //goes from 100% to 0%
volumeEngine = 0.5 + 1.0*currentSpeed/maxSpeed; //this should max at 0.75
}
else{
volumeIdle = 0.0;
volumeEngine = 0.75 + 0.25*currentSpeed/maxSpeed;
}
pitch = 0.75 + 0.5*currentSpeed/maxSpeed;

//send message “vehicle index soundnameIdle x y z h p r volume pitch”
//send message “vehicle index soundnameEngine x y z h p r volume pitch”

This should let the engine idle sound be heard when the vehicle is not moving, or moving very slow. I don’t know if this will work, but I bet with some tweaking it will sound ok.

Also, since this is for a boat it makes sense as there is no shifting or gears; the engine just ramps up. But if I want to apply this to another type of vehcile with a more complicated engine, it could be modified this:

pitch = 0.5 + 0.25*gear + 0.75*currentSpeed/maxSpeed;
volume = 0.5 + 0.75*gear + 0.25*currentSpeed/maxSpeed;

Where gear is used to make the sounds see-saw some for that vroom-vrooooom-vrooooom sound of changing gears.

Arithmetic Operations Timing

In GSP-130, Systems Architecture and Assembler, we had a lab to examine different mathematical operations and the time it takes to process them. The bar chart shows the results, comparing integer and floating point add, multiply and divide.

As I expected, integer add and multiply was faster than floating point, but what surprised me was the integer divide taking longer.