image Computational Thinking - Moving Together 2

Earlier we were able to move a set of 10 rabbits together, such that when one rabbit reaches a border, all rabbits change direction. We did it with Boolean attributes. In this tutorial, we can accomplish this same task using variable attributes. Instead of saying that a rabbit reaches the left border, we can simply say

When the position_x of a rabbit is less than 15, the brick becomes facing_east.

The reason for the value of 15 is that because the width of a character is 30, whenver the x-coordinate of a character is 15, it will be touching the left border.

We will similarly write the other sentences for the right border. Altogether, the following is the complete game plan.

There are 10 rabbits.
There is one brick. The brick is invisible.
When the brick is facing_east, the rabbits move right.
Otherwise, the rabbits move left.
When the position_x of a rabbit is less than 15, the brick becomes facing_east.
When the position_x of a rabbit is greater than 585, the brick becomes not facing_east.


Try it yourself

Can you make 3 rabbits and 3 foxes move together? Hint: both rabbits and foxes depend on the same brick arbiter!


Complete Sample Games for Computational Thinking

// Game #1. Shoot the Pearls and Avoid the Rocks.

There are 10 pearls. There are 10 rocks.
There is one brick. The brick is invisible.
You control the pointer.
The speed of the pointer is 4 pixels per frame.

When you press the left arrow, the pointer moves left.
When you press the right arrow, the pointer moves right.
When you press the spacebar on the keyboard, the pointer shoots up.

When the position_x of a pearl is less than 15, the brick becomes facing_east.
When the position_x of a pearl is greater than 585, the brick becomes not facing_east.
When the brick is facing_east, the pearls move right.
Otherwise, the pearls move left.
When the brick is facing_east, the rocks move left.
Otherwise, the rocks move right.

When a pearl is shot, the pearl disappears.
When a pearl is shot, the score increases by 1.
When the rock reaches the border, it wraps around.

When the score is equal to 10, you win.
When a rock is shot, game over.

Map:

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
---------p

// Game #2. Alien Tunnel.

The speed of the kitten is 3.
The speed of the topaz is 5.
The speed of the cheese is 5.
The speed of the diamond is 7.
The speed of the spinstar is 15.
The size of the diamond is 12.

//Player control.
You control the kitten.
The kitten falls down.
When up arrow is pressed, the kitten moves up.
When down arrow is pressed, the kitten moves down.
When space bar is pressed, the kitten becomes empowered for 0.1 second.
When the kitten is empowered , it inserts diamond.
When the kitten collides with border, the kitten explodes.
When the kitten collides with alien, the kitten explodes.
When the kitten collides with topaz, the kitten explodes.
When the kitten collides with cheese, the kitten explodes.

//Topaz moving together.
The apricot is invisible.
When the apricot is facing_up, the topazes move up.
Otherwise, the topazes move down.
When the position_y of a topaz is less than 30, the apricot becomes not facing_up.
When the position_y of a topaz is greater than 225, the apricot becomes facing_up.
When a topaz is not dead, the position_x of the topaz decreases by 1.
When a topaz collides with left border, it explodes.
When a topaz is not dead, it is white.

//cheese moving together.
The broccoli is invisible.
When the broccoli is facing_up, the cheeses move up.
Otherwise, the cheeses move down.
When the position_y of a cheese is less than 375, the broccoli becomes not facing_up.
When the position_y of a cheese is greater than 585, the broccoli becomes facing_up.
When a cheese is not dead, the position_x of a the cheese decreases by 1.
When a cheese collides with left border, it explodes.
When a cheese is not dead, it is white.

//Topaz and cheese spawn.
When the apricot is not dead, it becomes red.
When the apricot is red, it inserts topaz.
When the broccoli is not dead, it becomes red.
When the broccoli is red, it inserts cheese .

//Diamond cannon.
When a diamond is not dead, it moves right.
When a diamond collides with a border it explodes.
The angle of diamonds is 270.

//Enemy spawn.
The spinstar is invisible.
When the position_y of spinstar is less than 225, the position_y of the spinstar increases by 1.
When the position_y of the spinstar is greater than 225, the position_y of the spinstar decreases by 1.
When a spinstar collides with border, it reverses direction.
When a spinstar is not dead, it moves down with 20 percent probability.
When a spinstar is not dead, it moves up with 22 percent probability.
When a spinstar is not dead, it inserts an alien with 2 percent probability.
When an alien is not dead, it moves left.
When an alien collides with a diamond, it explodes and score increases by 3 points.
When an alien collides with a border, it explodes.

//Game over.
When the kitten is gone, you lose.
When score is greater than 50, you win.

Map:

-
-
-F-F-F-F-F-F-F-F-F
F-F-F-F-F-F-F-F-F-F@
-
-
-
-
-
-
--id--------------as
-
-
-
-
-z-z-z-z-z-z-z-z-z
z-z-z-z-z-z-z-z-z-zL


Next page

Tutorials Home