English · Dansk · Bahasa Malaysia
Step 7: Barriers

What we built
Four barriers of blocks between the ship and the aliens. A block takes three hits and changes colour from green to yellow to red before it is gone. A bullet that hits a block disappears.
What we gained
- Building a larger shape from many small objects (
BarrierBlock, BarrierWall)
- Showing the state of an object with its colour
- Reusing
is_hit for a new kind of collision
- Computing the block positions in a pure function (
barrier_positions)
Try it
Fire at a barrier and watch the block change colour.
Where the code is
src/barrier.py, src/rules.py: barrier_positions
Previous: Shooting aliens · Next: Game over and win · Overview