StarLogo Nova Activity: Paintball

Transcription

StarLogo Nova Activity: Paintball
Last Updated: 7/17/14
StarLogo Nova Activity: Paintball
You will create a game where the user controls a Player agent using keyboard keys to move and launch
paintballs of varying colors at stationary Turtle agents.
Prerequisites:






Navigate to profile
Create project
Rename project
Create agents
Give agents different traits (e.g. color/shape)
Create a breed
Learning Objectives:






Use keyboard controls to move an agent
Use conditional blocks in the context of keyboard controls
Explain how “if___ “ blocks work in the context of keyboard controls
Demonstrate how one agent can create another
Demonstrate how to view the world in the agent’s perspective
Differentiate between “Key typed” and “Key held” blocks
New Terms:

Collidee
New Blocks:




if___
key held?
take camera
Comparison blocks (>, <, =, etc.)
Read the description of each part and see if you can figure out how to put the blocks together. Then
check your solution. Test your program often to make sure that each chunk of code you add works
before moving on to the next part.
By: MIT Scheller Teacher Education Program. This work is licensed under a Creative Commons Attribution 4.0 License, which allows anyone to
re-distribute, re-use, and modify, on the condition that the creator is appropriately credited.
1
Last Updated: 7/17/14
PAGE INTENTIONALLY LEFT BLANK
By: MIT Scheller Teacher Education Program. This work is licensed under a Creative Commons Attribution 4.0 License, which allows anyone to
re-distribute, re-use, and modify, on the condition that the creator is appropriately credited.
2
Last Updated: 7/17/14
Part 1: Create Turtle agents.
Take a look at these skill cards for more information:

Agent Traits (2)
Steps



Create a new blank project and rename the project title to "Paintball (Your Username)".
On The World page, use a "When ___ pushed" block to create 50 Turtle agents and set the color
(ex: brown) and shape (ex: Cube), then scatter.
Do not forget to do some basic housekeeping by deleting all agents before creating the 50 new
agents.
Check your progress


Click the "Run Code" and "setup" buttons
You should see 50 scattered Turtle agents with the color and shape that you chose.
By: MIT Scheller Teacher Education Program. This work is licensed under a Creative Commons Attribution 4.0 License, which allows anyone to
re-distribute, re-use, and modify, on the condition that the creator is appropriately credited.
3
Last Updated: 7/17/14
Solution
By: MIT Scheller Teacher Education Program. This work is licensed under a Creative Commons Attribution 4.0 License, which allows anyone to
re-distribute, re-use, and modify, on the condition that the creator is appropriately credited.
4
Last Updated: 7/17/14
Part 2: Create Player breed and Player agent.
Take a look at these skill card(s) for more information:




Breeds (3)
Agent Traits (2)
Camera View (8)
Custom Shapes (16) (note that the URL is incorrect; use shapes in the drop-down menu)
Steps


Click on Edit Breeds and Add Breed. Name the new breed "Player” and click OK.
On The World page, add to the existing “When___ pushed” block to create 1 Player agent. Set
its color and shape, then have the Player agent take the camera, which places the camera
behind the shoulder of the Player agent.
Check your progress


Click the "Run Code" and "setup" buttons
You should see the SpaceLand from the perspective of your player agent.
By: MIT Scheller Teacher Education Program. This work is licensed under a Creative Commons Attribution 4.0 License, which allows anyone to
re-distribute, re-use, and modify, on the condition that the creator is appropriately credited.
5
Last Updated: 7/17/14
Solution
---->
---->
By: MIT Scheller Teacher Education Program. This work is licensed under a Creative Commons Attribution 4.0 License, which allows anyone to
re-distribute, re-use, and modify, on the condition that the creator is appropriately credited.
6
Last Updated: 7/17/14
Part 3: Program the Player agent to move in response to holding
down the arrow keys.
Take a look at these skill card(s) for more information:


Keyboard Controls (4)
Buttons (14)
Steps

On the Player page, drag out a "While___ toggled" block and use a series of "If___ " blocks to
match the arrow keys to their corresponding movement:
o Up arrow moves Forward 1
o Down arrow moves Backwards 1
o Right arrow turns right 10 degrees
o Left arrow turns left 10 degrees
More info:


The "If___ " block assigns one or more actions to happen only when the condition (in this case, a
key held) is true.
Save time by using cut and paste for similar pieces of code. Make sure that you drag a rectangle
around all the blocks you want to copy. You can also use Ctrl+c and Ctrl+v (or Cmd+c and Cmd+v
on Macs; note that this function is not available on Chrome in Macs) keyboard shortcuts.
Check your progress


Click the "Run Code" and "setup" and “forever” buttons.
You should be able to use the Keyboard arrow keys to move your Player agent around
SpaceLand.
By: MIT Scheller Teacher Education Program. This work is licensed under a Creative Commons Attribution 4.0 License, which allows anyone to
re-distribute, re-use, and modify, on the condition that the creator is appropriately credited.
7
Last Updated: 7/17/14
Solution
By: MIT Scheller Teacher Education Program. This work is licensed under a Creative Commons Attribution 4.0 License, which allows anyone to
re-distribute, re-use, and modify, on the condition that the creator is appropriately credited.
8
Last Updated: 7/17/14
Part 4: Create a Paintball breed and Program the Player agent to
launch paintball agents
Take a look at these skill card(s) for more information:



Breeds (3)
Keyboard Controls (4)
Agent Traits (2)
Steps


Use Edit Breeds to add a new breed called “Paintball”.
o Make sure that a Paintball tab appears in the Workspace
Navigate to the “Player” page and add a new "If___" block under the existing "If___" blocks that
map the arrow keys to movement.
o If spacebar is held down, create a new Paintball agent and have the new Paintball set its
size to 0.5, its shape to “Sphere” and its color to a random color.
Check your progress


Click the "Run Code", "setup" and "forever" buttons. Then press the spacebar.
When you press the spacebar, a paintball should appear.
By: MIT Scheller Teacher Education Program. This work is licensed under a Creative Commons Attribution 4.0 License, which allows anyone to
re-distribute, re-use, and modify, on the condition that the creator is appropriately credited.
9
Last Updated: 7/17/14
Solution
---->
---->
By: MIT Scheller Teacher Education Program. This work is licensed under a Creative Commons Attribution 4.0 License, which allows anyone to
re-distribute, re-use, and modify, on the condition that the creator is appropriately credited.
10
Last Updated: 7/17/14
Part 5: Program the Paintball agents to fly straight.
Take a look at these skill card(s) for more information:

Buttons (14)
Steps:

On Paintball page, use a “while___ toggled” block to program the paintballs to continually go
forward 1.
Check your progress


Click the "Run Code", "setup" and "forever" buttons. Then press the spacebar.
When you press the spacebar, a paintball should appear and should move forward continuously.
By: MIT Scheller Teacher Education Program. This work is licensed under a Creative Commons Attribution 4.0 License, which allows anyone to
re-distribute, re-use, and modify, on the condition that the creator is appropriately credited.
11
Last Updated: 7/17/14
Solution
By: MIT Scheller Teacher Education Program. This work is licensed under a Creative Commons Attribution 4.0 License, which allows anyone to
re-distribute, re-use, and modify, on the condition that the creator is appropriately credited.
12
Last Updated: 7/17/14
Part 6: Program the Paintball agents to delete when they reach the
edge of the world.
Tip: The SpaceLand is a coordinate grid with x going from -50 to 50 and y going from -50 to 50 and (0,0)
at its center.
Take a look at these skill card(s) for more information:

Agent Traits (2)
Steps:

Use "If ___" blocks to program the Paintballs to check their x and y traits to see if they have
reached the edge. If so, then delete the Paintball agent.
o Agents bounce when they reach edge, so they might never land exactly at 50. Try testing
for x > 48 or x > 49 instead of x = 50.
Check your progress


Click the "Run Code", "setup" and "forever" buttons. Then press the spacebar.
When a paintball reaches the edge of SpaceLand, it should disappear.
By: MIT Scheller Teacher Education Program. This work is licensed under a Creative Commons Attribution 4.0 License, which allows anyone to
re-distribute, re-use, and modify, on the condition that the creator is appropriately credited.
13
Last Updated: 7/17/14
Solution
By: MIT Scheller Teacher Education Program. This work is licensed under a Creative Commons Attribution 4.0 License, which allows anyone to
re-distribute, re-use, and modify, on the condition that the creator is appropriately credited.
14
Last Updated: 7/17/14
Part 7: Program Collision between Paintball and Turtle.
Take a look at these skill card(s) for more information:


Collision (19)
Agent Traits (2)
Steps:



Put a “on collision___ with___ do ” block on the Turtle page
The turtle will set its color to the color of the collidee (Paintball)
Then delete the collidee (paintball)
More info: The "collidee" block is in the Agents drawer. (In this case, the collidee is the Paintball.)
Check your progress:


Click the "Run Code", "setup" and "forever" buttons. Use keyboard keys to move and press the
spacebar.
When a paintball hits a turtle agent, the turtle agent should turn its own color to the paintball’s
color and the paintball agent should be deleted.
By: MIT Scheller Teacher Education Program. This work is licensed under a Creative Commons Attribution 4.0 License, which allows anyone to
re-distribute, re-use, and modify, on the condition that the creator is appropriately credited.
15
Last Updated: 7/17/14
Solution
By: MIT Scheller Teacher Education Program. This work is licensed under a Creative Commons Attribution 4.0 License, which allows anyone to
re-distribute, re-use, and modify, on the condition that the creator is appropriately credited.
16
Last Updated: 7/17/14
Part 8: Exit Ticket
The purpose of the exit ticket is to check your understanding and review what you’ve learned during this
activity. There are two parts and you can do either one or both. One part consists of several
programming tasks. The other part consists of a few concept questions, which you discuss with a partner.
Programming tasks


You may want to REMIX (make a copy of) your project before you attempt these tasks so that
you are working from another copy of the project.
Complete each task. Try each task on your own first. You may ask clarifying questions or for
hints. Although it should be self-evident if you’re able to complete these tasks, feel free to ask a
facilitator to check your solutions.
When finished with the tasks, click Save.
Program the player to launch 3 paintballs each time.
Make the player move faster (hint: take more steps each
time).
Program a new keyboard control so that each time the user presses t, the player
creates 10 new turtles and scatters them. (Don't forget to set the turtles' shape.)
By: MIT Scheller Teacher Education Program. This work is licensed under a Creative Commons Attribution 4.0 License, which allows anyone to
re-distribute, re-use, and modify, on the condition that the creator is appropriately credited.
17
Last Updated: 7/17/14
Paintball Concept Questions
Concept Question #1
With your partner look at the following piece of code and answer the questions below.
a) Which of the agents will “take camera”? What are its colour and shape?
b) Why does this happen?
By: MIT Scheller Teacher Education Program. This work is licensed under a Creative Commons Attribution 4.0 License, which allows anyone to
re-distribute, re-use, and modify, on the condition that the creator is appropriately credited.
18
Last Updated: 7/17/14
Concept Question #2
With your partner look at the following piece of code and answer the questions below.
a) Predict what will happen when you run this code assuming you have already created a paintball
agent.
b) How would you change or where would you move this code in order to have the player be the
one controlled by the arrow keys and space bar?
By: MIT Scheller Teacher Education Program. This work is licensed under a Creative Commons Attribution 4.0 License, which allows anyone to
re-distribute, re-use, and modify, on the condition that the creator is appropriately credited.
19
Last Updated: 7/17/14
Concept Questions #3
With your partner look at the following piece of code and answer the questions below.
a) Make the following edits to your code and run it. How does the Main Character agent move
differently? Why is this happening?
b) How does this make the game hard to play?
c) When might it be better to use “key typed” versus “key held”?
By: MIT Scheller Teacher Education Program. This work is licensed under a Creative Commons Attribution 4.0 License, which allows anyone to
re-distribute, re-use, and modify, on the condition that the creator is appropriately credited.
20
Last Updated: 7/17/14
Part 9: Extensions
Come with up a question to investigate or just tinker with the existing program. Note that the
extensions tend to progress from easier tasks to harder tasks. Some of them also require you learn to
use new blocks that haven’t been introduced yet. You are also welcome to come up with your own
extensions and just explore/try things on your own.
Decide how much time you want to spend on these extensions. When you’re ready to move on to
another tutorial, consult the roadmap to decide which activity you want to do next.
1. Modify the appearance of your agents – try size, shape, and color
2. Try to explore the "Sounds" drawer and make your turtles say something when they're hit!
3. Use the score widget to keep track of your “number of hits”
4. Create a new breed of hazards that the player needs to avoid. If the player touches a hazard, the
player dies.
5. Program a new keyboard command to make the player jump. (hint: use “yield” in between up
and down to simulate jumping; “yield” is a block in the Logic drawer)
6. Limit the number of paintballs (hint: use a new data box widget to keep track of and display this
information)
7. Create a new breed of ammo boxes that your agent needs to pick up to get more paintballs
By: MIT Scheller Teacher Education Program. This work is licensed under a Creative Commons Attribution 4.0 License, which allows anyone to
re-distribute, re-use, and modify, on the condition that the creator is appropriately credited.
21