Test it: https://retrogradeorbit.github.io/cloud-fighter Source: http://github.com/infinitelives/infinitelives.pixi
Didn't have much time today. Only a few hours after work and before bed. Put in the directional controls. And added Shooting.
For the directions I needed to work out if the player was turning left or right. So I took their present heading and rotated that vector 90 degrees to the right. Then I did a dot product with the vector of the analogue stick. If a dot product between two vectors is positive, then the angle between them (with their tails coincident) is an acute angle (less than 90 degrees). If it's negative its a larger, obtuse angle. So if its positive we turn to the right, if its negative we turn to the left.
The code for this was very succinct, but it actually didn't work as well as I'd hoped. When you hold the ship in one direction, the ship rotates to that position and then oscillates around the position, turning left, right, left, right, as it overshoots the final position with each frame. You cant see this on the ship itself because the oscillation is so small. But as soon as I added the bullets you can see it with two streams of bullets flying out alternating!
What I need to do is write a function that takes the present heading, the wished for heading, and returns a new heading that is slightly closer to the wished for heading, or if it's close enough, the actual wished for heading. Instead of returning :left or :right, it needs to return a vector.
I won't have much time again until the weekend, but I'm gonna try and get little bits done so the weekend can be as productive as possible.