I'm trying to get bullets to fire from the ship in the direction it is rotated. I've tried using the following, but it keeps firing long, weird lines to the top left corner of the screen. I have to admit that triggonometry stuff is vague to me...any tips?
Code:
double bvx,bvy,bpx,bpy;
void Bullet::InitObject(void)
{
dAngle = pSpaceship->getShipsAngle();
bvx = 10 * sin(dAngle) + pSpaceship->getShipsVelocity().XValue;
bvy = 10 * cos(dAngle) + pSpaceship->getShipsVelocity().YValue;
bpx = pSpaceship->getShipsPosition().XValue;
bpy = pSpaceship->getShipsPosition().YValue;
v2dVelocity = Vector2D(bvx,bvy);
v2dPosition = Vector2D(bpx,bpy);
}
///////////////////////////////////////////////////////////////////////////
void Bullet::DrawObject(void) //Draw the bullet as per coordinates
{
bvx = 10 * sin(dAngle);
bvy = -10 * cos(dAngle);
v2dVelocity += Vector2D(bvx,bvy);
pTheDrawEngine->LockBackSurface(); //Lock back surface
pTheDrawEngine->DrawLine(v2dPosition, v2dVelocity,
MyDrawEngine::YELLOW32);
pTheDrawEngine->UnlockBackSurface();//Unlock back surface
}