Dodgeball on the Moon

 Coding Dodgeball on the Moon 0 revised 10/17/16 1 revised 10/17/16 Let’s Begin! Open Internet Browser Go To: Scratch.mit.edu 2 revised 10/17/16 1.
Click on “create”.
3 revised 10/17/16 2. Click on moon 1. Click on space to get background options 4 revised 10/17/16 Events 1. From “Events” drag “When green flag clicked” 2. From “Looks” drag “Show” 3. Connect the two Looks 5 revised 10/17/16 Motion Data Create a new variable 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 10/17/16 Change “score” to “energy” by clicking on small black triangle.
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 “look” select and drag “set size to”. 6. Change value to “60%” Change “0” to be “100” for “energy”. 7 revised 10/17/16 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”. 3. Now right click on “if then” box and select duplicate. 4. Do this so that you have 4 if then boxes in total. With Mac hold down “control” and click mouse to select duplicate. 8 revised 10/17/16 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 10/17/16 Let’s test code. 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”. 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 revised 10/17/16 1. From “events” select and drag “when green flag clicked” and drag it into open space separate from first program. 2. From “Controls” 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”. 7. Change “hello” to “You Win!” in say hello block. 8. From “controls” select and drag “Stop all” below “say hello” 11 revised 10/17/16 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) 5.
6.
7.
8.
9.
12 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 “say hello” From “controls” select forever loop and place it around the two “if then” loops. revised 10/17/16 1. Next select new sprite by clicking on “New Sprite”. Select sports theme. 13 revised 10/17/16 1. Click on “sports” theme. 2. Click on “ball”. Then click “ok”. 14 revised 10/17/16 1. Click on the “Ball” sprite. 2. From “events 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”. Click on Ball sprite 15 revised 10/17/16 16 1. From “control” select and drag “when I start as a clone” and drag it into open space. 2. From “motion” select and drag “got to x”. 3. From “operator” 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. 8. Change value to “‐170” and “170”. 9. From “looks” select and drag “show”. 10. From “looks” select and drag “set size to”.
revised 10/17/16 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 “action” 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 “cat”. 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 10/17/16 1. Click on “things” theme. Then scroll down to “fruit salad”. 2. Click on “fruit salad”. Then click ok. 18 revised 10/17/16 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” drag “When green flag clicked” 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 10/17/16 1. From “Events” drag “When green flag clicked” and drag into open space. 2. From “control” select and drag “wait until”. 3. From “looks” select and drag “set size”. 4. From “sensing” select and drag “touching” 5. Change value to “cat”. 6. From “looks” select and drag “hide”. 7. From “data” drag out 2 “change score by” blocks. 8. Change value in first “change score” to “energy” and value to “10”. 9. From “events” select and drop “broadcast messge1”. 10. From “control” select and drop “forever” loop beginning below “when green flag checked” and to bottom. 20 revised 10/17/16 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. Move the “score” by clicking on it and dragging. 21 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. 4. Grab Fruit Bowl for extra energy. revised 10/17/16 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 10/17/16 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 10/17/16 Program developed by Thomas Hachten www. Coderkids.net 24 revised 10/17/16