Market Day London · Lesson 05 of 50 · Beginner · About 25 min
The map now needs room for stalls on both sides of the lane. Nia repeats one tile shape with a different position every time.

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 range(), nested for loops, Rect2, % remainder, even and odd, draw order.
-
Check the map size
Import Lesson 5. Find constants COLUMNS and ROWS at the top of main.gd. Count how many cells appear when you run.
const COLUMNS := 7Why it works Seven columns and five rows make 35 cells. The constants let the code refer to the map dimensions consistently.
-
Follow the row loop
In _draw, find for row in range(ROWS). List every y value the loop uses before a new row starts.
for row in range(ROWS):Why it works range(5) produces 0 through 4. Those are the five valid y values.
-
Follow the column loop
Look at the indented for column line. Explain what restarts for every row.
for column in range(COLUMNS):Why it works The inner loop runs once for every column in the current row. It starts at zero for the next row.
-
Build each tile shape
Follow the lines inside the column loop. Notice which point feeds Rect2 before the fill is drawn.
var tile := Rect2(point - Vector2.ONE * 27.0, Vector2.ONE * 54.0)Why it works Rect2 stores the tile’s corner and size. Subtracting 27 pixels from the centre sets the top-left corner of a 54-pixel square.
-
See how the paving alternates
Read the expression with % 2. Test (0,0), (1,0) and (0,1) by calculating their remainders.
(row + column) % 2 == 0Why it works An even total gives remainder zero. The expression uses a different colour for an odd total, like alternating paving stones.
-
Check the layer order
Run the project. Point out why the green marker remains visible after all 35 cells are filled.
draw_circle(marker, 18.0, MINT)Why it works The loops draw the base first. The marker draws last and appears in front of the paving.
Watch the values change
-
Start with row 0. The inner loop starts with column 0.
What you see. The first tile appears at the top left. -
Finish row 0. Columns 0–6 were all visited.
What you see. The next row begins back at the left. -
Finish the grid. Five sets of seven tiles have been drawn.
What you see. Nia’s marker appears over cell (3,3).
Predict before you run How many tiles appear if you change ROWS to 4 and COLUMNS to 6?
Reveal the answer
The loops visit 4 × 6 = 24 tiles. Nia at (3,3) still fits inside that smaller map.
Complete checkpoint
A 35-tile training market appears with alternating blues and a mint Nia marker.
main.gd
extends Control
const NIGHT := Color("#0d2335")
const PANEL := Color("#17374b")
const CREAM := Color("#fff4da")
const MINT := Color("#9ce4ce")
const GOLD := Color("#ffd789")
var board: Label
const ORIGIN := Vector2(47, 134)
const TILE := 57.0
const COLUMNS := 7
const ROWS := 5
var nia := Vector2i(3, 3)
func _ready() -> void:
var title := Label.new()
title.text = "Market Day London"
title.position = Vector2(42, 34)
title.add_theme_font_size_override("font_size", 34)
title.modulate = CREAM
add_child(title)
board = Label.new()
board.position = Vector2(45, 88)
board.add_theme_font_size_override("font_size", 22)
board.modulate = MINT
add_child(board)
_refresh()
func _draw() -> void:
draw_rect(Rect2(Vector2.ZERO, get_viewport_rect().size), NIGHT)
draw_rect(Rect2(32, 120, 431, 316), PANEL)
draw_rect(Rect2(487, 120, 437, 316), PANEL)
for row in range(ROWS):
for column in range(COLUMNS):
var point := cell_centre(Vector2i(column, row))
var tile := Rect2(point - Vector2.ONE * 27.0, Vector2.ONE * 54.0)
var tint := Color("#31596b") if (row + column) % 2 == 0 else Color("#284d61")
draw_rect(tile, tint)
var marker := cell_centre(nia)
draw_circle(marker, 18.0, MINT)
draw_string(ThemeDB.fallback_font, marker + Vector2(-10, 5), "Nia", HORIZONTAL_ALIGNMENT_LEFT, -1, 14, NIGHT)
draw_string(ThemeDB.fallback_font, Vector2(46, 468), "BRIAR LANE • TRAINING MAP", HORIZONTAL_ALIGNMENT_LEFT, -1, 16, GOLD)
func _refresh() -> void:
board.text = "Briar Lane • Nia is at column %d, row %d" % [nia.x, nia.y]
func cell_centre(cell: Vector2i) -> Vector2:
return ORIGIN + Vector2(cell) * TILE + Vector2.ONE * (TILE / 2.0)
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 these screen-building instructions to a Godot Control. That gives the script positions, children and input events. -
const NIGHT := Color("#0d2335")Use this dark ink colour behind the market. The fixed colour is also used for lettering on the mint marker and brighter signs. -
const PANEL := Color("#17374b")Use one lighter shade to group the map and controls against the dark background. -
const CREAM := Color("#fff4da")Keep the title and labels light enough to read against dark panels. -
const MINT := Color("#9ce4ce")Use this accent to highlight the status label and Nia’s marker. -
const GOLD := Color("#ffd789")Mark utility labels and the collection point with a pale yellow that stands apart from the paving. -
var board: LabelSave the opening label so later methods can change it without needing to create a new one. -
const ORIGIN := Vector2(47, 134)Set the pixel position of the upper-left corner used to lay out the market grid. -
const TILE := 57.0Keep neighbouring tile centres 57 pixels apart. -
const COLUMNS := 7Give the training lane seven columns with indices from 0 to 6. -
const ROWS := 5Give the training lane five rows with indices from 0 to 4. -
var nia := Vector2i(3, 3)Start Nia at column 3 and row 3. Store grid values instead of pixel coordinates. -
func _ready() -> void:Godot calls this once when the Market scene is ready to create the title, notice and controls. -
var title := Label.new()Create an unattached Label for the permanent title. It becomes visible when it is added to the scene. -
title.text = "Market Day London"Put the game name into the title label. The title stays fixed while smaller words underneath change. -
title.position = Vector2(42, 34)Leave a margin of 42 pixels from the left and 34 from the top. -
title.add_theme_font_size_override("font_size", 34)Set this title to a larger local font size. The rest of the labels can keep different sizes. -
title.modulate = CREAMSet the title’s drawing colour to the pale cream chosen above. -
add_child(title)Add the title to the running scene so Godot draws and maintains it. -
board = Label.new()Create the changing notice label and store it in the field used by other methods. -
board.position = Vector2(45, 88)Position the variable status words underneath the game name. -
board.add_theme_font_size_override("font_size", 22)Set a smaller font for status messages, which can be longer than the title. -
board.modulate = MINTTint the notice mint so it stands out as the changing information. -
add_child(board)Attach the notice beneath the title so the player sees the current message. -
_refresh()Write the latest cell location into the notice without creating another label. -
func _draw() -> void:Paint this section when Godot refreshes the Control. Draw the background first and the frontmost details last. -
draw_rect(Rect2(Vector2.ZERO, get_viewport_rect().size), NIGHT)Fill the visible window so there is a consistent dark background behind the game panels. -
draw_rect(Rect2(32, 120, 431, 316), PANEL)Draw the dark rectangle under the tile map. -
draw_rect(Rect2(487, 120, 437, 316), PANEL)Draw an adjacent rectangle behind the controls and basket information. -
for row in range(ROWS):Visit each row index from 0 through 4. -
for column in range(COLUMNS):For each row, visit column indices from 0 through 6. -
var point := cell_centre(Vector2i(column, row))Convert this loop pair into the pixel centre for one paving square. -
var tile := Rect2(point - Vector2.ONE * 27.0, Vector2.ONE * 54.0)Give the tile a 54-pixel square shape. The 57-pixel spacing leaves a small border between squares. -
var tint := Color("#31596b") if (row + column) % 2 == 0 else Color("#284d61")Use the remainder to alternate the paving colour. Equal parities use the same ink. -
draw_rect(tile, tint)Place the current square using the pixel rectangle and the chosen tint. -
var marker := cell_centre(nia)Convert the saved grid cell to the exact point where Nia’s visual marker belongs. -
draw_circle(marker, 18.0, MINT)Paint the small mint circle over the map paving or stall square. -
draw_string(ThemeDB.fallback_font, marker + Vector2(-10, 5), "Nia", HORIZONTAL_ALIGNMENT_LEFT, -1, 14, NIGHT)Put Nia’s name inside the circle so the marker does not rely on its colour alone. -
draw_string(ThemeDB.fallback_font, Vector2(46, 468), "BRIAR LANE • TRAINING MAP", HORIZONTAL_ALIGNMENT_LEFT, -1, 16, GOLD)Label the map with a quiet footer set apart from the playable square area. -
func _refresh() -> void:Update the status line from Nia’s currently stored map cell. -
board.text = "Briar Lane • Nia is at column %d, row %d" % [nia.x, nia.y]Read x as the column and y as the row, then show both values. -
func cell_centre(cell: Vector2i) -> Vector2:Convert a whole-number tile position into a pixel point for drawing. -
return ORIGIN + Vector2(cell) * TILE + Vector2.ONE * (TILE / 2.0)Multiply the tile coordinate by the 57-pixel spacing, start at ORIGIN and move another half tile to reach its centre.
Find and fix a bug
If only one horizontal strip shows, check the indentation of the inner column loop. It should be one tab deeper than the outer row loop.
Try a change
Ages 10–12 can try three rows with seven columns. Ages 13–16 can choose a striped paving rule based only on the column number.