shCode

Choose a lesson

Unit 11 module
Unit 2q5play — Applied Game Development8 modules
2.1q5play Foundations
Slides

2.1.1 Slides — q5play Foundations

Week 10

Unit 2.1 slides — canvas, sprites, keyboard input, and the frame loop. Includes runnable code examples.

Video

2.1.1 Video — Your first q5play sketch

Week 10

5-min walkthrough introducing canvas, sprite, and run cycle. Watch before the Hello Sprite lesson.

Reading

2.1.2 Reading — Frame loop: setup() and draw()

Week 10

How q5play calls `setup()` once and `draw()` every frame. Read before 2.1.3a (Canvas).

Worked Example

2.1.3 Worked Example — Minimum Sprite Program

Week 10

Reading

2.1.3a Reading — Canvas: new Canvas(w, h)

Week 10

How new Canvas(w, h) opens the drawing area and why (0, 0) is top-left with y increasing downward. Read before 2.1.3b (Sprite).

Reading

2.1.3b Reading — Sprite: new Sprite(x, y, w, h) + .color

Week 10

How new Sprite(x, y, w, h) creates a rectangle the engine renders for you, and how .color sets its fill. Read before 2.1.3c (lab).

Q5 Lesson

2.1.3c Lab — Drop one sprite, change its color

Week 10

Practice from 2.1.3b: create a canvas, drop a single sprite at the centre, and set its color. Three steps, no movement yet.

Reading

2.1.3d Reading — Storing the sprite in a let variable

Week 10

Why you declare a let at file scope and assign the sprite in setup() — and what goes wrong when you create sprites inside draw(). Read before 2.1.3e.

Reading

2.1.3e Reading — background(color) wipe rule

Week 10

Why background(color) must be the first call inside draw() to clear the previous frame — and what motion trails look like without it. Read before 2.1.3f.

Reading

2.1.3f Reading — Sprite property tour: pos, rotation, layer

Week 10

How to read and write the core sprite properties pos, rotation, and layer after the sprite is created. Read before 2.1.4 (worked example).

Q5 Lesson

2.1.5 Hello Sprite

Week 10

Your first q5play sketch: a canvas, a sprite, a background color.

Video

2.1.5 Video — The Frame Loop Explained

Week 10

3-min walkthrough of the setup/draw frame loop at 60 fps. Watch after Hello Sprite, before Make it Move.

Reading

2.1.6 Reading — kb.pressing(key)

Week 10

How `kb.pressing(key)` checks whether a key is held this frame. Read before 2.1.7a (Velocity).

Worked Example

2.1.7 Worked Example — Keyboard Movement

Week 10

Teacher-led walkthrough of the if/else-if/else pattern for keyboard movement and the drift-bug. Read before Make it Move.

Reading

2.1.7a Reading — Velocity: vel.x and vel.y

Week 10

How `sprite.vel.x` and `vel.y` work as pixels-per-frame values the engine integrates into position. Read after 2.1.7.

Reading

2.1.7b Reading — Movement pattern (if / else if / else)

Week 10

The canonical if/else-if/else pattern that maps key presses to velocity changes inside `draw()`. Read after 2.1.7a.

Reading

2.1.7c Reading — The else-to-zero rule

Week 10

Why velocity persists across frames and why the else branch is what stops the sprite. Read after 2.1.7b.

Q5 Lesson

2.1.7d Lab — Delete the else, watch drift

Week 10

Start from a working WASD movement pattern, delete the two else lines, observe drift, then restore them.

Reading

2.1.7e Reading — WASD-not-arrows

Week 10

Why graded labs use 'a'/'d'/'w'/'s' instead of arrow keys, and how to swap them into the movement pattern. Read after 2.1.7d.

Q5 Lesson

2.1.9 Make it Move

Week 10

Drive a sprite with the arrow keys by setting vel.x and vel.y based on what's pressed.

Assignment

2.1.9 Sprite Playground

Week 10

Build a sprite playground combining canvas, WASD-controlled sprite, auto-motion, and on-screen text. Auto-graded.

Assignment

2.1.10 Frame Loop Writeup

Week 10

Half-page written reflection on setup/draw and the 60fps math. AI-graded with hints.

Challenge

2.1.11 Challenges

Week 10

Pick one or more of the stretch challenges and implement them in the editor. Auto-graded.

→ View full module page
2.2Object-Oriented Programming
Slides

2.2.1 Slides — Object-Oriented Programming

Week 12

Unit 2.2 slides — classes, objects, `this`, and procedural vs OOP. Includes runnable code examples.

Video

2.2.2 Video — What `new Sprite()` actually does

Week 12

4-min DevTools walkthrough. Opens a running q5play sketch, inspects a Sprite instance, and names what a class is. Watch before the DevTools reveal example.

Reading

2.2.3 Reading — Class and instance

Week 12

The words class and instance and how they relate — a class is a blueprint; `new` builds one instance from it. Read before 2.2.3a.

Reading

2.2.3a Reading — The `new` operator

Week 12

What `new` does mechanically: allocate, run constructor, return. Read right after 2.2.3.

Reading

2.2.3b Reading — `constructor` and its parameters

Week 12

How the constructor receives arguments from `new` and stores them on `this`. Read right after 2.2.3a.

Worked Example

2.2.4 Worked Example — You've been using classes

Week 12

Reading

2.2.4a Reading — Properties: data on `this`

Week 12

A property is data stored on a single instance via `this.name = value`. Read before the property labs.

Q5 Lesson

2.2.4b Lab — Read a property

Week 12

Read `b.color` and `b.size` off a Box instance and print them to the on-canvas console using `console.log`. First practice with dot-notation reads.

Q5 Lesson

2.2.4c Lab — Write a property

Week 12

Mutate `b.color` on a space-bar press to practice assigning a new value to an instance property. First practice with dot-notation writes.

Q5 Lesson

2.2.4d Lab — Two sprites, two property values

Week 12

Instantiate b1 and b2 from the same class with different colors, then mutate only b1 to confirm each instance's state is independent.

Reading

2.2.5 Reading — `this` is a noun

Week 12

`this` always refers to one specific thing — the instance the method was called on. Read before the substitution rule example.

Worked Example

2.2.5a Worked Example — `this` is a pronoun

Week 12

Q5 Lesson

2.2.6 Your Turn — Build a Sprite

Week 12

Low-stakes autograded practice. Instantiate the Sprite class twice (rectangle form and circle form), set properties on each instance, and give one sprite a stroke. Bridges the 2.2.4 / 2.2.5 worked examples and the 2.2.8 Enemy class lab.

Worked Example

2.2.6a Worked Example — Sprite Showcase

Week 12

A tour of the Sprite class re-read as OOP. Every `new Sprite(...)` is a constructor call; every `.color` / `.stroke` is a property on an instance.

Video

2.2.7 Video — The `this` keyword

Week 12

3-min whiteboard walkthrough of `this` inside methods. Shows why `this.color` and `this.hp` refer to the specific instance the method was called on.

Reading

2.2.7a Reading — Methods: functions that live on a class

Week 12

Method declaration syntax: inside a class body, methods are written without the `function` keyword. Read before the method labs.

Q5 Lesson

2.2.7b Lab — Method with no params

Week 12

Write `Counter.tick()` — a method that takes no arguments and mutates `this.n`. First method you write from scratch.

Q5 Lesson

2.2.7c Lab — Method with parameters

Week 12

Add `Counter.addBy(n)` — a method that takes an argument and uses it to increment `this.n`. Keys 1/2/3 add different amounts.

Q5 Lesson

2.2.7d Lab — Method that returns a value

Week 12

Add `Counter.isHigh()` which returns `true` when `this.n > 10`. The driver uses the return value to color the display red.

Q5 Lesson

2.2.7e Lab — A method calling `this.otherMethod()`

Week 12

Write `Counter.bigStep()` which calls `this.addBy(5)` and returns `this.isHigh()` — one method dispatching another on the same instance.

Reading

2.2.7f Reading — Why `this.sprite`, not `extends Sprite`

Week 12

Composition over inheritance: why wrapping a Sprite as `this.sprite` is safer than inheriting from it. Read before the sprite mutation labs.

Q5 Lesson

2.2.7g Lab — Mutate `this.sprite.x` from a method

Week 12

Write `Mover.moveRight(dx)` which adds `dx` to `this.sprite.x`, reaching through composition to move the wrapped sprite.

Q5 Lesson

2.2.7h Lab — Cleanup with `this.sprite.delete()`

Week 12

Write `Bubble.pop()` which calls `this.sprite.delete()` so the object removes its own sprite on click.

Worked Example

2.2.8 Worked Example — Write an Enemy class (integration)

Week 12

Q5 Lesson

2.2.8a Lab — Three Enemies in three variables

Week 12

Instantiate e1, e2, and e3 from the Enemy class at three different positions — three independent instances, each in its own named variable.

Q5 Lesson

2.2.8b Lab — An array of Enemies

Week 12

Store five Enemy instances in a single array by pushing new Enemy(...) calls into `enemies` — practice managing many instances without separate named variables.

Q5 Lesson

2.2.8c Lab — Loop over an array of instances

Week 12

Write a `for...of` loop in `draw()` that calls `.render()` on each enemy — dispatching a method to every element in the array with one loop.

Reading

2.2.9 Reading — Parallel Arrays vs Classes

Week 12

Side-by-side comparison of the same problem (an 'enemy fleet') solved two ways: with parallel arrays (procedural) and with an array of class instances (OOP). Read between the Enemy class example and the Procedural-vs-OOP example.

Worked Example

2.2.10 Worked Example — Procedural vs OOP side-by-side

Week 12

Reading

2.2.10a Reading — When to reach for OOP (3-question checklist)

Week 12

Three yes-or-no questions that tell you whether a class is the right tool. Read after the Procedural vs OOP example.

Assignment

2.2.11 Collectible Class

Week 12

Write a Collectible class, instantiate at least 5, and detect overlap with the player. SLO-2 lab — the class is the point. Auto-graded.

Assignment

2.2.12 Procedural vs OOP Writeup

Week 12

1-page comparison of procedural and object-oriented programming.

Reading

2.2.12a Reading — Encapsulation, inheritance, polymorphism (vocabulary only)

Week 12

Name the three OOP pillars you'll encounter in downstream courses — no implementation required this week. Read at the close of Unit 2.2.

Challenge

2.2.13 Challenges

Week 12

Pick one (or more) OOP stretch challenges — extend your Enemy class, write a Player class, or try subclassing with `extends`. Auto-graded.

→ View full module page
2.3Collections and Physics Applications
Slides

2.3.1 Slides — Collections and Physics Applications

Week 13

Unit 2.3 slides — Groups, overlap detection, safe despawn, edge-triggered input, and ground-gated jumping. Includes runnable code examples.

Video

2.3.2 Video — Groups in q5play

Week 13

Why a `Group` is a class with shared defaults — and how a single line creates fifty enemies. Watch before `2.3.5 Groups Sandbox`.

Reading

2.3.3 Reading — q5play docs: Groups

Week 13

q5play docs chapter on Groups. Read before `2.3.5 Groups Sandbox`.

Worked Example

2.3.4 Worked Example — Iterating a Group

Week 13

Q5 Lesson

2.3.5 Groups Sandbox

Week 13

Groups let you treat many sprites as one. Create, configure, spawn into, and clean up a Group.

Video

2.3.6 Video — overlaps() boolean vs callback

Week 13

The two flavors of `overlaps()` and why the callback form is cleaner for despawn-on-collide. Watch before `2.3.7 Apple Catcher`.

Worked Example

2.3.7 Worked Example — Apple Catcher

Week 13

Reading

2.3.8 Reading — q5play docs: Collisions + Overlaps

Week 13

q5play docs chapter on collisions and overlap detection. Read before `2.3.10 Safe Despawn`.

Video

2.3.9 Video — The remove-during-iteration bug

Week 13

Live demo of why `for (let i = 0; i < group.length; i++)` + `.delete()` skips items, and how to fix it. Watch before `2.3.10 Safe Despawn`.

Worked Example

2.3.10 Worked Example — Safe Despawn

Week 13

Assignment

2.3.11 A13.1 Asteroid Field

Week 13

Combine Groups, overlap detection, and safe despawn into a playable asteroid scene. WASD steers the ship; an overlap with any asteroid ends the game.

Challenge

2.3.12 Challenges

Week 13

Pick one (or more) Groups stretch challenges — add a lives counter to Apple Catcher, vary apple sizes for varied points, or implement a `cull()` helper. Auto-graded.

Video

2.3.13 Video — kb.presses vs kb.pressing

Week 14

Why holding space launches a super-jump 60 frames in a row, and how the edge-triggered form fixes it. Watch before `2.3.15 Edge-triggered Input`.

Reading

2.3.14 Reading — q5play docs: Input edges

Week 14

q5play docs chapter on input — `kb.pressing` (level-triggered) vs `kb.presses` (edge-triggered). Read before `2.3.15 Edge-triggered Input`.

Worked Example

2.3.15 Worked Example — Edge-triggered Input

Week 14

Video

2.3.16 Video — Why your jump feels wrong

Week 14

The infinite-jump bug live, and the `colliding(ground)` fix. Watch before `2.3.18 Ground Detection`.

Reading

2.3.17 Reading — q5play docs: Colliding + Ground Detection

Week 14

q5play docs on `sprite.colliding(other)` and the ground-gated jump idiom. Read before `2.3.18 Ground Detection`.

Worked Example

2.3.18 Worked Example — Ground Detection

Week 14

Worked Example

2.3.19 Worked Example — Swinging Pendulum

Week 14

Assignment

2.3.20 A14.1 Space Jumper

Week 14

Build a one-sprite platformer: WASD moves, space jumps — but only when touching the ground.

Assignment

2.3.21 A14.1 Car on a Ramp

Week 14

Build a two-wheeled car using WheelJoints and drive it up a ramp with WASD. The harder of the two A14.1 options.

→ View full module page
2.4Animation & Camera
Slides

2.4.1 Slides — Animation & Camera

Week 15

Unit 2.4 slides — animated sprites with `addAni` / `changeAni`, camera follow, smoothing with `lerp`, and `layer` for render order. Includes runnable code examples.

Video

2.4.2 Video — Animating a sprite in q5play

Week 15

How `addAni` registers named animations and `changeAni` swaps the active one — driven by player state (idle vs run). Watch before `2.4.5 Animated Sprites Sandbox`.

Reading

2.4.3 Reading — q5play docs: Animation

Week 15

q5play docs chapter on Animation. Read before `2.4.5 Animated Sprites Sandbox`.

Reading

2.4.3a Reading — addAni(name, frames)

Week 15

How sprite.addAni(name, frame1, ...) registers a named animation and makes it the active default. Read before 2.4.3b (changeAni).

Reading

2.4.3b Reading — changeAni(name)

Week 15

How sprite.changeAni(name) swaps the active animation between previously registered names. Read before 2.4.4 (Worked Example).

Reading

2.4.3c Reading — frameDelay (cycle speed)

Week 15

How sprite.animation.frameDelay = N slows or speeds an animation cycle. Read before 2.4.5 (Animated Sprites Sandbox).

Reading

2.4.3d Reading — sprite.image (single-frame art)

Week 15

How sprite.image = url displays a still image without any animation cycle. Read before 2.4.5 (Animated Sprites Sandbox).

Worked Example

2.4.4 Worked Example — Animating a Sprite

Week 15

Q5 Lesson

2.4.5 Animated Sprites Sandbox

Week 15

Drive a sprite's visual from input state — the same swap pattern used by addAni / changeAni, with sprite.image swapping as the asset-free placeholder. Idle when standing, run when moving, jump when 'w' is held.

Video

2.4.6 Video — Camera follow explained with a flashlight

Week 15

Why the camera is a coordinate transform, not a 'real' object — the world stays put, only the viewport moves. Watch before `2.4.8 Worked Example — Camera Follow`.

Reading

2.4.7 Reading — q5play docs: Camera

Week 15

q5play docs chapter on Camera. Read before `2.4.8 Worked Example — Camera Follow`.

Reading

2.4.7a Reading — camera.x / camera.y

Week 15

How assigning camera.x and camera.y shifts the viewport center each frame. Read before 2.4.7b (Camera-follow pattern).

Reading

2.4.7b Reading — Camera-follow pattern

Week 15

How camera.x = player.pos.x inside draw() locks the viewport onto a moving sprite. Read before 2.4.8 (Worked Example — Camera Follow).

Reading

2.4.7c Reading — Smoothing with lerp

Week 15

How lerp(current, target, t) replaces a hard-set camera follow with a smooth elastic trail. Read before 2.4.9 (Worked Example — Smooth Camera).

Reading

2.4.7d Reading — sprite.layer (render order)

Week 15

How sprite.layer = N controls draw order so HUD elements always render on top of world geometry. Read before 2.4.10 (A15.1 Platformer).

Worked Example

2.4.8 Worked Example — Camera Follow

Week 15

Worked Example

2.4.9 Worked Example — Smooth Camera with lerp

Week 15

Assignment

2.4.10 A15.1 Side-Scrolling Platformer

Week 15

Combine animated sprites, a camera that follows the player, three or more platforms, working jump mechanics, and a visible end goal into a playable side-scroller. Auto-graded.

Challenge

2.4.11 Challenges

Week 15

Pick one (or more) Animation & Camera stretches — parallax background, mirror the sprite when it walks left, or add vertical camera follow. Auto-graded.

→ View full module page
2.5Game Saves
Slides

2.5.1 Slides — Your Game Forgets: The Problem

Week 16

Unit 2.5 opening slides — why game data disappears on refresh, what persistence means, and the plan for building a save/load system your players can count on.

Video

2.5.2 Video — Memory: What Stays, What Disappears

Week 16

A game resets to zero on refresh. Variables live in RAM — gone when the tab closes. Saved data lives on disk — still there tomorrow. This short video contrasts both so you understand what persistence actually means.

Reading

2.5.3 Reading — storeItem: Save Game Data

Week 16

How storeItem(key, value) writes a value into the browser's save slot so it survives page reloads. Your game can remember things between sessions.

Worked Example

2.5.4 Worked Example — Save a High Score on Game Over

Week 16

Step-by-step: build a survival game, detect when the game ends, and use storeItem to save the player's high score so it survives a reload.

Reading

2.5.5 Reading — getItem: Load Saved Data

Week 16

How getItem(key) reads back a value your game saved earlier. Covers the basics of retrieving save data — the string type gotcha is in 2.5.5a.

Reading

2.5.5a Reading — getItem Returns a String

Week 16

getItem always gives you a string, even when you stored a number. String comparisons give wrong results — here's the Number() fix and the || 0 fallback.

Worked Example

2.5.6 Worked Example — Load and Display a High Score

Week 16

Read your saved high score on startup, coerce it with Number(), display it next to the current score, and update it when the player beats their record.

Video

2.5.7 Video — More Than a Number: Saving Your Whole Game

Week 16

A high score is one number. But your game has position, level, inventory — many pieces. JSON bundles them together.

Reading

2.5.8 Reading — q5play docs: JSON.stringify(obj)

Week 16

JSON.stringify takes a JS object and turns it into a string you can store. Think of it as packing your game state into a box.

Reading

2.5.9 Reading — q5play docs: JSON.parse(str)

Week 16

JSON.parse unpacks a JSON string back into a JS object. It's the reverse of JSON.stringify.

Reading

2.5.10 Reading — q5play docs: Storing Structured Data

Week 16

The full pattern: build a save object, stringify it, store it. Then getItem, parse, and restore. Complete round-trip.

Worked Example

2.5.11 Worked Example — Save Full Player State

Week 16

Build a game with a moving player, score, and level. Save everything as one JSON object with storeItem.

Worked Example

2.5.12 Worked Example — Restore Full Player State from a Save

Week 16

Load a saved game: getItem, JSON.parse, coerce numbers, then apply to your game objects.

Reading

2.5.13 Reading — q5play docs: loadJSON is Async

Week 16

loadJSON loads external JSON files (levels, dialogue, config) — different from save/load. It's async and needs a callback.

Video

2.5.14 Video — Save Slots: Multiple Save Files

Week 16

One save isn't enough — games have multiple slots. Each slot is just a different key name passed to storeItem/getItem.

Reading

2.5.15 Reading — q5play docs: removeItem and clearStorage

Week 16

removeItem(key) deletes one saved key. clearStorage() wipes everything. When and how to use each.

Worked Example

2.5.16 Worked Example — Three Save Slots

Week 16

Build three save slots. Each slot is a differently-named key. Press 1/2/3 to save, load with a simple text menu.

Worked Example

2.5.17 Worked Example — Delete and Overwrite a Save Slot

Week 16

Manage save slots: delete old saves with removeItem, confirm before overwriting, handle the empty-slot case.

Video

2.5.18 Video — New Game or Continue?

Week 16

If a save exists, show 'Continue'. If not, only 'New Game'. The title screen pattern every game uses.

Worked Example

2.5.19 Worked Example — Title Screen Detects Existing Saves

Week 16

Build a title screen that checks for a save on startup. If save exists, show 'Press C to Continue'. Always show 'Press N for New Game'.

Worked Example

2.5.20 Worked Example — Confirm Before Overwriting a Save

Week 16

When the player tries to save over an existing slot, show an 'Are you sure?' prompt before writing.

Video

2.5.21 Video — Your Game, Automatically Saved

Week 16

Not every save needs a button press. Auto-save triggers on level transitions, checkpoints, or a timer — the player doesn't think about it.

Reading

2.5.22 Reading — Checkpoint Saves: Save on Milestones

Week 16

An auto-save fires when something important happens — reaching a checkpoint, finishing a level, hitting a score milestone.

Worked Example

2.5.23 Worked Example — Auto-Save on Level Complete or Timer

Week 16

Implement two auto-save triggers: when the player reaches a level-complete zone, and a timer-based save every 30 seconds.

Assignment

2.5.24 A16.1 Save System — Build Save/Load with Slots

Week 16

Graded: build a game with a complete save system — at least 3 save slots, load functionality, auto-save on level complete, and a Continue option on the title screen.

Challenge

2.5.25 Challenges — Extended Save Features

Week 16

Extend your save system: save file previews (show slot contents before loading), save timestamps, multiple profiles, or a 'delete all saves' with double-confirmation.

→ View full module page
2.6Game States
Slides

2.6.1 Slides — One Game, Many Screens

Week 17

Unit 2.6 opening slides — title screen, gameplay, pause, game over. Every screen is a state. One variable controls which screen is active.

Video

2.6.2 Video — State Machines in Games

Week 17

Every game has states: title → play → game over → title. A state machine is just a variable that remembers which screen you're on.

Reading

2.6.3 Reading — MDN: The switch Statement

Week 17

switch is like if/else but cleaner when checking one variable against many values. Syntax: switch(variable) { case VALUE: ... break; }

Reading

2.6.4 Reading — q5play docs: switch in draw()

Week 17

In q5play games, switch goes inside draw(). Each frame, it checks the state variable and draws the right screen.

Worked Example

2.6.5 Worked Example — switch with Three Cases

Week 17

A plain switch with three cases that each draw different text. Not a game yet — just getting comfortable with the syntax.

Reading

2.6.6 Reading — break and default in switch

Week 17

break exits the switch; without it, execution falls through to the next case. default handles unexpected values.

Reading

2.6.7 Reading — q5play docs: The state Variable

Week 17

One variable controls which screen is visible. Every frame, draw() checks state to decide what to render. This is the single source of truth for your game's screen.

Worked Example

2.6.8 Worked Example — One Variable, Many Screens

Week 17

Build three distinct screens — red, green, blue backgrounds with different text — all controlled by one state variable with switch.

Reading

2.6.9 Reading — Naming States: Conventions

Week 17

Use lowercase strings for state names: 'title', 'play', 'pause', 'gameover'. Be consistent. Good names make the switch statement self-documenting.

Video

2.6.10 Video — Building a Title Screen

Week 17

A title screen is just a state. It shows the game name, maybe instructions, and waits for the player to press a key to start playing.

Worked Example

2.6.11 Worked Example — Title Screen with Start Button

Week 17

Build a title screen state that shows the game name and 'Press ENTER to start'. When they press Enter, change state to 'play'.

Video

2.6.12 Video — Game Over and Restart

Week 17

The game over screen shows the final score and 'Press R to restart'. Restart means resetting variables + changing state back to 'play' (or 'title').

Worked Example

2.6.13 Worked Example — Three-State Machine: Title, Play, Game Over

Week 17

The complete beginner state machine: title screen → gameplay → game over → restart. The classic arcade loop.

Reading

2.6.14 Reading — q5play docs: Input-Driven Transitions

Week 17

Input-driven transitions happen when the player presses a key. Title → Play (press Enter), Play → Pause (press P). The player is in control.

Worked Example

2.6.15 Worked Example — Keyboard-Driven State Changes

Week 17

Build a game where every state transition is triggered by the keyboard: Enter (start), P (pause/unpause), Escape (quit to title).

Reading

2.6.16 Reading — q5play docs: Condition-Driven Transitions

Week 17

Condition-driven transitions happen automatically when something in the game changes. Score ≥ 100 → 'win', health ≤ 0 → 'gameover'. The game state triggers it.

Worked Example

2.6.17 Worked Example — Score Threshold Triggers Game Over

Week 17

Implement condition-driven transitions: score reaches 50 triggers a win screen, health drops to 0 triggers game over. The game decides when states change.

Video

2.6.18 Video — More States: Pause, Inventory, Settings

Week 17

Real games have more than 3 states. Pause freezes the action. Inventory shows items. Settings adjusts volume. All use the same switch pattern you already know.

Worked Example

2.6.19 Worked Example — Adding a Pause State

Week 17

Add a pause state to your game. When paused, stop movement and physics, show a PAUSED overlay. Press P to toggle pause on and off.

Worked Example

2.6.20 Worked Example — Win Screen State

Week 17

A win screen shows when the player reaches the goal. It's a distinct state with congratulations, final stats, and a 'Play Again?' option.

Video

2.6.21 Video — States Decide When to Save

Week 17

States and saves work together: when the player reaches 'gameover', auto-save their score. When they hit 'win', save their victory. States trigger saves.

Worked Example

2.6.22 Worked Example — Save on State Transition

Week 17

Worked Example

2.6.23 Worked Example — Continue Loads the Correct State

Week 17

Assignment

2.6.24 A16.2 Game States — State Machine with Persistence

Week 17

Graded: build a game with at least 4 states (title, play, pause, gameover) with full save/load integration. Saves trigger on state transitions. Continue restores the right state.

Challenge

2.6.25 Challenges — Extended State Features

Week 17

Extend your state machine: animated transitions, a loading screen state, state history (undo last transition), or an options/settings state that modifies gameplay.

Video

2.6.26 Video — What's Next: Looking Ahead to Unit 3

Week 17

You've built save systems and state machines — real game infrastructure. Unit 3 preview: what comes after the fundamentals.

→ View full module page
2.7Advanced Mechanics
Slides

2.7.1 Slides — Advanced Mechanics: One Last Toolkit

Week 17

Unit 2.7 opening slides — the three big ideas before capstone: mouse input, joints, and the slingshot pattern. Everything in this unit feeds directly into A17.1 and your capstone design.

Video

2.7.2 Video — Why Mechanics Matter for the Capstone

Week 17

This is the last content unit before you design your own game. Mouse input, joints, and the slingshot pattern are the final building blocks — learn them here and you'll have everything you need to pitch and build a real project.

Reading

2.7.3 Reading — q5play docs: mouse.x and mouse.y

Week 17

mouse.x and mouse.y give you the cursor's position on the canvas every frame. Read this before the mouse input worked examples.

Reading

2.7.4 Reading — q5play docs: mouse.pressing()

Week 17

mouse.pressing() is true every frame the mouse button is held down. Read this before 2.7.5 so you understand the held vs. one-shot difference.

Reading

2.7.5 Reading — q5play docs: mouse.presses()

Week 17

mouse.presses() is true on exactly one frame — the moment the button first goes down. Read this after 2.7.4 to see how one-shot input differs from held input.

Reading

2.7.6 Reading — Hit-Testing a Sprite with the Mouse

Week 17

A hit-test checks whether the cursor is currently over a sprite. This technique gates click-and-drag — the drag only starts when the mouse is on the sprite.

Worked Example

2.7.7 Worked Example — Click to Spawn a Sprite

Week 17

Video

2.7.8 Video — Drag and Release

Week 17

Clicking is one-shot, but dragging follows the cursor across frames — and physics will fight you if you don't know the trick. This video shows the snap-and-zero-velocity pattern that makes a drag feel smooth before you code it yourself.

Reading

2.7.9 Reading — Snap a Sprite to the Cursor

Week 17

How to move a sprite exactly to the cursor position each frame during a drag. Zeroing the velocity is the step that keeps physics from fighting your snap.

Worked Example

2.7.10 Worked Example — Drag a Sprite Around

Week 17

Video

2.7.11 Video — Joints in q5play

Week 17

Three joint types in five minutes: a distance joint keeps two sprites a fixed length apart, a hinge lets one pivot around another, and a slider rides a track. You don't need to master all three — just watch and pick the one that fits your game.

Reading

2.7.12 Reading — q5play docs: DistanceJoint

Week 17

How DistanceJoint constrains two sprites to stay at a fixed distance from each other. Read this before the pendulum worked example.

Worked Example

2.7.13 Worked Example — Pendulum with DistanceJoint

Week 17

Reading

2.7.14 Reading — q5play docs: HingeJoint

Week 17

How HingeJoint pins two sprites to a shared pivot point so they rotate around it. Read this before the rotating-arm worked example.

Worked Example

2.7.15 Worked Example — Rotating Arm with HingeJoint

Week 17

Reading

2.7.16 Reading — q5play docs: joint.delete()

Week 17

How joint.delete() releases a constraint at runtime so previously-joined sprites become independent. This is the release step in the slingshot pattern.

Reading

2.7.17 Reading — q5play docs: applyForce(fx, fy)

Week 17

applyForce(fx, fy) adds a one-frame impulse to a sprite — the physics engine turns it into motion. Read this before 2.7.19 Worked Example — Launch a Sprite with applyForce.

Reading

2.7.18 Reading — Vector from A to B

Week 17

Two numbers — dx and dy — encode the direction from one sprite to another. This is the math behind every force that points somewhere on purpose. Read this before 2.7.19 Worked Example — Launch a Sprite with applyForce.

Worked Example

2.7.19 Worked Example — Launch a Sprite with applyForce

Week 17

Video

2.7.20 Video — The Slingshot Pattern

Week 17

This is the moment the unit snaps together: a joint holds the ball, you drag it back with the mouse, release removes the joint, and a force vector launches it toward the target. Watch the whole pattern before you read the code.

Worked Example

2.7.21 Worked Example — Slingshot End-to-End

Week 17

Video

2.7.22 Video — Two-Player Local Input

Week 17

One keyboard, two players — WASD on the left, arrow keys on the right, each with their own sprite and score. This video shows the pattern once so you can wire it up in A17.1 without guessing.

Reading

2.7.23 Reading — Two Key Schemes, Independent State

Week 17

Two players on one keyboard means two separate key sets and two separate sets of variables — one for each player. Read this before 2.7.25 Worked Example — Two Paddles, Two Schemes.

Reading

2.7.24 Reading — q5play docs: sprite.bounciness

Week 17

sprite.bounciness controls how much energy a sprite keeps after a collision — 0 is a dead thud, 1 is nearly lossless. Read this before 2.7.24a Worked Example — Bounciness Comparison.

Worked Example

2.7.24a Worked Example — Bounciness Comparison

Week 17

Worked Example

2.7.25 Worked Example — Two Paddles, Two Schemes

Week 17

Assignment

2.7.26 A17.1 Two-Player Pong-Sumo

Week 17

Graded: build a two-player Pong-Sumo game — two paddles, one ball, push the ball past the opponent to score. Incorporates two-player input, push-collision physics, a win condition, and at least one joint. Auto-graded.

Challenge

2.7.27 Challenges — SliderJoint, Trebuchet, Swinging Rope

Week 17

Three optional stretch prompts for Unit 2.7: build a SliderJoint piston sandbox, a trebuchet that uses a DistanceJoint + HingeJoint together, or a swinging rope chain with three or more HingeJoints.

Video

2.7.28 Video — Wrap and Capstone Preview

Week 17

You've built every piece — mouse input, joints, forces, two-player games, state machines, saves. This short video closes Unit 2.7 and previews what Unit 2.8 asks you to do: design and pitch your own game from scratch.

→ View full module page
2.8Synthesis — Game Capstone
No lessons authored yet.
→ View full module page