Game mechanics in Construct 2

Construct 2 allows you to either customize your own mechanics, or you can use the readymade ones that come with the software. You can even code your own custom behaviors with JavaScript, if you want to. This option is more advanced, but as very few non-programming engines will allow you to do so, it's a useful feature.

Setting up a game mechanics project

So, where do we start? Let's open up a new project and save it as game mechanics. Go ahead and add a sprite to the project as well. We will be using this sprite for many game mechanics. Your project should look like the one shown in the following screenshot:

Setting up a game mechanics project

We now have a sprite that we can play around with to add game mechanics. Let's start off with the readymade game mechanics and after that we will move on to custom game mechanics.

Adding a game mechanics behavior to a sprite

Without game mechanics, sprites are just images. In order to make them interactive in your game, you have to add mechanics to them.

Click on Behaviors on the left-hand side in the Properties window pane. You should get a window that looks like the following screenshot:

Adding a game mechanics behavior to a sprite

In the Behaviors window, click on the plus sign. The Add behavior window will appear, as shown in the following screenshot:

Adding a game mechanics behavior to a sprite

Here, you can see a lot of behaviors that you can add. Not all of these are game mechanics, but a lot of them are. In Construct 2, we can add behaviors to the sprite. Most of these are game mechanics.

Tip

At this point, I should mention that you can easily add certain readymade behaviors here, but you can also customize each behavior in the event sheets, if you want to. Some designers tend to do this because they want complete control over everything that happens in their game.

Giving a sprite 8Direction movement

Making a moving sprite is important for most games. Construct 2 has a fantastic behavior that easily adds the moving game mechanics to your sprite/player.

Go ahead and scroll the behaviors list, you should reach the 8Direction behavior. Select that and you should see it appear in your sprite's Behaviors window.

Giving a sprite 8Direction movement

Editing the properties of a behavior

Some of the behaviors have properties, and some do not. Behavior properties exist to make changes to the behavior if necessary. For example, if you want your player to move faster, you can go edit the Behaviors property. When you give an object a behavior, you have added extra functionality to that object and can now edit more properties in the event list as a result. In the following screenshot, you can see some of the properties that you can edit in the layout editor:

Editing the properties of a behavior

Tip

Just because your game has running, jumping, and shooting mechanics, it doesn't automatically make it fun to play. It is the relationship between the mechanics, the player, the target audience, and the graphics that makes a game fun to play.

Let's take a look at all of these properties and how they affect the game play.

Creating a speed power-up

Let's take a look at the first one, Max speed. If you run the game, you will see that the player moves around the game in eight directions. Max speed is the maximum amount of speed of this movement.

Let's imagine for a moment that we want to add a power-up to the game. This power-up will make the player move twice as fast for a small period of time.

Inserting the power-up object

The first thing we need to do is add another Gameobject to the screen. When we collide with this game object, we will activate the power-up mechanic.

Adding a collision event

Right now, when we collide with the power-up box, nothing happens. That's because we have to add the mechanics for it.

  1. Go to the event sheet and click Add event to bring up the Add event window, which is shown in the following screenshot:
    Adding a collision event
  2. Go ahead and click on circle or whatever you have named your sprite. This should bring up the Add event dialog box for the circle, which should look like the following screenshot:
    Adding a collision event
  3. Click on On collision with another object. When the player collides with a specific object (the box), an action will happen.
  4. Once you select this, the Pick an object window should pop up. Select the BoxBlueStar, or whatever you have called your power-up object, as shown in the following screenshot:
    Adding a collision event
  5. After selecting BoxBlueStar in the Pick an object window, the following window should appear:
    Adding a collision event
  6. Click on Done and the event sheet should look like the following screenshot:
    Adding a collision event

Destroying the power-up on collision

Now, we need to add a few actions. The first action is going to be destroying the box. If we don't do this, the box will not be destroyed and it will look weird to the player. Add an action and click on the power-up box.

Go ahead and click on BoxBlueStar.

Destroying the power-up on collision

Click on Destroy, and your event sheet should look like the following screenshot:

Destroying the power-up on collision

Run the game and test to see whether the box does indeed get destroyed.

Increasing the player sprite's speed

We are almost finished. The next thing we need to do is change the settings so that the player speed is doubled for a short period of time. This is actually really simple to achieve! Add an action, select the player sprite, and click on Next.

Go ahead and select the circle. You should see a window similar to the following screenshot pop up:

Increasing the player sprite's speed

Here, you can see that by adding the 8Direction functionality, we have added more options for actions. Select Set max speed. It should bring up the Set max speed dialog box, which is shown in the following screenshot:

Increasing the player sprite's speed

We need to set it to 400, or whatever you want your power-up to increase the speed to. Once you are finished, click on Done.

Setting the duration of the speed boost

The last thing we need to do is set the duration for the increased speed. Add another action from the Add action window and select System, as shown in the following screenshot:

Setting the duration of the speed boost

Then, we need to select the Wait function in order to insert a small timer. After the Wait command is finished, the power-up will end and the player sprite will return to a normal speed of 200. Once you select Wait, the Parameters for System dialog box will appear. Type the number of seconds you want the power-up effect to last, as shown in the following screenshot:

Setting the duration of the speed boost

Restoring the player's speed to normal

After that, select the first Set maximum speed event and press Ctrl + C to copy. Then, select the Wait command and press Ctrl + V to paste. The second Set maximum speed command should be after the Wait command, as shown in the following screenshot:

Restoring the player's speed to normal

Double-click the second Set maximum speed action and set it to 200—the original speed. Your event sheet should look like this:

Restoring the player's speed to normal

Go ahead and try it out. You have just made your first game mechanics!

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

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