Faulty Flap: 2. The bird
Step 2 of 6: Adding the bird and the first events
In the Frame Editor > Layers Toolbar create a new Layer and select it. [[pic_test]] From the Library Window drag bird.Active in the Frame at coordinates (148,326).
- bird.Active: bird
This is an Active object, the Bouncing Ball Movement is assigned to it with an initial Direction of 24 (down) and an initialSpeed of 0.
The new Layer 2 that we created will contain the objects with which we will perform collisions tests.
Objects located on different layers cannot collide with each other.
The coordinates of an Active object are displayed in the Object Properties > Size / Position tab.
Your Frame should look like this:
Run the application and notice how the bird is flapping his wings, but without actually moving.
Let's make the bird jump first. In the Event List Editor insert a group of events called Game.Play and add the following events into it:
- User clicks with left button
: Play sample jump
(bird.Active) : Set direction to 8
(bird.Active) : Set speed to 75
(bird.Active) : Set deceleration to 65
- User double-clicks with left button
: Play sample jump
(bird.Active) : Set direction to 8
(bird.Active) : Set speed to 75
(bird.Active) : Set deceleration to 65
What happens with these events? When the player clicks or double-clicks with the left mouse button we make the bird move upwards by setting its Direction, Speed and Deceleration.
To insert a group of events right-click on a numbered cell in the list of events and select Insert > A group of events.
By default the Event List Editor displays only the icon of the objects. To display their name too, in the main menu select Tools > Preferences > Event List Editor tab and check Object's name.
And now let's make the bird fall. Insert another group of events called bird.Active. Move this group after theGame.Play group. Then add the following events into it:
- Speed of (bird.Active) = 0
+ (bird.Active) is facing a direction 8
(bird.Active) : Set direction to 24
(bird.Active) : Set deceleration to 0
- (bird.Active) is facing a direction 24
+ Every 00"-05
(bird.Active) : Set speed to Speed( " (bird.Active)" ) + 10
What happens with these events? When the upwards Movement of the bird is finished (i.e. when its Speed reaches 0) we simply make him move downwards by setting its Direction to 24.
And while the bird is moving downwards (i.e. while he is facing Direction 24) we increment its Speed by 10 every 5 hundredths of a second. We actually reproduce an acceleration here.
Run the application and notice how the bird jumps and falls dynamically.
We use two groups of events both related to the bird. This is because later we will deactivate the bird jump (the player input) and the bird fall separately. Please read on to find out why.
As soon as the application starts, the bird begins to fall. We must grant the player a moment to get ready, in other words we need a game intro.
In the Event List Editor uncheck Active when frame starts for both existing groups of events. This ensures that the bird won't move right from the beginning.
Then insert a new group of events called Game.Intro and leave Active when frame starts checked. Move that group to the top of the list of events.
Now add the following event in the Game.Intro group:
- User clicks with left button
: Activate group "Game.Play"
: Deactivate group "Game.Intro"
Then add the following event in the Game.Play group:
- Only one action when event loops
: Activate group "bird.Active"
What happens with these events? When the player clicks with the left mouse button the Game.Play group which is dealing with the bird jump is activated. And once that the Game.Play group is activated, the bird.Active group which is dealing with the bird fall is activated in turn.
Actually both groups of events could be activated with the same event. But doing it that way is a good programing habit for two reasons. Firstly because we follow a logical "game flow" where Game.Intro deactivates itself at the same time as it activates Game.Play.
Secondly because this will be useful later if you want to implement a pause system, where Game.Play activates bird.Active and Game.Pause deactivates it.
Run the application and notice that the bird won't move until you have left-clicked.
Spread the word!
You can share this document using the following buttons.