First-person shooter engine in 265 lines of Javascript


Hunter Loftis, who created the fractal terrain generation in 130 lines of Javascript engine, has done it again: a a full-blown first-person shooter engine in 265 lines (demo, source). He used a technique called ray casting, and goes into some detail about this choice and where this could go next.

What's next?

Because raycasters are so fast and simple, you can try lots of ideas quickly. You could make a dungeon crawler, first-person shooter, or a grand-theft-auto style sandbox. Hell, the constant-time makes me want to build an oldschool MMORPG with a massive, procedurally generated world. Here are a few challenges to get you started:

*
Immersion. This example is begging for full-screen mouse-lock with a rainy background and thunderclaps synchronized to the lightning.

*
An indoors level. Replace the skybox with a symmetric gradient or, if you're feeling plucky, try rendering floor and ceiling tiles (think of it this way: they're just the spaces between the walls you're already drawing!)

*
Lighting objects. We already have a fairly robust lighting model. Why not place lights in the world and compute wall lighting based on them? Lights are 80% of atmosphere.

*
Good touch events. I've hacked in a couple of basic touch controls so folks on phones and tablets can try out the demo, but there's huge room for improvement.

*
Camera effects. For example, zooming, blurring, drunk mode, etc. With a raycaster this are surprisingly simple. Start by modifying camera.fov in the console.

A first-person engine in 265 lines

(Thanks, Hunter!)