2. X
Contents
REQUIREMENTS:
This e-learning package requires you to:
1. Go through this presentation
2. Try the sample scripts provided.
3. Create a game using this presentation and the sample scripts to help you.
4. Submit your game through LMS.
RESOURCES:
You should have downloaded the attached files. You should have 2 partially
completed games:
- Alien
- Prevent_dengue
3. X
Use these button for
quick access to each set
of scripts.
Back to the home page.
Click to see more of
each script block.
Quits this presentation
Navigating
Next page
Previous page
4. X
Select a set of scripts to begin
See Sample scripts
Go to Task
5. X
Motion
Click on the scripts on the left to see what each script does
to the worm below.
6. X
Move 10 steps
Click on the scripts on the left to see what each script
does to the worm below.
Moves the sprite 10 steps in the current direction.
7. X
Turn clockwise
Click on the scripts on the left to see what each script
does to the worm below.
Turns the sprite (X) degrees clockwise.
8. X
Turn Anti-clockwise
Click on the scripts on the left to see what each script
does to the worm below.
Turns the sprite (x) degrees anti clockwise.
9. X
Point in direction: – 0o
Mouse over the different degrees to see what happens
0o
90o
-90o
180o
Points the sprit in a specified direction.
10. X
Point in direction: 180o
Mouse over the different degrees to see what happens
0o
90o
-90o
180o
Points the sprit in a specified direction.
11. X
Point in direction: -90o
Mouse over the different degrees to see what happens
0o
90o
-90o
180o
Points the sprit in a specified direction.
12. X
Point in direction : 90o
Mouse over the different degrees to see what happens
0o
90o
-90o
180o
Points the sprit in a specified direction.
13. X
Point towards:
Mouse over the different degrees to see what happens
Points the sprit in a specified direction.
14. X
Go to X: Y:
Instantly moves a sprite to a specified coordinate position.
X: 180
X: 150
Y: -200
Y: 200
Y: -150
Centre of the
stage is always
(0, 0)
X: -180
Go to X: 150 Y: -150
15. X
Go to (XX):
Instantly moves the sprite the location of another sprite or
mouse pointer.
Go to <Mouse pointer> Sprite goes to wherever the
mouse pointer goes
16. X
Glide ( )secs to X: Y:
Gradually moves the sprite to a specified position over a
number of seconds.
Y: 180
X: 100
X: 200
X: -200
Y: -50
Y: -180
Glide (3) secs to to X: 100 Y: -50
17. X
Change x by ( )
Moves the sprite left or right regardless of direction the
sprite is pointing.
Click the buttons belowt o compare the effect of the 3
different scripts.
Change x by (20)
Change x by (-20)
Move (20) steps
18. X
Change x by ( 20 )
Moves the sprite left or right regardless of direction the
sprite is pointing.
Click the buttons belowt o compare the effect of the 3
different scripts.
Change x by (20)
Change x by (-20)
Move (20) steps
19. X
Change x by ( -20 )
Moves the sprite left or right regardless of direction the
sprite is pointing.
Click the buttons belowt o compare the effect of the 3
different scripts.
Change x by (20)
Change x by (-20)
Move (20) steps
20. X
Move ( 20 ) steps
Moves the sprite left or right regardless of direction the
sprite is pointing.
Click the buttons belowt o compare the effect of the 3
different scripts.
Change x by (20)
Change x by (-20)
Move (20) steps
21. X
Move ( 20 ) steps
Moves the sprite left or right regardless of direction the
sprite is pointing.
Click the buttons below to compare the effect of the 3
different scripts.
Change y by (20)
Change y by (-20)
Move (20) steps
22. X
Change y by ( )
Moves the sprite up or down regardless of direction the
sprite is pointing.
Click the buttons below to compare the effect of the 3
different scripts.
Change y by (20)
Change y by (-20)
Move (20) steps
23. X
Change y by ( 20 )
Moves the sprite left or right regardless of direction the
sprite is pointing.
Click the buttons below to compare the effect of the 3
different scripts.
Change y by (20)
Change y by (-20)
Move (20) steps
24. X
Change y by ( -20 )
Moves the sprite left or right regardless of direction the
sprite is pointing.
Click the buttons below to compare the effect of the 3
different scripts.
Change y by (20)
Change y by (-20)
Move (20) steps
25. X
If on edge, bounce
Usually used when the sprite is moving. When the sprite touches
the edge of the screen, it will “bounce” and move in the opposite
direction.
Mouse over the button below to see an example.
Start
26. X
If on edge, bounce
Usually used when the sprite is moving. When the sprite touches
the edge of the screen, it will “bounce” and move in the opposite
direction.
Mouse over the button below to see an example.
Start
27. X
Looks
Click on the scripts on the left to see what each script does
to the worm below.
28. X
Switch costume
Switch to costume ( )
Next costume
Allows you to choose which
costume to switch to.
Automatically switches to the
next costume.
back
29. X
Switch costume
Lets say the worm below has 3 costume.
Costume 1
Costume 1
Click the commands below to see what
happens to the worm.
Switch to costume (costume 1)
Costume 2
Switch to costume (costume 2)
Switch to costume (costume 3)
Next costume
30. X
Switch costume
Lets say the worm below has 3 costume.
Costume 1
Costume 1
Click the commands below to see what
happens to the worm.
Switch to costume (costume 1)
Costume 2
Switch to costume (costume 2)
Switch to costume (costume 3)
Next costume
31. X
Switch costume
Lets say the worm below has 3 costume.
Costume 1
Costume 1
Click the commands below to see what
happens to the worm.
Switch to costume (costume 1)
Costume 2
Switch to costume (costume 2)
Switch to costume (costume 3)
Next costume
32. X
Switch costume
Lets say the worm below has 3 costume.
Costume 1
Costume 1
Click the commands below to see what
happens to the worm.
Switch to costume (costume 1)
Costume 2
Switch to costume (costume 2)
Switch to costume (costume 3)
Next costume
33. X
Say
Automatically creates a speech balloon to say a specified
text.
How are You?
Say [ How are you ? ] for (3) secs.
34. X
Think…
Similar to the “say” script, but creates a thought balloon
instead.
How are you?
Think [ How are you ? ] for (3) secs.
35. X
Change size by ( )
Changes the size by a specified amount each time the
script is used.
Negative numbers will shrink the sprite
Positive numbers will grow the sprite.
Change size by ( 50)
Size = 150%
Size = 100%
Change size by ( - 50)
Size = 50%
36. X
Set size to ( )%
Changes the size by a specified amount once only.
Only positive numbers used.
Click
here
and Set Size
to see difference between Change Size
Set size to (150)%
Size = 150%
Size = 100%
Set size to (50) %
Size = 50%
37. back
X
Change size vs Set size
The difference between change size and set size become obvious
when the same script is used multiple times.
script
Size = 100%
Used 1st time
Used 2nd time
Used 3rd time
Size = 130%
Size = 160%
Size = 190%
Size = 30%
Size = 30%
Size – 30%
Change size
by (30)
Size = 100%
Set size to
(30) %
38. X
Show and Hide
Show: the sprite can be seen (visible)
Hide: the sprite cannot be seen (invisible)
Show
Hide
39. X
Show and Hide
Show: the sprite can be seen (visible)
Hide: the sprite cannot be seen (invisible)
Show
Hide
40. X
Show and Hide
Show: the sprite can be seen (visible)
Hide: the sprite cannot be seen (invisible)
Show
Hide
41. X
Sounds
This set of scripts allows you to control sounds in your
game or animation.
Click on one of the highlighted scripts to check what they
do.
42. X
Play sound ( )
Plays a specified sound.
Sound effect must be imported into the sprite library for
you to be able to use them.
Click
Here
to find out how to import sounds
47. X
Play sound ( ) until done
Plays a specified sound and waits until the sound clip ends
before moving on to the next script.
Sound effect must be imported into the sprite library for
you to be able to use them.
Click
Here
to find out how to import sounds
48. X
Stop all sounds
Stops all sound effects in the game or animation.
Usually used when the game ends or when a condition is
met.
49. X
Control
Click on a set of control scripts.
Terminators
Loops and
conditionals
Examples
When key pressed;
When I receive;
When sprite clicked
Stop
Stop all
Examples
If, If.. Then.. Else;
Repeat loops
Forever loops
Broadcast
51. X
When (green flag) clicked
The green flag is usually used to start the game or
animation.
Click on the green
flag to start
52. X
When (green flag) clicked
The green flag is usually used to start the game or
animation.
Click on the green
flag to start
Click on another terminator to continue
53. X
When ( ) key pressed
Key press can also be used to start a game or animation.
Key press is a common method to control characters or
sprites in a game.
Space bar
Click on the
spacebar above
54. X
When ( ) key pressed
Key press can also be used to start a game or animation.
Key press is a common method to control characters or
sprites in a game.
Space bar
Click on the
spacebar above
Click “spacebar” to change costume again or click
MORE continue.
more
55. X
Key press as controls
Click on the arrow keys to see
what each key press does to the
worm above
Click on another terminator to
continue.
56. X
When sprite clicked
The sprite “worm” changes costume when clicked
and changes back after 0.25 seconds.
Try clicking on the worm, or click another terminator to
continue.
57. X
Loops and Conditionals
LOOPS
A set of scripts that repeats itself.
CONDITIONAL
LOOPS
A set of scripts that repeats itself
until a condition is fulfilled.
CONDITIONALS
An event that must happen to start
a set of scripts.
CONDITIONALS
An event that must happen to start
a set of scripts.
58. X
Forever Loops
Scripts inside the forever loop will be repeated over and over
again.
Forever Loops can be stopped when the “STOP ALL” command
is used.
Example:
60. X
Repeat ( )
Repeats the script inside the loop a fixed number of times.
In the script on the right, the
worm moves 10 steps and
waits for 0.5 seconds for 3
times. , and then changes
costume.
Click here to start
61. X
Repeat until < >
Repeats the script inside the loop a fixed number of times.
In the script on the right, the
worm moves 10 steps and
waits for 0.5 seconds until it
touches the edge , and then
changes costume.
Click here to start
62. X
“If” statements
If statements specify an event that must happen before the
scripts in the statement is run..
Select one of the options below to learn more.
IF < > …
IF < > … ELSE …
63. X
IF < > …
The event specified in < > must happen for the script to run.
The script on the right shows
part of a game.
Click on the larger number to
score a point.
IF you score 3 points, you win.
Click here to start
64. X
IF < > …
The event specified in < > must happen for the script to run.
The script on the right shows
part of a game.
Click on the larger number to
score a point.
IF you score 3 points, you win.
Click here to start
65. X
IF < > …
The event specified in < > must happen for the script to run.
The script on the right shows
part of a game.
Click on the larger number to
score a point.
IF you score 3 points, you win.
SCORE
Click here to start
Which number
is larger?
34
OR
45
0
66. X
IF < > …
The event specified in < > must happen for the script to run.
The script on the right shows
part of a game.
Click on the larger number to
score a point.
IF you score 3 points, you win.
SCORE
Next question
Correct!
1
67. X
IF < > …
The event specified in < > must happen for the script to run.
The script on the right shows
part of a game.
Click on the larger number to
score a point.
IF you score 3 points, you win.
SCORE
Which number
is larger?
50
OR
32
1
68. X
IF < > …
The event specified in < > must happen for the script to run.
The script on the right shows
part of a game.
Click on the larger number to
score a point.
IF you score 3 points, you win.
SCORE
Next question
Correct!
2
69. X
IF < > …
The event specified in < > must happen for the script to run.
The script on the right shows
part of a game.
Click on the larger number to
score a point.
IF you score 3 points, you win.
SCORE
Which number
is larger?
0
OR
-1
2
70. X
IF < > …
The event specified in < > must happen for the script to run.
The script on the right shows
part of a game.
Click on the larger number to
score a point.
IF you score 3 points, you win.
SCORE
End game
Correct!
YOU WIN !
3
71. X
IF < > …
The event specified in < > must happen for the script to run.
The script on the right shows
part of a game.
Click on the larger number to
score a point.
IF you score 3 points, you win.
Wrong answer! Please try again.
<< Back
72. X
IF < >… ELSE …
The event specified in < > must happen for the script to run.
IF < > … ELSE … is used when there are only 2 options. E.g: YES
or NO, TRUE or FALSE, A or B.
Compare the 2 scripts below:
Click each one to see how they work.
73. X
IF < >… ELSE …
Answer the question
below.
Click the correct
answer.
How many hours are there in a day?
(A) 24 hours
Answer A
(B) 30 hours
Answer B
(C) 78 hours
Answer C
74. X
IF < >… ELSE …
You Win!
How many hours are there in a day?
(A) 24 hours
Answer A
(B) 30 hours
Answer B
(C) 78 hours
Answer C
75. X
IF < >… ELSE …
Almost there!
How many hours are there in a day?
(A) 24 hours
Answer A
(B) 30 hours
Answer B
(C) 78 hours
Answer C
76. X
IF < >… ELSE …
Are you sure?
How many hours are there in a day?
(A) 24 hours
Answer A
(B) 30 hours
Answer B
(C) 78 hours
Answer C
77. X
IF < >… ELSE …
Answer the question below.
Click the correct answer
How many hours are there in a day?
(A) 24 hours
Answer A
(B) 30 hours
Answer B
(C) 78 hours
Answer C
78. X
IF < >… ELSE …
You Win!
How many hours are there in a day?
(A) 24 hours
Answer A
(B) 30 hours
Answer B
(C) 78 hours
Answer C
79. X
IF < >… ELSE …
Wrong Answer!
How many hours are there in a day?
(A) 24 hours
Answer A
(B) 30 hours
Answer B
(C) 78 hours
Answer C
80. X
IF < >… ELSE …
Wrong Answer!
How many hours are there in a day?
(A) 24 hours
Answer A
(B) 30 hours
Answer B
(C) 78 hours
Answer C
82. X
BROADCAST and RECEIVE
BROADCAST = Send a message
RECEIVE = receive the message
Change your
So much
Colour!
better!
Sprite 1
Back to controls
Sprite 2
83. X
BROADCAST and RECEIVE
BROADCAST = Send a message
Restart Animation
RECEIVE = receive the message
So much
better!
Notice this speech
balloon appeared too
early.
Sprite 1
Back to controls
Sprite 2
84. X
BROADCAST and RECEIVE
BROADCAST = Send a message
RECEIVE = receive the message
Lets change this to
BROADCAST AND WAIT.
So much
better!
Sprite 1
Back to controls
Sprite 2
86. X
BROADCAST and RECEIVE
BROADCAST = Send a message
RECEIVE = receive the message
Change your
So much
Colour!
better!
Sprite 1
Back to controls
Sprite 2
87. X
Broadcast vs Broadcast and Wait
• Broadcast:
– Sends the message and continues with the next
script
• Broadcast and wait
– Sends the message, waits for the message to be
received carried out, then continues with the next
script.
Back to controls
88. X
Sensing
Blocks found under the sensing section are never used
alone, except for Ask and Wait.
Sensing scripts are used together with other scripts,
usually conditional loops and “IF” statements
89. X
Operators
Operators may be used to specify conditions
They may be used together with sensing blocks control
blocks.
Click on one of the block on the left to continue.
91. X
Random Number Generator
One of the most commonly used script blocks in game
design. Generates a random number when used.
Click next to see examples:
92. X
Examples
Points the sprite in a random direction between 0 to 360.
Sets the variable (Scene) to either 1 or 2 randomly.
Moves the sprite to a random X-position between -200 and
200.
94. X
Join [ ] [ ]
Joins 2 words together.
Used together with the “say” script.
Example: Click the 2 scripts below to see what is said.
95. X
Join [ ] [ ]
Joins 2 words together.
Used together with the “say” script.
Example: Click the 2 scripts below to see what is said.
Your score is 5
96. X
Join [ ] [ ]
Joins 2 words together.
Used together with the “say” script.
Example: Click the 2 scripts below to see what is said.
Your answer A is correct!
97. X
Variables
A variable is a memory location set aside to store
data types such as numbers, text or dates. This
location will contain something when it is first
used. Hence, it is important to clear the location
and fill it with the value that you want. The
process of filling with a start value is called
initialisation.
98. X
Variables
A common variable that we will use frequently is the
score of a game. The score is a variable because it keeps
changing (varying) when the game is being played. We
use the “set” instruction to initialise a variable.
For example, we can set a variable “lives” to a start
value of 5 by using this instruction:
104. X
Hammer Scripts
Mouse over the scripts to see explanations
When the green flag is clicked,
the hammer is reset to the
position X: 0, Y: 122.
Hammer is visible (show).
105. X
Hammer Scripts
Mouse over the scripts to see explanations
When spacebar is pressed, the
hammer moves as if it is being
swung.
A broadcast message (hit) is sent
to see if the hammer hits the
alien spaceship.
106. X
Hammer Scripts
Mouse over the scripts to see explanations
When the right arrow key is
pressed, the hammer moves right
by 10 steps
If the x-position of the hammer is
more than 200, it is automatically
changed to 200.
This prevents the hammer from
going off the screen.
107. X
Hammer Scripts
Mouse over the scripts to see explanations
When the Left arrow key is
pressed, the hammer moves left
by 10 steps
If the x-position of the hammer is
less than -200, it is automatically
changed to 200.
This prevents the hammer from
going off the screen.
109. X
Alien Spaceship Scripts
Mouse over the scripts to see explanations
Initialisation:
The Alien spaceship is shown,
Lives is reset to 3
Score is reset to 0
Spaceship is moved to a random
x-position at y:128
110. X
Alien Spaceship Scripts
Mouse over the scripts to see explanations
Until score=5 or lives=0, the
spaceship is moved downwards
every 0.2 sec.
If the spaceship touches green
color (the ground), deduct 1 from
the variable lives.
Resets by appearing in another
random location.
111. X
Alien Spaceship Scripts
Mouse over the scripts to see explanations
If score = 5, the broadcast a WIN
message,
Otherwise, broadcast a loss
message.
112. X
Alien Spaceship Scripts
Mouse over the scripts to see explanations
When the broadcast message
“hit” is received, check to see if
spaceship is touching the
hammer.
If touching hammer (sprite 2),
increase the score by 1, hide the
spaceship.
Spaceship reappears at another
random x position at the top of
the screen.
114. X
Alien Spaceship Scripts
Mouse over the scripts to see explanations
When Green flag is clicked, the
game background is shown.
115. X
Alien Spaceship Scripts
Mouse over the scripts to see explanations
When the “lose” broadcast
message is received, change
background to shown lose-game
message.
116. X
Alien Spaceship Scripts
Mouse over the scripts to see explanations
When the “win” broadcast
message is received, change
background to shown win-game
message.
118. X
Game title: Prevent Dengue
STATE the problem
• This game is about killing Aedes mosquitoes to prevent the
spreading of dengue fever.
• The aim is to swing the bat to kill the mosquitoes. The
mosquito starts randomly from the left side of the screen
and moves towards the right.
• If the bat hits the mosquito, the score increases by 1. If the
mosquito is not hit, the number of lives which begins at 3
will decrease by 1.
• The game ends when 5 mosquitoes are killed or the
number of lives equals 0.
120. X
Game title: Prevent Dengue
THINK about what is needed
1. Refer to the flowchart to program the game.
2.
Plan the code for the background such that it switches to different
scenes depending on the different situations. The three scenes are start
of the game, end of the game when 5 mosquitoes are killed, and end of
the game when number of lives is zero.
3.
Plan the code for the bat such that it can only move up and down within
the screen; and it will swing back and forth when the space key is
pressed (to simulate hitting the mosquito).
4.
Plan the code for the mosquito such that it
a)
b)
c)
appears randomly at the left side of the screen;
moves from left to right; and
tracks the number of mosquitoes and number of lives.
121. X
Game title: Prevent Dengue
ENGAGE in coding
1. Open a new file and use all the images provided.
2. Create the code for the background and the bat as
planned.
3. Save the file as mosquito_<your name>.
4. Create the code for the mosquito as planned.
5. Save your work.
122. X
Game title: Prevent Dengue
SUBMIT your code through LMS.
Name your file as “dengue_your_name”
REFINE your code (Challenge)
- You may choose not to attempt this section.
- Add one or two more mosquitos to your
game.