Building a platform game - a beginner's guide

8

Index

Attached Files

The following files have been attached to this tutorial:

.capx

platform-tutorial-i.capx

Download now 608.15 KB

Contributors

Stats

49,619 visits, 198,424 views

Tools

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 6 Jan, 2012. Last updated 26 Feb, 2019

Wrapping it up

That about finishes this first part of the tutorial - except that we'll do one more thing to make the game easier to play:

I guess you've noticed that if Tim happens to miss a landing, he falls (that's another behavior that you get for free with Platform objects). If there's no floor to break his fall, he keeps going down and down until he's out of the layout altogether. To save having to run the layout again in that case, we can bring him back in again from the top (no doubt at the expense of a decline in his health, if we were scoring). Here's how:

Condition: Player -> Is outside layout (under 'Size & Position')

Action: Player -> Set position -> X: 370, Y: 100

That's enough to make him fall down and land on the bottom floor - but unless we also change the PlayerImages animation, he'll still appear to be falling even after he's landed. So we'll change the animation to 'Standing' - except that we also need to cover the in-game situation where Tim falls off one floor while your finger's still on an arrow key, so that he lands running.

That means that the animation which results from the condition 'Platform On landed' will depend on another condition: whether the Player is moving or not. Two 'either/or' sub-events are needed:

First, add the main event:

Condition: Player ->Platform On landed

Then right-click on the green arrow on the extreme left of the event and in the drop-down menu which appears, select 'Add', then in the sub-menu, select 'Add sub-event':

Condition: Player-> Platform: Is moving

Action: PlayerImages -> Set animation -> "Running"

Now add another sub-event with the same condition:

Condition: Player-> Platform: Is moving -> invert it

Action: PlayerImages -> Set animation -> "Standing"

... so that on your event sheet, the main event and its two sub-events appear like this:

While we're about it, we'll give him an alarmed expression when he falls:

Condition: Player -> Platform: On fall

Action: PlayerImages -> Set animation -> "Falling"

Well, that is the end of this first part of this Platform tutorial. The next part covers particular issues of scoring platform games, where we need to distinguish between different floors and have different scores for events that happen on each of them.

IBefore moving on, you might like to experiment with changing the Platform behavior properties for the Player, and seeing what effect it has on Tim's behavior (and how it makes the game easier or harder):

One more change you can experiment with is the PlayerImages running speed (in the Properties bar when you chick Animations - Edit, and shown alongside 'Speed' as frames per second).

[page="

Part 2: Scoring"]

Part 2: Scoring

In platform games, the score usually needs to take account of the particular location where each event happens. Before we deal with that issue, here's the scoring scheme we'll use for this tutorial game:

1. Tim gains points as he jumps up from floor to floor:

-- +1 for the first floor (British floor numbering, where the floor he's standing on is the ground floor and the first floor is the next one up - just like zero-based arrays ;) )

-- +2 for the second floor

-- +7 for the top floor (reflecting the difficulty of getting there!)

2. A score of 25 is needed to get to the next level (so Tim will have to keep jumping between floors to earn enough points).

3. He gets points only when he jumps up onto a floor, not when he jumps down onto one.

4. He has 3 Health points to start with and loses 1 for each time he falls out the bottom of the layout.

5. The game is over when his Health count drops to 0.

Clearly, we'll need some means of knowing which floor Tim has jumped onto, so that we can award him the points appropriate to that floor. And we need a way of telling whether Tim has moved up or down between floors.

First, we create two global variables to hold the changing values for the score and for Tim's health, and give them the necessary initial values:

Add global variable: score (leave the default type as 'Number' and the initial value as 0).

Add global variable: health (leave the default type as 'Number', and set the initial value to 3).

(If you're unsure how to create these variables, check page 6 of the 'Beginner's guide to Construct 2'.)

The initial value of score will need to be restored when Tim falls out of the layout and drops back in at the top, and his health rating will need to go down by one :

Now, how can we tell whether Tim is moving up or down between floors? Well, if we know what floor he's on at present and what floor he was on when last we checked, we can compare the two values: if his present floor value is greater than his previous floor value, he's moved up, and vice versa.

So, we'll first need to record the level of each floor. To do this, we set instance variables for each instance of the Flooring object (in other words, for each floor of the layout). That's explained in the Beginner's Guide to Construct 2. In the screenshot below, each numbered item matches the numbered steps in the instructions that follow:

(1) Go to the Layout 1 view and click on the ground floor sprite. (2) In the Properties Bar, click on 'Edit variables: Add / edit', and the 'Flooring: Instance variables' window will open up. (3) Click on the 'Add' icon, and in the 'New instance variable' dialog box, (4) enter 'floor' for 'Name' and click 'OK' (leaving the other flelds at their default values). Don't close the 'Flooring: Instance variables' window - we'll take this opportunity to set the points value for each floor.

Click on the 'Add' icon again and add a second instance variable named 'points'. (Again, leave the other fields at their default values.)

You should see these two instance variables appearing in the Properties Bar:

That's set the 'floor' and 'points' values for the ground floor. Now we need to do the same for the other floors. Still in the Layout 1 view, click on the first floor sprite. In the Properties Bar, replace each '0' for 'floor' and 'points' with '1':

Click on the second floor sprite, and give it '2' for 'floor' and '2' for 'points'. Give the top floor '3' for 'floor' and a mighty '7' for 'points'.

  • 1 Comments

  • Order by
Want to leave a comment? Login or Register an account!