Short answer: Math
Long answer:
There are a lot of shortcuts you can take here depending on where the gun output is in relationship to the point of rotation and the position of the player. For purposes of this explanation, I'm going to assume you are unable to take any of these shortcuts.
To start with, we need to know a few things:
1) The player's position
2) The point of rotation in relation to the player's position.
3) At angle 0 (no rotation), the point of the gun output in relation to the point of rotation
4) The angle of rotation
Note that all of these positions (except for #1, the player position) are relative to another point. Therefore if we assume there is no rotation, the point of gun output would simply be:
1 2 3
|
output = player_pos + rot_pos + gun_pos;
// that is... #1 + #2 + #3
|
So then the tricky part is rotating the gun. But really.. that's not all that tricky.
2D rotation is pretty simple. Given an angle 'theta' (#4), you can rotate any 2D point with the below code:
1 2 3 4 5
|
double sintheta = sin(theta);
double costheta = cos(theta);
rotated.x = (gun_pos.x * costheta) - (gun_pos.y * sintheta);
rotated.y = (gun_pos.y * costheta) + (gun_pos.x * sintheta);
|
'rotated' is now rotated around the origin (0,0). Since 'gun_pos' is a relative to the rotation point, we were already oringiated at 0,0.
So all we have to do from there is sub in our rotated point:
|
output = player_pos + rot_pos + rotated;
|
And that's where you'd spawn your bullet.