Building a simple video game using Unity.
I’ve always loved games. One of my earliest memories is of accompanying my father and sister to a secondhand game shop to pick out my first ever video game, Kirby’s Dream Land, for our new Game Boy. When I learned that games were made by actual people, I wanted nothing more than to build my own someday.
Nearly twenty years later, I was working as a software engineer at Coursera, an ed-tech company that provides online courses from top universities. Despite studying Computer Science in college, I’d never gotten around to building a game of my own. Thus, when all employees were issued a challenge to complete a Coursera Specialization, I knew immediately which one I’d choose: the University of Michigan’s Game Design and Development. When the time came to build my first custom game, I decided to build a side-scroller inspired by Kirby’s Dream Land.
As any gamer knows, the theme of a game can have a huge impact on how enjoyable it is to play. Since my goal was to learn game design and development, not distribute the finished game, I decided to base the theme on two things I happen to like: red pandas and food. In a premise not unlike Cloudy with a Chance of Meatballs, the player controls a red panda that flies around the screen, collecting food that magically falls from the sky. This would be a dream come true for any hungry animal (or person), so I dubbed it Dream of a Red Panda.
As a solo game developer, I knew I’d have to keep the game simple to finish in a reasonable timeframe. Once the player completes the intro sequence, which consists of jumping up a series of platforms, the panda begins to fly. After that, the player can earn points by collecting food, which tumbles from the sky at random intervals. Some of that food is bright green, which means that eating it will cost the player a heart. As time passes, the screen scrolls more quickly and the percentage of poisonous foods increases. Once the player loses all three hearts, the game ends and their score is recorded, if applicable.
The code for this game can be roughly divided into the following functions:
- Starting the game
- Scrolling the screen
- Randomly generating the food
- Programming the food to fall and tumble
- Collision detection
- Keeping track of hearts
- Ending the game
I was able to adapt many of these functions from a game we’d built earlier in the course, Super Sparty Bros. As with most Unity games, both Super Sparty Bros. and Dream of a Red Panda are written in C#. I’d never used the language prior to the course, but the syntax is similar enough to Java and C++ that it wasn’t difficult to pick up. Once the core mechanics of starting and ending the game were in place, I added custom code to automatically scroll the screen and generate the food. I also updated the core game event loop so the panda either walks or flies, depending on the progress of the current game.
To keep the focus on the design process, I won’t go too in-depth on the scripts, but I’ve included a few samples below to give an idea of what they look like. I’ll readily admit that I took a “hack-it-together” approach to extending the original code, so it isn’t stylistically ideal. That said, it compiles and runs bug-free, which is all I ask of a prototype!
Another one of my goals for the game was to create the sprite art from scratch. To create the sprites, I used Piskel, a free online pixel art editor.
Even compared to other forms of digital art, pixel art presents a unique set of challenges. With so little space on the canvas, striking the right balance between simplicity and detail can be difficult. In the case of the sprite above, I increased the size of the panda’s head relative to its body to allow more room for its distinctive facial marks.
The trickiest part of the process, however, was animating the sprites. For the player’s avatar, I created three distinct sprite sets: standing, walking, and flying.
For the standing animation, I created a few frames that wave the panda’s tail up and down, which give it a lifelike feeling even when the player isn’t moving.
For the walking animation, I created a four-frame sequence that alternates the legs forward and back, with frames repurposed from the standing animation to create a more natural transition.
Creating the base for the flying animation required only a few minor edits from the standing animation. However, I also added a few frames that could be used for positive or negative events. Since the sprite itself didn’t leave much room for emotion, I used the classic pixel-art trick of a speech bubble above the character.
Once the sprites were drawn, I tuned the timing of the animations in Unity until they felt natural.
Most of the other assets used in the game were included with Super Sparty Bros. However, I did create one additional sprite set for the food. The poisonous variants don’t have distinct sprites; instead, I apply a green filter to each type of food in Unity. The one exception is the panda’s beloved bamboo, which is never poisonous, but is hard to distinguish because of its natural green color. Tricky!
Learnings & Future Work
Thanks to this experience, I now have a much better idea of how to go about building a game. Game engines like Unity, which abstract away many of the more complex details, are a great starting point. Even so, everything from the art to the level design to the code requires incredible thoughtfulness and attention to detail. As such, I’ve developed a greater appreciation for game developers, especially tiny indie studios that build everything in-house
In its current form, Dream of a Red Panda is cute to look at, but it’s too simple to hold interest for long. To turn it into a production-ready game, I’d experiment with adding terrain, such as mountains or platforms, as well as flying enemies for the player to dodge. Another route could be to break the game into levels, each of which could feature unique collectibles and boss battles.
Though I don’t have any plans to continue working on the game at present, I have a feeling I’ll build another game someday. When that happens, I’ll be glad to have this experience under my belt.
I’m very grateful to Michigan State University and the instructors of the Game Design and Development Specialization for making their courses available online. In particular, Brian Winn’s thorough tutorials made learning Unity a breeze.
Care to play?
Dream of a Red Panda can be played here. The web player may appear blank for a minute or two while it loads–please be patient!