Exercise 1 · Chapter: DodgeRequired+50 XP
Here They Come
Set the stage. Rocks march towards the hero, on the ground line.
Move each rock one column left per frame, recycling past the left edge, and
draw each one on row GROUND in "dimgray".
Nothing collides yet — the rocks pass straight through the hero. That's fine; you'll fix it next. Getting the world moving first, and only then adding the rules, is a sane way to build any game.
Expected output
[9, 21, 33] [8, 20, 32] [7, 19, 31] [6, 18, 30]
Need a hint?
3 available · costs 5 XP each
python
def new_game():
return {"y": 0, "vy": 0, "rocks": [10, 22, 34], "is_playing": True}
def update(state, keys):
# Move each rock one column left, wrapping past the left edge.
return state
def draw(state):
grid = blank_grid()
for i in range(len(state["rocks"])):
grid[GROUND][state["rocks"][i]] = "dimgray"
grid[GROUND - state["y"]][6] = "gold"
return grid