image Tutorial on Jumping and Falling

So far, all the movements discussed have been in 2D. The player has a birds-eye view of the screen, and the characters can move east, west, north and south. By making a character "jump" or "fall", you change the perspective of the player so that the player is looking at the game straight on. This gives the impression of height and gravity without having to go 3D. We'll call this "2.5D". Consider the following examples:

  • When up arrow is pressed, the rabbit jumps.
  • When a fox collides with a ball, it jumps.
These two sentences are examples of jumping. Since characters always move up when jumping, you don't need to describe a direction to jump. Also, you cannot tell a character to jump at another character, since the target character may be far away.
Rabbits move east. Rabbits jump. In this example, when the rabbits jump, they will jump eastward. When you are in 2.5D, don't move a character upwards without using the jumping verb, since the gravity will keep it from moving up.
When the rabbit stomps on a fox, the fox explodes.
When the rabbit lands on a fox, the fox explodes.
When the rabbit collides with a fox, the rabbit explodes.
These two sentences describes two different types of collisions. They are both part of a game where a rabbit destroys a fox by jumping and landing on it - this is described with the word "stomp" (first sentence). But if the rabbit collides with a fox from any direction other than from the top, the rabbit dies (second sentence).
When the rabbit falls on a rock, the rabbit stops.
When the rabbit lands on a sapphire, the rabbit stops.
There are ways to stop a fall. First, certain objects, such as bricks, will automatically stop a falling character when the character lands on it. Most other objects will not stop the falling, so you have to specifically describe it. After a character lands, it can jump again. But if a character can fly, such as a bird, it can jump again before it lands.

Now, there are a few things to note about jumping.

When the rabbit lands on a brick, it bounces. When the verb 'bounce' is used to describe an object that is able to jump, this object becomes bouncy. That is, when it lands on a platform such as a brick, it will automatically bounce. If you do not intend for this, use verbs other than 'bounce'.
Finally, if an object can 'fly', then it can jump without first landing. Otherwise, an object will need to first land before it can jump again.


Sometimes objects only fall. Try the following and see what would happen:
There are 10 rabbits and 20 bricks.
The rabbits fall.
The rabbits move left.
When a rabbit touches the left border, it wraps around.

Now, add the following sentence, and see what would happen.
When a rabbit lands on a brick, it reverses direction.

Finally, change "reverses direction" to "bounces", what would happen?
When a rabbit lands on a brick, it reverses direction.

We see that when an object can jump or fall, the verb "bounce" can affect its behavior, as it makes the object 'bouncy'!


Try it yourself:
Example 1: Try placing 10 bricks on the canvas and make your controlled rabbit climb the bricks with pressing of the spacebar.

Challenge: Now try using 10 sapphires instead of bricks. Unlike bricks, sapphires do not automatically stop the rabbit from falling. Your challenge is to come up with a sentence that allows the rabbit to climb the sapphires.

Example 2: Try the following 2 examples. See which one lets the rabbit do a multi-jump (jump in air).


Complete Sample Games for Jumping

// Game #1. Get the spinstars.

You control the rabbit.
When you press spacebar, the rabbit jumps.
When an right arrow key is pressed, the rabbit moves right.
When an left arrow key is pressed, the rabbit moves left.

The topaz is invisible.
The diamond is invisible.
The speed of the dino is 3 pixels per frame.
The speed of the elephant is 2 pixels per frame.
When the dino reaches the topaz, the dino becomes notified.
When the dino reaches the diamond, the dino is not notified.
When the dino is notified, the dino moves right.
Otherwise, the dino moves left.
When the elephant reaches the topaz, the elephant becomes notified.
When the elephant reaches the diamond, the elephant is not notified.
When the elephant is notified, the elephant moves right.
Otherwise, the elephant moves left.
When the rabbit collides with the spinstar, the spinstar disappears.

When the rabbit reaches the border, gameover.
When the rabbit collides with a rock, gameover.
When the rabbit collides with a dino, gameover.
When the rabbit collides with an elephant, gameover.
When all the spinstars are gone, you win.

Map:

-
--s-------F--jsd
--k--------kkkk
-
-
-----F----D-----d
------kkkkkkkkkk
-
--ooo--------------k
-
--------k
------------k
----k--------------k
----------k----o
-
k---k
-------------------k
------------k
-r--------------s
-k--------------k

// Game #2. Stomp the dinos and bricks.

The player controls the kitten.
When the right arrow is pressed, the kitten moves right.
When the left arrow is pressed, the kitten moves left.
When the space bar is pressed, the kitten jumps.
The speed of the kitten is 5.
The speed of bricks is 1.3.
The speed of dinos is 2.
The speed of the ball is 2.

//Kitten movement.
When the kitten collides with a topaz, it reverses direction.
When the kitten collides with a border, it explodes.
When the kitten stomps on a dino, the dino explodes and score increases by 5.
When the kitten stomps on a brick, the brick becomes pink for 3 seconds and score increases by 1.
When the kitten stomps on a pink brick, the brick explodes.
When the kitten collides with a ball, it explodes.
When the kitten collides with a dino, it explodes.

//Brick movement.
Bricks[0,6] start by moving right.
Bricks[7,13] start by moving left.
When a brick collides with topaz, it reverses direction.

//Enemy movement.
The dinos start by moving random.
When a dino collides with a topaz, it reverses direction.
When a dino collides with a border, it reverses direction.
Ball[0] start by moving down.
Ball[1] start by moving up.
When the ball collides with border, it reverses direction.

//Game over.
When the kitten is gone, you lose.
When the score equals 20, you win.

Map:

Fl-------=---------F
F---D----------D---F
F---k----------k---F
F------------------F
F--------k---------F
F------------------F
F---k----------k---F
F------------------F
F--------k---------F
F------------------F
F---k----------k---F
F--------i---------F
F--------k---------F
F------------------F
F---k----------k---F
F------------------F
F--------k---------F
F---D----------D---F
F---k----------k---F
F-----------------lF

// Game #3. Jump Over the Pearls.

The player controls the rabbit.
When the up arrow is pressed, the rabbit jumps.
When the right arrow key is pressed, the rabbit moves right at 2.6 pixel per frame.
When the left arrow key is pressed, the rabbit moves left at 2.6 pixels per frame.
When the rabbit touches a topaz, it moves left at 1 pixels per frame.
The topaz is invisible.

When the rabbit touches a border, it explodes.
The donut starts off moving up.

When the donut touches a topaz, it reverses direction.
When the donut touches a topaz, it becomes active for 0.2 second.
When the donut is active, the donut inserts a pearl.
Then fox starts off moving right at 5 pixels per frame.
When the fox touches a border, it reverses direction.

The pearl moves left at 2 pixels per frame.
When a pearl touches a brick, it bounces.
When a pearl touches a fox, it jumps.
The fox is invisible.

When the rabbit is above a pearl, the rabbit destroys the pearl.
When the rabbit is above a pearl, the score adds 1.
When the rabbit collides with a pearl, the rabbit explodes.
When the score equals 19, you win.
When the rabbit explodes, the game is over.

Map:

-=
-
-
-
-
-
-
-
-
-
-
-
-
-
-------------------F
-
-
---------rx--------+
FFFFFFFFFFFFFFFFFFxF
kkkkkkkkkkkkkkkkkkkk


Programming Concepts (optional material):
Computers have been great at simulating scientific phenomenon. A computer simulation is a computer program that models a system, which can be physical or virtual. Jumping is one physical example. The gravitational pull exerted on an object makes its trajectory appear to slow down when it reaches the peak and speed up when it falls. Computer simulation plays important roles in many areas of our lives, from traffic control to weather forecasting, to many others. Can you think of other examples?

Many of the simulation models demand sophisticated math formulations to give a realistic feel and/or prediction. However, because computers are extremely good at number-crunching, they can process billions of mathematical operations per second, which we would otherwise be unable to do manually!


Next Page

Tutorials Home