Skip to main content

Stage 2: Draw the Crewmate

Course progressStage 2 of 10
~50 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

a player character drawn with Turtle code

Learn

how functions package drawing steps

Ship

a colorful crewmate-style player on the ship

Before you start

Make sure you finished Stage 1: Build the Ship Screen. Your Trinket project should already have your ship room with named LEFT, RIGHT, TOP, and BOTTOM boundary variables. Open the same file you used last stage and keep building from there.

The big idea

We are not importing a character. We are building one with code so students understand every shape on the screen.

New words
function
a named block of code you can run whenever you need it
stamp
a copy of the Turtle's current shape left on the screen
penup
move without drawing a line
parameter
a value you pass into a function

Python concept

Trace it

Functions

What it means: A function is a named recipe of steps. You define it once, then call it whenever you want those steps to run.

Tiny Python example:

def say_hello():
print("Hello")

say_hello()

In this game: `draw_crewmate()` is a function. It groups the stamping steps that draw the player.

Why it matters: Functions stop you from copying the same code again and again. They also give a chunk of code a clear job name.

Think first

Check: Functions

Which line creates the function: `def draw_crewmate():` or `draw_crewmate()`?

Check your thinking

`def draw_crewmate():` creates the function. `draw_crewmate()` calls it.

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

Why use a function?

Why is `draw_crewmate()` better than leaving all the stamp commands loose in the file?

Check your thinking

Because the same drawing can be run again after movement without copying the code.

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 - Create the player Turtle

`player` is one Turtle object. It has a position, a color, a size, and a shape. We call `penup()` right away because this Turtle is a character that moves around the screen, not a pencil that should draw a trail behind it.

player = turtle.Turtle()
player.penup()
player.speed(0)
player.color("tomato")
player.shape("circle")

You should see — no character appears yet. Creating the Turtle and setting its color is setup — the visible drawing happens in Step 3 when `draw_crewmate()` actually runs.

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 - Put drawing commands inside a function

A function lets us redraw the crewmate later after it moves. Without a function, we would have to copy the same stamp commands into every single arrow-key handler. Naming the recipe once means we can call it from anywhere.

You should see — defining a function does not run it. The screen still shows nothing until the last line of the file calls `draw_crewmate()` for the first time.

Your turn

Step 3 - Stamp body parts

`stamp()` leaves a copy of the Turtle's current shape on the screen. The same Turtle moves up, changes size and color, stamps the visor on top, then returns to the body position so the next call starts in the same spot.

You should see — a round tomato body with a light-cyan visor stamped above it. The Turtle ends up back at the body position, which is why calling `draw_crewmate()` a second time produces the same drawing instead of drifting upward.

Active coding checkpoint

Your turn

Write a tiny drawing function

Finish the function so it stamps a small visor above the player body. Watch the indentation after `def`.

def draw_visor():
player.color("sky blue")
player.shapesize(0.4, 1.3)
____________________

draw_visor()
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

`player.stamp()` belongs inside the function because it is one of the steps in the recipe.

def draw_visor():
player.color("sky blue")
player.shapesize(0.4, 1.3)
player.stamp()

draw_visor()
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.

player = turtle.Turtle()
player.penup()
player.speed(0)
player.color("tomato")
player.shape("circle")
player.setposition(0, 0)

def draw_crewmate():
player.clear()
player.turtlesize(2.2, 1.5)
player.stamp()
player.sety(player.ycor() + 20)
player.color("light cyan")
player.turtlesize(0.7, 1.1)
player.stamp()
player.color("tomato")
player.sety(player.ycor() - 20)

draw_crewmate()
Trace it

Trace the idea

  1. One Turtle draws several stamped shapes.
  2. `draw_crewmate()` can be called again after the player moves.
  3. Changing `player.color()` changes the suit.

Understand it

Trace it

Why this code works

  • A Turtle can be both a game object and a drawing tool. In this stage, the player Turtle stamps a simple character out of circles.
  • `clear()` removes old stamps made by this Turtle. That matters later because moving without clearing would leave a trail of old crewmates.
  • The function name should describe the job. `draw_crewmate` tells a reader exactly why those size and stamp commands are grouped.

If it breaks

Trace it

Troubleshooting wisdom

If a line drags behind the player as it moves, `player.penup()` never ran. Add it right after `player = turtle.Turtle()`, before any `setposition` call. The pen is down by default, so a character Turtle always needs an explicit `penup()`.

If the visor comes out the wrong color, the `color()` call happened after the `stamp()`. `stamp()` snapshots whatever the Turtle currently looks like, so set the color first, then stamp. Reorder those two lines and the visor flips to the new color.

If the character drifts upward a little every time `draw_crewmate()` runs, the function is forgetting to come home. The final `sety(player.ycor() - 20)` has to undo the visor's `+ 20` step exactly. The Turtle must end at the same y where it started.

Try this

Learning beat

Try this

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

Predict first
Move the final `player.color("tomato")` above the visor stamp. Predict what changes.
Compare
Try two suit colors. Which one is easiest to see on the dark ship background?
Connect
Stage 6 uses the same drawing pattern for the chaser. What should stay the same and what should change?

Test your stage

  • A player appears near the center.
  • The body and visor are different colors.
  • The drawing code is inside a function.