Museum of Lost Lights · Lesson 10 of 50 · Beginner to intermediate · About 46 min
Light enters from the left. A single turn at the mirror can send it toward the sleeping shell or away from it. Can you make both paths and choose the right one?

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/09 when the lesson builds on prior work, or copy the checkpoints/10 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 calculation without editing game state, Vector2 equality, function return, conditional expression, draw_circle, draw_line, source, destination.
-
Find the four board landmarks
Import Lesson 10 and run main.tscn. Find the amber source, the centred mirror, the upper shell and the lower dock. Open main.gd and compare their Vector2 values.
const SOURCE := Vector2(99, 284) const SHELL := Vector2(189, 194) const DOCK := Vector2(189, 374)Why it works Constants give these positions stable names. SOURCE and CENTRE have the same y, so the beam comes in horizontally. The two destinations have CENTRE’s x, so the outgoing beam is vertical.
-
Read the rule without drawing anything
Find beam_destination and sketch each choice on the 3-by-3 board. For the rising mirror, follow the return. Then read what happens with the falling mirror.
func beam_destination() -> Vector2: if facing == Mirror.RISING: return SHELL return DOCKWhy it works The function checks facing and gives back a position. return ends the function as soon as the proper destination is known. This function decides where the beam goes. The drawing is a different job.
-
Connect the two beam segments
Read the two draw_line calls in sequence. Start at SOURCE, stop at CENTRE, then keep going to destination. The centre must appear in both lines.
draw_line(SOURCE, CENTRE, Color("#41e0f1"), 5.0, true) draw_line(CENTRE, destination, Color("#41e0f1"), 5.0, true)Why it works Two straight segments give the beam one corner. Both calls use the same colour, width and smooth-edge setting so they look like one ray.
-
Choose the shell colour
Read the colour choice inside draw_circle. Put the two colour values on either side of the if and else. Tap Rotate mirror and check the shell with light on and off.
Color("#41e0f1") if destination == SHELL else Color("#618188")Why it works In GDScript, value_if_true if condition else value_if_false gives one value. This use chooses a colour. The branch in refresh_readout explains the result with words as well.
-
Make the drawing and words agree
Run and record the first outcome. Tap once and check both the text and the beam, then tap again. Check the same three steps with keyboard Space after the button has focus.
if beam_destination() == SHELL:Why it works _draw and refresh_readout both ask beam_destination for an answer. Keeping the puzzle decision in one function helps the visible beam and the message stay in sync.
Watch the values change
-
Start with the rising mirror beam_destination returns SHELL
What you see. The outgoing ray goes north. -
Read the shell status The destination equals the shell’s coordinate
What you see. The shell is bright and the label says North. -
Rotate once facing changes to Mirror.FALLING and beam_destination returns DOCK
What you see. The outgoing ray goes south and the shell dims. -
Rotate again The rising state and SHELL return
What you see. The shell wakes again.
Predict before you run If the falling mirror returned SHELL while the rising mirror also returned SHELL, what control would still work and what would stop changing?
Reveal the answer
The mirror would still turn after a tap. Both beam segments would keep reaching the same places. The shell would stay bright because both choices return SHELL.
Complete checkpoint
The beam begins going east from the amber point. With the rising mirror it goes north and wakes the shell. With the falling mirror it goes south to the dock.
main.gd
extends Control
enum Mirror {RISING, FALLING}
const ORIGIN := Vector2(54, 149)
const CELL: float = 90.0
const CENTRE := Vector2(189, 284)
const SOURCE := Vector2(99, 284)
const SHELL := Vector2(189, 194)
const DOCK := Vector2(189, 374)
var facing: Mirror = Mirror.RISING
var readout: Label
func _ready() -> void:
make_heading()
readout = Label.new()
readout.position = Vector2(54, 101)
readout.add_theme_font_size_override("font_size", 22)
add_child(readout)
var turn_button := Button.new()
turn_button.text = "Rotate mirror"
turn_button.position = Vector2(356, 181)
turn_button.custom_minimum_size = Vector2(220, 62)
turn_button.add_theme_font_size_override("font_size", 22)
turn_button.pressed.connect(turn_mirror)
add_child(turn_button)
turn_button.grab_focus()
refresh_readout()
func turn_mirror() -> void:
if facing == Mirror.RISING:
facing = Mirror.FALLING
else:
facing = Mirror.RISING
refresh_readout()
queue_redraw()
func mirror_offset() -> Vector2:
if facing == Mirror.RISING:
return Vector2(26, -26)
return Vector2(26, 26)
func _draw() -> void:
for row in range(3):
for column in range(3):
var corner := ORIGIN + Vector2(column, row) * CELL
draw_rect(Rect2(corner, Vector2(CELL - 4, CELL - 4)), Color("#22414c"))
var destination := beam_destination()
draw_circle(CENTRE, 35.0, Color("#326b72"))
draw_circle(SOURCE, 18.0, Color("#ffdb9b"))
draw_circle(SHELL, 19.0, Color("#41e0f1") if destination == SHELL else Color("#618188"))
draw_circle(DOCK, 19.0, Color("#8bb7cf"))
draw_line(SOURCE, CENTRE, Color("#41e0f1"), 5.0, true)
draw_line(CENTRE, destination, Color("#41e0f1"), 5.0, true)
var offset := mirror_offset()
draw_line(CENTRE - offset, CENTRE + offset, Color("#ffd381"), 8.0, true)
func beam_destination() -> Vector2:
if facing == Mirror.RISING:
return SHELL
return DOCK
func refresh_readout() -> void:
if beam_destination() == SHELL:
readout.text = "North · The shell is awake!"
else:
readout.text = "South · Try bouncing light toward the shell."
func make_heading() -> void:
var heading := Label.new()
heading.text = "Ocean Gallery · One mirror, two paths"
heading.position = Vector2(52, 36)
heading.add_theme_font_size_override("font_size", 38)
heading.add_theme_color_override("font_color", Color("#ffe1a8"))
add_child(heading)
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 ControlThe scene root behaves like a Control, the kind of Godot node used for a game’s text, controls and other interface pieces. -
enum Mirror {RISING, FALLING}Name the two possible mirror tilts. RISING looks like a forward slash and FALLING tilts down as it goes right. -
const ORIGIN := Vector2(54, 149)Pin the top-left corner of the floor at screen position (54, 149). Every tile measures its position from this point. -
const CELL: float = 90.0Give every cell a 90-pixel pitch and store it as a decimal-capable float. The tile colour leaves a small gap inside that pitch. -
const CENTRE := Vector2(189, 284)Put the mirror in the centre of the middle tile. The left edge plus 135 and the top edge plus 135 lead to this point. -
const SOURCE := Vector2(99, 284)Anchor the lamp on the left tile on the same y coordinate as the mirror. The first leg of the beam will always travel east. -
const SHELL := Vector2(189, 194)Put the sleeping shell one cell north of the mirror. Its y value is 90 lower than CENTRE.y. -
const DOCK := Vector2(189, 374)Put the safe dock one cell south of the mirror. Its y value is 90 higher than CENTRE.y. -
var facing: Mirror = Mirror.RISINGStart with the rising orientation. This changeable value is the one source for the next mirror drawing. -
var readout: LabelReserve a name for a Label node. The setup function puts the real Label there before the game first displays it. -
func _ready() -> void:Godot automatically calls this setup function after bringing this node and its children into the scene. The code below it prepares the first frame. -
make_heading()Build the title before the room makes its other controls. -
readout = Label.new()Create the Label now. Its stored reference lets later signal handlers change the same sign. -
readout.position = Vector2(54, 101)Use two numbers to give this control its position, measured right and down from the root. -
readout.add_theme_font_size_override("font_size", 22)Set a larger or smaller font here without changing the typography on the other controls. -
add_child(readout)Put the stored Label on the visible scene. Changes to its text now show on screen. -
var turn_button := Button.new()Make the player control that will ask the mirror to move. -
turn_button.text = "Rotate mirror"Tell players exactly what the next activation does. -
turn_button.position = Vector2(356, 181)Place the control to the right of the board where it will not cover a tile. -
turn_button.custom_minimum_size = Vector2(220, 62)Keep the tap area at least 220 pixels wide and 62 pixels tall. -
turn_button.add_theme_font_size_override("font_size", 22)Increase the button caption to 22 pixels so its instruction is easy to read. -
turn_button.pressed.connect(turn_mirror)Give the pressed signal the turn_mirror function. Every future activation will call it. -
add_child(turn_button)Display the control under the scene root and let it receive input. -
turn_button.grab_focus()Move keyboard focus to this control. After the window has focus, the player can activate it with Space as well as tapping it. -
refresh_readout()Use the starting mirror orientation to describe the initial beam destination. -
func turn_mirror() -> void:Group what happens after the player chooses Rotate mirror. -
if facing == Mirror.RISING:Check whether the current mirror choice equals RISING. -
facing = Mirror.FALLINGStore the falling orientation for the next label update and drawing. -
else:Runs the indented fallback instructions if none of the earlier tests passed. -
facing = Mirror.RISINGStore the rising orientation so the next update returns to that tilt. -
refresh_readout()Refresh the words from the new destination before scheduling another drawing pass. -
queue_redraw()Ask Godot to run _draw again. In the new drawing the code will read the new value of facing. -
func mirror_offset() -> Vector2:Find the position of one end of the mirror relative to its centre. The drawing also uses the opposite point. -
if facing == Mirror.RISING:Check whether the current mirror choice equals RISING. -
return Vector2(26, -26)Use an endpoint 26 pixels right and 26 pixels up. On screen, negative y moves upward. -
return Vector2(26, 26)Use an endpoint 26 pixels right and 26 pixels down. The first return already handled the rising choice. -
func _draw() -> void:Godot uses this callback to collect drawing commands for the board and its pieces. -
for row in range(3):Draw three rows. The row count starts at zero so the first row begins at ORIGIN. -
for column in range(3):For each of those rows, draw three columns before advancing to the next row. -
var corner := ORIGIN + Vector2(column, row) * CELLMultiply the grid address by 90 to turn it into a pixel offset, then add the board’s top-left corner. -
draw_rect(Rect2(corner, Vector2(CELL - 4, CELL - 4)), Color("#22414c"))Paint a filled teal square at this corner. Four pixels of unpainted width and height leave a visible seam between neighbours. -
var destination := beam_destination()Find where the beam should land this time. Both the outgoing line and the shell’s appearance use this value. -
draw_circle(CENTRE, 35.0, Color("#326b72"))Paint the round teal base of the mirror at the middle tile. -
draw_circle(SOURCE, 18.0, Color("#ffdb9b"))Mark the amber lamp source that begins the beam path. -
draw_circle(SHELL, 19.0, Color("#41e0f1") if destination == SHELL else Color("#618188"))Paint the sleeping shell bright cyan when the beam reaches SHELL. Otherwise the conditional expression picks the dim colour. -
draw_circle(DOCK, 19.0, Color("#8bb7cf"))Show the dock as a blue landing circle. That gives the beam a visible lower destination. -
draw_line(SOURCE, CENTRE, Color("#41e0f1"), 5.0, true)Draw the incoming eastbound line from the lamp to the mirror. -
draw_line(CENTRE, destination, Color("#41e0f1"), 5.0, true)Draw the outgoing line from that same mirror position to the point chosen by beam_destination. -
var offset := mirror_offset()Read a drawing offset that matches the current tilt. -
draw_line(CENTRE - offset, CENTRE + offset, Color("#ffd381"), 8.0, true)Put one end of the golden mirror on each side of its centre. Draw it 8 pixels thick with smoothed edges. -
func beam_destination() -> Vector2:Calculate the destination separately from drawing and words. Each part can ask this function for the same answer. -
if facing == Mirror.RISING:Use the rising tilt to decide if the eastbound beam should leave toward the north. -
return SHELLReturn the upper shell coordinate and leave the function. -
return DOCKIf the rising test did not pass, return the lower dock coordinate. -
func refresh_readout() -> void:Keep the code that changes the on-screen words together so both setup and player actions can call it. -
if beam_destination() == SHELL:Compare two Vector2 values to ask whether the calculated destination has the shell’s x and y coordinates. -
readout.text = "North · The shell is awake!"Tell the player that the northward path was successful. -
else:Use the alternate feedback when the destination is the dock. -
readout.text = "South · Try bouncing light toward the shell."Give the player a clue to try rotating the mirror again. -
func make_heading() -> void:Group the instructions that make the panel title. The room calls this once at startup. -
var heading := Label.new()Create a Label node and keep a reference under the name heading so the next lines all customise the same sign. -
heading.text = "Ocean Gallery · One mirror, two paths"Show the name of this museum task above its controls. -
heading.position = Vector2(52, 36)Put the title 52 pixels to the right and 36 pixels down from the root’s upper-left corner. -
heading.add_theme_font_size_override("font_size", 38)Set this heading’s font size to 38. The other labels keep their own sizes. -
heading.add_theme_color_override("font_color", Color("#ffe1a8"))Give only this label a warm gold text colour. The six characters after # describe red, green and blue light. -
add_child(heading)Connect the title to the scene tree so Godot can display it.
Find and fix a bug
If the label says the shell is awake but there is no output beam, check that the second draw_line starts at CENTRE and ends at destination, and check both calls are inside _draw. If the beam and label disagree, check both use beam_destination.
Try a change
Ages 10–12: Try five flips and predict north or south first each time. Ages 13–16: Add a second target label or move one destination to a different y coordinate. Keep the beam vertical after the mirror and test all outcomes.