How to fire cannon balls out of a rotatable cannon
I'm creating a game where you rotate a cannon, at the bottom of the screen, clockwise and counterclockwise with the left and right arrow keys. When you press space a cannonball fires out of the cannon at the appropriate angle. For example, if the cannon was rotated 45 degrees the cannon ball would move 20 pixels to the right and 20 pixels up every step.
I have everything besides the actual formula for creating the rise over run for the cannon ball.
Here is how the cannon ball moves, dictated by the move method:
Code:
public void move()
{
x += xspeed;
y += yspeed;
}
I want to convert the angle of the cannon into a xspeed and yspeed for the cannonball.
Any help or advice would be greatly appreciated.
Re: How to fire cannon balls out of a rotatable cannon