Skip to main content

Stage 4: Add Tasks to Collect

Course progressStage 4 of 10
~65 min
One game, one Trinket

Keep building in the workspace on the right.

This stage is part of the same Crewmate Task Dash project you started in Setup. Type each new code block into the Trinket rail and keep building on the last stage.

Build

task stations around the ship

Learn

how lists store several positions

Ship

collectible goals the player can visit

Before you start

Make sure you finished Stage 3: Move Through the Ship. Your Trinket project should already have arrow-key movement that respects the ship boundaries. Open the same file you used last stage and keep building from there.

The big idea

A task station is just a coordinate with a drawing. A list lets the game remember many task coordinates at once.

New words
list
a collection of values stored in order
tuple
a small grouped value like `(x, y)`
distance
how far apart two positions are
collectible
an object the player can pick up or complete
loop
a block of code that runs once for each item in a collection.
index
the position of an item in a list, starting at `0`.

Python concept

Trace it

Lists and tuples

What it means: A list stores many values. A tuple groups a few values that belong together, like one x/y position.

Tiny Python example:

colors = ["red", "blue", "green"]
point = (190, 120)

In this game: `tasks` is a list. Each task inside it is a tuple like `(-190, 120)`.

Why it matters: Games usually have many similar things: tasks, enemies, coins, rooms. Lists let one piece of code work with all of them.

Think first

Check: Lists and tuples

In `tasks = [(-190, 120), (190, 120)]`, which symbols show the list?

Check your thinking

The square brackets `[` and `]` show the list. The parentheses show each coordinate tuple.

Finished game target
Tasks 2/4Score 80
Crewmate playerTask stationShadow chaser

The player moves through the ship, collects tasks, and avoids the chaser. All playable shapes are drawn with Python Turtle code.

Build it

Think first

Unpack one task

If the task is `(190, 120)`, what values do `x` and `y` get in the loop?

Check your thinking

`x` gets `190`, and `y` gets `120`.

Your turn

Type, run, test

Read the code aloud before you run it. The goal is to understand what changed in the game.
Need a hint?

Add the new code to the same Trinket project. Keep previous stage code unless the stage says to replace a function.

Your turn

Step 1 - Store task coordinates in a list

The square brackets mean list. Each item inside is a tuple: one x value and one y value grouped together. Stuffing all four task positions into a single list means the drawing code can stay short no matter how many tasks you add later.

tasks = [(-190, 120), (190, 120), (-170, -120), (170, -120)]

You should see — nothing visible happens from this line alone. The list is just sitting in memory — `draw_tasks()` in Step 3 is what turns those numbers into glowing dots.

Need a hint?

Type and run one step at a time. If this step breaks, fix it before adding the next one.

Your turn

Step 2 - Loop through each task

`for x, y in tasks` unpacks each tuple. Python takes `(-190, 120)` and hands `x` the first number and `y` the second, then runs the loop body, then repeats for the next tuple. One pattern, four tasks.

You should see — no drawing yet — the loop is set up but the dot command is added in Step 3. When the loop does run, it visits the tasks in the order they appear in the list, which is the same order they will be drawn.

Your turn

Step 3 - Draw a dot at each coordinate

The task pen moves to each coordinate and draws a gold dot. One loop handles all task stations, so adding a fifth, sixth, or tenth task later is a single new tuple in the list with no other code change.

You should see — four gold task dots appear, one near each corner of the play area. Add `(0, 0)` to the list and a fifth dot appears at the center on the next run — that flexibility is the real payoff of using a list.

Active coding checkpoint

Your turn

Add a new task station

Add one task near the center of the room. Before running, predict where the new dot will appear.

tasks = [(-190, 120), (190, 120), (-170, -120), (170, -120), ________]
Need a hint?

Try this before opening the solution. Type the starter code, then fill in or fix the missing part yourself.

Stuck? Compare carefully
Answer check
Debug compare only

main.py

`(0, 0)` is the center of the Turtle screen, so the new task appears in the middle of the ship.

tasks = [(-190, 120), (190, 120), (-170, -120), (170, -120), (0, 0)]
Python code task
Full stage code

main.py

Use this as the stage target after you understand the smaller steps. Add it to your current Trinket file.

tasks = [(-190, 120), (190, 120), (-170, -120), (170, -120)]

def draw_tasks():
task_pen = turtle.Turtle()
task_pen.hideturtle()
task_pen.penup()
task_pen.color("gold")
for x, y in tasks:
task_pen.setposition(x, y)
task_pen.dot(24)

draw_tasks()
Trace it

Trace the idea

  1. Each task is an `(x, y)` pair.
  2. The loop visits every task coordinate.
  3. `dot(24)` draws a simple glowing station.

Understand it

Trace it

Why this code works

  • A list is useful when the game has many things that follow the same rule. All task stations are just coordinates, so one list fits.
  • A tuple is useful when two values belong together. A task x without its y is not a full position.
  • The loop is a promise: every coordinate in `tasks` gets the same drawing treatment.

If it breaks

Trace it

Troubleshooting wisdom

If Python prints a `SyntaxError` mentioning brackets or parentheses, the symbols are swapped or unbalanced. The outer `tasks = [ ... ]` uses square brackets because it is a list. Each coordinate inside uses parentheses because it is a tuple: `(-190, 120)`. Match them up character by character.

If only one task draws on screen, the `setposition` and `dot` calls are sitting outside the `for` loop. Indent both lines so they are inside the loop body — they should line up under the `for` line, not at the same level as it. Run again and all four dots should appear.

If a task dot is missing from the screen, its coordinate is probably past the room edge. Compare each `(x, y)` in `tasks` against your `LEFT`, `RIGHT`, `TOP`, and `BOTTOM` values. Anything outside those bounds is technically drawn but you can't see it.

Try this

Learning beat

Try this

Three short experiments. Predict before you run, then test your guess.

Predict first
Add `(0, 0)` to the list. Predict where the new task appears.
Compare
Move one task near a wall and one near the center. Which makes the route more interesting?
Connect
How is this list similar to a list of enemies or coins in another game?

Test your stage

  • Four task dots appear.
  • Task positions are stored in one list.
  • Changing a coordinate moves one station.