Puzzles and Programming
Creating an adventure game has been great fun, and Corona SDK is one of the reasons it has been possible for us. The engine has been created entirely from scratch in Corona, save for the occasional code snippet. As a lifelong player of LucasArts and Myst-style adventures, I had a reasonably clear idea of what functionality the engine needed, but it’s grown far bigger than the prototype I put together more than a year ago. Here’s a brief rundown of how the game works.
Actors, Props, and Rooms
Doggins is built on a theatre or film set metaphor, with each location (Room) containing a mix of Actors and set dressing (Props and Items). Props are typically pieces of set dressing that can be interacted with, while items are things that can be picked up and placed in the Inventory. All actors, and most props and items, have their own Lua file which is loaded when the room is created. Actor files contain sprite sheets for the character, along with a host of member functions to control them (Move, Flip, Idle, Rest, etc.).
We make heavy use of Corona’s Storyboard API, using it for loading rooms and displaying overlays, including the Inventory. Once I was used to it, Storyboard provided a helpful framework for both implementing the game and understanding its organization. Each Room is a Lua file laid out similarly to the Scene Template provided by Corona: local variables are forward referenced at the top of the file and created in the enterScene event, willEnterScene is used to set the room up to appear as it was when the player last left it (turning the light on, for example), enterScene contains touch functions for interactive objects, and exitScene disposes of audio and performs other cleanup tasks.
I typically don’t use Storyboard’s built-in transition library, as the “fade” effect changes the opacity of all objects in a display group, allowing you to see through them. Instead I’ve created my own “fadeIn” and “fadeOut” functions which create a black rectangle over the entire screen and adjust its opacity, better approximating a real fade. However, I do employ Storyboard transitions for some overlays.
I’ve nicknamed the Doggins engine the “Luna” engine, as his lunar adventure is both his and our first. The engine is essentially a LUA file of functions that execute common in-game tasks; these functions are referenced via global variables in the game’s main.lua file.
A typical bit of game scripting using these functions looks like this:
local function toExtForest ()
walkTo(-300, roomFloor, “walk”)
The walkTo function moves the character to a specific set of coordinates, using the “walk” animation and movement speed. waitForPlayer waits for the character to arrive at those coordinates, and then calls toExtForest. In that function, fadeOut is called, passing in the name of the next Storyboard scene to load when the fade is complete.
This allows me to write relatively readable code that can quickly be iterated on. I like to think that it’s at least a little bit like classic SCUMM code, but Ron Gilbert would probably (rightly) disagree.
Creating my own adventure game engine is something I never imagined I would do. It’s been a lot like playing an adventure game, actually: searching for clues, trying things that don’t work, scratching my head, and then feeling a rush of excitement when I finally realize the solution. Puzzle-solving and programming have a lot in common. Hopefully solving the game will be as rewarding for players as creating it has been for the two of us.