Chapter 3. Detecting Collisions

In this chapter, we will continue to develop the game that we started to create in Chapter 2, Let's make a game. Although we have many of the basic game mechanics in place, we do not yet have a very interesting game that will engage our players, so we're going to introduce an additional element of interactivity to make the game more challenging.

In its current form, the game allows our monkey to navigate the jungle scene without any difficulty, and that isn't going to be much fun for players of our game — we need a more interesting environment!

To make the game more challenging, we're going to add some dangerous enemies for the monkey to avoid, and we're also going to create a challenge for the player to complete — the monkey will have to collect some items as it makes its journey through the jungle.

In order to be able to collect these items, we need our monkey to detect collisions with other objects, so our game can respond accordingly. In this chapter, we're going to learn the important aspects of implementing collision detection within Stencyl.

By the end of this chapter, we will have a good understanding of the following topics:

  • Working with collision detection in Stencyl
  • Modifying an actor's collision shapes
  • Configuring collision shapes for tiles
  • Adding enemies and collectibles
  • Working with collision groups
  • Using collision sensors
  • Implementing terrain collision shapes

The target for this chapter is to progress with our development of the game so that it looks something like the following screenshot:

Detecting Collisions

As we can see, our monkey now has fruits to collect and dangerous animals to avoid!

Working with collision detection in Stencyl

If our monkey has to collect items and avoid enemies, we will need to detect collisions between the monkey and the various actors that will represent the enemies and collectible items. In other words, our game needs to know when these objects have bumped into each other!

Stencyl, as we may now expect, makes the job of working with collisions much easier than it would be if we had to hand code our game using a traditional programming language. We can easily specify which parts of our tiles and actors will cause a collision event, and we can also easily configure behaviors to carry out certain actions for us when collision events occur.

In fact Stencyl is already automatically managing collisions within our game! Let's have a look behind the scenes, using a very useful feature that has been built into Stencyl to help us manage the collision detection:

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

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