1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
//parent class
{
mName = "DefaultName";
mPosition = Vector3(0.0f, 0.0f, 0.0f);
mVelocity = Vector3(0.0f, 0.0f, 0.0f);
mFuelLevel = 100;
mDamage = 0;
}
Spaceship::Spaceship(const string& name,
const Vector3& pos,
const Vector3& vel,
int fuel,
int damage)
{
mName = name;
mPosition = pos;
mVelocity = vel;
mFuelLevel = fuel;
mDamage = damage;
}
//child class
class FighterShip : public Spaceship
{
public:
FighterShip(
const string& name,
const Vector3& pos,
const Vector3& vel,
int fuel,
int damage,
int numMissiles);
private:
int mNumMissiles;
};
FighterShip::FighterShip(const string& name,
const Vector3& pos,
const Vector3& vel,
int fuel,
int damage,
int numMissiles)
: Spaceship(name, pos, vel, fuel, damage)
{
mNumMissiles = numMissiles;
}
|