Hi guys! Still on the sidescrolling shooter thing... Right now, I have two superclasses. Mainly, the Weapon and Projectile classes.
class Weapon
{
protected:
int x;
int y;
int ammo;
int maxAmmo;
int fireRate;
int waitCount;
int weaponLevel;
public:
virtual ~Weapon();
public:
virtual void dragWeapon(int x, int y) = 0;
virtual void fire() = 0;
virtual void recharge() = 0;
virtual void fullCharge() = 0;
virtual char* getWeaponName() = 0;
virtual void incrementWeaponLevel();
};
class Projectile : public Sprite
{
protected:
bool active;
bool fired;
public:
virtual ~Projectile();
public:
virtual void update();
virtual void move(int x, int y);
virtual bool isFired();
virtual bool isActive();
virtual void makeInactive();
};
and several classes would extend from theser two superclasses. Now, I have subclassess called VulcanGun which extends from Weapon, and Vulcan which extends from Projectile. Here are the implementations.
#include "globals.h"
VulcanGun::VulcanGun()
{
//std::cout << "Creating VulcanGun object...\n";
}
VulcanGun::VulcanGun(int x, int y, int ammo, int maxAmmo, int fireRate, int wLevel)
{
this->x = x;
this->y = y;
this->ammo = ammo;
this->maxAmmo = maxAmmo;
this->fireRate = fireRate;
this->waitCount = 0;
weaponLevel = wLevel;
}
VulcanGun::~VulcanGun()
{
}
void VulcanGun::dragWeapon(int x, int y)
{
this->x = x;
this->y = y;
}
void VulcanGun::fire()
{
if (waitCount <= 0)
{
int pfPoolSize;
switch(weaponLevel)
{
case 1:
ProjectileFactory::projectilePool.push_back( ProjectileFactory::getProjectile(VULCAN) );
pfPoolSize= ProjectileFactory::projectilePool.size();
ProjectileFactory::projectilePool[pfPoolSize - 1]->move(x, y);
waitCount = fireRate;
play_sample( SoundManager::getSample(VULCAN_GUN_FIRE_SFX), 255, 0, 2000, 0);
break;
case 2:
ProjectileFactory::projectilePool.push_back( ProjectileFactory::getProjectile(VULCAN) );
ProjectileFactory::projectilePool.push_back( ProjectileFactory::getProjectile(VULCAN) );
pfPoolSize= ProjectileFactory::projectilePool.size();
ProjectileFactory::projectilePool[pfPoolSize - 1]->move(x, y);
ProjectileFactory::projectilePool[pfPoolSize - 2]->move(x, y + 20);
waitCount = fireRate;
play_sample( SoundManager::getSample(VULCAN_GUN_FIRE_SFX), 255, 0, 2000, 0);
break;
case 3:
ProjectileFactory::projectilePool.push_back( ProjectileFactory::getProjectile(VULCAN) );
ProjectileFactory::projectilePool.push_back( ProjectileFactory::getProjectile(VULCAN) );
ProjectileFactory::projectilePool.push_back( ProjectileFactory::getProjectile(VULCAN) );
pfPoolSize= ProjectileFactory::projectilePool.size();
ProjectileFactory::projectilePool[pfPoolSize - 1]->move(x, y);
ProjectileFactory::projectilePool[pfPoolSize - 2]->move(x + 10, y + 10);
ProjectileFactory::projectilePool[pfPoolSize - 3]->move(x, y + 20);
waitCount = fireRate;
play_sample( SoundManager::getSample(VULCAN_GUN_FIRE_SFX), 255, 0, 2000, 0);
break;
default:
break;
}
}
}
void VulcanGun::recharge()
{
--this->waitCount;
}
void VulcanGun::fullCharge()
{
this->waitCount = 0;
}
char* VulcanGun::getWeaponName()
{
return "Vulcan Gun";
}
#include "globals.h"
/*
Vulcan::Vulcan()
{
}
*/
Vulcan::Vulcan(int x, int y, int w, int h, int speed, bool active, bool fired)
{
this->x = x;
this->y = y;
this->width = w;
this->height = h;
this->speed = speed;
this->active = active;
this->fired = fired;
animation = new Animation(BitmapManager::getBitmap(VULCAN_SPRITE), 5, 4, BY_WIDTH);
}
Vulcan::~Vulcan()
{
//std::cout << "Deleting Vulcan...\n";
}
void Vulcan::update()
{
if (this->x < SCREEN_W)
{
move(this->x + speed, this->y);
animation->animate();
}
}
void Vulcan::move(int x, int y)
{
this->x = x;
this->y = y;
}
void Vulcan::draw()
{
draw_sprite(GameManager::buffer, animation->getCurrentAnimationFrame(), this->x, this->y);
}
as you can see with that, the VulcanGun and Vulcan classes seems to be too specifically designed for the main ship. I could not reuse them for use of the enemies. Do you guys have any idea what I could be missing? Thanks!