
33711.6. Spacewar v1.0
spriteData.y = -torpedoNS::HEIGHT; // Position off top screen
// edge
else if (spriteData.y < -torpedoNS::HEIGHT) // Else if off top screen
// edge
spriteData.y = GAME_HEIGHT; // Position off bottom
// screen edge
}
Listing 11.5. e update function from the Torpedo class.
//========================================================================
// Fire
// Fires a torpedo from ship
//========================================================================
void Torpedo::fire(Entity *ship)
{
if(fireTimer <= 0.0f) // If ready to fire
{
velocity.x = (float)cos(ship->getRadians()) * torpedoNS::SPEED;
velocity.y = (float)sin(ship->getRadians()) ...