Tilemaps, Cameras, and World Structure
▶ PRESS START
Lucas P. Cordova, Ph.D.
Willamette University | Tuesday, October 27, 2026
Lab 5 is due Thursday, October 29, 9:59 PM, and Thursday is playtest day: bring a build. No class Tuesday, November 3 (Advising Day). The alpha gate is Thursday, November 5.
The quest log
| When | What | Where |
|---|---|---|
| Thu Oct 29, 9:59 PM | Lab 5: game feel | Push to main, repo URL on Canvas |
| Thu Oct 29, in class | Playtest day: the whole class plays every game; focus-test reports | Bring a build that runs from a fresh clone |
| Tue Nov 3 | No class: Advising Day | Sprint time; student hours as usual |
| Thu Nov 5, 9:59 PM | Alpha gate and Stakeholder Review 2 in class | All MUSTs in or formally cut; tag alpha |
| Thu Nov 12, 9:59 PM | Sprint 2 report and peer evaluation | docs/sprint-2.md, FEEDBACK.md |
Nine days to the alpha, and one of the class days in between is a holiday. Today's studio is the last one before the gate.
Five rectangles by hand, three hundred by tilemap
WALLS.TSCN, SINCE WEEK 5Walls (StaticBody2D) ├─ TopRect (ColorRect) ├─ BottomRect (ColorRect) ├─ LeftRect (ColorRect) ├─ RightRect (ColorRect) ├─ BarRect (ColorRect) ├─ Top (CollisionShape2D) ├─ Bottom (CollisionShape2D) ├─ Left (CollisionShape2D) ├─ Right (CollisionShape2D) └─ Bar (CollisionShape2D)
A TileSet is the alphabet: a texture cut into equal squares, where each square (a tile) can carry collision shapes, terrain rules, and custom data. A TileMapLayer is a sentence written in that alphabet: a grid of cells, each holding one tile [1].
| A tile knows | Set where | Pays off when |
|---|---|---|
| Its picture: a region of the atlas texture | TileSet panel, atlas source | Every wall looks right without a single Sprite2D |
| Its collision polygon, on a physics layer | TileSet panel, per tile | The map is the StaticBody2D: walls stop Blitz |
| Its terrain bits (edges, corners) | TileSet, Terrain Sets | Autotiling picks the corner piece for you |
| Custom data: a tag, a cost, a berry value | TileSet, Custom Data Layers | Code asks the map what is under a cell |
Today: the first two rows. Terrains and custom data are in the sources for the teams that want them.
In main.tscn, on demo6:
The physics layer is the tileset's StaticBody2D. One checkbox here replaces five CollisionShape2Ds, and the layer map from week 2 still holds: the map is world; Blitz and the rival mask it.
The bottom panel now has TileSet and TileMap tabs:
assets/maze_tiles.png into the empty Tiles column on the left of the panel.Only the wall gets a polygon. A floor tile with collision is a floor nobody can walk on, and the symptom is Blitz frozen at spawn.
maze_tiles.png is already in assets/ on demo6: 144 by 48, three tiles, original pixels.
Open the TileMap tab at the bottom:
72, 72.Blitz stops at every painted wall and walks out of the window. The tiles work. The screen is the new problem.
Catch-up: git checkout demo7-lap1 has the whole maze painted.
| Symptom | Cause, and the cure |
|---|---|
| Blitz walks straight through the walls | No physics layer on the TileSet, or the polygon is on the floor tile. Inspector: Physics Layers has one element; wall tile has the rectangle. |
| Blitz is frozen at spawn | Spawned inside a wall cell, or the floor tile got a polygon. Move the spawn to a painted floor cell. |
| Every tile is a thin sliver | Tile Size was set after the texture. Remove the atlas source, set 48 by 48, drag the texture in again. |
| Painting does nothing | No tile selected in the palette, or the Eraser is active. Click the wall tile, pick Paint or Rect. |
| Walls show, but the window is empty on run | Ran the current scene with a tile scene open. Run the project. |
One node that follows, with limits and smoothing
A Camera2D decides which part of the world the window shows. Whichever camera is current (the first one in the tree, or the one you make current) centers the view on its own position, every frame [2].
Open player.tscn (double-click it in the FileSystem dock):
0, 0: that is Blitz's center.The view follows Blitz, eases into turns, and stops dead at the maze's edge. Four properties, zero code.
Catch-up: git checkout demo7-lap2.
Those four limit numbers describe this maze. A second maze with a different size makes them wrong, which is lap 3's problem.
Fingers up. We set every limit back to its default (a huge number) and run. Blitz walks to the right edge of the maze. The window shows:
1: the maze edge against the right side of the window, like before.
2: half maze, half empty void, with Blitz in the center.
3: the same thing; the maze is bigger than the window anyway.
Then we try it, and then we put the limits back.
A maze is a scene; the game runs a gauntlet of them
MAZES/MAZE_1.TSCNMaze (Node2D) maze.gd ├─ Tiles (TileMapLayer) the painted world ├─ PlayerSpawn (Marker2D) where Blitz starts ├─ RivalSpawn (Marker2D) where the rival starts ├─ Patrol (Node2D) │ ├─ Point1 (Marker2D) the rival's lane │ └─ Point2 (Marker2D) ├─ Fig (fig.tscn) └─ Exit (Area2D) snacks layer, masks player └─ CollisionShape2D
main.tscn.class_name Maze extends Node2D signal exited @onready var tiles: TileMapLayer = $Tiles @onready var player_spawn: Marker2D = $PlayerSpawn @onready var rival_spawn: Marker2D = $RivalSpawn func patrol_points() -> Array[Vector2]: var points: Array[Vector2] = [] for marker in $Patrol.get_children(): points.append(marker.position) return points func bounds() -> Rect2i: var cells := tiles.get_used_rect() var size := tiles.tile_set.tile_size return Rect2i(cells.position * size, cells.size * size) func _on_exit_body_entered(_body: Node2D) -> void: exited.emit()
class_name Maze gives the brain a type to hold: var maze: Maze.patrol_points() reads the lane off the markers. Move a marker in the editor, the rival walks a new route. No code changes.bounds() asks the tiles how big they are: get_used_rect() is in cells, so multiply by the tile size.exited: the brain never reaches into the maze's children.func _load_maze(index: int) -> void: if maze != null: maze.queue_free() maze_index = index maze = mazes[index].instantiate() add_child(maze) move_child(maze, 0) maze.exited.connect(_on_maze_exited) player.position = maze.player_spawn.position rival.position = maze.rival_spawn.position rival.patrol_points = maze.patrol_points() rival.calm() var box := maze.bounds() camera.limit_left = box.position.x camera.limit_top = box.position.y camera.limit_right = box.end.x camera.limit_bottom = box.end.y camera.reset_smoothing()
mazes is an exported Array[PackedScene]: drag the maze scenes into the Inspector in gauntlet order.queue_free() the old maze, instantiate() the next, move_child(maze, 0) so it draws under everything.bounds() now; lap 2's hand-typed numbers are gone, and a maze of any size works.reset_smoothing() so the view snaps to the new spawn instead of panning across two mazes.@export var mazes: Array[PackedScene] = [] func _on_maze_exited() -> void: if maze_index + 1 < mazes.size(): _load_maze(maze_index + 1) else: _change_state(State.ESCAPED)
Pac-Blitz, as promised in week 1: Blitz runs a gauntlet of mazes, one at a time. The exit pad loads the next; the last one ends the run in a new state, ESCAPED. Four states now, one more arm in the brain's door.
mazes/maze_3.tscn, drag it into the array. Zero lines of code.func _can_see_player() -> bool: var space := get_world_2d().direct_space_state var ray := PhysicsRayQueryParameters2D.create(global_position, player.global_position, 1) return space.intersect_ray(ray).is_empty()
State.CHASE: velocity = to_player.normalized() * stats.chase_speed if to_player.length() > stats.give_up_range or not _can_see_player(): _change_state(State.RETURN) State.RETURN: velocity = (leash - global_position).normalized() * stats.patrol_speed if global_position.distance_to(leash) < 12.0: _change_state(State.PATROL) elif to_player.length() < stats.sight_range and _can_see_player(): _change_state(State.CHASE)
leash it recorded on entering CHASE.NavigationAgent2D plus a navigation layer on the tileset [1]. In the sources; another week.| Rule | Why | In the maze |
|---|---|---|
| Loops, and a few dead ends | A loop gives the player a way out; a dead end is a trap the designer set | Maze 2 is a perfect maze with fourteen walls knocked out |
| Show the exit early | A goal the player can see turns wandering into planning | The yellow pad sits at the far corner, in view from the first corridor |
| One new thing per place | Teach, then test; the player learns the mechanic before the maze punishes it | Maze 1: the rival's lane. Maze 2: the fig matters |
| Bigger than the screen, on purpose | What the camera hides is tension; what it shows is information | The rival is often out of frame; its print line is not |
| Paint fast, play faster | A tilemap level costs minutes; the only way to know it works is to play it | Thursday is playtest day |
Your world, on your laptop, in twenty minutes
| Your game | Build this now |
|---|---|
| A world bigger than one screen (platformer, top-down, dungeon) | A TileMapLayer for the world with a physics layer, a Camera2D on the player with limits and smoothing |
| One screen, but walls or floors placed by hand | Replace the hand-placed StaticBody2Ds with a painted TileMapLayer; keep the camera fixed |
| Several places already (rooms, levels, tracks) | Make one place its own scene with Marker2D spawns and an exit signal; load it from the brain |
| None of the above | Do it in a fresh clone of rival-brains on demo6: paint a maze, add the camera, run |
Teams work in the team repo on a branch named tiles; one laptop drives, the other reads the slides and the demo7 branch. Any texture works as an atlas: a 32 by 32 square per tile is enough to start.
Twenty minutes, on the timer:
Stuck? The Nothing happened? slide, then the demo7 branch, then a hand up.
tiles branch now. A painted level is the fastest alpha progress most teams will make this week.Tiles carry the look and the collision. The map carries positions. The scene carries the place. The brain carries the order.
Sprint 2, toward the alpha
The rest of class is yours. The Sprint 2 board from Thursday is the to-do list; the top five cards should read like the alpha gate.
| Ask yourselves | Because |
|---|---|
Does the game run from a fresh clone of main right now? | Thursday is playtest day; a build that only runs on one laptop is a build nobody can play |
| Which MUST has no card, or no owner? | The alpha rubric counts every MUST as in, or cut in writing |
| Did today's build-along move an alpha card? | If the world is painted now, the card that said build level 1 is probably Done |
| Is Lab 5 on track for Thursday night? | The shell (title, HUD, pause, clear) is also an alpha rubric row: do it once, use it twice |
I am walking the room with the alpha checklist. Flag me down for anything stuck.
What you know now
Thu Oct 29: Lab 5 due 9:59 PM, and playtest day in class: bring a build. Tue Nov 3: no class. Thu Nov 5: the alpha gate and Stakeholder Review 2.
github.com/LucasCordova/rival-brains, branch demo7 (tags demo7-lap1 and demo7-lap2).