Direction of the bullet - how to have something else than left, right, top, bottom
- by Florian Margaine
I'm making a simple shooter game using canvas and javascript. The current code can be seen here.
To know which way I want the bullet to be shot, I simply have a direction property that can have 4 values (left, right, bottom, top), and I can then calculate the next position of the bullet easily.
However, I'd like to move the bullet to the mouse position, but I don't really see how to do this. How do I calculate the next position? I'm guessing there is some formula to calculate the line between two positions (the player's and the mouse's), but I don't have much idea yet.
So there is no obstacle, but I don't see how to calculate this, and be able have the next position of the bullet at each frame.