/**
 * Move direct to the destination.
 * @param field destination field
 * @return whether a move was made
 */
bool
MouseControl::moveHardTo(const V2 &field) const
{
    bool moved = false;
    const Unit *unit = m_controls->getActive();
    if (unit) {
        V2 loc = unit->getLoc();
        if (field.getX() < loc.getX()) {
            moved = m_controls->makeMove(unit->myOrder(Dir::DIR_LEFT));
        }
        else if (loc.getX() + unit->getW() <= field.getX()) {
            moved = m_controls->makeMove(unit->myOrder(Dir::DIR_RIGHT));
        }
        else if (field.getY() < loc.getY()) {
            moved = m_controls->makeMove(unit->myOrder(Dir::DIR_UP));
        }
        else if (loc.getY() + unit->getH() <= field.getY()) {
            moved = m_controls->makeMove(unit->myOrder(Dir::DIR_DOWN));
        }
    }
    return moved;
}
Beispiel #2
0
/**
 * Draw model.
 * Care about model shift during move.
 */
    void
View::drawModel(Cube *model)
{
    if (!model->isLost()) {
        V2 screenPos = getScreenPos(model);

        Anim::eSide side = Anim::SIDE_LEFT;
        if (!model->isLeft()) {
            side = Anim::SIDE_RIGHT;
        }
        model->anim()->drawAt(m_screen,
                screenPos.getX(), screenPos.getY(), side);
    }
}