add a handful of consts to PhysicsObject and modify draw to use getCoordinate, and replace old skin.png with new skin.png
#include "Projectile.hh"
#include "Graphics.hh"
#include "Timer.hh"
Projectile::Projectile(GameState &state, Vector position, Vector velocity, bool visible, float radius, TickCount age) :
PhysicsObject(state.world, PLAYER_MASS, position, velocity), state(state), visible(visible), radius(radius), age(age) {
birth_tick = world.tick_timer.get_ticks();
// Don't think these are needed anymore
std::vector<Vector> shape(4);
shape[0] = Vector(-1, -1);
shape[1] = Vector(-1, 1);
shape[2] = Vector(1, 1);
shape[3] = Vector(1, -1);
setShape(shape);
collision_elasticity = 0.9; // = shotType.elasticity
state.addProjectile(this);
}
Projectile::~Projectile (void) {
state.projectiles.remove(this);
}
void Projectile::onDestroy (Vector position, bool removeGround) {
if (removeGround)
world.removeGround(position, radius);
destroy();
}
void Projectile::onCollision (Vector collisionPoint) {
onDestroy(collisionPoint, true);
}
void Projectile::tick (TimeMS dt) {
// expire projectiles
if (world.tick_timer.get_ticks() > birth_tick + age)
onDestroy(position, true);
// super
PhysicsObject::tick(dt);
}
void Projectile::draw(Graphics *g, PixelCoordinate camera) const {
CL_GraphicContext *gc = g->get_gc();
if (visible) {
PixelCoordinate pos = getCoordinate() - camera;
CL_Quad projectile(
pos.x + 1, pos.y + 1,
pos.x - 1, pos.y + 1,
pos.x + 1, pos.y - 1,
pos.x - 1, pos.y - 1
);
gc->fill_quad(projectile, CL_Color::green);
}
}