src/Projectile.cc
changeset 211 d5d52fb191e4
parent 208 7709571e1131
child 222 293ddf4c067d
equal deleted inserted replaced
210:501b5a1918b5 211:d5d52fb191e4
     2 #include "Timer.hh"
     2 #include "Timer.hh"
     3 
     3 
     4 Projectile::Projectile(GameState &state, Vector position, Vector velocity, bool visible, float radius, TickCount age) :
     4 Projectile::Projectile(GameState &state, Vector position, Vector velocity, bool visible, float radius, TickCount age) :
     5     PhysicsObject(state.world, PLAYER_MASS, position, velocity), state(state), visible(visible), radius(radius), destroyed(false), age(age) {
     5     PhysicsObject(state.world, PLAYER_MASS, position, velocity), state(state), visible(visible), radius(radius), destroyed(false), age(age) {
     6     birth_tick = world.tick_timer.get_ticks();
     6     birth_tick = world.tick_timer.get_ticks();
     7     // Looks kind of dumb, for ammunition to have shape
     7     // Don't think these are needed anymore
     8     std::vector<Vector> shape(4);
     8     std::vector<Vector> shape(4);
     9     shape[0] = Vector(-1, -1);
     9     shape[0] = Vector(-1, -1);
    10     shape[1] = Vector(-1, 1);
    10     shape[1] = Vector(-1, 1);
    11     shape[2] = Vector(1, 1);
    11     shape[2] = Vector(1, 1);
    12     shape[3] = Vector(1, -1);
    12     shape[3] = Vector(1, -1);
    13     setShape(shape);
    13     setShape(shape);
       
    14 
    14     target_visible = false;
    15     target_visible = false;
    15     collision_elasticity = 0.9; // = shotType.elasticity
    16     collision_elasticity = 0.9; // = shotType.elasticity
    16     world.addProjectile(this);
    17     world.addProjectile(this);
    17 }
    18 }
    18 
    19 
    20 void Projectile::onCollision() {
    21 void Projectile::onCollision() {
    21     world.removeGround(position, radius);
    22     world.removeGround(position, radius);
    22     this->destroyed = true;
    23     this->destroyed = true;
    23 }
    24 }
    24 
    25 
    25 bool Projectile::isDestroyed (void) {
    26 bool Projectile::isDestroyed (void) const {
    26     return this->destroyed;
    27     return this->destroyed;
    27 }
    28 }
    28 
    29 
    29 void Projectile::draw(CL_GraphicContext *gc) {
    30 void Projectile::draw(CL_GraphicContext *gc) const {
    30     if (visible) {
    31     if (visible) {
    31   
    32   
    32         CL_Quad projectile(
    33         CL_Quad projectile(
    33                            (int)((position).x+1), (int)((position).y+1),
    34                            (int)((position).x+1), (int)((position).y+1),
    34                            (int)((position).x-1), (int)((position).y+1),
    35                            (int)((position).x-1), (int)((position).y+1),