Market Day London · Lesson 31 of 50 · Intermediate to advanced · About 35 min
Morning banners frame the market. The pavement must stay readable when a shower changes the colours of the street.

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_string, queue_redraw, nested range, Dictionary.get.
-
Import the editable checkpoint
In the Godot 4.7.2 Project Manager, select Import and open the project.godot in this lesson folder. Open main.gd in the FileSystem dock. Press F5 to run the market and F8 to stop it before editing.
Why it works This checkpoint already has a Control root with its script attached, so you can compare your edits to a working market scene.
-
Sketch the grid in text
In main.gd find PLAN, then count seven characters on any row. Change one full stop in the last row into #, press F5 and spot the new blocked square.
const PLAN := ["..A....","...#...","..#..B.","C......","...#...","...F..."]Why it works One character describes one tile, including plain pavement. Keeping row widths equal keeps the picture aligned.
-
Draw the street under the stalls
Find the first draw_rect in _draw. Temporarily change its border width from 36 to 20, run and compare the border on both sides.
draw_rect(Rect2(ORIGIN - Vector2(18, 12), TILE * Vector2(7, 6) + Vector2(36, 24)), Color("#314b62"))Why it works The market frame is painted first, then the tile layer sits on top. Tile widths stay the same even if you change the outside frame.
-
Walk the grid with two loops
Follow the loop for row, then the loop for column. Pick row 2 and column 5, count from zero and predict the label.
for column in range(PLAN[row].length()):Why it works The inner loop visits every character in one row. The outer loop then goes down to the next line.
-
Keep the signs in the foreground
Read the draw_string call, then change the word Collect to Pick-up in MARKS and run it once.
var sign_text: String = str(MARKS.get(kind, "Blocked"))Why it works A dictionary lets the label change without changing the C tile. The sign is drawn above pavement paint.
-
Redraw with rain
Choose Switch weather and watch pavement colours and rain strokes. Follow rainy and the redraw call in change_weather.
queue_redraw()Why it works queue_redraw schedules Godot to paint again reading the new weather. The text grid keeps the same stall positions.
Watch the values change
-
Open rainy is false.
What you see. The pavement is dry. -
Switch weather rainy becomes true and Godot redraws.
What you see. Rain strokes appear without moving the stalls. -
Add # to PLAN One tile matches the blocked marker.
What you see. It now has a dark background and a Blocked label.
Predict before you run Will weather move the bakery to another square?
Reveal the answer
No. The palette and marks use rainy. Location comes from the unchanged plan.
Complete checkpoint
A seven-column street with four stall labels. Switch weather changes the look while the plan remains stable.
main.gd
extends Control
const PLAN := ["..A....","...#...","..#..B.","C......","...#...","...F..."]
const MARKS := {"A": "Apples", "B": "Bread", "F": "Flowers", "C": "Collect"}
const TILE := Vector2(96, 47)
const ORIGIN := Vector2(145, 147)
var rainy := false
var status: Label
func _ready() -> void:
heading("Paint Briar Lane in layers", "STREET ART")
status = label("Dry pavement • same four stall signs", Vector2(46, 454), 18)
button("Switch weather", Vector2(715, 445), change_weather)
func change_weather() -> void:
rainy = not rainy
status.text = "Rainy pavement • same four stall signs" if rainy else "Dry pavement • same four stall signs"
queue_redraw()
func _draw() -> void:
base()
draw_rect(Rect2(ORIGIN - Vector2(18, 12), TILE * Vector2(7, 6) + Vector2(36, 24)), Color("#314b62"))
for row in range(PLAN.size()):
for column in range(PLAN[row].length()):
var kind: String = PLAN[row][column]
var at := ORIGIN + Vector2(column, row) * TILE
var paint := Color("#345975") if rainy else Color("#466575")
if kind == "#":
paint = Color("#192d44")
elif kind in MARKS:
paint = Color("#368678")
draw_rect(Rect2(at, TILE - Vector2(3, 3)), paint)
if kind != ".":
var sign_text: String = str(MARKS.get(kind, "Blocked"))
draw_string(ThemeDB.fallback_font, at + Vector2(10, 29), sign_text, HORIZONTAL_ALIGNMENT_LEFT, -1, 15, PAPER)
if rainy and kind == "." and (row + column) % 3 == 0:
draw_line(at + Vector2(20, 33), at + Vector2(71, 33), Color("#77a9b8"), 2.0)
const INK := Color("#173353")
const PAPER := Color("#fff4db")
const MINT := Color("#a8e0c1")
const GOLD := Color("#ffd291")
func heading(caption: String, topic: String) -> void:
label("MARKET DAY LONDON / " + topic, Vector2(44, 36), 15, GOLD)
label(caption, Vector2(44, 66), 31)
func label(words: String, at: Vector2, pixels: int = 20, ink: Color = PAPER) -> Label:
var item := Label.new()
item.text = words
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(words: String, at: Vector2, action: Callable, width: float = 164.0) -> Button:
var control := Button.new()
control.text = words
control.position = at
control.custom_minimum_size = Vector2(width, 43)
control.pressed.connect(action)
add_child(control)
return control
func base(colour: Color = Color("#193652")) -> void:
draw_rect(Rect2(Vector2.ZERO, size), Color("#11263e"))
draw_rect(Rect2(Vector2(22, 20), size - Vector2(44, 40)), colour)
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 PLAN := ["..A....","...#...","..#..B.","C......","...#...","...F..."]The six strings form one shared map. One character describes one tile and the brackets make the rows an Array. -
const MARKS := {"A": "Apples", "B": "Bread", "F": "Flowers", "C": "Collect"}The dictionary translates map keys into stall signs. Changing a sign here updates every matching tile. -
const TILE := Vector2(96, 47)This Vector2 pairs the horizontal and vertical steps between tile corners in pixels. -
const ORIGIN := Vector2(145, 147)Leave room for the title and give the board an upper-left corner at pixel 145, 147. -
var rainy := falseCreates a variable named rainy. 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("Paint Briar Lane in layers", "STREET ART")Calls heading with the values in its parentheses. -
status = label("Dry pavement • same four stall signs", Vector2(46, 454), 18)Stores the new value in status. The expression calls label with the values in its parentheses. -
button("Switch weather", Vector2(715, 445), change_weather)Calls button with the values in its parentheses. -
func change_weather() -> void:Defines change weather, 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. -
rainy = not rainyThe Boolean operator not flips the current weather. One press switches to rain and the next returns to dry. -
status.text = "Rainy pavement • same four stall signs" if rainy else "Dry pavement • same four stall signs"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 draw the map again. It will call _draw() with the changed weather value. -
func _draw() -> void:Godot calls this when the node needs drawing. The instructions inside paint the current state. -
base()Calls base with the values in its parentheses. -
draw_rect(Rect2(ORIGIN - Vector2(18, 12), TILE * Vector2(7, 6) + Vector2(36, 24)), Color("#314b62"))Multiply the tile dimensions by seven columns and six rows, then add a border on each edge. -
for row in range(PLAN.size()):Repeats the indented instructions for each value in range(PLAN.size()). -
for column in range(PLAN[row].length()):For each row, loop over its columns. Reading PLAN[row][column] then gives one letter or symbol. -
var kind: String = PLAN[row][column]Creates a variable named kind. The expression looks up the item or key written between the square brackets. The type after the colon says what kind of value it can hold. -
var at := ORIGIN + Vector2(column, row) * TILEMultiply the column and row by their tile steps, then add ORIGIN. The multiplication matches each coordinate with its own step size. -
var paint := Color("#345975") if rainy else Color("#466575")Creates a variable named paint. The expression builds a colour from these values. Godot infers the type from the first value. -
if kind == "#":Checks kind == "#". The indented instructions below run only if this test passes. -
paint = Color("#192d44")Stores the new value in paint. The expression builds a colour from these values. -
elif kind in MARKS:The in operator asks if the character has a key in MARKS. All four marked tiles get the same stall background. -
paint = Color("#368678")Stores the new value in paint. The expression builds a colour from these values. -
draw_rect(Rect2(at, TILE - Vector2(3, 3)), paint)Take three pixels from width and height to leave room between tiles. -
if kind != ".":Checks kind != ".". The indented instructions below run only if this test passes. -
var sign_text: String = str(MARKS.get(kind, "Blocked"))get() returns the sign for a known key or the fallback text Blocked. The str() conversion supplies the type that draw_string expects. -
draw_string(ThemeDB.fallback_font, at + Vector2(10, 29), sign_text, HORIZONTAL_ALIGNMENT_LEFT, -1, 15, PAPER)Paints a piece of text with a font at a position measured from the node's origin. -
if rainy and kind == "." and (row + column) % 3 == 0:Both rain and an open tile are required. The remainder of row plus column divided by three scatters puddles in a repeating pattern. -
draw_line(at + Vector2(20, 33), at + Vector2(71, 33), Color("#77a9b8"), 2.0)Paints a line between two points with the chosen colour and width. -
const INK := Color("#173353")Creates a constant named INK. The expression builds a colour from these values. Godot infers the type from the first value. -
const PAPER := Color("#fff4db")Creates a constant named PAPER. The expression builds a colour from these values. Godot infers the type from the first value. -
const MINT := Color("#a8e0c1")Creates a constant named MINT. The expression builds a colour from these values. Godot infers the type from the first value. -
const GOLD := Color("#ffd291")Creates a constant named GOLD. The expression builds a colour from these values. Godot infers the type from the first value. -
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("MARKET DAY LONDON / " + topic, Vector2(44, 36), 15, GOLD)Calls label with the values in its parentheses. -
label(caption, Vector2(44, 66), 31)Calls label with the values in its parentheses. -
func label(words: String, at: Vector2, pixels: int = 20, ink: Color = PAPER) -> 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 = wordsUpdates item.text, which controls the words a player sees. The expression reads words. -
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(words: String, at: Vector2, action: Callable, width: float = 164.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 control := Button.new()Creates a variable named control. The expression creates a new Button object. Godot infers the type from the first value. -
control.text = wordsUpdates control.text, which controls the words a player sees. The expression reads words. -
control.position = atUpdates control.position, which controls the node's local x and y location. The expression reads at. -
control.custom_minimum_size = Vector2(width, 43)Updates control.custom_minimum_size, which controls the smallest space the layout should reserve for this control. The expression packs x and y into one value. -
control.pressed.connect(action)Links a signal to the function that should run when the event happens. -
add_child(control)Adds the new node to the scene tree so that Godot can run and draw it. -
return controlFinishes the function and hands its result back to the caller. The expression reads control. -
func base(colour: Color = Color("#193652")) -> void:Defines base, 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. -
draw_rect(Rect2(Vector2.ZERO, size), Color("#11263e"))Paints a rectangle at the given position and size. -
draw_rect(Rect2(Vector2(22, 20), size - Vector2(44, 40)), colour)Paints a rectangle at the given position and size.
Find and fix a bug
If a new stall has no label, add its character and name to MARKS. A lower-case key is a distinct character.
Try a change
Ages 10–12 can add their own pavement colours. Ages 13–16 can add a weather theme and test readable label contrast on both palettes.