Today I fixed the player's oscillation bug. The function now returns a vector. I still use the dot product method to determine if the player is turning left or right, but then I apply the turn to the heading vector (left or right depending on the dot product) and then I calculate the dot product again for this new heading. If it was left and now it's right, or it was right and now it's left, I know the turn has overshot the destination vector and I just return the destination vector. This cured the oscillation bug and the players turning feels more solid now.
I then removed the autofire. I'm going to start with the old school notion of one press, one bullet. It's a little painful to shoot a lot, but that's good. If I get time I can add an autofire pickup later in the game to make life easier.
Onto the enemies. I started with a basic wandering boid, with a little bit of seeking the player. I set up the 'e' key to spawn a new enemy somewhere near the player on screen. And I drew a rough outline of a plane into the sprite sheet. The difficulty came in making the enemy adjust for the players 'position'.
There were two ways to go. I could actually move the player around, like in a conventional game, and make the camera track the player to keep the player centered. This is a method I've used in past game jams. But the game is much simpler than other games I've built. The player is always in the center, and the world only exists for one screen around them. Really it's all an illusion. The parallax clouds just wrap around and are randomly placed. So there is no 'level' to speak of in a conventional sense. So I decided to keep the world's co-ordinate system static, with the player permanently anchored at the center [0 0], and to move everything relative to the players direction around them. This is more like the technique that would have been used back in the day on old 8 bit computers.
To do this I moved all the players state into a state atom in a separate name space. And then just adjusted the boids position in its go-loop each frame by the last velocity. This worked well and it does feel like you are flying around a world, even though the world is flying around you.
Next task is to implement some collision detection. Bullets shoot planes and collisions go boom!
Play the game here: https://retrogradeorbit.github.io/cloud-fighter/ and don't forget to press the 'e' key to spawn enemies.