Market Day London · Lesson 07 of 50 · Beginner · About 27 min
The buyer queue stops at the end of Briar Lane. Nia’s map should explain why another move has not changed her location.

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/06 when the lesson builds on prior work, or copy the checkpoints/07 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 candidate move, Rect2i, has_point(), not, early return, validation.
-
Locate the candidate
Open Lesson 7 and compare _move with Lesson 6. Identify which line still adds the step to Nia’s cell.
var next := nia + stepWhy it works The new value is a proposal. Nia’s saved location stays separate until the rules accept the proposal.
-
Describe the market bounds
Trace Rect2i with its four arguments. Use the diagram and your map to point to each value.
Rect2i(0, 0, COLUMNS, ROWS).has_point(next)Why it works The first two values set the corner to (0,0). The dimensions then allow x from 0 to 6 and y from 0 to 4.
-
Read the question backwards
Find the word not. Say what would make the whole if condition true.
if not Rect2i(0, 0, COLUMNS, ROWS).has_point(next):Why it works has_point answers whether next is inside the rectangle. not reverses the answer, so the branch is for points outside.
-
Stop on an invalid move
Find return. Point out the assignment below that would normally store next.
board.text = "End of the lane • Nia stays put."Why it works An early return finishes the function before assigning an invalid location. The message explains why nothing moved.
-
Reach the end and test
Press Right four times starting from (3,3). Observe the first three new cells and the response to the fourth press.
nia = nextWhy it works Three legal steps reach x=6. The next x value would be 7, which is outside the 7-column map.
-
Make a legal move again
After the warning, press Left and inspect the caption. It should report the new valid location.
_refresh()Why it works The guarded move updates nia and calls _refresh only after passing the boundary check.
Watch the values change
-
Arrive at (6,3). The point lies on the final valid column.
What you see. The sign shows column 6, row 3. -
Press Right again. The candidate (7,3) lies outside.
What you see. The marker stays and the sign explains why. -
Press Left. The candidate (5,3) lies inside.
What you see. The marker moves and the coordinate sign returns.
Predict before you run Is cell (0,4) inside the bounds, and is cell (0,5) inside?
Reveal the answer
Cell (0,4) is inside. Cell (0,5) is just below the five-row grid, which ends at row 4.
Complete checkpoint
Legal moves advance Nia one tile. An invalid move leaves her where she is and displays the end-of-lane sign.
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()
_add_button("Up", Vector2(635, 163), _move.bind(Vector2i.UP))
_add_button("Left", Vector2(517, 221), _move.bind(Vector2i.LEFT))
_add_button("Down", Vector2(635, 221), _move.bind(Vector2i.DOWN))
_add_button("Right", Vector2(753, 221), _move.bind(Vector2i.RIGHT))
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)
func _add_button(caption: String, point: Vector2, action: Callable) -> void:
var button := Button.new()
button.text = caption
button.position = point
button.custom_minimum_size = Vector2(108, 50)
button.pressed.connect(action)
add_child(button)
func _move(step: Vector2i) -> void:
var next := nia + step
if not Rect2i(0, 0, COLUMNS, ROWS).has_point(next):
board.text = "End of the lane • Nia stays put."
return
nia = next
_refresh()
queue_redraw()
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. -
_add_button("Up", Vector2(635, 163), _move.bind(Vector2i.UP))Place the Up button above the centre of the direction button cluster. It later supplies a step of (0,-1). -
_add_button("Left", Vector2(517, 221), _move.bind(Vector2i.LEFT))Place the Left button to the left of Down. It supplies a step of (-1,0). -
_add_button("Down", Vector2(635, 221), _move.bind(Vector2i.DOWN))Place the Down button below Up. It supplies a step of (0,1). -
_add_button("Right", Vector2(753, 221), _move.bind(Vector2i.RIGHT))Place the Right button beside Down. It supplies a step of (1,0). -
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. -
func _add_button(caption: String, point: Vector2, action: Callable) -> void:Receive a caption, screen position and callable to reuse the same control construction for different actions. -
var button := Button.new()Create a Godot button that the player will be able to activate after it is attached. -
button.text = captionUse the words provided by the caller to explain what this button does. -
button.position = pointPlace the button using the point sent by _ready. -
button.custom_minimum_size = Vector2(108, 50)Reserve a large area for the button so its label and touch target are easier to distinguish. -
button.pressed.connect(action)Tell Godot which stored action should run when the button emits its pressed signal. -
add_child(button)Put the button into the active scene so it can display and receive input. -
func _move(step: Vector2i) -> void:Receive one direction as a whole-number change to Nia’s column and row. -
var next := nia + stepCalculate the proposed grid cell. Nia is still at the saved cell while the game checks the proposal. -
if not Rect2i(0, 0, COLUMNS, ROWS).has_point(next):Ask whether the proposal is outside this zero-based rectangle. Points on the far right or bottom border are outside. -
board.text = "End of the lane • Nia stays put."Explain the rejected press while leaving the saved grid position alone. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
nia = nextAccept the new position only after the bounds branch has been passed. -
_refresh()Write the latest cell location into the notice without creating another label. -
queue_redraw()Request a repaint so Nia’s marker now appears at the new cell.
Find and fix a bug
If Nia disappears after a boundary press, inspect whether nia = next has been moved above the check or return is no longer indented inside the if branch.
Try a change
Ages 10–12 can demonstrate all four lane ends. Ages 13–16 can add the attempted coordinate to the warning for sharper debugging.