Lesson 14: Building the Fleet โ Nested Loops + Spacing Math (Matthes Ch 13 ยง3)
Learning Intentions
- Fill the screen with rows and columns of aliens using nested loops and a bit of spacing math.
Success Criteria
- A full fleet (6+ columns ร 2+ rows) appears when I run the program.
- Spacing between aliens is even.
- I can explain number_aliens_x = available_x // (2 * alien_width).
๐ Do Now โ Error of the Day
Whiteboard challenge โ if the screen is 1200 px wide and each alien is 60 px wide (with 60 px gap between), how many aliens fit in a row? Write your calculation.
๐ I Do โ Teacher Demo
Derive the fleet-math formula on the whiteboard. Live-code _create_fleet() with nested for-loops: outer rows, inner columns. Calculate number_aliens_x, number_rows from screen dimensions.
๐ค We Do โ Build Together
Class builds the full fleet together. Nested loops. Magical moment when the grid appears. Tune the row/column counts together.
๐ You Do โ Your Turn
Try 3 rows of 5, or 2 rows of 10. Which layout do you prefer? Arcade quests cover nested loops + spacing arithmetic.
- Whiteboard: screen 1200 px wide, alien 60 px โ how many fit with gaps?
- Write _create_fleet: calculate number_aliens_x from screen width
- Outer loop: rows. Inner loop: columns. Create Alien, position, add to group
- Test โ you should see a full grid
๐ฎ Practice Quests โ work through these
Loading practice quests for this lesson...
Three tiers โ pick yours
Support
_create_fleet skeleton with the math pre-done. Whiteboard grid math diagram
Core
Follow the plan as written. Attempt the arcade quests above at your own pace.
Extension
Complete all quests above + try a Boss battle for bonus XP. Help a classmate if you finish.
Extensions
- 3 different alien row colours across 3 rows (image swap, not inheritance).
- Fleet starts 50 px lower to leave room for future score UI.
๐ Exit Ticket โ Coding Journal
Journal: why do we use a NESTED loop (not two separate loops) to build the fleet?
Evidence of Learning
Full fleet visible on screen with consistent even spacing.