C Coroutines for Game Entity State Management

State management is one of the more difficult aspects of game programming. Entities in your game must behave differently depending on their internal state, and may depend on the state of other objects as well.

There are several approaches to solving this problem – the naive approach being lots and lots of conditionals. Finite state machines approach the problem by objectifying state and state transitions. More recently, with the growing popularity of higher level languages like Lua, Python, and C#, coroutines have become a popular choice for mitigating the complexities of managing state.

I have implemented coroutines in C, and it’s turning out great. Here’s how to do it!
Continue reading “C Coroutines for Game Entity State Management”

Victory at the Rosetta Stone Game Jam!


David McDonough, Jack Cooke, and I polished off a 1st place win at Rosetta Stone’s first annual 36 hour game jam in Harrisonburg Virginia on Saturday.

The requirements for the game were given out beforehand, and were very open-ended: make a game that “teaches.”  Coming from Firaxis, we decided to make a strategy game, and settled on a “virus” theme.  We liked the idea of a virus strategy game because we could abstract things visually (simple shapes with cool shaders – no characters to animate).  The simulation aspect of the game play could also be very simple, and amounted to little more than three numbers driving a physics-based steering system (like this).

Each of us had some basic knowledge about how vira spread in the body, and we really didn’t go out of our way to do any additional research.  One of Sid Meier’s 10 Rules of Game Design (we’re not really sure which one this is – he changes the order all the time) is to “make the game first, then do the research.”   This may sound a bit strange at first, but it makes sense.  If the game isn’t fun, it doesn’t engage the player and loses the ability to teach.  If the simulation is to detailed or esoteric, the player can’t easily grok it, and  you lose them.  Civilization is a great example of this.  It is built from the assumed historical knowledge of the average gamer (unless you fire up the Civilpedia).  The game doesn’t teach by relaying historical facts, rather it does so by allowing the player to engage in a simulation that, while not historically accurate, illustrates very clearly the dynamics of industry, diplomacy, war, and culture.

The game we ended up with at the end of the day is called Pathogen.  It features game play that is very similar to Phil Hassey’s Galcon with a 3D play surface.  You move your swarm of vira from cell to cell, expanding your population and avoiding autoimmune cells as you go.   Before each level, you load out with three “mutation cards” which give you power-ups as you hit certain population milestones.  The game is very simple, but illustrates well the balancing act a virus must perform when successfully infecting it’s host. Continue reading “Victory at the Rosetta Stone Game Jam!”

Cell (Worley) noise in Unity3D

Cell NoiseNoise algorithms are a fantastic thing to have in your 3D graphics bag of tricks.  I can’t tell you how many times Perlin noise has saved my life.  Unfortunately, most good noise algorithms don’t lend themselves particularly well to computation on the GPU.  Enter Cell noise.

Cell noise, otherwise known as Worley noise,  is actually a visualization of a Voronoi diagram: given a random scattering of points, color each pixel on the surface relative to the distance from the closest randomly scattered point.  Cell noise appears all over nature, it looks great, and is easy to compute!  A cell noise function can give us a volume of noise, which we can sample in a fragment shader, giving us seamless patterns on any object – no UV mapping required.  Cool!

Continue reading “Cell (Worley) noise in Unity3D”