Game Dev From Zero · Episode 10 · Season 1 finale

Tiny platformer

Everything from season 1 in one little game: the loop, variables, delta time, coordinates, movement, gravity, a jump on an event, and collision. Grab the 3 souls, then turn on the hitboxes and switch collision off to see what the code is really doing.

The game ← → / A D move · Space / W / ↑ jump · R restart

souls: 0 / 3
hitboxes
collision

overlaps(ghost, box) live, against the nearest box

With collision on, the ghost gets pushed back out every frame, so it only ever touches things: that's why the answer is nearly always false. Switch collision off and walk through the wall.

The code lit = running now


      
Show the real JavaScript

Things to try

  1. Grab all 3 souls. (One floats over the gap: jump from the very edge to grab it.)
  2. Turn the hitboxes on. The ghost is a box. So is everything else.
  3. Switch collision off, and walk into the wall. Watch the four checks turn true.
  4. With collision off, try to stand on anything. Why do you fall straight through?
  5. Open the real JavaScript. Find the &&s (that's how JavaScript writes "and"). Find gravity. Find the jump.