X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2FHeroTag.cpp;h=6dc5e86fa11d261063def6720f0bd6b82ed73e59;hb=a3ba4dc677ad7c92eeb78b20b642241563605c9d;hp=a83ba8b9fc1f019dd5695816db09388cb653d5fe;hpb=3c72a71fbf6de96333a641051a20c6bf8b3a5df3;p=l2e.git diff --git a/src/battle/HeroTag.cpp b/src/battle/HeroTag.cpp index a83ba8b..6dc5e86 100644 --- a/src/battle/HeroTag.cpp +++ b/src/battle/HeroTag.cpp @@ -1,96 +1,96 @@ -/* - * HeroTag.cpp - * - * Created on: Aug 6, 2012 - * Author: holy - */ - #include "HeroTag.h" #include "AttackChoice.h" +#include "BattleState.h" #include "Hero.h" #include "Resources.h" -#include "../geometry/operators.h" -#include "../geometry/Vector.h" +#include "../math/Vector.h" #include "../graphics/Font.h" #include "../graphics/Frame.h" #include "../graphics/Gauge.h" #include "../graphics/Sprite.h" -using geometry::Point; -using geometry::Vector; +using math::Vector; using graphics::Frame; namespace battle { -void HeroTag::Render(SDL_Surface *screen, int width, int height, Point position, bool active) const { +const graphics::Sprite *HeroTag::HeroSprite() const { + return battle->HeroAt(index).Sprite(); +} + +void HeroTag::Render(SDL_Surface *screen, int width, int height, const Vector &position, bool active) const { + const Resources &r(battle->Res()); + // frame - const Frame *frame(active ? res->activeHeroTagFrame : res->heroTagFrame); - Vector frameOffset(frame->BorderWidth(), frame->BorderHeight()); - Vector alignOffset(align == LEFT ? 4 * res->heroTagFont->CharWidth() : 0, 0); + const Frame *frame(active ? r.activeHeroTagFrame : r.heroTagFrame); + Vector frameOffset(frame->BorderSize()); + Vector alignOffset((index % 2) ? 4 * r.heroTagFont->CharWidth() : 0, 0); frame->Draw(screen, position, width, height); + const Hero &hero(battle->HeroAt(index)); + // gauges // NOTE: assuming frame border is unit size until charsets are impemented - int gaugeX((align == LEFT ? 10 : 6) * res->heroTagFont->CharWidth()); + int gaugeX(((index % 2) ? 10 : 6) * r.heroTagFont->CharWidth()); // 4 units reserved for hero, gaugeX already includes frame offset - int gaugeWidth(width - gaugeX - (align == LEFT ? 1 : 5) * res->heroTagFont->CharWidth()); + int gaugeWidth(width - gaugeX - ((index % 2) ? 1 : 5) * r.heroTagFont->CharWidth()); // health gauge, second line - Vector healthGaugeOffset(gaugeX, frameOffset.Y() + res->heroTagFont->CharHeight()); - res->healthGauge->Draw(screen, position + healthGaugeOffset, gaugeWidth, hero->RelativeHealth(gaugeWidth)); + Vector healthGaugeOffset(gaugeX, frameOffset.Y() + r.heroTagFont->CharHeight()); + r.healthGauge->Draw(screen, position + healthGaugeOffset, gaugeWidth, hero.RelativeHealth(255)); // mana gauge, third line - Vector manaGaugeOffset(gaugeX, frameOffset.Y() + 2 * res->heroTagFont->CharHeight()); - res->manaGauge->Draw(screen, position + manaGaugeOffset, gaugeWidth, hero->RelativeMana(gaugeWidth)); + Vector manaGaugeOffset(gaugeX, frameOffset.Y() + 2 * r.heroTagFont->CharHeight()); + r.manaGauge->Draw(screen, position + manaGaugeOffset, gaugeWidth, hero.RelativeMana(255)); // ikari gauge, fourth line - Vector ikariGaugeOffset(gaugeX, frameOffset.Y() + 3 * res->heroTagFont->CharHeight()); - res->ikariGauge->Draw(screen, position + ikariGaugeOffset, gaugeWidth, hero->RelativeIP(gaugeWidth)); + Vector ikariGaugeOffset(gaugeX, frameOffset.Y() + 3 * r.heroTagFont->CharHeight()); + r.ikariGauge->Draw(screen, position + ikariGaugeOffset, gaugeWidth, hero.RelativeIP(255)); // labels - int labelX((align == LEFT ? 5 : 1) * res->heroTagFont->CharWidth()); + int labelX(((index % 2) ? 5 : 1) * r.heroTagFont->CharWidth()); // level Vector levelLabelOffset(gaugeX, frameOffset.Y()); - res->heroTagLabels->Draw(screen, position + levelLabelOffset, 0, 0); + r.heroTagLabels->Draw(screen, position + levelLabelOffset, r.levelLabelCol, r.levelLabelRow); // hp - Vector healthLabelOffset(labelX, frameOffset.Y() + res->heroTagFont->CharHeight()); - res->heroTagLabels->Draw(screen, position + healthLabelOffset, 0, 1); + Vector healthLabelOffset(labelX, frameOffset.Y() + r.heroTagFont->CharHeight()); + r.heroTagLabels->Draw(screen, position + healthLabelOffset, r.healthLabelCol, r.healthLabelRow); // mp - Vector manaLabelOffset(labelX, frameOffset.Y() + 2 * res->heroTagFont->CharHeight()); - res->heroTagLabels->Draw(screen, position + manaLabelOffset, 0, 2); + Vector manaLabelOffset(labelX, frameOffset.Y() + 2 * r.heroTagFont->CharHeight()); + r.heroTagLabels->Draw(screen, position + manaLabelOffset, r.manaLabelCol, r.manaLabelRow); // cm - Vector moveLabelOffset(labelX, frameOffset.Y() + 3 * res->heroTagFont->CharHeight()); - res->heroTagLabels->Draw(screen, position + moveLabelOffset, 0, 3); + Vector moveLabelOffset(labelX, frameOffset.Y() + 3 * r.heroTagFont->CharHeight()); + r.heroTagLabels->Draw(screen, position + moveLabelOffset, r.moveLabelCol, r.moveLabelRow); // ip - Vector ikariLabelOffset(labelX + 3 * res->heroTagFont->CharWidth(), frameOffset.Y() + 3 * res->heroTagFont->CharHeight()); - res->heroTagLabels->Draw(screen, position + ikariLabelOffset, 0, 4); + Vector ikariLabelOffset(labelX + 3 * r.heroTagFont->CharWidth(), frameOffset.Y() + 3 * r.heroTagFont->CharHeight()); + r.heroTagLabels->Draw(screen, position + ikariLabelOffset, r.ikariLabelCol, r.ikariLabelRow); // numbers // level - Vector levelNumberOffset(gaugeX + res->heroTagLabels->Width(), levelLabelOffset.Y()); - res->heroTagFont->DrawNumber(hero->Level(), screen, position + levelNumberOffset, 2); + Vector levelNumberOffset(gaugeX + r.heroTagLabels->Width(), levelLabelOffset.Y()); + r.heroTagFont->DrawNumber(hero.Level(), screen, position + levelNumberOffset, 2); // health - Vector healthNumberOffset(labelX + res->heroTagLabels->Width(), healthLabelOffset.Y()); - res->heroTagFont->DrawNumber(hero->Health(), screen, position + healthNumberOffset, 3); + Vector healthNumberOffset(labelX + r.heroTagLabels->Width(), healthLabelOffset.Y()); + r.heroTagFont->DrawNumber(hero.Health(), screen, position + healthNumberOffset, 3); //mana - Vector manaNumberOffset(labelX + res->heroTagLabels->Width(), manaLabelOffset.Y()); - res->heroTagFont->DrawNumber(hero->Mana(), screen, position + manaNumberOffset, 3); + Vector manaNumberOffset(labelX + r.heroTagLabels->Width(), manaLabelOffset.Y()); + r.heroTagFont->DrawNumber(hero.Mana(), screen, position + manaNumberOffset, 3); // name - res->normalFont->DrawString(hero->Name(), screen, position + frameOffset + alignOffset, 5); + r.normalFont->DrawString(hero.Name(), screen, position + frameOffset + alignOffset, 5); // attack icon - if (choice->GetType() != AttackChoice::UNDECIDED) { - Vector attackIconOffset(labelX + res->heroTagLabels->Width(), frameOffset.Y() + 3 * res->heroTagFont->CharHeight()); - res->attackChoiceIcons->Draw(screen, position + attackIconOffset, 0, choice->GetType()); + if (battle->HeroAt(index).GetAttackChoice().GetType() != AttackChoice::UNDECIDED) { + Vector attackIconOffset(labelX + r.heroTagLabels->Width(), frameOffset.Y() + 3 * r.heroTagFont->CharHeight()); + r.attackChoiceIcons->Draw(screen, position + attackIconOffset, 0, battle->HeroAt(index).GetAttackChoice().GetType()); } // hero - hero->Sprite()->Draw(screen, position + HeroOffset(), 0, hero->Health() > 0 ? 0 : 2); + HeroSprite()->DrawCenter(screen, position + HeroOffset(), 0, battle->HeroAt(index).Health() > 0 ? 0 : 2); } Vector HeroTag::HeroOffset() const { return Vector( - (align == LEFT) ? res->normalFont->CharWidth() : 10 * res->normalFont->CharWidth(), - res->normalFont->CharWidth()); + ((index % 2) ? battle->Res().normalFont->CharWidth() : 10 * battle->Res().normalFont->CharWidth()) + HeroSprite()->Width() / 2, + battle->Res().normalFont->CharWidth() + HeroSprite()->Height() / 2); } }