# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
+../src/graphics/Font.cpp \
../src/graphics/Frame.cpp \
../src/graphics/Gauge.cpp \
../src/graphics/Sprite.cpp
OBJS += \
+./src/graphics/Font.o \
./src/graphics/Frame.o \
./src/graphics/Gauge.o \
./src/graphics/Sprite.o
CPP_DEPS += \
+./src/graphics/Font.d \
./src/graphics/Frame.d \
./src/graphics/Gauge.d \
./src/graphics/Sprite.d
# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
+../src/graphics/Font.cpp \
../src/graphics/Frame.cpp \
../src/graphics/Gauge.cpp \
../src/graphics/Sprite.cpp
OBJS += \
+./src/graphics/Font.o \
./src/graphics/Frame.o \
./src/graphics/Gauge.o \
./src/graphics/Sprite.o
CPP_DEPS += \
+./src/graphics/Font.d \
./src/graphics/Frame.d \
./src/graphics/Gauge.d \
./src/graphics/Sprite.d
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, HeroTag::Alignment((i + 1) % 2)));
+ heroTags.push_back(HeroTag(&heroes[i], &attackChoices[i], heroTagFrame, activeHeroTagFrame, healthGauge, manaGauge, ikariGauge, heroTagSprites, heroTagFont, HeroTag::Alignment((i + 1) % 2)));
}
}
namespace app { class Input; }
namespace graphics {
+ class Font;
class Frame;
class Gauge;
class Sprite;
: 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)
+ 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)
: background(background)
, monstersLayout(&monstersLayout)
, heroesLayout(&heroesLayout)
, manaGauge(manaGauge)
, ikariGauge(ikariGauge)
, heroTagSprites(heroTagSprites)
+ , heroTagFont(heroTagFont)
, attackTypeMenu(attackIcons)
, moveMenu(moveIcons)
, activeHero(-1) { }
const graphics::Gauge *manaGauge;
const graphics::Gauge *ikariGauge;
const graphics::Sprite *heroTagSprites;
+ const graphics::Font *heroTagFont;
AttackTypeMenu attackTypeMenu;
MoveMenu moveMenu;
std::vector<geometry::Point<int> > monsterPositions;
#include "Hero.h"
#include "../geometry/operators.h"
#include "../geometry/Vector.h"
+#include "../graphics/Font.h"
#include "../graphics/Frame.h"
#include "../graphics/Gauge.h"
#include "../graphics/Sprite.h"
// gauges
// NOTE: assuming frame border is unit size until charsets are impemented
- int gaugeX((align == LEFT ? 10 : 6) * frameOffset.X());
+ int gaugeX((align == LEFT ? 10 : 6) * font->CharWidth());
// 4 units reserved for hero, gaugeX already includes frame offset
- int gaugeWidth(width - gaugeX - (align == LEFT ? 1 : 5) * frameOffset.X());
+ int gaugeWidth(width - gaugeX - (align == LEFT ? 1 : 5) * font->CharWidth());
// health gauge, second line
- Vector<int> healthGaugeOffset(gaugeX, 2 * frameOffset.Y());
+ Vector<int> healthGaugeOffset(gaugeX, frameOffset.Y() + font->CharHeight());
healthGauge->Draw(screen, position + healthGaugeOffset, gaugeWidth, hero->RelativeHealth(gaugeWidth));
// mana gauge, third line
- Vector<int> manaGaugeOffset(gaugeX, 3 * frameOffset.Y());
+ Vector<int> manaGaugeOffset(gaugeX, frameOffset.Y() + 2 * font->CharHeight());
manaGauge->Draw(screen, position + manaGaugeOffset, gaugeWidth, hero->RelativeMana(gaugeWidth));
// ikari gauge, fourth line
- Vector<int> ikariGaugeOffset(gaugeX, 4 * frameOffset.Y());
+ Vector<int> ikariGaugeOffset(gaugeX, frameOffset.Y() + 3 * font->CharHeight());
ikariGauge->Draw(screen, position + ikariGaugeOffset, gaugeWidth, hero->RelativeIP(gaugeWidth));
// labels
- int labelX((align == LEFT ? 5 : 1) * frameOffset.X());
+ int labelX((align == LEFT ? 5 : 1) * font->CharWidth());
// level
Vector<int> levelLabelOffset(gaugeX, frameOffset.Y());
sprites->Draw(screen, position + levelLabelOffset, 0, 0);
// hp
- Vector<int> healthLabelOffset(labelX, 2 * frameOffset.Y());
+ Vector<int> healthLabelOffset(labelX, frameOffset.Y() + font->CharHeight());
sprites->Draw(screen, position + healthLabelOffset, 0, 1);
// mp
- Vector<int> manaLabelOffset(labelX, 3 * frameOffset.Y());
+ Vector<int> manaLabelOffset(labelX, frameOffset.Y() + 2 * font->CharHeight());
sprites->Draw(screen, position + manaLabelOffset, 0, 2);
// cm
- Vector<int> moveLabelOffset(labelX, 4 * frameOffset.Y());
+ Vector<int> moveLabelOffset(labelX, frameOffset.Y() + 3 * font->CharHeight());
sprites->Draw(screen, position + moveLabelOffset, 0, 3);
// ip
- Vector<int> ikariLabelOffset(labelX + 3 * frameOffset.X(), 4 * frameOffset.Y());
+ Vector<int> ikariLabelOffset(labelX + 3 * font->CharWidth(), frameOffset.Y() + 3 * font->CharHeight());
sprites->Draw(screen, position + ikariLabelOffset, 0, 4);
+ // numbers
+ // level
+ Vector<int> levelNumberOffset(gaugeX + sprites->Width(), levelLabelOffset.Y());
+ font->DrawNumber(hero->Level(), screen, position + levelNumberOffset, 2);
+ // health
+ Vector<int> healthNumberOffset(labelX + sprites->Width(), healthLabelOffset.Y());
+ font->DrawNumber(hero->Health(), screen, position + healthNumberOffset, 3);
+ //mana
+ Vector<int> manaNumberOffset(labelX + sprites->Width(), manaLabelOffset.Y());
+ font->DrawNumber(hero->Mana(), screen, position + manaNumberOffset, 3);
+
// hero
Vector<int> heroOffset(
(align == LEFT) ? yOffset : width - hero->Sprite()->Width() - yOffset,
#include <SDL.h>
namespace graphics {
+ class Font;
class Frame;
class Gauge;
class Sprite;
};
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, Alignment align)
- : hero(hero), choice(choice), frame(frame), activeFrame(activeFrame), healthGauge(healthGauge), manaGauge(manaGauge), ikariGauge(ikariGauge), sprites(sprites), align(align) { }
+ 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() { }
public:
const graphics::Gauge *manaGauge;
const graphics::Gauge *ikariGauge;
const graphics::Sprite *sprites;
+ const graphics::Font *font;
Alignment align;
};
--- /dev/null
+/*
+ * Font.cpp
+ *
+ * Created on: Aug 8, 2012
+ * Author: holy
+ */
+
+#include "Font.h"
+
+#include "../geometry/operators.h"
+#include "../geometry/Vector.h"
+
+#include <cmath>
+
+using geometry::Point;
+using geometry::Vector;
+using std::pow;
+
+namespace graphics {
+
+void Font::DrawDigit(int digit, SDL_Surface *dest, Point<int> position) const {
+ sprite->Draw(dest, position, digitsCol + digit, digitsRow);
+}
+
+void Font::DrawNumber(int numberIn, SDL_Surface *dest, Point<int> positionIn, int digits) const {
+ int number(numberIn);
+ if (digits > 0 && numberIn >= pow(10.0, digits)) {
+ numberIn = pow(10.0, digits) - 1;
+ }
+
+ Point<int> position(positionIn);
+ Vector<int> step(sprite->Width(), 0);
+
+ if (digits > 0) {
+ int i(digits - 1);
+ while (number < pow(10.0, i)) {
+ position += step;
+ --i;
+ }
+ }
+
+ int m(10);
+ while (m <= number) {
+ m *= 10;
+ }
+
+ while (m > 9) {
+ m /= 10;
+ DrawDigit((number / m) % 10, dest, position);
+ position += step;
+ }
+}
+
+}
--- /dev/null
+/*
+ * Font.h
+ *
+ * Created on: Aug 8, 2012
+ * Author: holy
+ */
+
+#ifndef GRAPHICS_FONT_H_
+#define GRAPHICS_FONT_H_
+
+#include "Sprite.h"
+#include "../geometry/Point.h"
+
+#include <SDL.h>
+
+namespace graphics {
+
+class Font {
+
+public:
+ explicit Font(const Sprite *sprite, int digitsCol = 0, int digitsRow = 0) : sprite(sprite), digitsCol(digitsCol), digitsRow(digitsRow) { }
+
+public:
+ int CharWidth() const { return sprite->Width(); }
+ int CharHeight() const { return sprite->Height(); }
+ void DrawDigit(int digit, SDL_Surface *dest, geometry::Point<int> position) const;
+ void DrawNumber(int number, SDL_Surface *dest, geometry::Point<int> position, int digits = 0) const;
+
+private:
+ const Sprite *sprite;
+ int digitsCol;
+ int digitsRow;
+
+};
+
+}
+
+#endif /* GRAPHICS_FONT_H_ */
#include "battle/Monster.h"
#include "battle/PartyLayout.h"
#include "geometry/Point.h"
+#include "graphics/Font.h"
#include "graphics/Frame.h"
#include "graphics/Gauge.h"
#include "graphics/Sprite.h"
using battle::Monster;
using battle::PartyLayout;
using geometry::Point;
+using graphics::Font;
using graphics::Frame;
using graphics::Gauge;
using graphics::Sprite;
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);
+ 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);
Gauge manaGauge(gauges, 0, 32, 0, 0, 16, 6, 1, 6);
Gauge ikariGauge(gauges, 0, 48, 0, 0, 16, 6, 1, 6);
- BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &attackIconsSprite, &moveIconsSprite, &heroTagFrame, &activeHeroTagFrame, &healthGauge, &manaGauge, &ikariGauge, &heroTagSprite));
+ BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &attackIconsSprite, &moveIconsSprite, &heroTagFrame, &activeHeroTagFrame, &healthGauge, &manaGauge, &ikariGauge, &heroTagSprite, &heroTagFont));
battleState->AddMonster(monster);
battleState->AddMonster(monster);
battleState->AddMonster(monster);