1 / 16

StarLogoTNG 101

Learn how to create a treasure hunt game using programming blocks in StarLogoTNG. This lesson covers forever loops and procedures.

mcclaran
Download Presentation

StarLogoTNG 101

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Today’s Agenda • Review • Mini-lesson on new programming blocks • Create v1 of treasure hunt game • Wrap-up

  3. 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.

  4. Programming Tip Use the canvas sections to keep your program organized

  5. Programming Tip Use the mini-map on the upper right corner of the canvas to quickly navigate to different sections of your program.

  6. 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 movementwhen theplayer presses various keyboard keys to control the player agent from 1st person point of view • Collisions: between player and treasure and hazard agents

  7. 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.

  8. 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

  9. 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?

  10. 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.

  11. 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.

  12. 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.

  13. 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?

  14. 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”

  15. 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)

  16. 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?

More Related