Cabin Crew 04 · Plot Ari’s aisle position

Cabin Crew Express · Lesson 04 of 50 · Beginner · About 30 min

The briefing is complete. Ari stands in row 2, one tile wide in the centre of the passenger cabin.

A level view along the aisle of a regional aircraft, with two navy seats on each side.
What you’ll make Use a row number and a coordinate helper to draw the trainee in the aisle.

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/03 when the lesson builds on prior work, or copy the checkpoints/04 folder to try this lesson on its own. Read the file names in the steps before editing.

Cabin address. Ari stands in column 2 and row 2. → Scale to the screen. Multiply by 54, then add the grid origin. → Centre the marker. Add 27 pixels in each direction.
Cabin address → Scale to the screen → Centre the marker
Godot checkpoint window for Plot Ari’s aisle position
From the running Godot checkpoint.

Build it step by step

Language and tools in this lesson Vector2i, Vector2, origin, pixels, return, _draw, range.

  1. Open the aisle checkpoint

    Open main.gd. Use the complete Lesson 4 script in a working copy and run the scene at a 960 × 540 viewport.

    Why it works This lesson changes from a briefing to a drawing. A known viewport gives the board and controls consistent space.

  2. Give Ari a row

    Find crew_row and AISLE. Read crew_row as row 2 and AISLE as column 2, where columns count from zero.

    const AISLE := 2

    Why it works A row is a whole number. Column 2 is the middle of five columns.

  3. Pick the upper-left grid point

    Read GRID_ORIGIN (64, 112) and TILE 54.0 as pixel dimensions. Draw the origin on paper.

    const GRID_ORIGIN := Vector2(64, 112)
    const TILE := 54.0

    Why it works The origin is the top-left corner of the first tile location. TILE describes the space from one tile column or row to its neighbour.

  4. Calculate the centre

    Add cell_centre under _refresh_board. Read the arithmetic in three parts: scale the coordinates, add the origin, move half a tile.

    func cell_centre(cell: Vector2i) -> Vector2:
    	return GRID_ORIGIN + Vector2(cell) * TILE + Vector2.ONE * (TILE / 2.0)

    Why it works Vector2i is a grid address. Vector2 can use fractions for drawing. The return line hands back the final pixel location.

  5. Draw a line of aisle tiles

    Look inside _draw after its background. Find range(LAST_ROW + 1) and count its values from 0 to 6.

    	for row in range(LAST_ROW + 1):
    		var point := cell_centre(Vector2i(AISLE, row))
    		draw_rect(Rect2(point - Vector2.ONE * 25.0, Vector2.ONE * 50.0), AISLE_BLUE)

    Why it works range stops before its argument. Adding one gives the galley row 0 plus all six passenger rows.

  6. Draw and verify Ari

    Read the four words on the sign after running and check that the Ari marker uses the same number.

    	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)

    Why it works Ari is drawn after the aisle rectangles. Both the marker and the sign use crew_row as their source of truth.

Watch the values change

  1. Read the logical cell Ari is at (2, 2).
    What you see. The numbers are grid units.
  2. Find its screen centre (64, 112) + (108, 108) + (27, 27).
    What you see. The point is (199, 247) pixels.
  3. Draw Ari over the aisle The same crew_row says Row 2.
    What you see. The marker aligns with the sign.

Predict before you run Where is the centre of the galley tile at column 2 and row 0?

Reveal the answer

(199, 139) pixels. Only the y value changes because the galley is in the same aisle column.

Complete checkpoint

The aisle has seven square tiles, with Ari at the third one from the top. The sign says Ari at Row 2.

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):
		var point := cell_centre(Vector2i(AISLE, row))
		draw_rect(Rect2(point - Vector2.ONE * 25.0, Vector2.ONE * 50.0), AISLE_BLUE)
	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
  1. extends ControlAttach this script to a Control node so it can use labels and on-screen buttons.
  2. const GRID_ORIGIN := Vector2(64, 112)Use a fixed drawing origin so the aisle, seats and trainee share one coordinate system.
  3. const TILE := 54.0Centre neighbouring cells 54 pixels apart. The rectangles themselves are a little smaller.
  4. const AISLE := 2Column 2 is the third of the five visible columns. Ari stays within this centre aisle.
  5. const LAST_ROW := 6The last passenger row is 6. Row 0 is reserved for the galley.
  6. const NAVY := Color("#0a2138")Use this dark blue as the cabin background, and behind some text on the pale marker.
  7. const AISLE_BLUE := Color("#4c8099")Column 2 is the third of the five visible columns. Ari stays within this centre aisle.
  8. const TEAL := Color("#8ce4ce")Use the mint accent for Ari and for the small request indicators.
  9. var crew_row: int = 2This single integer identifies Ari’s position. The sign, marker and seat lookup all depend on it.
  10. var board: LabelKeep the same briefing Label available both to the setup and later callback functions.
  11. func _ready() -> void:Godot calls this once when the starting cabin Control is ready to create its children.
  12. board = Label.new()Create the actual Label and store its reference in the script-wide board variable.
  13. board.position = Vector2(40, 48)Give the sign a small upper-left margin on the 960 × 540 practice screen.
  14. board.add_theme_font_size_override("font_size", 30)Make the status easy to read without changing every Label in the project.
  15. add_child(board)Attach the briefing to this Control so Godot can draw it in the active scene.
  16. _refresh_board()Refresh what the player sees using the current cabin row.
  17. func _refresh_board() -> void:Work out what to call the current row before preparing the latest sign.
  18. 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.
  19. board.text = "Cabin Crew Express | Ari at %s" % placeDisplay the named place using the same row value that controls the marker.
  20. 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.
  21. 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.
  22. func _draw() -> void:Godot calls here when the screen needs repainting. Draw the background first, then the cells and marker.
  23. draw_rect(Rect2(Vector2.ZERO, get_viewport_rect().size), NAVY)Paint over the whole viewport to provide the dark surface behind the cabin map.
  24. for row in range(LAST_ROW + 1):Visit row zero and the six passenger rows. range stops before LAST_ROW + 1.
  25. var point := cell_centre(Vector2i(AISLE, row))Creates a variable named point. The expression calls cell_centre with the values in its parentheses. Godot infers the type from the first value.
  26. draw_rect(Rect2(point - Vector2.ONE * 25.0, Vector2.ONE * 50.0), AISLE_BLUE)Paints a rectangle at the given position and size.
  27. 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.
  28. draw_circle(point, 20.0, TEAL)Place Ari’s teal circle over the tile rectangles.
  29. 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 the token appears near a tile corner, confirm that the final term adds half of TILE in both directions.

Try a change

Age 10–12: change crew_row to 4 and count the tiles. Age 13–16: move GRID_ORIGIN 24 pixels right and work out both pixel coordinates before running.