/** * Handles collision logic between a ship and a projectile */ void System::Collide(Ship& ship, Projectile& proj) { if(proj.getMass() == 0 || ship.getMass() == 0) return; double dx = proj.getPosition().x-ship.getPosition().x; double dy = proj.getPosition().y-ship.getPosition().y; double separationSquared = dx*dx+dy*dy; //May be inaccurate with verlet double totalDamageRange = proj.getCollisionRange() + ship.getCollisionRange(); if(separationSquared < (totalDamageRange * totalDamageRange)) { ship.Damage(proj.getDamage()); proj.Destroy(); } }
void RemoteProcessClient::writeProjectile(const Projectile& projectile) { writeBoolean(true); writeLong(projectile.getId()); writeDouble(projectile.getMass()); writeDouble(projectile.getX()); writeDouble(projectile.getY()); writeDouble(projectile.getSpeedX()); writeDouble(projectile.getSpeedY()); writeDouble(projectile.getAngle()); writeDouble(projectile.getAngularSpeed()); writeDouble(projectile.getRadius()); writeLong(projectile.getCarId()); writeLong(projectile.getPlayerId()); writeEnum<ProjectileType>(projectile.getType()); }