Example #1
0
///
/// \brief  "Fires" a round from the Ship's ammo collection. The count of
///         ammo is decremented thereafter.
/// \return void
///
void    Ship::fire()
{
    if (ammo_pos_ != ammo_.end()) {
        vector2 bP(0, 0);

        // calculate the position of the bullet at the 'nose' of the ship
        float ra = to_radians(rot_angle_);
        rotate_vector((C_ - center_), ra, bP);
        bP += pos_ + center_;

        (*ammo_pos_).fire(bP, vel_ * 5);

        ++ammo_pos_;
    } else {
        DEBUG_PRINT << ">>> OUT OF AMMO -- RELOADING!" << std::endl;

        reloadAmmo();
    }
}
Example #2
0
//TODO: range from edges, not center?
bool withinRange(Unit* a, int r, Unit* b)
{
    QPoint aP(a->x() + a->width()/2, a->y() + a->height()/2);
    QPoint bP(b->x() + b->width()/2, b->y() + b->height()/2);
    return (bP - aP).manhattanLength() <= r;
}