Friday, November 20, 2015

Data Driven

I must say that data driven programming can be very effective in games. What does data driven programming mean to me? Writing a generic system that takes in variables to be used during processing.

For example, a generic system for game projectiles where variables include: speed, image file, sound effect, shoot delay, etc.

Another system for particle effects.

Another system for zombies.

Another system for weapons.

Etc.

Exposure

My first exposure to this approach was way back in 1999, when I explored the Kingpin: Life of Crime game source out of curiosity. I considered sprinkled code like this to be relatively welcoming:

G_Items.c from Kingpin: Life of Crime
At the time I found most of the other code to be rather esoteric. Even without programming expertise, one can safely assume the code above represents data for a fuse key. It is noticed while playing that  "world/pickups/coil.wav" is the sound effect that plays when picked up, and uses "models/pu_icon/coil/tris.md2" as an inanimate 3D model file. At the time, I modified some of these values and ran the game to my amusement, eager to learn more.

Data driven in Zombie Guard

Fast forward to 2015. Such a seemingly minor experience had a drastic impact on me. Most of my game projects are data driven - partly out of habit and partly out of simplicity. For example, here is the data for the blunderbuss that can be upgraded five times in Zombie Guard:


Additionally, here is one of the five sets of data for the blunderbuss at rank 1, referenced in the wtypes table inside g.wg_blunderbuss:


Data like this is passed into the function for shooting the weapon, and the generic system for projectiles uses this data as well. It is easy to compare and contrast various weapons.

One of the greatest benefits of this approach is that it scales well as content is added to a game project. For example, I could easily create a new weapon by duplicating just the data for this blunderbuss and modifying some of the variables.

Any fancy special case behavior can be controlled through a new value.

Sometimes hard coding is better

Sometimes a data driven approach is not always better. I was fortunate to have forgone the approach in Defend Your Nuts for the weapons, instead, opting for a hard coded approach.

Defend Your Nuts features a bow with variable number of arrow projectiles, an instant single-target rifle, a bazooka with baby rockets, and a shotgun with variable instant damaging pellets. How could I generalize this? It would have been over engineering, since I knew firmly I was never going to append additional weapon content.


There are two examples of shootEquippedWeapon above. The first is the data driven approach, which for such few number of weapons, would have been more complicated than the second approach that ultimately I pursued.

In other words, data driven approaches can be suitable for large volumes of features that share similar functionality, specified through a set of data. It depends on the situation. Otherwise, other approaches can offer more flexibility.

Room for growth

I'll probably continue to make use of data driven programming. In the future I want to utilize Excel spreadsheets as a means of authoring my data. That way, data variable names are only written once for each column, useful graphs can be generated off to the side, computations can be utilized to help me balance the game.

In the first example above from Kingpin, written in C, you would have to consider the layout of the structure and maintain the correct order of value types. It was just the nature of the language. In my examples using Lua, equating the variable names gets rather tedious too.

I see spreadsheets as being very useful in my future projects...

Sunday, November 15, 2015

Battle Modifiers

Lots of things to blog about! For this post, I want to focus on a small feature that took a few iterations.

I like to sprinkle in a bit of randomization into my games. Little surprises here and there to keep things interesting. In my previous game Zombie Tactics, characters could go off and scavenge for supplies during a battle. It offered risk versus reward - scavenging with many characters would provide the best rewards, but the player would risk getting wiped out with the remaining characters during a battle. On the other hand, not scavenging would be safer in the short run, but would forgo improved equipment and bonuses in the long run.

The simplest approach I took for Zombie Guard was a spinner wheel, reminiscent of prize wheels at a carnival. It was designed to offer temporary benefits and disadvantages. It was decorated with placeholder art. First of all, I was discouraged to spend a great deal of time making it look presentable. It was confusing too. Even worse, tapping the wheel did not feel very interactive. I like to at least give the illusion of choice.



The second iteration was just naive grid of selections. At least here, it felt like there was a choice, even though the function was just simply returning a random battle modifier. Overall this approach felt very rushed. With this implementation of the feature, it worked, but the the game was better off without it.



The latest iteration uses props from the current mission as objects to "search". There is a chance of finding something advantageous like extra ammo and landmines, at the risk of uncovering temporary setbacks like weakened defenses and stronger zombies.



It took a bit of effort to squeeze everything onto the screen. I could not write the names of the battle modifiers and the descriptions because it was just too much text on the screen. Also to prevent the player from forgetting the modifiers, sequentially I present each one being applied to the battle area with the description.

I found some good sound effects and utilized an existing particle effect. This feature now is more intriguing and cohesive with the rest of the game. 

It does take a bit of time to add in all those little movement transitions of the interface, but is well worth it. Corona helps make this easy through transitions with curved interpolation options. For example, the movement of the perks is "outExpo", meaning an exponential curve that starts very quickly and ends gradually.

Image by CoronaLabs
easing.inExpo ; easing.outExpo ; easing.inOutExpo ; easing.outInExpo
My general approach to game design is to offer a steady amount of progression of unlocked features, that is all polished with cool art, animations, special effects, and audio. If the game difficulty is balanced correctly, it can offer steady "fun" and keep the player engaged over time.