Cabin Crew Express · Lesson 05 of 50 · Beginner · About 31 min
Ari’s practice cabin has two seats on each side of a single aisle. The front galley has room for just the aisle tile.

Download the projects from the course page. In Godot’s Project Manager, choose Import, select project.godot, and use Run Project (F5). Start from checkpoints/04 when the lesson builds on prior work, or copy the checkpoints/05 folder to try this lesson on its own. Read the file names in the steps before editing.


Build it step by step
Language and tools in this lesson nested loops, for, range, continue, Rect2, inline conditional, draw_rect.
-
Sketch the board
On paper, number rows 0–6 and columns 0–4. Put the aisle in column 2 and mark the four passenger seat columns.
Why it works The algorithm uses that same layout. There are five visual columns, but the centre is a walkway.
-
Loop through each row
In _draw, replace the aisle-only loop. Put the row loop first and indent the column loop within it.
for row in range(LAST_ROW + 1): for column in range(5):Why it works The inner loop runs once for every possible column of the current row. The outer loop then advances to the next row.
-
Leave space beside the galley
Before calculating a point in the inner loop, add the galley test and the indented continue.
if row == 0 and column != AISLE: continueWhy it works continue immediately moves to the next column. This skips four candidate tiles in row 0.
-
Make one rectangle for each allowed tile
Read tile as a rectangle with a top-left position and size. Each tile is 50 pixels wide and sits in a 54-pixel pitch.
var point := cell_centre(Vector2i(column, row)) var tile := Rect2(point - Vector2.ONE * 25.0, Vector2.ONE * 50.0)Why it works Subtracting 25 from the centre locates the corner. The four pixels between neighbouring tiles make the board easier to read.
-
Distinguish the aisle
Use the shorter conditional line to choose the aisle paint or the seat paint. Run the scene.
var paint := AISLE_BLUE if column == AISLE else Color("#193f58") draw_rect(tile, paint)Why it works The line assigns AISLE_BLUE when column equals AISLE and a darker colour otherwise. Ari is drawn last over the board.
-
Count against your sketch
Count six full passenger rows and the one galley tile before looking at the status sign.
Why it works Six rows of five plus one galley tile gives 31 filled squares. Counting catches off-by-one errors.
Watch the values change
-
Check row 0, column 0 The row is zero and the column is not the aisle.
What you see. The loop skips the square. -
Check row 0, column 2 The column is the aisle.
What you see. Godot paints the galley square. -
Check row 1, column 1 The row is a passenger row and the column is a seat.
What you see. Godot paints a dark seat square.
Predict before you run How many filled squares would there be if you removed the continue rule?
Reveal the answer
There would be 35. Every one of the seven rows would draw five squares.
Complete checkpoint
The cabin shows six rows of four seat tiles, a continuous aisle, and a single galley tile above them.
main.gd
extends Control
const GRID_ORIGIN := Vector2(64, 112)
const TILE := 54.0
const AISLE := 2
const LAST_ROW := 6
const NAVY := Color("#0a2138")
const AISLE_BLUE := Color("#4c8099")
const TEAL := Color("#8ce4ce")
var crew_row: int = 2
var board: Label
func _ready() -> void:
board = Label.new()
board.position = Vector2(40, 48)
board.add_theme_font_size_override("font_size", 30)
add_child(board)
_refresh_board()
func _refresh_board() -> void:
var place := "Galley" if crew_row == 0 else "Row %d" % crew_row
board.text = "Cabin Crew Express | Ari at %s" % place
func cell_centre(cell: Vector2i) -> Vector2:
return GRID_ORIGIN + Vector2(cell) * TILE + Vector2.ONE * (TILE / 2.0)
func _draw() -> void:
draw_rect(Rect2(Vector2.ZERO, get_viewport_rect().size), NAVY)
for row in range(LAST_ROW + 1):
for column in range(5):
if row == 0 and column != AISLE:
continue
var point := cell_centre(Vector2i(column, row))
var tile := Rect2(point - Vector2.ONE * 25.0, Vector2.ONE * 50.0)
var paint := AISLE_BLUE if column == AISLE else Color("#193f58")
draw_rect(tile, paint)
var point := cell_centre(Vector2i(AISLE, crew_row))
draw_circle(point, 20.0, TEAL)
draw_string(ThemeDB.fallback_font, point + Vector2(-10, 5), "Ari", HORIZONTAL_ALIGNMENT_LEFT, -1, 15, NAVY)
GDScript line by line
Follow the line numbers, including the indent at the start of each line. Find the code the game will run first, then look for the function that reacts when you tap or change something.
Read main.gd line by line
-
extends ControlAttach this script to a Control node so it can use labels and on-screen buttons. -
const GRID_ORIGIN := Vector2(64, 112)Use a fixed drawing origin so the aisle, seats and trainee share one coordinate system. -
const TILE := 54.0Centre neighbouring cells 54 pixels apart. The rectangles themselves are a little smaller. -
const AISLE := 2Column 2 is the third of the five visible columns. Ari stays within this centre aisle. -
const LAST_ROW := 6The last passenger row is 6. Row 0 is reserved for the galley. -
const NAVY := Color("#0a2138")Use this dark blue as the cabin background, and behind some text on the pale marker. -
const AISLE_BLUE := Color("#4c8099")Column 2 is the third of the five visible columns. Ari stays within this centre aisle. -
const TEAL := Color("#8ce4ce")Use the mint accent for Ari and for the small request indicators. -
var crew_row: int = 2This single integer identifies Ari’s position. The sign, marker and seat lookup all depend on it. -
var board: LabelKeep the same briefing Label available both to the setup and later callback functions. -
func _ready() -> void:Godot calls this once when the starting cabin Control is ready to create its children. -
board = Label.new()Create the actual Label and store its reference in the script-wide board variable. -
board.position = Vector2(40, 48)Give the sign a small upper-left margin on the 960 × 540 practice screen. -
board.add_theme_font_size_override("font_size", 30)Make the status easy to read without changing every Label in the project. -
add_child(board)Attach the briefing to this Control so Godot can draw it in the active scene. -
_refresh_board()Refresh what the player sees using the current cabin row. -
func _refresh_board() -> void:Work out what to call the current row before preparing the latest sign. -
var place := "Galley" if crew_row == 0 else "Row %d" % crew_rowShow Galley for row zero. For a passenger row, insert its number after Row. -
board.text = "Cabin Crew Express | Ari at %s" % placeDisplay the named place using the same row value that controls the marker. -
func cell_centre(cell: Vector2i) -> Vector2:Convert a whole-number tile address into the pixel centre used to draw a tile or Ari’s marker. -
return GRID_ORIGIN + Vector2(cell) * TILE + Vector2.ONE * (TILE / 2.0)Add a scaled address and a half-tile shift to the grid origin. The returned Vector2 is measured in pixels. -
func _draw() -> void:Godot calls here when the screen needs repainting. Draw the background first, then the cells and marker. -
draw_rect(Rect2(Vector2.ZERO, get_viewport_rect().size), NAVY)Paint over the whole viewport to provide the dark surface behind the cabin map. -
for row in range(LAST_ROW + 1):Visit row zero and the six passenger rows. range stops before LAST_ROW + 1. -
for column in range(5):For each row, inspect columns zero through four before advancing to the next row. -
if row == 0 and column != AISLE:At the galley, skip seats on both sides but keep the aisle square. -
continueSkip the rest of this inner-loop pass. Godot continues with the next column. -
var point := cell_centre(Vector2i(column, row))Calculate this one tile’s centre using the column as x and row as y. -
var tile := Rect2(point - Vector2.ONE * 25.0, Vector2.ONE * 50.0)Use a 50 × 50 rectangle centred on the point. Four pixels separate it from its neighbours. -
var paint := AISLE_BLUE if column == AISLE else Color("#193f58")Choose the lighter paint for column 2 and dark paint for any seat column. -
draw_rect(tile, paint)Paint the current tile. Its rectangle and colour were calculated on the two lines above. -
var point := cell_centre(Vector2i(AISLE, crew_row))The trainee stays in the aisle column. crew_row decides how far down the aisle to draw Ari. -
draw_circle(point, 20.0, TEAL)Place Ari’s teal circle over the tile rectangles. -
draw_string(ThemeDB.fallback_font, point + Vector2(-10, 5), "Ari", HORIZONTAL_ALIGNMENT_LEFT, -1, 15, NAVY)Identify the trainee on the teal circle, so the marker does not rely on colour alone.
Find and fix a bug
If there is only one horizontal row of drawing, check that the column loop and its drawing steps are indented inside the row loop.
Try a change
Age 10–12: draw a paper version and colour its aisle. Age 13–16: temporarily add a row and explain how the loop bounds affect the filled-square count.