The ship movement depends on the coordinate system used in your graphics.
Since you've said 90 degrees is "right", I'm going to assume that you're using clockwise bearings, with 0 degrees as "up".
Rather than manipulating the angle to convert from the cartesian convention of 0 degrees being right and then rotating clockwise, it's easier to simply flip around which trigonometric function you call for each axis.
Graphics2D
, like most other graphics systems, uses increasing X coordinates as you move right, so:
delta_x = Math.sin(angle * Math.PI / 180.0)
You should be able to trivially see that this gives delta_x = 1.0
for 90 degrees, and delta_x = -1.0
for 270 degrees.
In Graphics2D
Y coordinates increase as you move downwards (i.e. [0, 0]
is at top-left), so use:
delta_y = -Math.cos(angle * Math.PI / 180.0)
Giving delta_y = -1.0
for 0 degrees, and delta_y = 1.0
for 180 degrees.
If you were using a system with [0, 0]
at bottom-left you would just remove the unary minus (-
) from the delta_y
formula.