]> git.localhorst.tv Git - l2e.git/commitdiff
added struct for battle resources
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 8 Aug 2012 17:45:46 +0000 (19:45 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 8 Aug 2012 17:48:35 +0000 (19:48 +0200)
src/battle/BattleState.cpp
src/battle/BattleState.h
src/battle/HeroTag.cpp
src/battle/HeroTag.h
src/battle/Resources.h [new file with mode: 0644]
src/battle/states/SelectSpell.cpp
src/main.cpp

index f1e3d07caffc17676d1d5bcd85bc8b5f19a75c1b..ae882a614ed981f4083626ebab77ad894d813cbc 100644 (file)
@@ -50,7 +50,7 @@ void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) {
        heroesLayout->CalculatePositions(background->w, background->h, heroesPositions);
        attackChoices.resize(heroes.size());
        for (vector<Hero>::size_type i(0), end(heroes.size()); i < end; ++i) {
        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)));
        }
 }
 
        }
 }
 
index 858b111c426283008570054b8f48030dee72901a..484e4529c6a49d7d78776b3de9420f286a96bcdf 100644 (file)
@@ -14,6 +14,7 @@
 #include "HeroTag.h"
 #include "Monster.h"
 #include "MoveMenu.h"
 #include "HeroTag.h"
 #include "Monster.h"
 #include "MoveMenu.h"
+#include "Resources.h"
 #include "../app/State.h"
 #include "../geometry/Point.h"
 #include "../geometry/Vector.h"
 #include "../app/State.h"
 #include "../geometry/Point.h"
 #include "../geometry/Vector.h"
@@ -37,20 +38,13 @@ class BattleState
 : public app::State {
 
 public:
 : 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)
        : 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:
        , activeHero(-1) { }
 
 public:
@@ -70,9 +64,9 @@ public:
        virtual void Render(SDL_Surface *);
 
 public:
        virtual void Render(SDL_Surface *);
 
 public:
+       const Resources &Res() const { return *res; }
        AttackTypeMenu &GetAttackTypeMenu() { return attackTypeMenu; }
        MoveMenu &GetMoveMenu() { return moveMenu; }
        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; }
 
        bool HasMoreHeroes() const { return activeHero < (int) heroes.size(); }
        void NextHero() { ++activeHero; }
@@ -102,14 +96,7 @@ private:
        SDL_Surface *background;
        const PartyLayout *monstersLayout;
        const PartyLayout *heroesLayout;
        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;
        AttackTypeMenu attackTypeMenu;
        MoveMenu moveMenu;
        std::vector<geometry::Point<int> > monsterPositions;
index 33c42db72de3f0b7d270eaace92d9c1f5ad1b47c..01cee4485f463ed1c68fce599c7fb6e47f0aa08e 100644 (file)
@@ -8,6 +8,7 @@
 #include "HeroTag.h"
 
 #include "Hero.h"
 #include "HeroTag.h"
 
 #include "Hero.h"
+#include "Resources.h"
 #include "../geometry/operators.h"
 #include "../geometry/Vector.h"
 #include "../graphics/Font.h"
 #include "../geometry/operators.h"
 #include "../geometry/Vector.h"
 #include "../graphics/Font.h"
 
 using geometry::Point;
 using geometry::Vector;
 
 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
 
 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 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
        // 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
        // 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
        // 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
        // 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
 
        // 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());
        // level
        Vector<int> levelLabelOffset(gaugeX, frameOffset.Y());
-       sprites->Draw(screen, position + levelLabelOffset, 0, 0);
+       res->heroTagLabels->Draw(screen, position + levelLabelOffset, 0, 0);
        // hp
        // 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
        // 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
        // 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
        // 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
 
        // 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
        // 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
        //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(
 
        // hero
        Vector<int> heroOffset(
index 542b8c1b34190d1d53e2b2d5e92848d6ec252162..d361252dec1e48070ad9197b8d112981eb662cf4 100644 (file)
@@ -23,6 +23,7 @@ namespace battle {
 
 class AttackChoice;
 class Hero;
 
 class AttackChoice;
 class Hero;
+struct Resources;
 
 class HeroTag {
 
 
 class HeroTag {
 
@@ -33,8 +34,8 @@ public:
        };
 
 public:
        };
 
 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:
        ~HeroTag() { }
 
 public:
@@ -43,13 +44,7 @@ public:
 private:
        const Hero *hero;
        const AttackChoice *choice;
 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;
 
 };
        Alignment align;
 
 };
diff --git a/src/battle/Resources.h b/src/battle/Resources.h
new file mode 100644 (file)
index 0000000..7c37bca
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * 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_ */
index 66b55f16d9dfe785a6c60ae5d54af51aaa7d0ed7..1b012503551b23b73d386ae5eb81b8a49f6baeec 100644 (file)
@@ -63,13 +63,13 @@ void SelectSpell::UpdateWorld(float deltaT) {
 
 void SelectSpell::Render(SDL_Surface *screen) {
        parent->Render(screen);
 
 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));
        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
        // 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);
 }
 
 }
 }
 
 }
index 97a93994a634c8bcd018fb75803fcbc656d175a4..29c08a5fbda46a2ea20acd511af27761c0db3add 100644 (file)
@@ -11,6 +11,7 @@
 #include "battle/Hero.h"
 #include "battle/Monster.h"
 #include "battle/PartyLayout.h"
 #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"
 #include "geometry/Point.h"
 #include "graphics/Font.h"
 #include "graphics/Frame.h"
@@ -120,29 +121,40 @@ int main(int argc, char **argv) {
                dekar.SetMana(0);
                dekar.SetIP(0);
 
                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);
                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);
 
                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);
                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);
                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);
 
                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);
                battleState->AddMonster(monster);
                battleState->AddMonster(monster);
                battleState->AddMonster(monster);