Tuesday, February 5, 2008

Play With Your Peas: A game prototyping challenge


Oh la la! It is time for another game prototyping challenge. As has become the tradition around here, you provide the brilliant code and I provide you with a complete set of free graphics that help make you look spiffy.

This game design stems from a peculiar fetish of mine. I don't normally talk about this in public, but...how to say this. I have a thing for casual building games filled with adorable little creatures. Late at night, when the rest of the world is busy sleeping, you'll find me fantasizing about the lurid offspring of Lemmings and SimGolf. For a moment, close your eyes and savor the sweet thought of DMA's DNA all mixed up with Will and Sid's unappreciated love child. Oh yes.

The game idea inspired by these questionable thoughts is called Play With Your Peas. Here are the basics:
  • Peas: You have a bunch of fun loving sentient peas that like to climb tall objects and jump off of them. They think they are ninjas. You know they are suicidal.
  • Happy points: If the peas land safely, they generate happy points. The more things that they bounce off of on the way down, the more points you get. Think of a successful pea landing like scoring a combo in Tony Hawk.
  • What you do: Here's the trick. You can't manipulate the peas. You can only add blocks to the landscape. Add a soft landing spot and your falling peas won't splat. Add a spring in the right spot and they'll fly up into the air. Can you build a brilliant playground that delights your peas?
  • Score: Your score is the time it takes you to reach 20 million points. If you want to simply play with your peas, go for it. If you want to beat the high scores, you must be Elite and build your landscape with great efficiency so that you maximize your pea combos.
Many thanks to Axcho for dredging up this ancient design from the dusty storage shed of my past.


Game Tokens
There are only a few types of elements on the screen
  • Peas: Little AI characters that run around the environment. You can't interact with them directly.
  • Plate: All action takes place in a box that bounds the sides and bottoms of the screen. No objects can exist outside of the screen.
  • Blocks: The user can place blocks on the screen. There are multiple types of blocks such as platforms, springs, jello and more.
  • Flags: These mark the spots where peas have lept from in the past.
  • Tools: A sidebar of tools that lets you choose the type of block to place.
  • Happy Score: A counter that tells you how many happy points you've collected so far.
  • Time: A counter that tells you how much time has elapsed since the beginning of the level.
Basic Pea AI
Peas have three main modes:
  • Navigating the environment: In its primary mode, the pea navigates the environment in an attempt to reach a jumping spot.
  • Falling: When a pea is falling, it is treated like a simple bouncy ball interacting with the world.
  • Being scored: Once a falling pea comes to a rest, it is scored.
Navigating the environment
The peas traverse the environment in search of ledges to jump off. This is the hard part of building this particular game design. I'll describe the high level behavior, but I leave the implementation as an exercise for the mad programmers of the world.
  • Look for a ledge: After a pea is scored, it immediately looks for a nearby ledge to jump from.
  • Wander: If there is no ledge nearby, the peas wanders in a particular direction, slowly climbing over obstacles and working its way up as high as possible.
  • Calculate path to ledge: When it finds the ledge, it calculates a rapid path to the ledge.
Moving smoothly across a complex environment can be broken down into a series of movement segments.


  • Walk on a flat surface:
  • Climb a block wall: Some blocks can be climbed, others cannot.
  • Climb up a ramp: Some ramps can be climbed.
  • Jump a gap: If there is a 1 square gap, a pea can jump over it. Remember they think they are ninjas.
  • Wall jump: Peas can also jump onto a wall that is 1 square above their head to the left or the right. Think of this like moving how a knight in chess moves.
Jumping spots.
A block surrounded by space has two default jumping spots, one on the left side and one on the right side. Once a pea reaches a jumping spot, he will jump. A couple things happen at this point.
  • A flag is automatically planted at the jumping spot.
  • The pea jumps and his AI switches from navigating the landscape to being a simple bouncing ball.
The flag tracks several things
  • How many peas have jumped from the jumping spot. As the number gets closer to 100%, the flag slowly rises to the top of the pole.
  • If a peas spots multiple jumping spots, they will always head towards the jumping spot that has the highest completion percentage. This ensures that the user is focusing on one or two jumping spots, not a half dozen.
  • When the flag reaches 100%, the jumping spot becomes inactive and no other peas can jump from this location. The user gets a large bonus for having a completed jumping point.
  • Peas remember which jumping spots they've jumped from and will not jump from that point again.
The flag also serves an important balancing role. Once a flag is planted, several building limitations come into play.
  • The user cannot place another block on the square occupied by the flag.
  • The user cannot remove the block under the flag.
These rules prevent the user from recycling jumping locations and they also slowly eat up the space on the board so that the user needs to work around the detritus of their previous efforts.

Bouncing
When your pea falls, it bounces off of blocks that get in its way. Some blocks, such as gelatin, slow you down. Others, like springs, give you an additional boost. However, your pea is not indestructible.
  • If you land on a standard block after falling a distance more than two blocks, you pea will die. A dead pea means less opportunity to score.
The skill of the game is building environments that yield the maximum number of bounces while still managing to land your peas safely in the end.

It is possible for the player to create cul-de-sacs where the pea will bounce indefinitely. One potential balancing feature is to add in a counter that keeps track of how many times specific blocks have been hit. If the hit count on single block gets too high, the pea yells out 'It's a trap!' Even if a trapped pea is released, you get no points.

Scoring
When a peas finally comes to a stop and it survives it's journey, it gets a happy score.
  • Happy score = Total bounces * (Spring Bounces * Spring Value + Normal Bounces * Normal value + Gel bounces * Gel Value + Successful Landing)
The pea's happy score is added to the player's total score. This is a moment of grand celebration. If you have a particle system, this is a great time to use it. I've provided graphics so that a happy pea can yell out "Ninja!", his career aspirations finally complete. Once the peas is scored, he moves on and starts looking for a new jumping spot to leap from.

Building blocks
Okay! Now we have some cute little characters that jump about the screen in some logical manner. Finally, it is time to talk about building your world.

Along the left side of the screen is a toolbox that contains the blocks you can use in the level. To select a block, click on it and it will highlight.

To place the block, click on an empty square. The blocks aren't added immediately since they have a build sequence they must follow.
  • Initial delay: We want to prevent users from micromanaging the flow of their peas by quickly placing blocks. In order to do this, blocks stay ghosted for a short period of time before they fade into solidity.
  • Check for peas in the square: While the block is ghosted, any peas that are in the space can move out of the square without colliding with the new block. This helps us avoid accidentally squishing peas.
  • Block peas moving into the square: New peas that try to move into the square are collided with using the collision rules associated with that block type.
  • You can place other blocks while a block is in the process of being built.
Deleting blocks
You can remove blocks as well.
  • First click on the delete tool.
  • Your cursor will turn into the red delete cursor. Feel the power!
  • Click on the block you wish to delete. As you mouse over the block
  • The block will become ghosted. There is a short delay before the block is removed.
  • After the delay is over, the block finally fades away. During the exit animation, peas will pass through the block as if it isn't there.
  • You can delete other blocks while a block is in the process of being deleted.
Remember, you can't delete a block that has a flag attached.

Standard Blocks
  • Climbing: Peas can climb the sides of the block.
  • Walking: Peas move across the surface of the block at full speed.
  • Collision with top: Falling peas stop when they land on the top of the block. If the fall is greater than 2 blocks in height, the pea dies.
  • Collision with side: Falling peas bounce off the side
Spring Blocks
  • Climbing: Peas can't climb the sides of the block.
  • Walking: Peas move across the surface of the block at full speed.
  • Collision with top: Falling peas are launched upward with greater velocity if they fall on the top of the block. Angle of incidence equals angle of reflection.
  • Collision with side: Falling peas bounce off the side
Gelatin Blocks
  • Climbing: Peas can't climb the sides of the block.
  • Walking: Peas move across the surface of gelatin at 1/2 speed.
  • Collision with top: Falling peas stop when they land on the top of the block. Gelatin provides a safe landing spot for high jumpers.
  • Collision with side: Falling peas bounce off the side
Ramp Blocks
  • Climbing: Peas can climb the backside of the ramp.
  • Walking: Peas climb up or down the ramp at full speed.
  • Collision with top: Falling peas bounce off the sides of the ramp at an angle and lose a little velocity. If they hit the ramp from a height larger than 3 blocks, they die.
  • Collision with side: Falling peas bounce off the side
Winning
In order to win a Play With Your Peas session, you need to complete certain goals on a level, much like Tony Hawk. The simplest is "Reach X number of points". Your final score is the time that it takes you to reach the goal. A new player might take 10 minutes to reach 10,000,000 points. An expert player, skilled in crazy combos, might take 2 minutes.

My hope is that casual players will have fun figuring out the system, setting up interesting combos. They'll generally ignore the clock. Eventually, they'll reach the goal and feel good about 'beating the game'. Their score is then compared against a number of other times in a high score list.

More driven players will feel a natural urge to compete by replaying the level for a better time. To facilitate this, we should have "Try Again" button on the high score screen.

Areas to prototype
Even though this design has a relatively small number of moving parts, the emergent behavior should be complex. There are three distinct areas that well are worth prototyping. I've listed them in order of priority.
  1. Pea falling physics: In order to do the pea falling correctly, you need a simple physics engine that deals with balls and planes.
  2. Block and scoring balancing: Balancing the size, properties and scoring of each block is a classic balancing problem. This is an area that will likely take hours to get right.
  3. Pea navigation: If you can get peas traversing a series of blocks in a smooth and believable fashion, you are halfway through the design. This involves some tricky path finding. If you want to stub this behavior out, spawn peas at a jumping flag and remove them once they are scored.
Some design notes
One problem that is common to AI-driven systems is that most of the behaviors go on underneath the cover, away from the player's eyes. It is very easy to fall into the trap of creating an intricate AI that 'plays itself' but is completely incomprehensible to the player.

Instead of asking how you might make the most realistic AI system, I prefer to steal a page from Nintendo's playbook. Instead ask "What is the simplest system that drives forward the player experience?"

Peas climb. Peas fall. Peas get scored. All of these activities are very apparent to the user. Instead of complex internal logic, the design focuses on explicit external behaviors. Any internal logic such as the path finding system exists only to the minimum degree necessary to support the external behavior. We won't build SkyNet using these sort of AI techniques, but we can make more enjoyable games.

Conclusion
If you create something inspired by this prototyping challenge, send it this way! I'll post it on the website for everyone to check out and comment on. Take shortcuts, mangle the design, find the fun.

Enjoy!
Danc.

Assets
I've provide the graphics for PlayWithYourPeas in two versions. First, all the graphics have been saved out as PNGs. I also included the Expression Design source file so you can make modifications to the original vectors.
References
Updated 2-11-2008: I added in the Block-Place-Normal.png to the zip that was previously missing. I also fixed some of the file names.

Updated 2-14-2008: I renamed the Ramp tools so that they follow the same naming convention as the blocks. The pea shadow is now seperated out. The single pixel alignment errors on the tools and the normal block are now fixed.