Into the warp we go
With a solid evening's work, we now have a functioning warp level. Hurray! You can try out this rough version at http://air.github.io/encounter.
It's all an illusion
In the simulation we're setting up a field of static spheres. They don't go anywhere, but just sit there looking stoic. At the same time we disable the player forward/back controls, and use
tween.js to ramp up the player speed as if they had their foot on the gas. The goal is to have the player kept busy dodging and feel a real fear of death.
Without a frame of reference, it looks like the asteroids are flying at you. Well. I think it does anyway. Being honest, once you know how it works you start to lose perspective : )
My god, it's full of colours
The multi-coloured asteroids in this build I got for free. By sheer accident I discovered that
three.js will give you a random matte colour if you leave the material undefined. An ideal quick hack to emulate the psychedelic original. To be completely accurate I need to randomize against the palette defined in
C64.js, but you won't tell anyone (ssh).
Hurt me plenty
The asteroid field is a super-naive algorithm right now. We simply loop 800 times and place the asteroids in a random location within 200k units of the player - basically forming a giant circle of death. If your numbers are unlucky you will spawn right in an asteroid and it's game over. DEAL WITH IT.
A side-effect of this quaint approach is that you can actually emerge from the circle into free space, which is a bit dull. In the next iteration we need to dynamically create new asteroids in the path of the player as they weave about and keep them occupied for the whole warp run.
Collisions are brute force. On every single frame, we just check the centre-to-centre distance between the player and every single asteroid.
Finally I turned off the pseudo-crosshairs I'd been working with. This was another happy accident: By rendering the player sphere as a wireframe, the camera peeking out from inside happened to see a vertex directly ahead, giving us a super-cheap crosshair*.
* Crosshair singular or plural? Who could possibly say.
Alas the lines filled the screen and really messed with the cool darkness of warp - as well as obscuring asteroids far away - so it had to go. Now we don't render the player at all unless we switch into an external camera, which only happens when you bite the bullet. Or indeed asteroid.
Stay safe out there.