Build an FPS
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
- Build the arena: a floor, pillars, a sky, and a fixed camera to look at them.
- Add the player: walk, look and jump, with a crosshair.
- Spawn an enemy: one enemy that chases you.
- Shoot and detect hits: a gun, a ray from the crosshair, and an enemy that dies after three hits.
- Show enemy health: a bar over the enemy that faces you and empties as you hit it.
- Spawn waves: clear the arena and a bigger wave comes.
- 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 FPS | In the tutorial |
|---|---|
| three guns, switched with F; hold to fire | one gun, one shot a click |
| muzzle flash, tracers and impact sparks | none |
| red walkers, flyers that drop a cage, pink brutes and a green boss | red walkers |
| harder waves: more kinds, faster enemies | one more walker each wave |
| a health bar at the bottom, a hit marker, a damage flash | one line of text at the top |
| a game-over screen of its own | the engine's HUD dialog |
| FIRE and switch buttons on phones | mouse only |
| a tiled floor drawn by a shader | a 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.