src/Projectile.cc
author saiam
Thu, 04 Dec 2008 21:10:41 +0000
changeset 199 f5c86420facd
parent 197 d9ac888de778
child 200 2dbf40661580
permissions -rw-r--r--
Jeejee, hirvee hinaus ohi toistaseks.
#include "Projectile.hh"

Shot::Shot(GameState &state, Vector position, Vector velocity, bool visible) :
    PhysicsObject((PhysicsWorld &) state, PLAYER_MASS, position, velocity), state(state), visible(visible), destroyed(false) {
    // Looks kind of dumb, for ammunition to have shape
    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);
    target_visible = false;
    collision_elasticity = 0.9; // = shotType.elasticity
    world.addProjectile(this);
}

 
void Shot::onCollision() {
    world.removeGround(position, 20);
    this->destroyed = true;
}

bool Shot::isDestroyed (void) {
    return this->destroyed;
}

void Shot::draw(CL_GraphicContext *gc) {


    CL_Quad player(
                   (int)((position).x+1), (int)((position).y+1),
                   (int)((position).x-1), (int)((position).y+1),
                   (int)((position).x+1), (int)((position).y-1),
                   (int)((position).x-1), (int)((position).y-1)
                   );

    gc->fill_quad(player, CL_Color::green);

    const uint16_t chlen = 10;
    uint16_t x = player.center().x;
    uint16_t y = player.center().y;
    if(target_visible) {
        if (facingRight) {
            gc->draw_line(x, y,
                          x + std::cos(aim)*chlen,
                          y - std::sin(aim)*chlen,
                          CL_Color::black);
        } else {
            gc->draw_line(x, y,
                          x - std::cos(aim)*chlen,
                          y - std::sin(aim)*chlen,
                          CL_Color::black);
        }
    }
}