The Makings of an In-Office Horse Race: Part 1

Here at Uncorked, we like to challenge each other to do fun projects that take us beyond our typical day-to-day work. One of these regular challenges, aptly named “Little Friday,” involves us drawing a team of three Uncorkedologists’ names from a bin and then having that team draw a 3D printed tchotchkes, which becomes their theme, from a golden trash can. From this theme, we have to put on a presentation or event showcasing our interpretation of that theme.

A couple months back, I was chosen along with two other colleagues. Our theme was simple: a horseshoe. Needless to say, meetings were had and ideas were thrown around. We came to the conclusion that we wanted to do something that was creative, something that involved everyone, and something that encouraged interaction.

First we were thinking about some sort of horse racing game, where we would build some kind of physical object that would move in some way to simulate a horse moving forward in a race. For example, rolling an object down a plank or shaking a platform to get it to move. The more we thought about this, the more we realized that it felt fun but needed to be more engaging. How would we be able to get 20-30 people involved in a game the size of a table?

Keeping in mind the desire to have max engagement, the thought of a video game continued coming back to me. But how would it work? How would we make it fun? And would it be too much work? All these things were important factors.

Developing the Uncorked Derby

Once we decided to pursue the horse race idea, my teammate Melodee began building out these incredible papercraft decorations that included hats and apparel—because you certainly cannot have a derby without getting dressed up for it! Along with the attire, we would serve the proper drinks: mint juleps. My other teammate, our COO John, would make sure we had the complete experience by taking bets (with fake money of course) on the outcomes of the races. The whole thing was starting to become a really fun and engaging ordeal. But it was my job to put together the actual race.

How to Create a Horse Race

After evaluating all the options, I decided the best way to go was to do a video game type of interface to display the race. And since we have a large TV display in our social space, it would allow the users to easily see what is happening.

I decided to use Unity for the game engine because it’s an easy-to-use system that makes game development a breeze. I highly recommend it to anyone who is interested in game development. The drag and drop style placement for elements makes it very easy to start using. It also supports C# and JavaScript in addition to its own Boo programming language—My preference is to use C# for Unity projects, so that is what I chose here.

Now, I am not much of a graphic designer, which is why I decided to take advantage of the internet’s plethora of free clip art. In my search for images, I found this great snippet of a horse running and went with it. I added in some grass, dirt, and a fence and we had a race track. And in Unity it’s as simple as dragging those elements into the game scene and arranging them as you desire.

Now that I had my race track, it was time to set up the horses.

In Unity you can import a set of images that you want to make into a sprite, which is a 2D object used for things like characters or props. Once imported, you can make an animation from them. In this case, these images were simply gif files—so the transparency was already applied for me. If you have ever done old game programming and dealt with bitblt, having an image that does it automatically is amazing.

After I created the object for an animated horse, I arranged a few of them on the track and they were ready-to-go. Now it was time to bring the game to life

Adding Logic to the Horses

To attach actions to a GameObject in Unity, you have to build a script that defines those actions.

The typical Unity script looks like this:


using UnityEngine;
using System.Collections;
using System;
using UnityEngine.UI;

public class Main : MonoBehaviour {
// Use this for initialization
void Start () {

}
void Update () {

}
}


From this simple structure you have a start function to use for setting up the object run—and an update function. This update function will be called every tick of the game. This is where you place logic to detect that something has happened, or that something needs to happen. All of our scripts in this game will follow this standard Unity setup.

Writing the Script

The script for the horse is pretty simple. It needs to be able to detect some sort of input that drives the horses forward, as well as control the animation of the horses if they are moving, and stop them when they are not. I decided there should be two inputs.

In my initial basic test, I used two keys that were alternately pressed. One gives the horse life and one gets it running. They need to be alternated or the horse will not run. Unity makes this key input crazy simple. The logic looked like this:


if (Input.GetKeyDown (leftKey)) {
   processFoot (true);

}

if (Input.GetKeyDown (rightKey)) {
   processFoot (false);
}



Simply detect the key being pressed and send the signal that we did the true or false value. This logic lived inside the previously described update function. So this is being pulled every tick of the game cycle. And the processFoot function is setup to ask if this is a full cycle of the true, false, true values. If so, it will know to play the horse animation, move the figure forward, and then wait a few ticks to stop the animation. This gives the horse animation a few runs while it moves forward. Now that I had a working logic for the horses, I could drag the logic script onto each of the horse objects. This attaches the script to the object and puts that setup and update into play when the game is run.

I also needed a script that would be an overall register of the game functions—in other words to make the entire game run and not just the horses. This one I simply called “main,” and attached it to a generic empty GameObject in our scene. This script has logic for starting the race when you hit spacebar, detecting where the horses are in the race, knowing when someone wins, displaying the scores after the race has ended, and resetting the game when you press “[.” Then there is one more script that is attached to the timer object—it just shows the clock counting as the race goes.

At this point I had a working game in Unity with a pretty nice graphical layout from the free art acquired online, and it was able to be played via a keyboard. Uncorkedologists could fully play the race at this point, if multiple people huddled around a keyboard and slammed on keys alternating as fast as they could. And while that would be a fun game right there, it would have been very crowded to have all those people around a single keyboard. And it would have only been eight people playing. We needed more involvement. So, in talking with my team, a new plan was hatched: We should have each horse be run by two people.

To accomplish this, we would need some physical objects and controllers. But that’s enough for one post. Check in with the blog next Thursday to hear about how we evolved the race.

Share Via

View Comments