StarLogoTNG 101

StarLogoTNG 101
Treasure Hunt Game Unit
Lesson 5: Moving Enemies
Today’s Agenda
•
•
•
•
Review and share ideas
Mini-lesson on new programming blocks
Implement moving enemies
Wrap-up
Review
• Add a keyboard control so that if you press the “L”
key, your player makes the “laugh” sound.
• Define a procedure in the treasure section called
“announce if blue” that makes the agent say “I’m
blue!” if the agent is blue. Have the treasure agents
call the procedure in the Forever block.
• In the collision block between player and treasure,
add an IF statement that checks if the treasure is
blue. If it is blue, player gets an extra 100 points.
Moving Enemies
• Another way of making the treasure hunt
game more interesting and challenging is to
implement moving “enemies.”
• These enemies can do any number of things
to make game play difficult for the player, but
today, we’ll program their movement.
• Brainstorm: What do you want to happen to
the player and the enemy when they collide?
New block: Random
• Found in the Math drawer
• Takes a number argument
• Returns a random value
between 1 and the number
argument
• For example, random 10
returns a value between 1
and 10
Random block exercise
•
What will happen when each of the following
uses of the random block is executed?
New block: Say
• Found in the Text drawer
• Takes a text argument
• Text includes letters, punctuation
marks, and numbers displayed as
characters
• When executed, a speech bubble pops
up above the agent that shows the
text argument
• How did the say instruction help you
figure out the obstacle course game?
What are some creative ways you can
use it in your treasure hunt game?
Treasure Game v.2
• Open “treasure game your initials.sltng”
• Save next version
• About the treasure game
– Setup: creates 1 player agent; creates treasure agent
and non-moving hazards agents; creates moving
“enemy” agents
– Run (forever): agents of player breed call a keyboard
controls procedure; agents of “enemy” breed calls a
“enemy movement” procedure
Guided Programming
• Create a new breed called “moving enemy” and select a shape
for it.
• In the setup block, create 10 moving enemy agents and scatter
them.
• Create a procedure called “Enemy movement” and just put one
instruction “forward 1” for now.
• Call the procedure in the “moving enemy” section of the run
block.
• Click setup in the runtime window. Before you click run, what do
you think will happen when you click run? How will the enemy
agents move? Now click run.
• Questions: What happens when the moving enemy agents hit
the edge of the board? Is it hard or easy to avoid the enemy
agent?
Programming Activity
• Program different movement instructions in
the “enemy movement” procedure and see
what happens. (Hint: Try using random)
• Implement collision results between the
moving enemy and the player.
• What can you do with a collision between an
enemy agent and another enemy agent? Be
creative!
Wrap Up
• What variations of movement did you try in the
Enemy Movement procedure?
• 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?