starlogotng 101 treasure hunt game unit lesson 4: forever and procedures

16
StarLogoTNG 101 Treasure Hunt Game Unit Lesson 4: Forever and Procedures

Upload: myron-ryan

Post on 16-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: StarLogoTNG 101 Treasure Hunt Game Unit Lesson 4: Forever and Procedures

StarLogoTNG 101

Treasure Hunt Game UnitLesson 4: Forever and Procedures

Page 2: StarLogoTNG 101 Treasure Hunt Game Unit Lesson 4: Forever and Procedures

Today’s Agenda

• Review• Mini-lesson on new programming blocks• Create v1 of treasure hunt game• Wrap-up

Page 3: StarLogoTNG 101 Treasure Hunt Game Unit Lesson 4: Forever and Procedures

Review

• What is the purpose of the Setup block? What blocks typically go in the Setup block?

• If you don’t put a “scatter” block, where are the agents placed when you create them?

• Program a collision block between turtle and treasure agents so that the treasure moves up into the air 1 step and change its color to purple.

Page 4: StarLogoTNG 101 Treasure Hunt Game Unit Lesson 4: Forever and Procedures

Programming Tip

Use the canvas sections to keep your program

organized

Page 5: StarLogoTNG 101 Treasure Hunt Game Unit Lesson 4: Forever and Procedures

Programming Tip

Use the mini-map on the upper right corner of the canvas to quickly navigate to different sections of

your program.

Page 6: StarLogoTNG 101 Treasure Hunt Game Unit Lesson 4: Forever and Procedures

Treasure Game v.1

• File menu > Open Project > “treasure game”• Save as “treasure game your initials.sltng”• About the treasure game

– Setup: creates 1 player agent; creates treasure agents and non-moving hazards agents

– Run (forever): player agent(s) calls a procedure that executes movement when the player presses various keyboard keys to control the player agent from 1st person point of view

– Collisions: between player and treasure and hazard agents

Page 7: StarLogoTNG 101 Treasure Hunt Game Unit Lesson 4: Forever and Procedures

Guided Programming 1: Setup

• Breed Editor:– Rename turtle breed to “player” (or your choice) and

select a new character– Make new breed called “treasure” (or your choice)– Make new breed called “hazard” (or your choice)

• Drag setup block to setup section of canvas– Attach “clear everyone” block– Create 1 player agent– Create treasure and hazard agents and randomly scatter

them

• Click on setup in runtime window to check that the setup does what you want.

Page 8: StarLogoTNG 101 Treasure Hunt Game Unit Lesson 4: Forever and Procedures

New Block: Forever

• Found in the “Setup and Run” drawer

• Repeats instructions placed in this block over and over again, in order from top to bottom, and then starts at the top again.

• Each breed has its own section.

• Turn on/off by clicking on the green arrow

• Can also run from runtime window

Page 9: StarLogoTNG 101 Treasure Hunt Game Unit Lesson 4: Forever and Procedures

Guided Programming 2: Forever

• Drag a Forever block to the runtime section of canvas.

• Rename the Forever block “Run.”• Attach the If/then keyboard controls stack to

the Player section of the Run block.• Turn on the Run block and test the keyboard

controls.• What would happen if you move the Keyboard

Controls stack to the treasure section?

Page 10: StarLogoTNG 101 Treasure Hunt Game Unit Lesson 4: Forever and Procedures

About Procedures

• Recall the cake making analogy: procedures are like those sub-tasks (make the batter, bake the cake, decorate the cake)

• Procedures make programs easier to build and to understand.

Make a cake

Make the batter

Bake the cake

Decorate the cake

Page 11: StarLogoTNG 101 Treasure Hunt Game Unit Lesson 4: Forever and Procedures

New Block: Procedure

Guided Programming 3: Make a procedure of the keyboard movement controls that are currently in the player section of the run block. Replace those instructions with a call to the procedure.

To make (or “define”) a procedure:• Position your canvas in the Player

section.• Drag a green “procedure” block

from the “Procedure” drawer.• Rename the procedure “keyboard

controls.”• Drag the if/then blocks and

connect them to the procedure block.

Page 12: StarLogoTNG 101 Treasure Hunt Game Unit Lesson 4: Forever and Procedures

New Block: Procedure

• To “call” a procedure is to use a block with the procedure’s name; the procedure’s instructions are executed in the place where it’s called.

• Each breed and programming section has its own procedures (found in “my blocks” palette).

To call the “keyboard controls” procedure:• Go to the “my blocks” palette and

open the “Player” drawer. • Find the procedure that’s labeled

“keyboard controls” and drag it to the empty player section of the run block.

• Start the run block to make sure that the keyboard controls are working properly.

Page 13: StarLogoTNG 101 Treasure Hunt Game Unit Lesson 4: Forever and Procedures

New Blocks: Score

• Score is a variable. This means that it represents a number that can change.

• You can change the value of score using set score, found in the “Setup and Run” palette.

• Set score takes either a single number or a mathematical expression that is evaluated to a single number.

• For example, if you want to increase the score, you can drag out the addition block from the “Math” palette.

• The pink score block represents the current value of score. Drop that in the left side of the expression. Drag a pink number block on the right side of the expression and change the number to the amount you want the score to increase.

• You can also change the sign of the math expression block by clicking on the down arrow next to the operator symbol.

• Think: What are some ways to use score in your treasure game? When should the score be changed?

Page 14: StarLogoTNG 101 Treasure Hunt Game Unit Lesson 4: Forever and Procedures

New Blocks: Score

• A simpler way of increasing or decreasing the score is to use “inc score” and “dec score”

• So instead of “set score (score + 5)”, you can just use “inc score 5”

• Similarly, instead of “set score (score – 5)”, you can just use “dec score 5”

Page 15: StarLogoTNG 101 Treasure Hunt Game Unit Lesson 4: Forever and Procedures

Programming Activities

• Implement collision results between the treasure and hazard agents and the player.

• Implement score-keeping. (Hint: don’t forget to attach the “show score” and “set score 0” blocks in the setup block!)

• Explore different starting conditions. (Hint: you can have more than 1 setup block)

Page 16: StarLogoTNG 101 Treasure Hunt Game Unit Lesson 4: Forever and Procedures

Wrap Up

• What collision results did you try?• What worked? What didn’t work?• What challenges did you have?• What was fun?• What questions do you have?• What new game ideas do you have?