Task: MIL-003#1 Task: MIL-003#2 Task: MIL-003#3 Task: MIL-003#4 Task: MIL-003#5 Task: MIL-003#6
1.1 KiB
1.1 KiB
English · Dansk · Bahasa Malaysia
Step 5: Alien movement
What we built
Every second the fleet moves one step sideways. When the next step would take an alien past the edge, the fleet drops closer and turns around. The time is read with time.monotonic, and the decision is made by the pure functions is_due and next_fleet_move.
What we gained
- Moving by time, not by counting frames, so the speed does not depend on the computer
- Writing the decision of the next move as a function that returns the change and the new direction
- Dropping and reversing at an edge
- Testing a time rule by passing the time in
Try it
Wait a few seconds and watch the fleet move.
Where the code is
src/fleet.py: update, move; src/rules.py: is_due, next_fleet_move
Previous: Alien fleet · Next: Shooting aliens · Overview
