Maze chompers (such as Pac Man)

What would any 2D game development guide be if we didn't tell you how to make (without a doubt) the most popular video game of all time? Songs were made about Pac Man, movies (such as the inclusion of Pac Man in Pixels), the first game with spin-offs, lines in video arcades. The whole world suffered from Pac Man fever for nearly five years!

So, how do you make a maze chomper in Buildbox? Well, believe it or not...there's a template for that as well. The template is called Stage Clear. Since we're getting a bit tired of the stock monochrome primitive graphics, we went ahead and replaced some of the graphics in our test project with elements that come with Buildbox.

The basic template does have a maze, coins, and a character to eat them. However, there are some key elements that are missing to make this a classic maze chomper game. We need to include some roaming enemies and teleport channels to make this more like the classic maze chomper games.

Before we do all that, we deleted all of our graphic assets from the Asset Library and built a maze that looks like this:

Maze chompers (such as Pac Man)

So, our gaming field is set for a scene, so now let's add a character and an enemy and start working on how to make that enemy roam around on the stage.

Roaming enemies

Unfortunately, there is no logic behavior (at this time) to make enemies chase characters (nor run from them). However, we can simulate this type of behavior by using the Transform object. Here's how we set it up.

In the following screenshot, you can see several transform objects placed around the map. You can also get an idea of how they change the movement of our enemy to send it roving around the map:

Roaming enemies

If the exact path doesn't make sense to you...that's ok. You don't need to see the specifics of every intersection of motion. What you do need to know is how we can have the same object (our enemy) traverse the same section of the map in different ways. So, let's take a look:

Roaming enemies

The preceding screenshot is one section of the stage. Ignore our character here...let's take a look at how we make our enemy move through this section:

  1. Our enemy approaches this section from underneath and touches this bumper (which transforms the motion of the enemy to move left). Also, this bumper shifts the enemy down slightly so that it avoids bumper 3 and 4, while remaining above 5 as well.
  2. This bumper moves the enemy down, and shifts it slightly to the right (so that it avoids re-touching this bumper on its way back up).
  3. The enemy was sent down by bumper 2, and back up by an off-screen bumper. Once it hits bumper 3, the enemy moves to the right. Notice that bumper 3 is slightly higher than bumper 1.
  4. Since our enemy is slightly higher than it was when it was sent left by bumper 1, it will now hit bumper 4 and be sent up to another section.
  5. The enemy now returns to this section from the upper section (missing bumper 4 on its way back down, and is sent to the right by bumper 5).
  6. Bumper 5 is low enough to send our enemy to the right and have it miss bumpers 4 and 1. When the enemy hits bumper 6, it's sent back to the lower section of the map to start its loop all over again.

And there it is... the easy way to have a roaming enemy. You can always add more enemies and either have them use the same bumpers, or ones that only work for them to add some complexity.

Now we just add some portals (two groups of two portals each), and drop some coins on the stage (that each have a reward of one coin) as shown here:

Roaming enemies

And, to finish it up, we need to know when all of the coins have been consumed by our character. On the UI screen, we just select our All Coins event listener and set the Session Total parameter to 19 (the number of coins on our screen). What we've done here is sensed how many coins our character has eaten, and triggered Game Over once they've eaten them all. This parameter is illustrated here:

Roaming enemies

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.21.158