Example #1
0
/**
 * Draw the overlay and processes button events.
 */
void Overlay::draw(float dt)
{
    // update the current turn label

    Level::turn t = level->getCurrentTurn();

    bool herot = (t == Level::HERO_TURN);
    bool haggist = (t == Level::HAGGIS_TURN);
    bool actiont = (t == Level::ACTION_TURN);

    heroturn->setEnabled(herot);
    haggisturn->setEnabled(haggist);
    actionturn->setEnabled(actiont);

    // update the progress bars

    Hero *h = level->getHero();
    bars[0]->setProgress((float) h->getHealth() / (float) h->getMaxStat());
    bars[1]->setProgress((float) h->getEnergy() / (float) h->getMaxStat());
    bars[2]->setProgress((float) h->getAmmo() / (float) h->getMaxStat());

    // update the action buttons

    actions[0]->setEnabled(WaitAction::canWait(h));
    actions[1]->setEnabled(WalkAction::canWalk(h));
    actions[2]->setEnabled(JumpAction::canJump(h));
    actions[3]->setEnabled(GrenadeAction::canThrow(h));
    actions[4]->setEnabled(PsychicAction::canPsychic(h));

    // do something depending on the state
    // check for action button presses
    // if it is the haggis' turn, do nothing
    if(!haggist)
    {
        for (int i=0; i<(int)actions.size(); i++)
        {
            if (actions[i]->isPressed())
            {
                actions[i]->reset();  //set pressed = false
                //only handle button if in right state
                if(state == NORMAL)
                {
                    handleButton(i);
                }
                else if(action == i)
                {
                    action = -1;
                    handleCellSelection(); //to return state to normal
                }
            }
        }
    }

    if ((state == WAITING_FOR_CELL) && maze)
    {
        // check if a cell has been selected
        if (maze->getSelection())
        {
            handleCellSelection();
        }
    }
}