GDC Day 1: Math for Games Programmers

GDC '13 logo

For the second year in a row, I attended the Math for Games Programmers tutorial at GDC today. As expected, there was a fair amount of review, but I also learned some cool new things!

The earlier talks on splines, blending, matrices, etc. were basically review for me, but it was nice to have that refresher. That said, one tip came up that really stood out to me for matrix math. Matrices are multiplied in a sort of “reverse” order, for example:

Rotation * Translation = translate-then-rotate

Incidentally, this is actually the same order you’d write functions while programming:

rotate( translate( point ) ) = translate-then-rotate( point )

Nifty!

Jim van Verth’s talk on quaternions was absolutely fantastic. He spent the talk discussing how quaternions work rather than why we use them. Questions like “why four values?,” “why do we input theta over 2 instead of the entire angle?,” “how can we visualize 4D space?” and more are covered. As a bonus, the tutorial will actually make it to the GDC vault this year, so definitely check out the talk if you can! If you don’t have vault access, you should be able to pick up the slides at http://essentialmath.com/tutorial.htm once they’re posted.

Dual numbers sound useful, but I’m not sure how often I’ll use the content of the lecture. That said, “you can basically get the derivative for free” is a pretty awesome thing to keep in mind. They’re pretty interesting from a mathematical standpoint.

The talk on Orthogonal Matching Pursuit and K-SVD for Sparse Encoding went way over my head, but I still pulled a good deal of information from it. I think I have a rough idea of how compression works now. I have some research to do!

The talk on Computational Geometry was pretty interesting, though it seemed more or less the same as last year. Still, it was good to get the review – I had forgotten a lot of it. I also learned about higher order surfaces on the GPU (i.e. tesselation, etc.), which was new to me!

Finally, the talk on Interaction With 3D Geometry by Stan Melax was amazing. It was a super-fast-paced crash-course on a huge number of subjects that left me really inspired to start writing some tech demos to learn how all of the concepts work. I’ll definitely be watching it on the vault.

Tomorrow: Physics!

Planning Out an OUYA Launch Title

Photo of prototype running on OUYA

After hammering out a prototype for the CREATE game jam (partly to prove to myself I can make this game), I’ve been planning out the development cycle for my upcoming OUYA game, Project Onslaught. In terms of time frame, there are a few known dates:

  1. February 11th – CREATE finalists announced
  2. February 18th – CREATE winners announced. At this point, I’ll know for sure what my budget is. Keeping my fingers crossed!
  3. March 4th – Classes begin again for me, splitting my focus
  4. March 8th – Chuck, fellow OUYA enthusiast, comes to visit for a while and help out, which will help offset classes starting up again
  5. March 25-29 – GDC week
  6. March 28 – OUYA Launch Party (but not necessarily console launch)

There’s no official launch date set yet, but as the “launch” party is during GDC week in March, the apparent best plan of action is to be done by GDC. That said, they could hypothetically launch the console any time in March based on the Kickstarter dates, but I highly doubt it’ll be in the beginning of the month. Ultimately, that gives me about 8 weeks to develop a 3D hack ‘n slash game.

I’ll also be starting “from scratch” in the sense that I won’t be using the prototype code. I went into the CREATE game jam with the rule that I won’t carry over the prototype code so I could make it as hacky as needed to meet the deadline, and I’ll be sticking to it. It wasn’t wasted time – it was a solid proof of concept, and it gave me a much better sense of how to structure everything.  Plus, looking back at it for reference is fine, I just won’t be copying it fully.

With the 8-week time frame in mind, I needed to figure out what the minimum viable product (MVP) is. The MVP, as its name implies, is the bare minimum that needs to get done by launch for a solid game release. Updates after launch are definitely planned, but when the game comes out, we’ll need:

  • 4-player support, local multiplayer
  • 4 hero types to choose from, so everyone can be something different if they want
  • Arcade Mode – Basically, one or more game modes that are focused on high scores, replayability, etc. Arcade mode will be free content.
  • Campaign Mode – At least the first “chapter” available. The first level or two will be free, with the full campaign available for purchase (potentially released on a chapter-by-chapter basis)
  • Power-ups/consumables – think Gauntlet: Dark Legacy. These have the potential to add a lot of fun to gameplay, and should also help the player feel like a complete badass from time to time
  • Basic character progression. At a minimum, XP and levels that give more HP. Preferably, a few basic stats that can be increased. Nothing more complex than that – it should be a game you can sit down and play without fiddling with complex stats/builds/etc

With all of that in mind, I’ve got a rough, tentative schedule written out. It’s super-duper subject to change, but for now:

  • Week of Jan 27: Re-implement player controls and basic combat mechanics (i.e. attack stuff to kill it). Hopefully knock out multiple hero types in one shot.
  • Week of Feb 3: Enemies. Lots of work on enemies, to give lots of options for building levels/scenarios. Also includes polishing combat mechanics.
  • Week of Feb 10: Build Arcade mode. Pretty much a more robust variation of the existing combat prototype. Cross fingers and hope to win CREATE prize money to fund art assets
  • Week of Feb 17: Start working on a framework to build levels for the campaign mode. Discover I won prize money and rejoice! Or, failing that, congratulate the winners on a job well done =]
  • Week of Feb 24: Finish campaign-building framework, and anything else missing in core gameplay.
  • Weeks of March 3, 10: Content! Build content! (Also a buffer for slips in earlier plans)
  • Week of March 17: Feature freeze. Polish. Only finishing up campaign content along with polishing and bug fixes – anything that hasn’t made it in yet won’t be in at launch (but hopefully will be shortly afterward!)
  • Week of March 24: GDC week! Potential launch week! Network, talk about the game, go to talks, etc.
  • Following weeks: Game maintenance, work on new content, etc.

I will, of course, be posting blog updates along the way as things progress. I wholeheartedly expect the schedule to change drastically before I’m done, but I’ve got a rough outline hammered out for now at least until more details develop. Part of the reason all of March is content is that I’ll also be busy with schoolwork, so I’d prefer content development and polishing to hardcore coding binges. That, and it gives a bit of flexibility if the console launch is announced earlier than expected.

It’s going to be an intense two months, but if it’s anything like the game jam was: this is going to be damn fun!

Project Onslaught: OUYA CREATE Entry Complete!

Prototype Features:

  • Supports up to 4 players!
  • Each player controls a warrior character
  • Enemy skeletons will spawn in an arena as the party fights to survive!
  • Game stats are displayed once the entire party is defeated. Try and beat your friends!

Development photos: Imgur album

Downloads: Android APK

Cross-post on OUYAForum.com here!

Official OUYA forum post here!

OUYA CREATE Update: Interfaces!

I spent today learning NGUI, a pretty awesome UI library for Unity. I’ve got health bars for players working, and a main menu screen in progress! I also created a thread on OUYAForum.com – it looks like some people are interested in the game!

Here’s a teaser photo of the prototype running on the OUYA:

WIP Hack n Slash OUYA photo

And as a bonus, here’s how the scene actually looks in Unity:

Unity3D scene view of Hack n Slash WIP prototype

The interface elements are on a different layer from the rest of the game, which means the main camera can’t see the UI, and the UI camera can’t see the rest of the game. However, the interface elements are still off to the side for the sake of simplicity/cleanliness. Implementing it was surprisingly painless with a combination of the NGUI tutorial videos and these nice videos by BurgZergArcade. My code ended up a bit different from the BZA tutorials, though. Here’s a code snippet from the health bars:

using UnityEngine;
using System.Collections;

public class HealthBar : MonoBehaviour
{
    private UISlider slider;

    void Awake()
    {
        slider = GetComponent<UISlider>();
    }

    public void UpdateDisplay(float percentHealth)
    {
        slider.sliderValue = percentHealth;
    }
}

Then, when the player takes damage, their script just calls healthBar.UpdateDisplay((float)playerHP / maxHP); to update the health bar. Easy!

Progress is looking good for CREATE!

OUYA CREATE Game Jam: 3 days to go!

I’ve spent the better part of this week working on a prototype for the OUYA CREATE game jam with my friend Dan Whiddon (Redsting Games). We also have a forum thread on OUYAForum.com along with another on the official OUYA forums!

The long-term game idea is a hack ‘n slash similar to the Gauntlet series. I have a lot of fond memories playing games like Gauntlet: Dark Legacy with my friends and with my dad, so it was the natural choice for a fun console game to make! Given the CREATE game jam is only 10 days long, though, we came up with a few constraints/goals to keep things in check:

  • Shoot for 2-5mins of polished gameplay. Quality over quantity.
  • Fight in an arena rather than along a level, as we likely won’t have time to make a good level for content.
  • End either when the player(s) die (high score?), or after a boss fight that goes into a teaser screen
  • Focus on making gameplay fun over making new features. This mostly means focusing on combat mechanics.
  • Plan to throw the code away afterward and re-write it. Let the prototype be exactly that: a prototype, not the final product. This will let us throw in hacks and work-arounds as needed without spending too much time on code cleanliness, which will help a lot with the short deadline.

Overall, our progress has been pretty awesome! I only had limited experience with Unity3D before now, but I’ve been amazed at how easy it is to use. Even as a newbie, you can pretty much blunder your way through the interface and API and still be incredibly productive.

We’ve got three days left in the game jam: time to make the most of it!

Un-learning your coursework: Commenting

In an effort to not lose points on their grade, many students will end up writing code like this:

#include <stdio.h>   // For input and output
#include <string.h>  // For string-related functions

// Main method
int main(int argc, char* argv[])
{
    int numChars = 0; // create integer variable numCharacters and set it to 0
    for (int i = 0; i < argc; ++i) // loop once for each argument
    {
        numChars += strlen(argv[i]); // add the length of string argv[i] to numChars
    }
    printf("Number of characters in arguments: %d\n", numChars); // Output the calculated number of characters
    return 0; // no errors while running
} // end main

The excess of comments clutters the code and makes it less readable, the exact opposite of your goal. Even worse, some graders will take points off if you don’t comment this heavily. Ugh.

For your coursework, just go along with whatever the instructor asks for; commenting style is not worth sacrificing your grades over. In the meantime, start un-learning some bad habits by considering the advice below.

Don’t point out the obvious.

Let your code speak for itself. Any programmer who looks at your code will know that “++i;” means that i is being incremented; you don’t need to repeat that information. The same goes for common programming idioms; for example, it’s pretty easy to recognize “for (i = 0; i < value; ++i)” as looping through something value times.

Save comments for when you’re doing something subtle or unintuitive. Of course, if you end up in that situation, remember this next guideline:

Bad code requires many comments. Good code needs few.

If you’re anything like me, your first impulse when you realize your code is hard to follow is to write a comment explaining it. However, “just comment it” shouldn’t be the first solution. If possible, try to re-write the code so it’s clearer.

Comment bug fixes.

Depending on how you fix a bug, it might be worth putting a comment there explaining the bug you just fixed. It prevents the problem of someone coming along later (possibly even yourself!) and saying, “This is over-complicated. I’ll just re-write it to be simpler…” and re-introducing a bug you already fixed. That being said, if you’re using unit tests, you’re probably safe if you just write a regression test for that bug and call it a day.

// Good example: explains a possibly unintuitive piece of code
void updatePlayer(Player& player)
{
   ...
   if (player.x > CAMERA_BOUNDS)
      doSomething();   // BUGFIX: Prevents the edge case where [...]
   ...
}

// Bad example: points out the obvious
void someFunction()
{
   int x = 0;
   while(x < 10)
   {
      ...
      ++x; // BUGFIX: loop didn't end
   }
}

Comment function headers.

You can probably guess what this function does if you find it in a header file:

float max(float x, float y);

However, you don’t want to code based on “this function probably does what I want it to.” You’ll probably go through the code and double-check what it does – no big deal, the function is only two lines anyway, right? And then so will everyone else who uses this function. Every. Single. Time.

You don’t necessarily need a super-verbose JavaDoc-style comment at the top of every function, but you should at least write a quick comment saying what the function does:

// Returns the greater of two floats
float max(float x, float y);

Furthermore, if someone else forgot to add in that comment, write it yourself after you figure out the function and save everyone some time. Make sure you’re correct, though! Incorrect comments are worse than no comments in most cases.

Stick to established commenting styles

Even if there’s no official, formal commenting policy for a project, please keep your new code consistent with the old. Remember just above where I said “You don’t necessarily need a super-verbose JavaDoc-style comment…”? That doesn’t apply if every other function in your project has one. Consistency trumps personal preference here.

Follow these guidelines judiciously.

No rules are set in stone. Let’s say you’re using a super-fast but super-complex algorithm because you’ve optimized that part of your code heavily. Of course it’s going to require a lot of comments. Just make sure to keep that complexity encapsulated behind a nice interface.

With that, I’ll leave you with how I would personally write the program at the top of this post:

// Arglength - Prints the total number of characters passed in as arguments, including the program name
// Author: Zachary Hoefler

#include <stdio.h>
#include <string.h>

// Entry point
int main(int argc, char* argv[])
{
    int numChars = 0;
    for (int i = 0; i < argc; ++i)
    {
        numChars += strlen(argv[i]);
    }
    printf("Number of characters in arguments: %d\n", numChars);

    return 0;
}

New portfolio piece – Wooga Fighter!

I’ve just finished with a massive overhaul of my resume, along with an update to my portfolio. The latest game in my portfolio is this awesome project:

The arcade machine in action!

Yep, that’s an arcade cabinet we built and a Wooga-themed fighting game to play on it. Enjoy!

What learning Haskell has taught me

I’ve been learning to program in Haskell using the book Learn You a Haskell For Great Good (free online!). After the first few chapters, I decided to try tackling some of the problems on Project Euler. I’m quite surprised at what I’ve learned about my programming habits.

For the uninitiated: Haskell is a purely-functional programming language, and Project Euler is a site that has a bunch of math problems meant to be solved programatically.

Most importantly, I’ve realized that my gut instinct when something runs too slow is throw more memory at it. “I know! I’ll cache the value in an array and save the calculation!” However, when coding in Haskell, the “purely functional” detail tends to ruin that idea pretty quickly. By using Haskell to solve the problems on Project Euler, I’m forced to actually refine the algorithm itself and research the math behind a subject rather than just throwing memory at it. This research also led me to reading about prime number sieves, RSA encryption, and a bunch of other information I would’ve never thought to even look up.

I’ve also learned that I tend to think in terms of loops. When approaching an algorithm, I break things down into “OK, I need to do this, this and this, and then repeat that until this comes up” However, Haskell doesn’t have for or while loops; you’ll generally do things recursively. Until learning Haskell, I’d mentally filed recursion under “one of those things you cover in class and then never actually need”. Whoops. Turns out recursion is surprisingly powerful.

What it comes down to is this: In just two days, learning Haskell has significantly changed how I approach programming. If you’ve never played with purely-functional programming, I highly recommend trying it out. Plus, learning you a Haskell is all in the name of great good; you can’t afford not to! Click the cover below to go right to the book’s website and follow along for free:

Learn You a Haskell cover

Learn You a Haskell for Great Good

 

Playing with Adobe Stage3D

I’ve been playing with Adobe Stage3D a fair bit lately. For the uninitiated, Stage3D is Adobe’s new API for hardware-accelerated 3D in Flash. The transition from programming in a mature API (i.e. Direct3D 11) to Adobe’s new one is a bit jarring, and the documentation is pretty sparse, but it’s definitely fun to play with!

I’m currently working on creating a 3D shoot-em-up, with the project hosted on github.

Thoughts on the API

Setting up the development environment was painful back in late 2011 when one needed to modify the Flex SDK, but since then it’s become pretty much painless. In FlashDevelop, you just need to make sure you set the compiler option “-swf-version=13″ along with targeting Flash Player 11+, and you’re all set. FlashBuilder is equally straightforward.

The Stage3D API is definitely usable, but figuring out how to sanely structure a program with it was a bit of a headache at first. The most important thing I had to keep in mind was that Stage3D is not DirectX – things are simply done differently. When parsing a mesh, my gut instinct was to define a vertex structure with position, UV coordinates, normals, etc., which drove me right into a wall. Stage3D does not have an equivalent to Direct3D’s D3D11_INPUT_ELEMENT_DESC. Ultimately, it turned out that it was both easier and clearer to just keep a separate Vector for each of the vertex attributes and then upload those separately to the graphics card.

Switching from HLSL to AGAL hasn’t been too difficult, but to be fair I have enough experience with assembly languages that I’m comfortable with them. Also, I’m a bit of a newbie when it comes to shaders, and thus most shaders I’ve written have been pretty simple. That all being said, the EasyAGAL library makes AGAL a lot less painful and significantly more usable by wrapping all of the instructions in ActionScript. You still write the same programs with the same instructions, but code completion, syntax highlighting, being able to effectively write macros, etc. is a huge step forward.

Of course, you could bypass that entire headache by using a 3D engine like Away3D, but that’s no fun. =]

Useful Stage3D Links

Given how relatively new Stage3D is, there aren’t many resources available online. That being said, here are a few pages I found useful:

  • The main Stage3D page has some useful links to get you started.
  • Make sure to check out Adobe’s game development page.
  • This tutorial walks you through making a 2D shoot-em-up using Stage3D for hardware acceleration. I’ve only skimmed it, but it has some cool examples of things like batched geometry and generating mipmaps dynamically.
  • The book Adobe Flash 11 Stage3D (Molehill) Game Programming Beginner’s Guide is decent, though most of what I’ve gotten out of it has been seeing some examples of using Stage3D’s API. The book doesn’t really walk you through Stage3D so much as show examples and explain them chunk by chunk, but it’s a start. The code is unfortunately rather messy… in particular, it suffers from the same fate as most “intro to 3D game programming” type books where almost everything is shoved into one file. The final game’s main AS file is over 2000 lines of code, for example. All that being said, it’s still incredibly helpful when so few resources are currently available. While it’s by no means the best programming book I’ve laid my eyes on, it gets the job done and provides some much-needed examples of Stage3D in use.
  • EasyAGAL is an awesome library.
  • Pixelante Game Studios has a number of tutorials up on their site, though they’re more along the lines of useful code snippets and tips than full-on tutorials.
  • iFlash3D.com has some useful blog posts, though it seems like most things posted lately are thinly-veiled plugs for their Flash3D Librarian tool for sale.

Heretics! (Portfolio Update)

Heretics main menu screenshot I’ve updated my portfolio with my latest project, Heretics. It’s a 2D platformer written entirely in C++ and DirectX 11. It even includes a boss fight! Check it out.

Follow

Get every new post delivered to your Inbox.

Join 670 other followers