Thursday, September 30, 2010

Let's Make Us a Game! -- Building The World

Last week, we gave some thought to the basic concept of our adventure game, starring a puppy named Riley whose only goal in this slice of his life is to confiscate and eat the family's turkey dinner (or some manageable portion of it, say, a leg).  This week, we're actually going to start building something using Inform 7.

A more substantial project would require considerably more effort in this planning stage, but I'm cutting to the chase here -- our game will be small enough that we can patch up any errors as we go, and I think the lessons learned from my lack of planning will be more interesting than any rules or maxims I might offer.  So let's get to work implementing the game world.

First, I've drawn up a simple, approximate map using Christopher Madsen's GUEmap utility:


Inform 7's shorthand programming convention expects us to provide description content immediately after establishing that something exists.  So as I lay out the map, I'm going to write some preliminary descriptions of each room.  I'm also going to establish the location of two key objects I know we are going to need based on our general story concept -- the turkey, and the player.  Note that rooms are defined in relation to each other -- if this were a larger map, I'd have to give some more thought to the implementation so I don't lose track of the details.  But this design only has a handful of rooms, so I'll just wing it based on my crude map.

Here's the initial source code -- Inform 7 uses natural language, so this text should be fairly readable to non-programmers:



Mom's Kitchen is a room. "This is where the magic happens. Strange and mysterious scents fill the air, and the floor is always worth checking for treasure."

The turkey is here. "One scent in particular stands out -- rich and juicy and tasty."

The Hallway is north of the kitchen. "The hallway is often populated by feet and shoes coming and going, but it's quiet at the moment."

The Back Yard is north of the hallway. "The back yard is full of grass and bugs and the occasional squirrel. A large tree provides shade on hot summer days. A lovely puddle of mud remains from yesterday's rain."

The Mud Puddle is in the back yard. "Mud, glorious mud! Rich and thick and pungent, made of dirt and worms and everything else that is wonderful in this world."

The Dining Room is east of the hallway. "This is where the people eat. It is a sumptuous palace of steel and fabric, with chairs rising high into the air. The dinner table dominates the room, overshadowing everything else with its promise of tasty past and future."

The Dinner Table is in the Dining Room.
 
The player is in The Back Yard.



Note that, at this time, there are no obstacles implemented, so we (as the player) are free to maneuver around the map and make sure the layout works.  The Inform 7 parser and engine will prevent Riley from going in unworkable directions to places that don't exist, so we don't have to worry about those details.  You may also note that my initial room descriptions don't provide any useful detail as to which directions are navigable.  We will fix that for the player's sake, but since we set it up and drew the map, we know how the navigation works.

I click the Go button in Inform 7, and am pleased to see that the text compiles without throwing any immediate errors.  But right from the get-go, we run into a problem -- I haven't used "in" properly.  The Mud Puddle is being treated as a thing placed in the Back Yard, not as a location on its own (and the same problem afflicts the Dinner Table.)  So this doesn't quite play as I wanted it to:


Riley's Adventure 
An Interactive Fiction by GamingAfter40
Release 1 / Serial number 100905 / Inform 7 build 6E72 (I6/v6.31 lib 6/12N) SD

Back Yard
The back yard is full of grass and bugs and the occasional squirrel. A large tree provides shade on hot summer days. A lovely puddle of mud remains from yesterday's rain.

Mud, glorious mud! Rich and thick and pungent, made of dirt and worms and everything else that is wonderful in this world.

>go puddle
That's not something you can enter.
 


Fixing the mud puddle will take a little bit of work.  We need to treat the Mud Puddle as a container inside the Back Yard, that is, an object that's truly IN the yard, but is big enough to enter.  We want it to present itself as part of the room-level description only when we're NOT inside it, so we don't confuse the player as to whether Riley is actually in or just near the puddle.  We also want to account for the transitions between the back yard and the puddle with some evocative puppy prose.  And we need to make sure the player's not allowed to take the mud puddle.  (Thinking about future puzzles, I will leave open the possibility of taking some mud -- but we won't worry about implementing that detail right now.)

The changes required are rather extensive -- the Back Yard description is changed so as not to include the mud puddle description itself, and the Mud Puddle gets redefined with some special actions. We'll also move the description of the mud to be the target of an explicit EXAMINE command.



The Back Yard is north of the hallway.  "The back yard is full of grass and bugs and the occasional squirrel. A large tree provides shade on hot summer days."

The Mud Puddle is an enterable container.  The Mud Puddle is in the Back Yard.   "[if the player is not inside the Mud Puddle]A lovely puddle of mud remains from yesterday's rain."

After entering the Mud Puddle, say "SPLASH!  Mud, glorious mud!  It squishes delightfully between your claws."

After exiting from the Mud Puddle, say "You hop out of the mud puddle, dripping awesomely muddy water."

Instead of taking the Mud Puddle, say "You can probably take some mud with you, but picking the entire puddle up is beyond even your puppy powers."

Instead of examining the Mud Puddle, say "It's rich and thick and pungent, made of dirt and worms and everything else that is wonderful in this world."




Fixing the dining room table presents a similar challenge.  But we want the player to be able to get onto the table, not inside it, so we define it as a supporter instead of a container.  The Inform 7 environment will take care of many of the other details -- for example, it assumes that any supporter is fixed in place, so we don't have to explicitly reject attempts to take it.

One special thing we want to do to emphasize Riley's small size is make sure that the player has to CLIMB to get onto the table, instead of simply ENTERing it or GOing there, which default supporter behavior allows.  We'll flesh this out with more details later to create a puzzle; there are other, and probably better, ways to implement some of this don't-enter-but-climb behavior, but this approach will suffice for now.  Also, it's reasonable to let the player travel DOWN from the table, with a little descriptive detail for the jump down.  And we should make sure that the player can't break the world's reality by repeatedly climbing up once Riley is already on the table.

We're also covering one new detail here -- we want to represent the Dining Room itself differently from different perspectives, depending on whether Riley is on the floor looking up, or is currently standing on the table.  So we'll add some conditional logic to that room's description using Inform 7's [if][otherwise][end if] conditional phrasing.



The Dining Room is east of the hallway. "This is where the people eat. It is a sumptuous palace of steel and fabric, with chairs [if the player is not on the Dinner Table]rising high into the air.[otherwise]surrounding the table.  From up here you can see the whole dining room.[end if]"

The Dinner Table is an enterable supporter.  The Dinner Table can be climbed.  The Dinner Table is in the Dining Room. "[if the player is not on the Dinner Table]The dinner table dominates the room, overshadowing everything else with its promise of tasty past and future."

Instead of entering the Dinner Table when the player is not on the Dinner Table, say "Perhaps you could climb up there?"

Instead of climbing or entering the Dinner Table when the player is on the Dinner Table, say "You're already up here."

Instead of climbing the Dinner Table: say "You jump high, higher, and then clamber up onto the dinner table."; move player to the Dinner Table.

Instead of going down when the player is on the Dinner Table, try getting off the Dinner Table.


After getting off the dinner table, say "You hop off the dinner table, landing on the floor with a mighty (small) oof."



With these refinements, we have created a very small, but complete and navigable game world.  Next time, we'll set up a few physical obstacles to help drive the story.


 

No comments:

Post a Comment