I have a space type shooter game where a ship shoots bullets. The ship can rotate 360 degrees. Basically the ship faces the mouse cursor as the cursor moves around the screen. Right now the bullets do not leave from the center of the ship, they move based on the rotation so they are offset sometimes. It looks weird so I want to fix it.
Here is the rotation code for the player
and here is the code to create the bullet
a = gun->fire(pos_x, pos_y, player, 16);
]]>Where are you drawing the centre of your ship - is it (posX, posY) or (posX+16, posY+16)? Also is pos_x the same as posX?
Basically, if I understand correctly, you want to start the bullet at (cx + r * cos(ang), cy + r * sin(ang)) where ang is the angle the ship is pointing, (cx, cy) is the ship's centre, and r is the distance from the ship's centre to the point where you want the bullet to appear. (I'm assuming your ship has a gun at the end of its nose, like the one in Asteroid)
]]>correct, the bullet should leave from the center of the player and travel out the nose of the ship, here is the player draw
]]>
You probably want to draw the center of your ship at (posX, posY) instead:
al_draw_rotated_bitmap(image, (width / 2), (height / 2), posX, posY, faceAngle, 0);
]]>