Market Day London · Lesson 04 of 50 · Beginner · About 24 min
The counter team gives Nia a map. A square’s column and row can locate her without referring to the colour of the 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/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.


Build it step by step
Language and tools in this lesson Vector2i, Vector2, .x and .y, coordinate origin, cell centre, _draw.
-
Read the training location
Open Lesson 4’s main.gd in Godot. Find Nia’s starting cell in the variables above _ready.
var nia := Vector2i(3, 3)Why it works Vector2i stores two whole numbers. On this map the first number is the column and the second is the row.
-
Measure from the origin
Find the top-left map origin and the tile length. Mark that start on the illustration before running.
const ORIGIN := Vector2(47, 134)Why it works The origin is the map’s corner in screen pixels. TILE says how many pixels one square spans.
-
Find a tile centre
Follow the calculation in cell_centre. Multiply the column and row by the tile size, add the origin and then add half a tile in both directions.
return ORIGIN + Vector2(cell) * TILE + Vector2.ONE * (TILE / 2.0)Why it works The multiplication reaches a square’s upper-left corner. The extra half puts the marker in the middle.
-
Connect coordinates to drawing
In _draw, find the line that takes the centre of Nia’s current cell. Then find draw_circle on the next line.
var marker := cell_centre(nia)Why it works The game stores a cell, while the drawing uses pixels. cell_centre joins the two coordinate systems.
-
Run and compare both views
Press F5. Match the large caption to the green Nia marker inside the single practice square.
board.text = "Briar Lane • Nia is at column %d, row %d" % [nia.x, nia.y]Why it works Both the label and marker describe one value. The label uses nia.x and nia.y, and the marker converts those values to pixels.
-
Move the starting point
Change nia to Vector2i(1, 2) and run again. Describe separately what happened left-to-right and top-to-bottom.
var nia := Vector2i(3, 3)Why it works A smaller x moves the marker left. A smaller y moves it up because screen y grows downwards.
Watch the values change
-
Read Nia’s starting cell. Nia is at grid cell (3,3).
What you see. The sign displays column 3, row 3. -
Convert to pixels. x is 47 + 171 + 28.5 and y is 134 + 171 + 28.5.
What you see. The marker appears near (247,334). -
Change Nia’s x to 1. Her row remains 3.
What you see. The marker moves two tiles left.
Predict before you run Which direction does Nia move if only her y changes from 3 to 4?
Reveal the answer
She moves one row down. x did not change, so the column stays at 3.
Complete checkpoint
One visible tile contains Nia. The display agrees with her initial grid cell (3,3).
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)
var point := cell_centre(nia)
draw_rect(Rect2(point - Vector2.ONE * 27.0, Vector2.ONE * 54.0), Color("#31596b"))
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. -
var point := cell_centre(nia)Calculate the centre of the only practice tile using Nia’s location. -
draw_rect(Rect2(point - Vector2.ONE * 27.0, Vector2.ONE * 54.0), Color("#31596b"))Paint a 54-pixel square around the centre. The rest of the practice map appears in the next lesson. -
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 the green marker lands at a corner, check the last term in cell_centre. Adding half the tile size on each axis places the mark in the centre.
Try a change
Ages 10–12 can pick a few new start cells and predict the directions. Ages 13–16 can write down their exact pixel centres before testing.