heroesLayout->CalculatePositions(background->w, background->h, heroesPositions);
attackChoices.resize(heroes.size());
for (vector<Hero>::size_type i(0), end(heroes.size()); i < end; ++i) {
- heroTags.push_back(HeroTag(&heroes[i], &attackChoices[i], heroTagFrame, activeHeroTagFrame, healthGauge, manaGauge, ikariGauge, heroTagSprites, heroTagFont, HeroTag::Alignment((i + 1) % 2)));
+ heroTags.push_back(HeroTag(&heroes[i], &attackChoices[i], res, HeroTag::Alignment((i + 1) % 2)));
}
}
#include "HeroTag.h"
#include "Monster.h"
#include "MoveMenu.h"
+#include "Resources.h"
#include "../app/State.h"
#include "../geometry/Point.h"
#include "../geometry/Vector.h"
: public app::State {
public:
- BattleState(SDL_Surface *background, const PartyLayout &monstersLayout, const PartyLayout &heroesLayout, const graphics::Sprite *attackIcons, const graphics::Sprite *moveIcons, const graphics::Frame *heroTagFrame, const graphics::Frame *activeHeroTagFrame, const graphics::Gauge *healthGauge, const graphics::Gauge *manaGauge, const graphics::Gauge *ikariGauge, const graphics::Sprite *heroTagSprites, const graphics::Font *heroTagFont, const graphics::Frame *selectFrame)
+ BattleState(SDL_Surface *background, const PartyLayout &monstersLayout, const PartyLayout &heroesLayout, const Resources *res)
: background(background)
, monstersLayout(&monstersLayout)
, heroesLayout(&heroesLayout)
- , heroTagFrame(heroTagFrame)
- , activeHeroTagFrame(activeHeroTagFrame)
- , healthGauge(healthGauge)
- , manaGauge(manaGauge)
- , ikariGauge(ikariGauge)
- , heroTagSprites(heroTagSprites)
- , heroTagFont(heroTagFont)
- , selectFrame(selectFrame)
- , attackTypeMenu(attackIcons)
- , moveMenu(moveIcons)
+ , res(res)
+ , attackTypeMenu(res->attackIcons)
+ , moveMenu(res->moveIcons)
, activeHero(-1) { }
public:
virtual void Render(SDL_Surface *);
public:
+ const Resources &Res() const { return *res; }
AttackTypeMenu &GetAttackTypeMenu() { return attackTypeMenu; }
MoveMenu &GetMoveMenu() { return moveMenu; }
- const graphics::Frame &GetSelectFrame() const { return *selectFrame; }
bool HasMoreHeroes() const { return activeHero < (int) heroes.size(); }
void NextHero() { ++activeHero; }
SDL_Surface *background;
const PartyLayout *monstersLayout;
const PartyLayout *heroesLayout;
- const graphics::Frame *heroTagFrame;
- const graphics::Frame *activeHeroTagFrame;
- const graphics::Gauge *healthGauge;
- const graphics::Gauge *manaGauge;
- const graphics::Gauge *ikariGauge;
- const graphics::Sprite *heroTagSprites;
- const graphics::Font *heroTagFont;
- const graphics::Frame *selectFrame;
+ const Resources *res;
AttackTypeMenu attackTypeMenu;
MoveMenu moveMenu;
std::vector<geometry::Point<int> > monsterPositions;
#include "HeroTag.h"
#include "Hero.h"
+#include "Resources.h"
#include "../geometry/operators.h"
#include "../geometry/Vector.h"
#include "../graphics/Font.h"
using geometry::Point;
using geometry::Vector;
+using graphics::Frame;
namespace battle {
void HeroTag::Render(SDL_Surface *screen, int width, int height, Point<int> position, bool active) const {
// frame
- Vector<int> frameOffset;
- if (active) {
- activeFrame->Draw(screen, position, width, height);
- frameOffset = Vector<int>(activeFrame->BorderWidth(), activeFrame->BorderHeight());
- } else {
- frame->Draw(screen, position, width, height);
- frameOffset = Vector<int>(frame->BorderWidth(), frame->BorderHeight());
- }
+ const Frame *frame(active ? res->activeHeroTagFrame : res->heroTagFrame);
+ Vector<int> frameOffset(frame->BorderWidth(), frame->BorderHeight());
+ frame->Draw(screen, position, width, height);
int yOffset((height - hero->Sprite()->Height()) / 2);
// gauges
// NOTE: assuming frame border is unit size until charsets are impemented
- int gaugeX((align == LEFT ? 10 : 6) * font->CharWidth());
+ int gaugeX((align == LEFT ? 10 : 6) * res->heroTagFont->CharWidth());
// 4 units reserved for hero, gaugeX already includes frame offset
- int gaugeWidth(width - gaugeX - (align == LEFT ? 1 : 5) * font->CharWidth());
+ int gaugeWidth(width - gaugeX - (align == LEFT ? 1 : 5) * res->heroTagFont->CharWidth());
// health gauge, second line
- Vector<int> healthGaugeOffset(gaugeX, frameOffset.Y() + font->CharHeight());
- healthGauge->Draw(screen, position + healthGaugeOffset, gaugeWidth, hero->RelativeHealth(gaugeWidth));
+ Vector<int> healthGaugeOffset(gaugeX, frameOffset.Y() + res->heroTagFont->CharHeight());
+ res->healthGauge->Draw(screen, position + healthGaugeOffset, gaugeWidth, hero->RelativeHealth(gaugeWidth));
// mana gauge, third line
- Vector<int> manaGaugeOffset(gaugeX, frameOffset.Y() + 2 * font->CharHeight());
- manaGauge->Draw(screen, position + manaGaugeOffset, gaugeWidth, hero->RelativeMana(gaugeWidth));
+ Vector<int> manaGaugeOffset(gaugeX, frameOffset.Y() + 2 * res->heroTagFont->CharHeight());
+ res->manaGauge->Draw(screen, position + manaGaugeOffset, gaugeWidth, hero->RelativeMana(gaugeWidth));
// ikari gauge, fourth line
- Vector<int> ikariGaugeOffset(gaugeX, frameOffset.Y() + 3 * font->CharHeight());
- ikariGauge->Draw(screen, position + ikariGaugeOffset, gaugeWidth, hero->RelativeIP(gaugeWidth));
+ Vector<int> ikariGaugeOffset(gaugeX, frameOffset.Y() + 3 * res->heroTagFont->CharHeight());
+ res->ikariGauge->Draw(screen, position + ikariGaugeOffset, gaugeWidth, hero->RelativeIP(gaugeWidth));
// labels
- int labelX((align == LEFT ? 5 : 1) * font->CharWidth());
+ int labelX((align == LEFT ? 5 : 1) * res->heroTagFont->CharWidth());
// level
Vector<int> levelLabelOffset(gaugeX, frameOffset.Y());
- sprites->Draw(screen, position + levelLabelOffset, 0, 0);
+ res->heroTagLabels->Draw(screen, position + levelLabelOffset, 0, 0);
// hp
- Vector<int> healthLabelOffset(labelX, frameOffset.Y() + font->CharHeight());
- sprites->Draw(screen, position + healthLabelOffset, 0, 1);
+ Vector<int> healthLabelOffset(labelX, frameOffset.Y() + res->heroTagFont->CharHeight());
+ res->heroTagLabels->Draw(screen, position + healthLabelOffset, 0, 1);
// mp
- Vector<int> manaLabelOffset(labelX, frameOffset.Y() + 2 * font->CharHeight());
- sprites->Draw(screen, position + manaLabelOffset, 0, 2);
+ Vector<int> manaLabelOffset(labelX, frameOffset.Y() + 2 * res->heroTagFont->CharHeight());
+ res->heroTagLabels->Draw(screen, position + manaLabelOffset, 0, 2);
// cm
- Vector<int> moveLabelOffset(labelX, frameOffset.Y() + 3 * font->CharHeight());
- sprites->Draw(screen, position + moveLabelOffset, 0, 3);
+ Vector<int> moveLabelOffset(labelX, frameOffset.Y() + 3 * res->heroTagFont->CharHeight());
+ res->heroTagLabels->Draw(screen, position + moveLabelOffset, 0, 3);
// ip
- Vector<int> ikariLabelOffset(labelX + 3 * font->CharWidth(), frameOffset.Y() + 3 * font->CharHeight());
- sprites->Draw(screen, position + ikariLabelOffset, 0, 4);
+ Vector<int> ikariLabelOffset(labelX + 3 * res->heroTagFont->CharWidth(), frameOffset.Y() + 3 * res->heroTagFont->CharHeight());
+ res->heroTagLabels->Draw(screen, position + ikariLabelOffset, 0, 4);
// numbers
// level
- Vector<int> levelNumberOffset(gaugeX + sprites->Width(), levelLabelOffset.Y());
- font->DrawNumber(hero->Level(), screen, position + levelNumberOffset, 2);
+ Vector<int> levelNumberOffset(gaugeX + res->heroTagLabels->Width(), levelLabelOffset.Y());
+ res->heroTagFont->DrawNumber(hero->Level(), screen, position + levelNumberOffset, 2);
// health
- Vector<int> healthNumberOffset(labelX + sprites->Width(), healthLabelOffset.Y());
- font->DrawNumber(hero->Health(), screen, position + healthNumberOffset, 3);
+ Vector<int> healthNumberOffset(labelX + res->heroTagLabels->Width(), healthLabelOffset.Y());
+ res->heroTagFont->DrawNumber(hero->Health(), screen, position + healthNumberOffset, 3);
//mana
- Vector<int> manaNumberOffset(labelX + sprites->Width(), manaLabelOffset.Y());
- font->DrawNumber(hero->Mana(), screen, position + manaNumberOffset, 3);
+ Vector<int> manaNumberOffset(labelX + res->heroTagLabels->Width(), manaLabelOffset.Y());
+ res->heroTagFont->DrawNumber(hero->Mana(), screen, position + manaNumberOffset, 3);
// hero
Vector<int> heroOffset(
class AttackChoice;
class Hero;
+struct Resources;
class HeroTag {
};
public:
- HeroTag(const Hero *hero, const AttackChoice *choice, const graphics::Frame *frame, const graphics::Frame *activeFrame, const graphics::Gauge *healthGauge, const graphics::Gauge *manaGauge, const graphics::Gauge *ikariGauge, const graphics::Sprite *sprites, const graphics::Font *font, Alignment align)
- : hero(hero), choice(choice), frame(frame), activeFrame(activeFrame), healthGauge(healthGauge), manaGauge(manaGauge), ikariGauge(ikariGauge), sprites(sprites), font(font), align(align) { }
+ HeroTag(const Hero *hero, const AttackChoice *choice, const Resources *res, Alignment align)
+ : hero(hero), choice(choice), res(res), align(align) { }
~HeroTag() { }
public:
private:
const Hero *hero;
const AttackChoice *choice;
- const graphics::Frame *frame;
- const graphics::Frame *activeFrame;
- const graphics::Gauge *healthGauge;
- const graphics::Gauge *manaGauge;
- const graphics::Gauge *ikariGauge;
- const graphics::Sprite *sprites;
- const graphics::Font *font;
+ const Resources *res;
Alignment align;
};
--- /dev/null
+/*
+ * Resources.h
+ *
+ * Created on: Aug 8, 2012
+ * Author: holy
+ */
+
+#ifndef BATTLE_RESOURCES_H_
+#define BATTLE_RESOURCES_H_
+
+namespace graphics {
+ class Font;
+ class Frame;
+ class Gauge;
+ class Sprite;
+}
+
+namespace battle {
+
+struct Resources {
+
+ graphics::Sprite *moveIcons;
+ graphics::Sprite *attackIcons;
+
+ graphics::Frame *heroTagFrame;
+ graphics::Frame *activeHeroTagFrame;
+
+ graphics::Font *heroTagFont;
+ graphics::Sprite *heroTagLabels;
+
+ graphics::Gauge *healthGauge;
+ graphics::Gauge *manaGauge;
+ graphics::Gauge *ikariGauge;
+
+ graphics::Frame *selectFrame;
+
+
+ Resources()
+ : moveIcons(0)
+ , attackIcons(0)
+
+ , heroTagFrame(0)
+ , activeHeroTagFrame(0)
+
+ , heroTagFont(0)
+ , heroTagLabels(0)
+
+ , healthGauge(0)
+ , manaGauge(0)
+ , ikariGauge(0)
+
+ , selectFrame(0)
+ { }
+
+};
+
+}
+
+#endif /* BATTLE_RESOURCES_H_ */
void SelectSpell::Render(SDL_Surface *screen) {
parent->Render(screen);
- const Frame &frame(battle->GetSelectFrame());
- Point<int> position(frame.BorderWidth(), frame.BorderHeight());
+ const Frame *frame(battle->Res().selectFrame);
+ Point<int> position(frame->BorderWidth(), frame->BorderHeight());
Vector<int> offset(battle->CalculateScreenOffset(screen));
- int width(battle->BackgroundWidth() - 2 * frame.BorderWidth());
+ int width(battle->BackgroundWidth() - 2 * frame->BorderWidth());
// TODO: replace with font height
- int height(frame.BorderHeight() * 13);
- frame.Draw(screen, position + offset, width, height);
+ int height(frame->BorderHeight() * 13);
+ frame->Draw(screen, position + offset, width, height);
}
}
#include "battle/Hero.h"
#include "battle/Monster.h"
#include "battle/PartyLayout.h"
+#include "battle/Resources.h"
#include "geometry/Point.h"
#include "graphics/Font.h"
#include "graphics/Frame.h"
dekar.SetMana(0);
dekar.SetIP(0);
- SDL_Surface *attackIcons(IMG_Load("test-data/attack-type-icons.png"));
- Sprite attackIconsSprite(attackIcons, 32, 32);
- SDL_Surface *moveIcons(IMG_Load("test-data/move-icons.png"));
- Sprite moveIconsSprite(moveIcons, 32, 32);
- SDL_Surface *heroTagSprites(IMG_Load("test-data/hero-tag-sprites.png"));
- Sprite heroTagSprite(heroTagSprites, 32, 16);
- SDL_Surface *numbers(IMG_Load("test-data/numbers.png"));
- Sprite numbersSprite(numbers, 16, 16);
+ battle::Resources battleRes;
+
+ SDL_Surface *attackIconsImg(IMG_Load("test-data/attack-type-icons.png"));
+ Sprite attackIconsSprite(attackIconsImg, 32, 32);
+ battleRes.attackIcons = &attackIconsSprite;
+ SDL_Surface *moveIconsImg(IMG_Load("test-data/move-icons.png"));
+ Sprite moveIconsSprite(moveIconsImg, 32, 32);
+ battleRes.moveIcons = &moveIconsSprite;
+ SDL_Surface *heroTagImg(IMG_Load("test-data/hero-tag-sprites.png"));
+ Sprite heroTagSprite(heroTagImg, 32, 16);
+ battleRes.heroTagLabels = &heroTagSprite;
+ SDL_Surface *numbersImg(IMG_Load("test-data/numbers.png"));
+ Sprite numbersSprite(numbersImg, 16, 16);
Font heroTagFont(&numbersSprite);
- SDL_Surface *tagFrames(IMG_Load("test-data/tag-frames.png"));
- Frame heroTagFrame(tagFrames, 16, 16, 1, 1, 0, 33);
- Frame activeHeroTagFrame(tagFrames, 16, 16);
+ battleRes.heroTagFont = &heroTagFont;
+ SDL_Surface *tagFramesImg(IMG_Load("test-data/tag-frames.png"));
+ Frame heroTagFrame(tagFramesImg, 16, 16, 1, 1, 0, 33);
+ battleRes.heroTagFrame = &heroTagFrame;
+ Frame activeHeroTagFrame(tagFramesImg, 16, 16);
+ battleRes.activeHeroTagFrame = &activeHeroTagFrame;
SDL_Surface *gauges(IMG_Load("test-data/gauges.png"));
Gauge healthGauge(gauges, 0, 16, 0, 0, 16, 6, 1, 6);
+ battleRes.healthGauge = &healthGauge;
Gauge manaGauge(gauges, 0, 32, 0, 0, 16, 6, 1, 6);
+ battleRes.manaGauge = &manaGauge;
Gauge ikariGauge(gauges, 0, 48, 0, 0, 16, 6, 1, 6);
+ battleRes.ikariGauge = &ikariGauge;
SDL_Surface *selectFrameImg(IMG_Load("test-data/select-frame.png"));
Frame selectFrame(selectFrameImg, 16, 16);
+ battleRes.selectFrame = &selectFrame;
- // TODO: create a container for all the battle resources
- BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &attackIconsSprite, &moveIconsSprite, &heroTagFrame, &activeHeroTagFrame, &healthGauge, &manaGauge, &ikariGauge, &heroTagSprite, &heroTagFont, &selectFrame));
+ BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
battleState->AddMonster(monster);
battleState->AddMonster(monster);
battleState->AddMonster(monster);