Skip to content

Build an FPS ​

Building the world…

Quick FPS · Credits

All credits and licences

This is Quick FPS, the finished example, running in the page. Press Play to try it before you build your own.

What you will build ​

A first-person arena game: you walk an arena of pillars under a low sun, enemies come for you, and you shoot them down. Seven chapters take an empty Vite app to a game with:

  • an arena with solid pillars, and a player who walks, looks and jumps;
  • enemies that chase you;
  • a gun, and shots that hit what the crosshair is on;
  • a health bar floating over each enemy;
  • waves, each bigger than the last;
  • your own health, a game over and a restart.

The chapters ​

  1. Build the arena: a floor, pillars, a sky, and a fixed camera to look at them.
  2. Add the player: walk, look and jump, with a crosshair.
  3. Spawn an enemy: one enemy that chases you.
  4. Shoot and detect hits: a gun, a ray from the crosshair, and an enemy that dies after three hits.
  5. Show enemy health: a bar over the enemy that faces you and empties as you hit it.
  6. Spawn waves: clear the arena and a bigger wave comes.
  7. Finish the game loop: enemies bite, you can die, and a dialog starts the game again.

Each chapter changes a few files and says what you should see when you reload. Every code block headed with a file name (// src/combat.ts) is that whole file, with the lines the chapter adds highlighted.

The tutorial game and the full example ​

The tutorial builds a smaller game than the one above. Both have the arena, walking, chasing enemies, the sci-fi gun, floating health bars and waves. Only the full example has:

In Quick FPSIn the tutorial
three guns, switched with F; hold to fireone gun, one shot a click
muzzle flash, tracers and impact sparksnone
red walkers, flyers that drop a cage, pink brutes and a green bossred walkers
harder waves: more kinds, faster enemiesone more walker each wave
a health bar at the bottom, a hit marker, a damage flashone line of text at the top
a game-over screen of its ownthe engine's HUD dialog
FIRE and switch buttons on phonesmouse only
a tiled floor drawn by a shadera plain grey floor

Where to go next, at the end, points to the files in website/demos/quick-fps/ that add each of these.

Before you start ​

Follow Getting started first: a Vite app with marble3 installed and the two Vite settings in place. Then go to chapter 1.