Dodgeball on the Moon - Junior Achievement USA

Coding
Dodgeball on the Moon
0
revised 1/17/17
Create your own computer game!



You are going to creat a real computer program for a game.
You are using “event driven” programming.
You must tell the computer everything you want it to do, and your instructions must be exact.
Design your game

Before you begin a game, plan the following:
o The game’s charecters
o Where are they
o The objective of the game (score, beat the clock, get through a maze, etc)
o How to do you control action (arrow keys, mouse, etc.)
This game design is: Dodgeball on the moon



Scratchy the cat is the character
Scratchy eats fruit bowls for energy and to win the game. When scratchy eats 5 fruit baskets game is over. You Win!
Scratchy has to not get hit by dodgeballs. Every time scratchy is hit, the cat loses energy. When energy goes to zero game is over. You Lose!
Let’s Begin!
Open Internet Browser
Go To: Scratch.mit.edu
1
revised 1/17/17
1.
2
Click on “create”.
revised 1/17/17
1. Click on landscape icon to
select background
Drag components into this work
space
3
revised 1/17/17
2. Click on moon
1. Click on space to get
background options
Drag components into
this work space
Drag components into
this work space
4
revised 1/17/17
Events
Drag
compon
ents
into this
work
space
Looks
Drag
compon
ents
into this
work
space
1. Click on Cat
sprite to begin
coding
5 Drag components
into this work
2. From “Events” drag
“When green flag clicked”
3. From “Looks” drag “Show”
4. Connect the two
2. Click on Scripts
Drag components
into this work space
revised 1/17/17
Motion
Drag
compon
ents
into this
work
space
Data
Drag
compon
ents
into this
work
space
Create a new variable
Drag components
into this work space
1. From “Motion” select “go to x” and
drag under “show”. Leave “x” and “y”
at “0”
2. From “Data” select “Make a variable”
name it “energy”. Click “Ok”
3. From “Data” select “Make a variable”
name it “score”. Click “ok”.
6
revised 1/17/17
Change “score” to
“energy” by clicking
on small black
triangle.
7
Change “0” to be
“100” for
“energy”.
1. From “Data” select “set score” and drag
under “go to x”.
2. From “Data” select another “set score”
and drag under “set score”.
3. Change first “set score” to “energy” by
clicking on small black triangle and
changing name to “energy”
4. On “energy” change the “O” to be “100”.
5. From “looks” select and drag “set size to”.
6. Change value to “60%”
revised 1/17/17
1. From “Control” select and drag “if then”
block.
2. From “Sensing” select and drag “key space
pressed” and drag it into open space in “If
then”.
Right click on orange “if then” box to
get drop down to select “duplicate”.
With Mac hold down “control” and
click mouse to select duplicate.
8
3. Now right click on “if then” box and select
duplicate.
4. Do this so that you have 4 if then boxes in
total.
revised 1/17/17
1. In the key pressed module, set first one
to “right arrow” second one to “left
arrow”, third one to “up arrow”, and
fourth one to “down arrow” by clicking
on the triangle in the box.
2. From “Motion” select and drag “Change
X By” and drag it into open space in “If
then”. Do this for the first two “If then”.
3. From “Motion” select and drag “Change
Y By” and drag it into open space in “If
then”. Do this for the 3rd and 4th “If
then”.
4. Change the value in the 2nd and 4th from
“10” to “-10”
9
revised 1/17/17
Let’s test code.
1. Click on the green flag. This
launches the program.
2. Use arrow keys to move cat
around. Try all four arrows.
3. Press Red Stop sign to stop
program.
10
1. From “Looks” select and drag “Next
Costume” and drag it into open space in
“If then” below “change by”. Do this for
all 4 “if then”.
2. From “Control” select and drag “Forever”
and drag it so that it includes all 4 of the
“If then”.
revised 1/17/17
1. From “events” select and drag “when
green flag clicked” and drag it into open
space separate from first program.
2. From “Control” select and drag “if then”
and drag below “when clicked”.
3. From “Operators” select and drag the
“box = box” diagram and drag into the if
space at top.
4. From “Data” select and drag “Score” and
drag below “when clicked”.
5. Add “5” to the right box in the if then
field. (this is winning score)
6. From “looks” select “Say Hello for 2
seconds”.
7. Change “hello” to “You Win!” in say hello
block.
8. From “controls” select and drag “Stop
all” below “you win”
11
revised 1/17/17
5.
6.
7.
8.
From “looks” select “Show” and drag into “if then loop”.
From “looks” select “say hello” and drag below “show”
Change “hello” to “Game Over!”
From “controls” select and drag “Stop all” below “Game
Over”
9. From “controls” select forever loop and place it around the
two “if then” loops.
12
1. From “Controls” select and drag “if
then” and drag below “when clicked”.
2. From “Operators” select and drag the
“box < box” (less than) diagram and
drag into the if space at top.
3. From “Data” select and drag “energy”
and drag below “when clicked”.
4. Add “1” to the right box in the if then
field. (this will mean you are out of
energy)
revised 1/17/17
1.
Next select new sprite by
clicking on symbol located
beside “New Sprite”. Select
sports theme.
Drag components into this work
space
13
revised 1/17/17
1.
Click on “sports” theme.
2.
14
Click on “ball”.
Then click “ok”.
revised 1/17/17
Click on Ball sprite
15
1. Click on the “Ball” sprite.
2. From “events” select and drag “when green
flag clicked” and drag it into open space.
3. From “looks” select and drag “hide” and drag
it into open space.
4. From “controls” select and drag “Wait”.
5. Change value to “7” seconds.
6. From “control” select and drag “Repeat”.
7. Change value to “5”.
8. From “control” select and drag “create clone
of myself” and place in repeat loop.
9. From “control” select and drag a “Wait”.
10. Change value to “5” seconds.
11. From “looks” select and drag “next costume”
and place under “wait”.
revised 1/17/17
1. From “control” select and drag “when I start as a clone” and drag it into
open space.
2. From “motion” select and drag “go to x”.
3. From “operators” select and drag “pick random” and place in “x” and then
select another “pick random” and place in “Y”
4. Change value to “-240” and “240” for “X”.
5. Change value to “-180” and “180” for “Y”.
6. From “motion” select and drag “point in direction”.
7. From “operator” select and drag “pick random” and place in “point in
direction”.
8. Change value to “-170” and “170”.
9. From “looks” select and drag “show”.
10. From “looks” select and drag “set size to”.
16
revised 1/17/17
Let’s test code.
1. Click on the green flag. This
launches the program.
2. Use arrow keys to move cat
around. Try to get scratchy to
hit dodgeballs.
3. Watch energy score go down.
17
1. From “motion” select and drag “move 10 steps” and drag it into
open space.
2. From “motion” select and drag “if on edge, bounce”.
3. From “control” select and drag “if then” loop.
4. From “sensing” select and drag “touching” and place in the “if
then” look top space.
5. Change value in “touching” to “sprite”.
6. From “data” select and drag “change score by”.
7. Change value to “energy”.
8. Change by value to “-1”.
9. From “control” select and drag “forever” loop above “move 10
steps to below “if loop”.
revised 1/17/17
1. Next select new sprite by
clicking on symbol located
beside “New Sprite”.
2. Click on “things” theme. Then
scroll down to “fruit salad”.
3. Click on “fruit salad”. Then
click ok.
18
revised 1/17/17
16. From “looks” select and drag “hide”
17. From “motion” select and drag “go to x y”.
18. From “operator” select and drag “pick random” and place in
“x” and then another for “y”.
19. Change values for “x” to “-200” and “200”.
20. Change values for “y” to “-150” and “150”.
21. From “control” select and drag “wait”.
22. Change value to “3” seconds.
23. From “control” select and drag a “forever” loop. Start
above “Show” and down to bottom.
19
1. Click on the “Fruit Bowl” sprite.
2. From “events” select and drag “when green flag clicked” and
drag it into open space.
3. From “looks” select and drag “hide” and drag it into open
space.
4. From “looks” select and drag “set size”.
5. Change value to “75%”.
6. From “motion” select and drag “go to x y”.
7. From “operator” select and drag “pick random” and place in
“x” and then another for “y”.
8. Change values for “x” to “-200” and “200”.
9. Change values for “y” to “-150” and “150”.
10. From “control” select and drag “wait”.
11. Change value to “7” seconds.
12. From “looks” select and drag “show”.
13. From “sound” select and drag “play sound pop”.
14. From “control” select and drag a “wait”.
15. Change value to “4” seconds.
revised 1/17/17
1. From “Events” drag
“When green flag clicked” and
drag into open space.
2. From “control” select and drag
“wait until”.
3. From “sensing” select and drag
“touching”
4. Change value to “sprite”.
5. From “looks” select and drag
“hide”.
6. From “data” drag out 2 “change
score by” blocks.
7. Change value in first “change
score” to “energy” and value to
“10”.
8. From “events” select and drop
“broadcast messge1”.
9. From “control” select and drop
“forever” loop beginning below
“when green flag checked” and
to bottom.
20
revised 1/17/17
1. Click on “cat” sprite.
2. From “events” select and drag
“when I receive message1”
place in an open space.
3. From “sounds” select and drag
“play sound meow”
4. Click on “display of score” in
upper left and drag it to the
upper right.
5. Click on “Save” to save your
work.
Let’s test code.
Move the “score” by
clicking on it and
dragging.
21
1. Click on the green flag. This
launches the program.
2. Use arrow keys to move cat
around. Try to get scratchy to
hit dodgeballs.
3. Watch energy score go down.
4. Grab Fruit Bowl for extra
energy.
revised 1/17/17
Extended Lesson
You can add some Comments at the beginning of the game to explain to players how the game works. Just slide down code and add these instructions.
1. Go back into Cat Sprite and split
code after “Set” then insert
these.
2. From “Looks” select and drag 3
“say Hello” options.
3. From “Looks” select and drag
“set size”.
4. Change “set size” to “60%”
5. In the first “Say Hello” change
time to “1” second”
6. In the second “Say Hello”
change “Hello” to say “Eat the
fruit to score and don’t get hit
by the dodge ball” and change
time to “3” seconds”
7. In the third “Say Hello” change
“Hello” to say “Use the arrow
keys to control scratchy. Eat 5
fruits to win” and change time
to “3” seconds”
8. Reconnect the string of code.
22
revised 1/17/17
1. Type in a User
name. (Don’t use
your real name)
2. Choose a password
3. Confirm password
4. Write down user
and password on
paper provided
5. Click “next”
1. Answer three
questions
2. Click “next”
3. Then save game.
23
revised 1/17/17
Program developed by Thomas Hachten
www. Coderkids.net
24
revised 1/17/17