Cabin Crew Express · Lesson 31 of 50 · Intermediate to advanced · About 38 min
Ari needs a clear cabin map before service starts. Paint the aircraft from its shell to the item the player is looking for.

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/30 when the lesson builds on prior work, or copy the checkpoints/31 folder to try this lesson on its own. Read the file names in the steps before editing. Keep the checkpoint ZIP intact and make edits in an extracted working copy.


Build it step by step
Language and tools in this lesson draw_rect, draw_line, draw_string, range, queue_redraw.
-
Open the editable checkpoint
Start Godot 4.7.2, choose Import in Project Manager and select the project.godot file for this lesson. Open main.gd in FileSystem, then press F5. Stop the game with F8 before editing.
Why it works This folder is its own project with a Control scene and an attached script. You can run it without files from any other lesson.
-
Paint the cabin shell first
Find _draw. Change the lighter shell colour from #5e8398 to #59748a and run. The labels and seats should stay readable.
draw_rect(Rect2(226, 159, 554, 254), Color("#36576a") if night else Color("#5e8398"))Why it works Later draw calls sit above earlier calls. The fuselage shape is behind every item.
-
Keep the main aisle straight
Look for the narrow rectangle between the seats. Track its x position and width when the game runs.
draw_rect(Rect2(471, 167, 73, 240), Color("#28495a"))Why it works Rect2 takes x, y, width and height. The same aisle x position applies to each row.
-
Repeat the seat pairs
Read range(4). Count rows 1 through 4 on screen, then try replacing 4 with 3 for one run.
for row in range(4):Why it works range starts at zero. row + 1 shows the numbers passengers see on tickets.
-
Make the active seat easy to see
Change ACTIVE from 3F to 2A. Check which seat gets the thicker border and why the printed label also changes.
var trim := Color("#ffca7b") if id == ACTIVE else Color("#7eb4b3")Why it works id is an input to draw_seat. The comparison controls trim and width for one seat without moving it.
-
Switch the cabin lights
Press Switch lighting twice. Follow the Boolean and the redraw request in the script.
queue_redraw()Why it works A redraw reads the new day or night palette. Seat addresses come from the same drawing loop in both modes.
Watch the values change
-
Open the scene night is false and ACTIVE is 3F.
What you see. The light cabin and bright border are visible. -
Switch lighting night becomes true and _draw runs again.
What you see. The aisle and seats stay put while paint changes. -
Change ACTIVE to 2A The equality check now succeeds for 2A.
What you see. The thick trim moves to the new seat.
Predict before you run If you use row instead of row + 1 to build the seat ID, which is the first row?
Reveal the answer
The display begins at row 0. Keep row + 1 so the first passenger row is 1.
Complete checkpoint
The cabin has four rows with two seats on either side. Switch lighting changes the palette while the marked seat remains 3F.
main.gd
extends Control
const LEFT := ["A", "B"]
const RIGHT := ["E", "F"]
const ACTIVE := "3F"
var night := false
var status: Label
func _ready() -> void:
heading("Let the aircraft cabin take shape", "LAYERS")
status = label("Day lighting • seat 3F is active", Vector2(48, 124))
button("Switch lighting", Vector2(48, 437), change_lighting)
func change_lighting() -> void:
night = not night
status.text = "Night lighting • seat 3F is active" if night else "Day lighting • seat 3F is active"
queue_redraw()
func draw_seat(id: String, at: Vector2, light: Color) -> void:
var area := Rect2(at, Vector2(81, 45))
var trim := Color("#ffca7b") if id == ACTIVE else Color("#7eb4b3")
draw_rect(area, light)
draw_rect(area, trim, false, 2.0 if id == ACTIVE else 1.0)
draw_line(at + Vector2(8, 12), at + Vector2(73, 12), trim, 2.0)
draw_string(ThemeDB.fallback_font, at + Vector2(29, 34), id, HORIZONTAL_ALIGNMENT_LEFT, -1, 17, Color.WHITE)
func _draw() -> void:
draw_rect(Rect2(Vector2.ZERO, size), Color("#122536"))
draw_rect(Rect2(226, 159, 554, 254), Color("#36576a") if night else Color("#5e8398"))
draw_rect(Rect2(471, 167, 73, 240), Color("#28495a"))
var seat_colour := Color("#233750") if night else Color("#365572")
for row in range(4):
var y := 177.0 + row * 55.0
for column in range(2):
draw_seat(str(row + 1) + LEFT[column], Vector2(273 + 94 * column, y), seat_colour)
draw_seat(str(row + 1) + RIGHT[column], Vector2(557 + 94 * column, y), seat_colour)
draw_circle(Vector2(244, y + 23), 7, Color("#b6dae4"))
draw_circle(Vector2(763, y + 23), 7, Color("#b6dae4"))
func heading(caption: String, topic: String) -> void:
label("CABIN CREW EXPRESS / " + topic, Vector2(48, 41), 15, Color("#ffca7b"))
label(caption, Vector2(48, 73), 27)
func label(text: String, at: Vector2, pixels: int = 20, ink: Color = Color("#f7f4e9")) -> Label:
var item := Label.new()
item.text = text
item.position = at
item.add_theme_font_size_override("font_size", pixels)
item.add_theme_color_override("font_color", ink)
add_child(item)
return item
func button(text: String, at: Vector2, action: Callable, width: float = 155.0) -> Button:
var item := Button.new()
item.text = text
item.position = at
item.custom_minimum_size = Vector2(width, 47)
item.pressed.connect(action)
add_child(item)
return item
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 ControlStarts with Godot's Control type. This script gets the abilities of that type and adds the game's own rules. -
const LEFT := ["A", "B"]Use the two seat letters you will draw on the left of each numbered row. -
const RIGHT := ["E", "F"]Use the two seat letters on the right. The two sides do not need to share letter sequences. -
const ACTIVE := "3F"Keep this seat ID separate from the day and night colours. It describes which passenger is in focus. -
var night := falseCreates a variable named night. The expression uses the yes-or-no value false. Godot infers the type from the first value. -
var status: LabelDeclares status for later use. A colon followed by a type says which kind of value belongs here. -
func _ready() -> void:Godot calls this once after the scene and its children are ready. Use it to set up the room and connect controls. -
heading("Let the aircraft cabin take shape", "LAYERS")Calls heading with the values in its parentheses. -
status = label("Day lighting • seat 3F is active", Vector2(48, 124))Stores the new value in status. The expression calls label with the values in its parentheses. -
button("Switch lighting", Vector2(48, 437), change_lighting)Calls button with the values in its parentheses. -
func change_lighting() -> void:Defines change lighting, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
night = not nightFlip the current mode. This changes the next picture, without altering the seat positions. -
status.text = "Night lighting • seat 3F is active" if night else "Day lighting • seat 3F is active"Updates status.text, which controls the words a player sees. The expression chooses one of two values by checking the condition in the middle. -
queue_redraw()Ask Godot to call _draw again with the updated day or night flag. -
func draw_seat(id: String, at: Vector2, light: Color) -> void:Reuse the same drawing procedure at any address by supplying an ID, pixel position and seat colour. -
var area := Rect2(at, Vector2(81, 45))Describe the seat rectangle by its upper left corner and its fixed 81 by 45 pixel size. -
var trim := Color("#ffca7b") if id == ACTIVE else Color("#7eb4b3")Compare this ID with the active ID so exactly one border gets the warm accent. -
draw_rect(area, light)Paints a rectangle at the given position and size. -
draw_rect(area, trim, false, 2.0 if id == ACTIVE else 1.0)Draw an outline because false means an unfilled rectangle. Make the active edge twice as thick. -
draw_line(at + Vector2(8, 12), at + Vector2(73, 12), trim, 2.0)Paints a line between two points with the chosen colour and width. -
draw_string(ThemeDB.fallback_font, at + Vector2(29, 34), id, HORIZONTAL_ALIGNMENT_LEFT, -1, 17, Color.WHITE)Paints a piece of text with a font at a position measured from the node's origin. -
func _draw() -> void:Godot calls this when the node needs drawing. The instructions inside paint the current state. -
draw_rect(Rect2(Vector2.ZERO, size), Color("#122536"))Paints a rectangle at the given position and size. -
draw_rect(Rect2(226, 159, 554, 254), Color("#36576a") if night else Color("#5e8398"))Paint the background shell before drawing the aisle and seats on top of it. -
draw_rect(Rect2(471, 167, 73, 240), Color("#28495a"))The fixed x position of this aisle produces a straight corridor through all four rows. -
var seat_colour := Color("#233750") if night else Color("#365572")Creates a variable named seat_colour. The expression builds a colour from these values. Godot infers the type from the first value. -
for row in range(4):Repeat the row layout four times. Internally the loop counts zero through three. -
var y := 177.0 + row * 55.0Convert the row number into a pixel y position using a starting offset and a constant gap. -
for column in range(2):Draw the two seats on each side using the same column index. -
draw_seat(str(row + 1) + LEFT[column], Vector2(273 + 94 * column, y), seat_colour)Turn the row index into a passenger row number and append the left-side seat letter. -
draw_seat(str(row + 1) + RIGHT[column], Vector2(557 + 94 * column, y), seat_colour)Keep the same row and spacing while moving to the right bank of seats. -
draw_circle(Vector2(244, y + 23), 7, Color("#b6dae4"))Paints a filled circle or outline in this node's local coordinates. -
draw_circle(Vector2(763, y + 23), 7, Color("#b6dae4"))Paints a filled circle or outline in this node's local coordinates. -
func heading(caption: String, topic: String) -> void:Defines heading, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
label("CABIN CREW EXPRESS / " + topic, Vector2(48, 41), 15, Color("#ffca7b"))Calls label with the values in its parentheses. -
label(caption, Vector2(48, 73), 27)Calls label with the values in its parentheses. -
func label(text: String, at: Vector2, pixels: int = 20, ink: Color = Color("#f7f4e9")) -> Label:Defines label, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var item := Label.new()Creates a variable named item. The expression creates a new Label object. Godot infers the type from the first value. -
item.text = textUpdates item.text, which controls the words a player sees. The expression reads text. -
item.position = atUpdates item.position, which controls the node's local x and y location. The expression reads at. -
item.add_theme_font_size_override("font_size", pixels)Calls item.add_theme_font_size_override with the values in its parentheses. -
item.add_theme_color_override("font_color", ink)Calls item.add_theme_color_override with the values in its parentheses. -
add_child(item)Adds the new node to the scene tree so that Godot can run and draw it. -
return itemFinishes the function and hands its result back to the caller. The expression reads item. -
func button(text: String, at: Vector2, action: Callable, width: float = 155.0) -> Button:Defines button, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var item := Button.new()Creates a variable named item. The expression creates a new Button object. Godot infers the type from the first value. -
item.text = textUpdates item.text, which controls the words a player sees. The expression reads text. -
item.position = atUpdates item.position, which controls the node's local x and y location. The expression reads at. -
item.custom_minimum_size = Vector2(width, 47)Updates item.custom_minimum_size, which controls the smallest space the layout should reserve for this control. The expression packs x and y into one value. -
item.pressed.connect(action)Links a signal to the function that should run when the event happens. -
add_child(item)Adds the new node to the scene tree so that Godot can run and draw it. -
return itemFinishes the function and hands its result back to the caller. The expression reads item.
Find and fix a bug
If seat 3F never changes colour, check the uppercase F in ACTIVE. String comparisons distinguish F from f.
Try a change
Ages 10–12 can design a second lighting palette. Ages 13–16 can derive the aisle width and positions from constants and test a wider seat layout.