Exemplo n.º 1
0
void CreatureUI::drawName(int x, int y, float scale, bool visible) const
{
    //Health Bar
    Creature* n = (Creature*)this;
    int hp = n->getHealth();
    if (hp == 0 && (n->getID() != GlobalVariables::getPlayerID())) return;
    oRGBA col = getHealthColor(hp);
    // FIXME (nfries88): This is the wrong color! But it proves the code works.
    if(!visible) col = oRGBA(255./2., 255./2., 255./2., 255.);

    g_engine->drawRectangle(x-1, y-1, 28, 4, oRGBA(0,0,0,255));
    g_engine->drawRectangle(x, y, 26*(hp/100.), 2, col);

    //Name
    std::string name = n->getName().c_str();
    name[0] = toupper(name[0]);

    // NOTE (Kilouco): Not calculated here anymore.
    //volatile float centralizationoffset = (g_engine->sizeText(name.c_str(), "gamefont" ) / 2);

    x = (x + 14); // - centralizationoffset);
    y -= 12;

    g_engine->drawTextGW(name.c_str(), "gamefont", x, y, scale, col);
}
Exemplo n.º 2
0
bool UnitBase::update() {
    if(active) {
        targeting();
        navigate();
        move();
        if(active) {
            turn();
        }
    }

    if(getHealth() <= 0.0f) {
        destroy();
        return false;
    }

    if(active && (getHealthColor() != COLOR_LIGHTGREEN) && !goingToRepairYard && owner->hasRepairYard() && (owner->isAI() || owner->hasCarryalls())
            && !isInfantry() && !isAFlyingUnit() && !forced && target.getObjPointer() == NULL) {
        doRepair();
    }


    if(recalculatePathTimer > 0) recalculatePathTimer--;
    if(findTargetTimer > 0) findTargetTimer--;
    if(primaryWeaponTimer > 0) primaryWeaponTimer--;
    if(secondaryWeaponTimer > 0) secondaryWeaponTimer--;
    if(deviationTimer != INVALID) {
        if(--deviationTimer <= 0) {
            quitDeviation();
        }
    }

	return true;
}
Exemplo n.º 3
0
void UnitBase::drawSelectionBox() {

    SDL_Surface* selectionBox = NULL;

    switch(currentZoomlevel) {
        case 0:     selectionBox = pGFXManager->getUIGraphic(UI_SelectionBox_Zoomlevel0);   break;
        case 1:     selectionBox = pGFXManager->getUIGraphic(UI_SelectionBox_Zoomlevel1);   break;
        case 2:
        default:    selectionBox = pGFXManager->getUIGraphic(UI_SelectionBox_Zoomlevel2);   break;
    }

    SDL_Rect dest = {   screenborder->world2screenX(realX) - selectionBox->w/2,
                        screenborder->world2screenY(realY) - selectionBox->h/2,
                        selectionBox->w,
                        selectionBox->h };
	SDL_BlitSurface(selectionBox, NULL, screen, &dest);

	int x = screenborder->world2screenX(realX) - selectionBox->w/2;
	int y = screenborder->world2screenY(realY) - selectionBox->h/2;
	for(int i=1;i<=currentZoomlevel+1;i++) {
        drawHLine(screen, x+1, y-i, x+1 + ((int)((getHealth()/(float)getMaxHealth())*(selectionBox->w-3))), getHealthColor());
	}
}