In order to respond to the tilt of the device, we need to use the device's accelerometer. These aren't the easiest things to deal with, and our implementation is a bit naïve. Unfortunately, it doesn't take long until you start getting into the math that's more than a bit complicated, and so lies outside the scope of this project.
Accelerometer-based input is hard – really hard. So hard, in fact, that the game doesn't have a particularly good implementation of it. You are encouraged to experiment with a lot of devices and algorithms to come up with a good control scheme.
To turn on the accelerometer check, we first have to set up a watch for it:
tiltWatch = navigator.accelerometer.watchAcceleration ( updateAccelerometer, accelerometerError, { frequency: 40 } );
This sets up a 40 milliseconds watch–not really quite as fast as I'd like, but workable. Every 40 milliseconds, the updateAccelerometer...