Skills – Programming a Shooter

Game Design
Programming a Shooter
www.computerscienceuk.com
Starter
• On your whiteboards write down an
example script block to get a sprite
moving right when the right arrow is
pressed.
www.computerscienceuk.com
Learning Objectives
• Learning Objectives
– To understand how to use variables to record the direction of the
character
– To understand how to program the firing of a bullet from your main
character.
• Success Criteria
– To develop the platform game (started last week) so that the
character can fire a bullet left and right.
Literacy – Key Words
Variable
‘Storage box’ used in programming to store data
Sprite
Programmable objects in Scratch
Scripts
Blocks of programming code in Scratch
www.computerscienceuk.com
Hands up if you know how to
program a shooter in Scratch?
www.computerscienceuk.com
What needs to happen to create
a shooter? Planning
1. We need a main character
2. We need an object to fire
3. We need out object to follow (attach
to) the main character
4. When the cat is facing right, we want
the object to move to the right when
we press space
5. When the cat is facing left, we want
the object to move to the left when
we press space
www.computerscienceuk.com
How can we record if the
character is facing right of left?
Answer:
We can use a variable which can be set to:
0 when the left arrow key is pressed
1 when the right arrow key is pressed
www.computerscienceuk.com
1
1. Use a variable to record which way
the main sprite is facing
2
3
www.computerscienceuk.com
Whiteboard Practice
• Write the script to move the sprite left
when the left arrow is pressed. The script
must also set a variable to 0 (so that the
direction can be recorded)
www.computerscienceuk.com
Whiteboard Practice…again
• Write the script to move the sprite right
when the right arrow is pressed. The
script must also set a variable to 1 (so
that the direction can be recorded)
www.computerscienceuk.com
How is this done?
www.computerscienceuk.com
2. Program the shooter (object firing)
After we press the green flag
We check if the space is pressed
If it is and the direction is left (0), the
bullet points to the left (-90), it is
shown and it moves 10 steps.
This is repeated until the bullet hits
the edge of the stage.
If the space is pressed and the
direction is right (1), the bullet points
to the right (90), it is shown and it
moves 10 steps.
This is repeated until the bullet hits
the edge of the stage.
If however, the space is not pressed,
the bullet hides and stays
permanently with the main
character.
www.computerscienceuk.com
Hands up if you know how to
program a shooter in Scratch?
www.computerscienceuk.com
Write down
on your
whiteboard,
in your own
words, how
this script
works
3 minutes
www.computerscienceuk.com
2. Program the shooter (object firing)
After we press the green flag
We check if the space is pressed
If it is and the direction is left (0), the
bullet points to the left (-90), it is
shown and it moves 10 steps.
This is repeated until the bullet hits
the edge of the stage.
If the space is pressed and the
direction is right (1), the bullet points
to the right (90), it is shown and it
moves 10 steps.
This is repeated until the bullet hits
the edge of the stage.
If however, the space is not pressed,
the bullet hides and stays
permanently with the main
character.
www.computerscienceuk.com
Programming Task 1 and 2
Open the Lesson Task Sheet and complete the tasks
1. Open your semi completed game from last week (a sprite that jumps
from platform to platform).
2. Create a variable (call it direction) and adapt your movement scripts
so that direction = 0 when the left arrow is pressed and direction = 1
if the right arrow is pressed. Then print screen your script and explain
how it works in the worksheet.
3. Create a bullet sprite.
4. Add a script to your bullet sprite so that it follows the main character
(hidden) and fires in the correct direction when a key of your choice
is pressed. Then print screen your script and explain how it works in
the worksheet.
Use this presentation for support if you require it.
’20 Minutes’
www.computerscienceuk.com
Assessment Criteria
Level
Programming Skills
•
7
6
5
4
•
•
•
•
•
•
•
•
I fully understand how the script programs the shooter and my
explanations are detailed and clearly show my
understanding.
I can create the correct script blocks without help.
I can see how other objects can be programmed in a similar
way.
I understand how the scripts programs the shooter and my
explanations are detailed and clearly show my
understanding.
I can create the correct script blocks without help.
I generally understand how the scripts create the shooter but
my explanation is brief and not that clear.
I can create the correct script blocks but do need a little help
from the help guides.
I don’t fully understand how the scripts program the shooter.
I struggle to make the correct script blocks to program the
shooter.
www.computerscienceuk.com