2 - MIT

StarLogoTNG 101
Treasure Hunt Game Unit
Lesson 2: Keyboard Controls
Today’s Agenda
•
•
•
•
Review
Mini-lesson on new programming blocks
Obstacle course programming challenge
Wrap-up
Review
• What do you predict will be the agent’s
movement when it executes the
following block?
• What about this stack of blocks?
Review
•
•
•
•
File menu > Open project “movement review.sltng”
File menu > Save next version
5 minute programming challenge!
Create the tallest stack of movement blocks that does
not change the position or direction of the agent.
• Rule: You may not use the same pink argument block
more than once.
• Hint: You may test your stack as many times as you
want during the 5 minutes.
Programming Tip
Another way to delete
a block is to drag and
drop it anywhere in
the palette
Player Controls
• Have you seen or played Nintendo Wii?
• Why do people like it? What’s special about it?
• All computer games involve some kind of player
control. Besides the Wii remote, what are other
devices used by players to control the character
or action in a game?
• Today, we will implement keyboard controls to
move an agent around spaceland.
New Block: If / then
• Found in the “Logic” drawer
• First part (“test condition”) must evaluate to true or
false
• If test condition is true, the blocks in the “then”
section is executed. If false, ignore the “then” section.
• Example: see first program
Exercise: If / then block
• What do you think these IF blocks will do
when executed by an agent? Explain your
thinking.
New Blocks: Keyboard detect
• Found in the “Controls”
drawer.
• Question mark means that
the blocks tests if that
particular key is pressed –
evaluates to true or false.
• Click on down arrow on the
right side of the block to
select a different keyboard
key to test.
Obstacles
WATCH THE TEACHER DEMONSTRATE THE
FOLLOWING STEPS FIRST.
• File menu > Open project “obstacles.sltng”.
• File menu > Save next version
• About obstacles project:
– Terrain: maze / obstacle course
– Setup: creates 1 player agent that starts in a corner of the
board; also creates “treasure” blocks and other agents that
are obstacles (you’ll find out)
– Run: nothing happens yet
– Game ends when the player collects all the treasure.
Programming Activity 1
WATCH THE TEACHER DEMONSTRATE THE
FOLLOWING STEPS FIRST.
• Program instructions to control the agent’s movement from
the agent’s point of view:
–
–
–
–
Up arrow key = move forward
Left arrow key = turn left
Right arrow key = turn right
Down arrow key = move backward
• Click on Run in the Runtime window to test out the
controls. What happens when the player agent walks on
different kinds of terrain (dips, hills, platforms)?
• Try out different values for the arguments (# of steps and
degrees) and see what happens.
Programming Activity 2
• Objective: collect all treasure in the
obstacle course
• Program additional keyboard controls to
get past obstacles.
• Consult the reference guide for
descriptions of NEW blocks that could
be useful.
Wrap Up
• What strategies and new blocks did you try to
get past the obstacles?
• What worked? What didn’t work?
• What challenges did you have?
• What was fun?
• What questions do you have?