CS 276 // GAME SYSTEMS IN GODOT

Bigger Than the Screen.

Tilemaps, Cameras, and World Structure

Lucas P. Cordova, Ph.D.

Willamette University  |  Tuesday, October 27, 2026

SCORE 000276HI 999999

Outline

QUEST LOG

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.

CS 276
LEVEL 01

Save Point

The quest log

SCORE 000276HI 999999

Quest log

WhenWhatWhere
Thu Oct 29, 9:59 PMLab 5: game feelPush to main, repo URL on Canvas
Thu Oct 29, in classPlaytest day: the whole class plays every game; focus-test reportsBring a build that runs from a fresh clone
Tue Nov 3No class: Advising DaySprint time; student hours as usual
Thu Nov 5, 9:59 PMAlpha gate and Stakeholder Review 2 in classAll MUSTs in or formally cut; tag alpha
Thu Nov 12, 9:59 PMSprint 2 report and peer evaluationdocs/sprint-2.md, FEEDBACK.md
CHECKPOINT

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.

CS 276
LEVEL 02

The Wall Problem

Five rectangles by hand, three hundred by tilemap

SCORE 000276HI 999999

Where the walls came from

WALLS.TSCN, SINCE WEEK 5
Walls (StaticBody2D) ├─ TopRect (ColorRect) ├─ BottomRect (ColorRect) ├─ LeftRect (ColorRect) ├─ RightRect (ColorRect) ├─ BarRect (ColorRect) ├─ Top (CollisionShape2D) ├─ Bottom (CollisionShape2D) ├─ Left (CollisionShape2D) ├─ Right (CollisionShape2D) └─ Bar (CollisionShape2D)
  • Five walls: five rectangles to draw and five shapes to size, by hand, twice each.
  • A maze on a 32 by 18 grid has about three hundred wall cells. Nobody is placing six hundred nodes.
  • Every wall is the same 48-pixel square. The only information in a wall is where it is.
  • So: define the square once, then paint positions.
CS 276

Tiles

DEFINITION

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 knowsSet wherePays off when
Its picture: a region of the atlas textureTileSet panel, atlas sourceEvery wall looks right without a single Sprite2D
Its collision polygon, on a physics layerTileSet panel, per tileThe map is the StaticBody2D: walls stop Blitz
Its terrain bits (edges, corners)TileSet, Terrain SetsAutotiling picks the corner piece for you
Custom data: a tag, a cost, a berry valueTileSet, Custom Data LayersCode 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.

CS 276

Lap 1, step 1: the layer and its set

LIVE DEMO

In main.tscn, on demo6:

  1. Select Main in the Scene dock. Add a child node: search TileMapLayer, Create. Rename it Maze.
  2. With Maze selected, in the Inspector find Tile Set, click <empty>, choose New TileSet.
  3. Click the new TileSet resource to expand it. Set Tile Size to 48 by 48. (The sprites are 32; the corridors get breathing room.)
  4. Still inside the TileSet: Physics Layers, Add Element. Set its Collision Layer to world only and clear its mask.
  5. Save the scene.
PATTERN

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.

CS 276

Lap 1, step 2: the atlas

LIVE DEMO

The bottom panel now has TileSet and TileMap tabs:

  1. Open the TileSet tab at the bottom of the editor.
  2. From the FileSystem dock, drag assets/maze_tiles.png into the empty Tiles column on the left of the panel.
  3. Godot asks whether to automatically create tiles in the atlas. Answer Yes. Three 48-pixel tiles appear: wall, floor, exit pad.
  4. Switch the panel to Select mode (top of the panel) and click the wall tile.
  5. In the panel's right column, expand Physics, then Physics Layer 0. Click the Reset to default tile shape button: a full-tile rectangle fills the wall.
  6. Save the scene.
WATCH OUT

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.

CS 276

Lap 1, step 3: paint

LIVE DEMO

Open the TileMap tab at the bottom:

  1. With Maze selected, the palette shows the three tiles. Click the wall tile.
  2. Pick the Rect tool in the panel's toolbar. Drag a border around the viewport: top row, bottom row, left column, right column.
  3. Keep dragging rectangles until the border runs past the window: the maze is 32 by 18 cells, 1536 by 864 pixels, the window is 1152 by 648.
  4. Switch to the Paint tool for corridors. Right-drag erases. Draw at least one loop and a few dead ends.
  5. Select the Walls node, right-click it, Delete Node. Select Player and set its Position to a floor cell, for example 72, 72.
  6. Save the scene. Run the project. Walk right. Keep walking.
CHECKPOINT

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.

CS 276

Nothing happened?

SymptomCause, and the cure
Blitz walks straight through the wallsNo 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 spawnSpawned inside a wall cell, or the floor tile got a polygon. Move the spawn to a painted floor cell.
Every tile is a thin sliverTile Size was set after the texture. Remove the atlas source, set 48 by 48, drag the texture in again.
Painting does nothingNo 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 runRan the current scene with a tile scene open. Run the project.
CS 276
LEVEL 03

The Camera

One node that follows, with limits and smoothing

SCORE 000276HI 999999

Camera2D

DEFINITION

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].

  • Put it under the player and it follows for free: the camera's position is the player's position.
  • Limits clamp the view to the world's edges, so the void past the maze never shows.
  • Position smoothing lets the view lag a little behind the player. Sudden turns stop feeling like a camera bolted to a head.
  • Drag margins are the other style: the camera sits still until the player nears the edge of a box. Platformers like it.
  • Lab 5's camera had Anchor Mode: Fixed Top Left and never moved. Today's is Drag Center, the default, and moves all the time.
CS 276

Lap 2: a camera under Blitz

LIVE DEMO

Open player.tscn (double-click it in the FileSystem dock):

  1. Select the Player root. Add a child node: Camera2D. Leave its position at 0, 0: that is Blitz's center.
  2. In the Inspector, expand Position Smoothing. Turn Enabled on. Set Speed to 8.
  3. Expand Limit. Left 0, Top 0, Right 1536, Bottom 864: the size of the painted maze.
  4. Save the scene. Run the project. Walk the maze. Watch the edges.
CHECKPOINT

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.

WATCH OUT

Those four limit numbers describe this maze. A second maze with a different size makes them wrong, which is lap 3's problem.

CS 276

Predict: the limits

PREDICT

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.

CS 276
LEVEL 04

World Structure

A maze is a scene; the game runs a gauntlet of them

SCORE 000276HI 999999

One maze, one scene

MAZES/MAZE_1.TSCN
Maze (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
  • Everything that is true of this maze lives in this scene: the tiles, the spawns, the lane, the way out.
  • Nothing that is true of the game lives here: the player, the rival, the HUD, the brain all stay in main.tscn.
  • Marker2D is a position with a name. The editor shows it as a cross; the game sees a Vector2.
  • Week 6's rule: the scene tree is the component system. A maze is a part you can swap.
CS 276

maze.gd: the part describes itself

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.
  • The exit re-emits as exited: the brain never reaches into the maze's children.
CS 276

game.gd: loading a maze

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.
  • The maze tells the brain where things go. The brain places them.
  • The camera limits come from 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.
CS 276

The gauntlet

@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)
PATTERN

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.

  • TITLE loads maze 0, so restarting after CAUGHT or ESCAPED is the same reset it always was.
  • Adding a third maze is: paint it, save it as mazes/maze_3.tscn, drag it into the array. Zero lines of code.
  • The same shape fits a platformer's levels, a dungeon's rooms, a racer's tracks: a scene per place, a brain that loads them in order.
CS 276

Walls block sight

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)
  • A straight-line chaser hugs the first wall in its way, so the rival only chases what it can see: a ray on the world layer, from it to Blitz.
  • Lose sight, and a new room, RETURN, walks it back to the leash it recorded on entering CHASE.
  • Real maze pathfinding is NavigationAgent2D plus a navigation layer on the tileset [1]. In the sources; another week.
CS 276

Level design, in one slide

RuleWhyIn the maze
Loops, and a few dead endsA loop gives the player a way out; a dead end is a trap the designer setMaze 2 is a perfect maze with fourteen walls knocked out
Show the exit earlyA goal the player can see turns wandering into planningThe yellow pad sits at the far corner, in view from the first corridor
One new thing per placeTeach, then test; the player learns the mechanic before the maze punishes itMaze 1: the rival's lane. Maze 2: the fig matters
Bigger than the screen, on purposeWhat the camera hides is tension; what it shows is informationThe rival is often out of frame; its print line is not
Paint fast, play fasterA tilemap level costs minutes; the only way to know it works is to play itThursday is playtest day
CS 276
LEVEL 05

Build-Along

Your world, on your laptop, in twenty minutes

SCORE 000276HI 999999

Pick your lane

Your gameBuild 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 handReplace 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 aboveDo it in a fresh clone of rival-brains on demo6: paint a maze, add the camera, run
CO-OP MODE

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.

CS 276

Co-op: paint your world

CO-OP MODE

Twenty minutes, on the timer:

  1. TileMapLayer, new TileSet, tile size set first, one physics layer on world.
  2. Drag a texture into the TileSet panel, Yes to auto-create, give the solid tiles a Reset to default polygon.
  3. Paint a border and a few walls that run past the window. Delete what they replace.
  4. Camera2D under the player: smoothing on, limits set to the painted size.
  5. Run it. Walk to every edge. Round clear: show me a wall that stops you and an edge the camera stops at.

Stuck? The Nothing happened? slide, then the demo7 branch, then a hand up.

CS 276

Round clear

  • Every lane ends with the same test: a wall that stops you and an edge the camera honors.
  • Commit the tiles branch now. A painted level is the fastest alpha progress most teams will make this week.
  • Teams on lane three: is the place a scene yet, with its own spawns? Then the brain can load it, and the second place is free.
  • Everyone: which numbers did you type by hand today that belong to the level? Those move with the level, into the scene.
CHECKPOINT

Tiles carry the look and the collision. The map carries positions. The scene carries the place. The brain carries the order.

CS 276
LEVEL 06

Studio

Sprint 2, toward the alpha

SCORE 000276HI 999999

Sprint 2 studio

CO-OP MODE

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 yourselvesBecause
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.

CS 276
LEVEL 07

Game Over Screen

What you know now

SCORE 000276HI 999999

Checkpoint reached

CHECKPOINT
  • A TileSet defines each tile once (picture, collision polygon, more); a TileMapLayer paints positions. The map is the StaticBody2D.
  • Tile size first, then the texture, then the polygon on the solid tiles only.
  • A Camera2D under the player follows for free. Limits stop the void; smoothing stops the whiplash.
  • A place is a scene: tiles, Marker2D spawns, an exit that emits. The brain loads places from an exported array.
  • Numbers that describe a place move with the place: the camera asks the maze for its bounds.
  • Walls block sight: a ray on the world layer, and a RETURN room so the rival finds its lane again.
QUEST LOG

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.

CS 276

Sources

  • [1] Godot docs: Using TileSets, Using TileMaps, TileMapLayer, TileSet (physics, terrains, navigation, custom data layers).
  • [2] Godot docs: Camera2D (limits, position smoothing, drag margins), 2D movement overview.
  • [3] Godot docs: PhysicsDirectSpaceState2D.intersect_ray, NavigationAgent2D, Navigation introduction.
  • [4] Rogers, Level Up! The Guide to Great Video Game Design, 2nd ed. (Wiley, 2014): level design chapters.
  • [5] Schell, The Art of Game Design: A Book of Lenses, 3rd ed. (CRC Press, 2019): the lenses of the toy and of the world.
  • [6] Brown, How Level Design Can Tell a Story and Super Mario 3D World's 4 Step Level Design, Game Maker's Toolkit (video essays).
  • [7] Demo repo: github.com/LucasCordova/rival-brains, branch demo7 (tags demo7-lap1 and demo7-lap2).
CS 276