First-person shooter engine in 265 lines of Javascript



Raycasting is what the original Wolfenstein 3D and Doom used. So it’s well suited for JavaScript. Though this looks like the Wolf3D generation, not Doom.

More of a first person stabber, in fact.


Doom used binary space partitioning - a different beast. Blake Stone used raycasting, IIRC.

Ok, I hate javascript.
But this is niiiiiice!

I wish more people could code as simply and straightforward as this.

1 Like

They’re both raycasting - just throwing a light ray to see where it hits. But Wolfenstein does it with a simple grid layout. Doom uses BSP to divide the casting space up efficiently so you can get away from the grid.

See here for some details:

Wow, cool. I was half expecting each line to be 100 bajillion characters long, but that code is really clean, simple, and easy to read through and understand.


Yes, I am aspiring to this level. He’s awesome.


Ok, I hate javascript.

Just out of curiosity, what do you prefer instead?

1 Like
1 Like

I wanna see it combined with this:

insane in the membrane.

Oh geez, that’s right. I used to know all that stuff.

I need to go dust off my Doom & Doom II mods.

I can’t get the demo to have a decent framerate in Firefox… It only advances through the frames when my mouse is moving, and it’s eating a vast amount of CPU.

“Stop using Firefox then,” said every frustratingly myopic coder ever.

Turns out it works in chrome.

Just FYI, if your last experience with Javascript was horrible spaghettis of jQuery written by “web designers” six years ago, come back and look again. JS frameworks, standards and, most importantly, expectations of clean code, have moved on a LOT since then.

1 Like

Flamebait aside, but I use flex and actionscript, and java. Actionscript 3 is ecmascript 2, which is what javascript was supposed to update to. Its much more like java and has strict typing, and real classes, which js doesn’t and though you can do some hacky things with that, it can quickly turn into completely unmanageable code. AS also has native E4X xml objects which is crazy easy and powerful, js can do xml, but it’s not as good, and that’s why most js uses JSON for its ajax data. (the x is supposed to be for xml :smile:

What I hate most about js is the overuse of inline functions… within inline functions, within inline functions… That’s just crazy. And if you miss 1 comma everything goes boom.

This code, however, is a wonderful example of clean code that can be done in JS. Not hacky, tricky stuff that some were expecting.
It’s not per se elegant, but this is what I would call ‘crystallizing’ your code, which is refining it down to exactly and only what it needs to be. No extra variables or functions that you may need later, or might be cool at some point.
Every single thing here is used and nothing wasted, no extraneous junk to muck things up. And that’s why they can keep it short, and explain how the whole thing works beautifully.

And now is the time that other coders will grab it and muck it all up :wink:

What is your definition of elegant? It’s OK to pay something an unreserved compliment. That doesn’t make you weak.

“Pleasingly ingenious and simple” is what I go by and this fits that definition pretty darn well.

Flamebait aside

I’m glad you put that aside, because that wasn’t my intention. I just enjoy hearing about what people like to go along with what they don’t like. :smiley: