Exercise 1 · Chapter: Coin QuestOptional+50 XP
Coin Quest: Draw the Hero
What this step looks like when it works
🪙 Every game starts with something on screen. Ours is a hero.
Write draw(state). It gets the game state and must return a grid — the
picture for this frame.
- Start from
blank_grid() - Work out the hero's row:
GROUND - state["y"] - Paint the hero
"gold"— 2 squares wide, 2 squares tall, at columns 5 and 6 - Return the grid
state["y"] is how high the hero is off the ground. Right now it's always 0,
so the hero stands still — that's fine. Press Run to see him.
Expected output
........................................ ........................................ ........................................ ........................................ ........................................ ........................................ ........................................ ........................................ ........................................ ........................................ ........................................ .....AA................................. .....AA................................. ########################################
Need a hint?
3 available · costs 5 XP each
python
def draw(state):
grid = blank_grid()
row = GROUND - state["y"]
# Paint 4 gold squares here: columns 5 and 6, rows `row` and `row - 1`
return grid