Midnight Deck Dash · Lesson 04 of 50 · Beginner · About 30 min
Sol is waiting two columns across and one row down on the deck plan. Make the map show that position as a brass token.

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, return, origin, tile size, _draw, Color.
-
Set a practice viewport
Open Project > Project Settings. Under Display > Window, set Viewport Width to 960 and Viewport Height to 540. The completed checkpoint already has these settings.
Why it works A known canvas size keeps the whole practice board visible later when you add keys and buttons.
-
Store an address with two numbers
Open main.gd and use the deck script shown in this checkpoint. Find player_cell in the fields. Read it as column 2, row 1, counting each from zero.
var player_cell := Vector2i(2, 1)Why it works Vector2i holds two whole-number coordinates. In this game x is the column and y is the row. The first cell is at (0, 0).
-
Name the board measurements
Put BOARD_ORIGIN and TILE_SIZE above the player variable. The origin is 40 pixels across and 124 pixels down from the top-left of the window.
const BOARD_ORIGIN := Vector2(40, 124) const TILE_SIZE := 76Why it works Layout constants make it possible for several draw instructions to share the same deck measurements.
-
Calculate a cell’s centre
Add cell_centre below _refresh_log. Read the calculation in three parts: scale the address, add the board origin and move half a tile to the centre.
func cell_centre(cell: Vector2i) -> Vector2: return BOARD_ORIGIN + Vector2(cell) * TILE_SIZE + Vector2.ONE * (TILE_SIZE / 2.0)Why it works Vector2 can hold fractional coordinates suited to drawing. Vector2.ONE is (1, 1) and return hands the resulting position back to the draw instructions.
-
Paint a token at that point
Add _draw and run with F5. The rectangle paints the background. The large brass circle is painted next, then the smaller dark circle is painted at the same point.
func _draw() -> void: draw_rect(Rect2(Vector2.ZERO, get_viewport_rect().size), OCEAN) draw_circle(cell_centre(player_cell), 20.0, BRASS) draw_circle(cell_centre(player_cell), 7.0, INK)Why it works Godot calls _draw to paint shapes. The instruction order controls which shapes are visible on top.
-
Move the starting address on paper first
Work out the centre of (0, 0), then change player_cell in a working copy and compare the result. Restore (2, 1) after checking.
Why it works The even tile width gives a 38-pixel shift to the middle, even when the column and row are zero.
Watch the values change
-
Read the address player_cell is (2, 1).
What you see. The two numbers are measured in tiles. -
Scale and offset Combine (152, 76), the origin (40, 124) and the half-tile pair (38, 38).
What you see. The centre is (230, 238) pixels. -
Draw the two circles The circles use one centre and different radii.
What you see. A brass ring marks Sol.
Predict before you run Find the centre if player_cell is changed to (0, 0).
Reveal the answer
The centre is (78, 162). The zero cell offsets leave the origin (40, 124), and the half tile adds (38, 38).
Complete checkpoint
A navy screen displays the brass courier token and the text says Courier at (2, 1).
main.gd
extends Control
const BOARD_ORIGIN := Vector2(40, 124)
const TILE_SIZE := 76
const DECK_SIZE := Vector2i(7, 5)
const OCEAN := Color("#0b2137")
const BRASS := Color("#f2bc64")
const INK := Color("#07111e")
var player_cell := Vector2i(2, 1)
var sign: Label
func _ready() -> void:
sign = Label.new()
sign.position = Vector2(40, 47)
sign.add_theme_font_size_override("font_size", 28)
add_child(sign)
_refresh_log()
func _refresh_log() -> void:
sign.text = "Promenade | Courier at (%d, %d)" % [player_cell.x, player_cell.y]
func cell_centre(cell: Vector2i) -> Vector2:
return BOARD_ORIGIN + Vector2(cell) * TILE_SIZE + Vector2.ONE * (TILE_SIZE / 2.0)
func _draw() -> void:
draw_rect(Rect2(Vector2.ZERO, get_viewport_rect().size), OCEAN)
draw_circle(cell_centre(player_cell), 20.0, BRASS)
draw_circle(cell_centre(player_cell), 7.0, INK)
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 ControlGives the root of this lesson the positioning and sizing features of a Godot Control, which is the type created by choosing User Interface in the scene editor. -
const BOARD_ORIGIN := Vector2(40, 124)Defines the board’s top-left pixel position. All tile drawing starts relative to these two coordinates. -
const TILE_SIZE := 76Defines the width and height of one square tile in pixels. A move of one cell means a shift of 76 pixels in the drawing. -
const DECK_SIZE := Vector2i(7, 5)Defines seven columns and five rows. With zero-based addresses the last tile is (6, 4). -
const OCEAN := Color("#0b2137")Names the dark blue background colour. The hash sits inside a colour string here, so it is not a GDScript comment. -
const BRASS := Color("#f2bc64")Names the gold used by the courier and cargo art from a hex colour triplet. -
const INK := Color("#07111e")Names the dark colour used to draw smaller shapes on top of the gold for contrast. -
var player_cell := Vector2i(2, 1)Places the courier in the third column and second row because grid coordinates start at zero. -
var sign: LabelDeclares a script-wide reference with the Label type. _ready fills it, and other functions can then update the same on-screen label. -
func _ready() -> void:Godot calls this method after the scene is ready. Its indented steps make the dispatch label and any controls before the player can use them. It does not return a value. -
sign = Label.new()Makes the label and saves it to the script-wide sign variable. This line uses assignment without var so it does not create a second, local variable named sign. -
sign.position = Vector2(40, 47)Places the address readout near the top of the practice window, 40 pixels from the left and 47 down. -
sign.add_theme_font_size_override("font_size", 28)Makes the coordinate readout 28 points tall using a font size override for this particular Label. -
add_child(sign)Adds the Label to this node so it becomes part of the active scene and Godot can display its text. -
_refresh_log()Rebuilds the address text from the current position. A later move or reset calls the same helper after it changes player_cell. -
func _refresh_log() -> void:Defines where the courier’s position is converted into readable text. Keeping it here gives setup, movement and reset a shared update. -
sign.text = "Promenade | Courier at (%d, %d)" % [player_cell.x, player_cell.y]Builds the position text with x as the column first and y as the row second. Both coordinates are whole numbers. -
func cell_centre(cell: Vector2i) -> Vector2:Converts a grid address to a pixel position. The input cell has whole numbers, and the Vector2 result can represent fractional pixels. -
return BOARD_ORIGIN + Vector2(cell) * TILE_SIZE + Vector2.ONE * (TILE_SIZE / 2.0)Multiplies the column and row by the tile size, adds the board’s pixel origin, then moves half a tile across and down. For (2, 1), that yields (230, 238). -
func _draw() -> void:Godot calls this drawing method when the canvas needs a frame. Earlier drawing lines appear under later lines. -
draw_rect(Rect2(Vector2.ZERO, get_viewport_rect().size), OCEAN)Paints the dark blue behind the whole viewport. Rect2 combines a top-left point and a size. -
draw_circle(cell_centre(player_cell), 20.0, BRASS)Draws one brass circle at the courier’s current pixel centre with a 20-pixel radius. -
draw_circle(cell_centre(player_cell), 7.0, INK)Adds a dark inner circle at the same centre. Drawing a smaller circle after the brass one produces the ring effect.
Find and fix a bug
If Sol seems to sit on an edge, check the half-tile addition. Leaving it out puts the token at the cell’s corner.
Try a change
Choose another address. Calculate its centre by hand, change the script and run. Try both (1, 2) and (6, 4).