1) What do I need to do?
π― Your mission: Ship and laser
Make a ship turtle at the bottom (y = -170). Write left and right functions that change its x with setx.
Make a hidden laser turtle and a fire function connected to "space".
Write a game_loop that moves the laser up when firing is True, and uses ontimer to repeat.
2) What do I need to know?
Plan the defence
The plan: a hero ship at the bottom moves left and right. Press space to fire a laser upward.
A list of aliens marches side to side. When they reach the edge, they all drop down and turn around.
If a laser hits an alien (distance < 20), the alien vanishes and you score!
It's the same game loop idea as Snake: move, check hits, ontimer again.
π§° Your toolkit for this mission
Everything you need to know to finish this lesson on your own:
Player moves
Left/right keys slide the ship.
How to write it: Change x with ship.setx(ship.xcor() - 20).
def left():
ship.setx(ship.xcor() - 20)Firing
A bullet turtle moves up each timer tick.
How to write it: bullet.sety(bullet.ycor() + 15) inside your timer function.
Hits
Bullet close to an invader = hit.
How to write it: if bullet.distance(invader) < 20: then score and reset.
Many invaders
Keep them in a list and loop through it.
How to write it: for inv in invaders: move and check each.
for inv in invaders:
inv.sety(inv.ycor() - 1)Think about it
Look at this code. What happens next, and why? Say it in your own words.
speed = -speed
Watch & explore βΆ
Power-up: Plan the defence
See it happen
1 / 3ship.setx(ship.xcor() + 20)
The ship slides left and right along the bottom.
3) Run the code & terminal output
Press βΆ RUN and your program's messages appear here!


Captain Py
Our next adventure is yours to create.
