../src/battle/Monster.cpp \
../src/battle/MoveMenu.cpp \
../src/battle/PartyLayout.cpp \
+../src/battle/SmallHeroTag.cpp \
../src/battle/TargetSelection.cpp
OBJS += \
./src/battle/Monster.o \
./src/battle/MoveMenu.o \
./src/battle/PartyLayout.o \
+./src/battle/SmallHeroTag.o \
./src/battle/TargetSelection.o
CPP_DEPS += \
./src/battle/Monster.d \
./src/battle/MoveMenu.d \
./src/battle/PartyLayout.d \
+./src/battle/SmallHeroTag.d \
./src/battle/TargetSelection.d
../src/battle/Monster.cpp \
../src/battle/MoveMenu.cpp \
../src/battle/PartyLayout.cpp \
+../src/battle/SmallHeroTag.cpp \
../src/battle/TargetSelection.cpp
OBJS += \
./src/battle/Monster.o \
./src/battle/MoveMenu.o \
./src/battle/PartyLayout.o \
+./src/battle/SmallHeroTag.o \
./src/battle/TargetSelection.o
CPP_DEPS += \
./src/battle/Monster.d \
./src/battle/MoveMenu.d \
./src/battle/PartyLayout.d \
+./src/battle/SmallHeroTag.d \
./src/battle/TargetSelection.d
#include "../common/Item.h"
#include "../common/Spell.h"
#include "../geometry/operators.h"
+#include "../graphics/Frame.h"
#include "../graphics/Sprite.h"
#include <algorithm>
ikariMenus[i] = res->ikariMenuPrototype;
LoadIkariMenu(i);
heroTags[i] = HeroTag(this, i);
+ smallHeroTags[i] = SmallHeroTag(this, i);
}
int tagHeight(attackTypeMenu.Height());
heroTagPositions[2] = Point<int>(xOffset, BackgroundHeight() - tagHeight);
heroTagPositions[3] = Point<int>(xOffset + tagWidth, BackgroundHeight() - tagHeight);
+ tagHeight = res->normalFont->CharHeight() * 4 + res->smallHeroTagFrame->BorderHeight() * 2;
+ tagWidth = res->normalFont->CharWidth() * 6 + res->smallHeroTagFrame->BorderWidth() * 2;
+ xOffset = (BackgroundWidth() - 4 * tagWidth) / 2;
+ int yOffset(BackgroundHeight() - tagHeight);
+ smallHeroTagPositions[0] = Point<int>(xOffset, yOffset);
+ smallHeroTagPositions[1] = Point<int>(xOffset + 2 * tagWidth, yOffset);
+ smallHeroTagPositions[2] = Point<int>(xOffset + tagWidth, yOffset);
+ smallHeroTagPositions[3] = Point<int>(xOffset + 3 * tagWidth, yOffset);
+
itemMenu = res->itemMenuPrototype;
LoadInventory();
}
void BattleState::Render(SDL_Surface *screen) {
Vector<int> offset(CalculateScreenOffset(screen));
-
RenderBackground(screen, offset);
RenderMonsters(screen, offset);
-// RenderHeroes(screen, offset);
- RenderHeroTags(screen, offset);
}
void BattleState::RenderBackground(SDL_Surface *screen, const Vector<int> &offset) {
}
}
+void BattleState::RenderSmallHeroTags(SDL_Surface *screen, const Vector<int> &offset) {
+ int tagHeight(res->normalFont->CharHeight() * 4 + res->smallHeroTagFrame->BorderHeight() * 2);
+ int tagWidth(res->normalFont->CharWidth() * 6 + res->smallHeroTagFrame->BorderWidth() * 2);
+
+ SDL_Rect rect;
+ rect.x = offset.X();
+ rect.y = offset.Y() + BackgroundHeight() - tagHeight;
+ rect.w = BackgroundWidth();
+ rect.h = tagHeight;
+ SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, 0, 0, 0));
+ rect.y += res->normalFont->CharHeight() / 8;
+ rect.h -= res->normalFont->CharHeight() / 4;
+ SDL_FillRect(screen, &rect, res->heroesBgColor);
+
+ for (int i(0); i < numHeroes; ++i) {
+ smallHeroTags[i].Render(screen, tagWidth, tagHeight, smallHeroTagPositions[i] + offset);
+ }
+}
+
}
#include "Monster.h"
#include "MoveMenu.h"
#include "Resources.h"
+#include "SmallHeroTag.h"
#include "../app/State.h"
#include "../geometry/Point.h"
#include "../geometry/Vector.h"
bool AttackSelectionDone() const { return activeHero >= numHeroes; }
int NumHeroes() const { return numHeroes; }
+ int MaxHeroes() const { return 4; }
int MaxMonsters() const { return monsters.size(); }
const std::vector<geometry::Point<int> > &MonsterPositions() const { return monsterPositions; }
bool MonsterPositionOccupied(int index) { return index >= 0 && index < int(monsters.size()) && monsters[index].Health() > 0; }
const std::vector<geometry::Point<int> > &HeroesPositions() const { return heroesPositions; }
- bool HeroPositionOccupied(int index) { return index >= 0 && index < numHeroes; }
+ bool HeroPositionOccupied(int index) const { return index >= 0 && index < numHeroes; }
void SetRunaway() { ranAway = true; }
void ClearAllAttacks();
void RenderMonsters(SDL_Surface *screen, const geometry::Vector<int> &offset);
void RenderHeroes(SDL_Surface *screen, const geometry::Vector<int> &offset);
void RenderHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
+ void RenderSmallHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
private:
void LoadSpellMenu(std::vector<Hero>::size_type heroIndex);
graphics::Menu<const common::Item *> itemMenu;
graphics::Menu<const common::Item *> ikariMenus[4];
HeroTag heroTags[4];
+ SmallHeroTag smallHeroTags[4];
geometry::Point<int> heroTagPositions[4];
+ geometry::Point<int> smallHeroTagPositions[4];
AttackChoice attackChoices[4];
int numHeroes;
int activeHero;
}
void HeroTag::Render(SDL_Surface *screen, int width, int height, Point<int> position, bool active) const {
+ const Resources &r(battle->Res());
+
// frame
- const Frame *frame(active ? battle->Res().activeHeroTagFrame : battle->Res().heroTagFrame);
+ const Frame *frame(active ? r.activeHeroTagFrame : r.heroTagFrame);
Vector<int> frameOffset(frame->BorderWidth(), frame->BorderHeight());
- Vector<int> alignOffset((index % 2) ? 4 * battle->Res().heroTagFont->CharWidth() : 0, 0);
+ Vector<int> 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(((index % 2) ? 10 : 6) * battle->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 - ((index % 2) ? 1 : 5) * battle->Res().heroTagFont->CharWidth());
+ int gaugeWidth(width - gaugeX - ((index % 2) ? 1 : 5) * r.heroTagFont->CharWidth());
// health gauge, second line
- Vector<int> healthGaugeOffset(gaugeX, frameOffset.Y() + battle->Res().heroTagFont->CharHeight());
- battle->Res().healthGauge->Draw(screen, position + healthGaugeOffset, gaugeWidth, hero.RelativeHealth(255));
+ Vector<int> healthGaugeOffset(gaugeX, frameOffset.Y() + r.heroTagFont->CharHeight());
+ r.healthGauge->Draw(screen, position + healthGaugeOffset, gaugeWidth, hero.RelativeHealth(255));
// mana gauge, third line
- Vector<int> manaGaugeOffset(gaugeX, frameOffset.Y() + 2 * battle->Res().heroTagFont->CharHeight());
- battle->Res().manaGauge->Draw(screen, position + manaGaugeOffset, gaugeWidth, hero.RelativeMana(255));
+ Vector<int> manaGaugeOffset(gaugeX, frameOffset.Y() + 2 * r.heroTagFont->CharHeight());
+ r.manaGauge->Draw(screen, position + manaGaugeOffset, gaugeWidth, hero.RelativeMana(255));
// ikari gauge, fourth line
- Vector<int> ikariGaugeOffset(gaugeX, frameOffset.Y() + 3 * battle->Res().heroTagFont->CharHeight());
- battle->Res().ikariGauge->Draw(screen, position + ikariGaugeOffset, gaugeWidth, hero.RelativeIP(255));
+ Vector<int> ikariGaugeOffset(gaugeX, frameOffset.Y() + 3 * r.heroTagFont->CharHeight());
+ r.ikariGauge->Draw(screen, position + ikariGaugeOffset, gaugeWidth, hero.RelativeIP(255));
// labels
- int labelX(((index % 2) ? 5 : 1) * battle->Res().heroTagFont->CharWidth());
+ int labelX(((index % 2) ? 5 : 1) * r.heroTagFont->CharWidth());
// level
Vector<int> levelLabelOffset(gaugeX, frameOffset.Y());
- battle->Res().heroTagLabels->Draw(screen, position + levelLabelOffset, 0, 0);
+ r.heroTagLabels->Draw(screen, position + levelLabelOffset, r.levelLabelCol, r.levelLabelRow);
// hp
- Vector<int> healthLabelOffset(labelX, frameOffset.Y() + battle->Res().heroTagFont->CharHeight());
- battle->Res().heroTagLabels->Draw(screen, position + healthLabelOffset, 0, 1);
+ Vector<int> healthLabelOffset(labelX, frameOffset.Y() + r.heroTagFont->CharHeight());
+ r.heroTagLabels->Draw(screen, position + healthLabelOffset, r.healthLabelCol, r.healthLabelRow);
// mp
- Vector<int> manaLabelOffset(labelX, frameOffset.Y() + 2 * battle->Res().heroTagFont->CharHeight());
- battle->Res().heroTagLabels->Draw(screen, position + manaLabelOffset, 0, 2);
+ Vector<int> manaLabelOffset(labelX, frameOffset.Y() + 2 * r.heroTagFont->CharHeight());
+ r.heroTagLabels->Draw(screen, position + manaLabelOffset, r.manaLabelCol, r.manaLabelRow);
// cm
- Vector<int> moveLabelOffset(labelX, frameOffset.Y() + 3 * battle->Res().heroTagFont->CharHeight());
- battle->Res().heroTagLabels->Draw(screen, position + moveLabelOffset, 0, 3);
+ Vector<int> moveLabelOffset(labelX, frameOffset.Y() + 3 * r.heroTagFont->CharHeight());
+ r.heroTagLabels->Draw(screen, position + moveLabelOffset, r.moveLabelCol, r.moveLabelRow);
// ip
- Vector<int> ikariLabelOffset(labelX + 3 * battle->Res().heroTagFont->CharWidth(), frameOffset.Y() + 3 * battle->Res().heroTagFont->CharHeight());
- battle->Res().heroTagLabels->Draw(screen, position + ikariLabelOffset, 0, 4);
+ Vector<int> 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<int> levelNumberOffset(gaugeX + battle->Res().heroTagLabels->Width(), levelLabelOffset.Y());
- battle->Res().heroTagFont->DrawNumber(hero.Level(), screen, position + levelNumberOffset, 2);
+ Vector<int> levelNumberOffset(gaugeX + r.heroTagLabels->Width(), levelLabelOffset.Y());
+ r.heroTagFont->DrawNumber(hero.Level(), screen, position + levelNumberOffset, 2);
// health
- Vector<int> healthNumberOffset(labelX + battle->Res().heroTagLabels->Width(), healthLabelOffset.Y());
- battle->Res().heroTagFont->DrawNumber(hero.Health(), screen, position + healthNumberOffset, 3);
+ Vector<int> healthNumberOffset(labelX + r.heroTagLabels->Width(), healthLabelOffset.Y());
+ r.heroTagFont->DrawNumber(hero.Health(), screen, position + healthNumberOffset, 3);
//mana
- Vector<int> manaNumberOffset(labelX + battle->Res().heroTagLabels->Width(), manaLabelOffset.Y());
- battle->Res().heroTagFont->DrawNumber(hero.Mana(), screen, position + manaNumberOffset, 3);
+ Vector<int> manaNumberOffset(labelX + r.heroTagLabels->Width(), manaLabelOffset.Y());
+ r.heroTagFont->DrawNumber(hero.Mana(), screen, position + manaNumberOffset, 3);
// name
- battle->Res().normalFont->DrawString(hero.Name(), screen, position + frameOffset + alignOffset, 5);
+ r.normalFont->DrawString(hero.Name(), screen, position + frameOffset + alignOffset, 5);
// attack icon
if (battle->AttackChoiceAt(index).GetType() != AttackChoice::UNDECIDED) {
- Vector<int> attackIconOffset(labelX + battle->Res().heroTagLabels->Width(), frameOffset.Y() + 3 * battle->Res().heroTagFont->CharHeight());
- battle->Res().attackChoiceIcons->Draw(screen, position + attackIconOffset, 0, battle->AttackChoiceAt(index).GetType());
+ Vector<int> attackIconOffset(labelX + r.heroTagLabels->Width(), frameOffset.Y() + 3 * r.heroTagFont->CharHeight());
+ r.attackChoiceIcons->Draw(screen, position + attackIconOffset, 0, battle->AttackChoiceAt(index).GetType());
}
// hero
#include "../graphics/Menu.h"
+#include <SDL.h>
+
namespace common {
class Inventory;
class Item;
graphics::Frame *heroTagFrame;
graphics::Frame *activeHeroTagFrame;
+ graphics::Frame *smallHeroTagFrame;
+ graphics::Frame *lastSmallHeroTagFrame;
graphics::Font *heroTagFont;
graphics::Sprite *heroTagLabels;
graphics::Sprite *ringMenuIcon;
graphics::Sprite *jewelMenuIcon;
+ int levelLabelCol;
+ int levelLabelRow;
+ int healthLabelCol;
+ int healthLabelRow;
+ int manaLabelCol;
+ int manaLabelRow;
+ int moveLabelCol;
+ int moveLabelRow;
+ int ikariLabelCol;
+ int ikariLabelRow;
+
+ Uint32 heroesBgColor;
+
Resources()
: swapCursor(0)
, heroTagFrame(0)
, activeHeroTagFrame(0)
+ , smallHeroTagFrame(0)
+ , lastSmallHeroTagFrame(0)
, heroTagFont(0)
, heroTagLabels(0)
, helmetMenuIcon(0)
, ringMenuIcon(0)
, jewelMenuIcon(0)
+
+ , levelLabelCol(0)
+ , levelLabelRow(0)
+ , healthLabelCol(0)
+ , healthLabelRow(0)
+ , manaLabelCol(0)
+ , manaLabelRow(0)
+ , moveLabelCol(0)
+ , moveLabelRow(0)
+ , ikariLabelCol(0)
+ , ikariLabelRow(0)
+
+ , heroesBgColor(0)
{ }
};
--- /dev/null
+/*
+ * SmallHeroTag.cpp
+ *
+ * Created on: Aug 11, 2012
+ * Author: holy
+ */
+
+#include "SmallHeroTag.h"
+
+#include "BattleState.h"
+#include "../geometry/operators.h"
+#include "../geometry/Vector.h"
+#include "../graphics/Font.h"
+#include "../graphics/Frame.h"
+#include "../graphics/Gauge.h"
+
+using geometry::Point;
+using geometry::Vector;
+using graphics::Font;
+using graphics::Frame;
+using graphics::Sprite;
+
+namespace battle {
+
+void SmallHeroTag::Render(SDL_Surface *screen, int width, int height, geometry::Point<int> position) const {
+ const Resources &r(battle->Res());
+ const Frame *frame((index == battle->MaxHeroes() - 1) ? r.lastSmallHeroTagFrame : r.smallHeroTagFrame);
+ const Font *font(r.normalFont);
+ const Sprite *labels(r.heroTagLabels);
+
+ frame->Draw(screen, position, width, height);
+
+ if (battle->HeroPositionOccupied(index)) {
+ const Hero &hero(battle->HeroAt(index));
+
+ int gaugeWidth(width - 2 * frame->BorderWidth() - labels->Width());
+ Vector<int> nameOffset(frame->BorderWidth(), frame->BorderHeight());
+ Vector<int> hpLabelOffset(nameOffset.X(), nameOffset.Y() + font->CharHeight());
+ Vector<int> mpLabelOffset(hpLabelOffset.X(), hpLabelOffset.Y() + font->CharHeight());
+ Vector<int> ipLabelOffset(mpLabelOffset.X(), mpLabelOffset.Y() + font->CharHeight());
+ Vector<int> hpGaugeOffset(hpLabelOffset.X() + labels->Width(), hpLabelOffset.Y());
+ Vector<int> mpGaugeOffset(mpLabelOffset.X() + labels->Width(), mpLabelOffset.Y());
+ Vector<int> ipGaugeOffset(ipLabelOffset.X() + labels->Width(), ipLabelOffset.Y());
+
+ font->DrawString(hero.Name(), screen, position + nameOffset, 5);
+ labels->Draw(screen, position + hpLabelOffset, r.healthLabelCol, r.healthLabelRow);
+ labels->Draw(screen, position + mpLabelOffset, r.manaLabelCol, r.manaLabelRow);
+ labels->Draw(screen, position + ipLabelOffset, r.ikariLabelCol, r.ikariLabelRow);
+ r.healthGauge->Draw(screen, position + hpGaugeOffset, gaugeWidth, hero.RelativeHealth(255));
+ r.manaGauge->Draw(screen, position + mpGaugeOffset, gaugeWidth, hero.RelativeMana(255));
+ r.ikariGauge->Draw(screen, position + ipGaugeOffset, gaugeWidth, hero.RelativeIP(255));
+ }
+
+}
+
+}
--- /dev/null
+/*
+ * SmallHeroTag.h
+ *
+ * Created on: Aug 11, 2012
+ * Author: holy
+ */
+
+#ifndef BATTLE_SMALLHEROTAG_H_
+#define BATTLE_SMALLHEROTAG_H_
+
+#include "../geometry/Point.h"
+
+#include <SDL.h>
+
+namespace graphics {
+ class Font;
+ class Frame;
+ class Gauge;
+}
+
+namespace battle {
+
+class BattleState;
+
+class SmallHeroTag {
+
+public:
+ SmallHeroTag() : battle(0), index(0) { }
+ SmallHeroTag(const BattleState *battle, int heroIndex)
+ : battle(battle), index(heroIndex) { }
+
+ void Render(SDL_Surface *screen, int width, int height, geometry::Point<int> position) const;
+
+private:
+ const BattleState *battle;
+ int index;
+
+};
+
+}
+
+#endif /* BATTLE_SMALLHEROTAG_H_ */
battle->RenderBackground(screen, offset);
battle->RenderMonsters(screen, offset);
battle->RenderHeroes(screen, offset);
- // render small tags
+ battle->RenderSmallHeroTags(screen, offset);
RenderTitleBar(screen, offset);
}
battle->RenderBackground(screen, offset);
battle->RenderMonsters(screen, offset);
battle->RenderHeroes(screen, offset);
- // render small tags
+ battle->RenderSmallHeroTags(screen, offset);
RenderTitleBar(screen, offset);
}
monstersLayout.AddPosition(Point<Uint8>(208, 104));
PartyLayout heroesLayout;
heroesLayout.AddPosition(Point<Uint8>(48, 152));
- heroesLayout.AddPosition(Point<Uint8>(80, 168));
heroesLayout.AddPosition(Point<Uint8>(128, 152));
+ heroesLayout.AddPosition(Point<Uint8>(80, 168));
heroesLayout.AddPosition(Point<Uint8>(160, 168));
SDL_Surface *monsterImg(IMG_Load("test-data/monster.png"));
SDL_Surface *heroTagImg(IMG_Load("test-data/hero-tag-sprites.png"));
Sprite heroTagSprite(heroTagImg, 32, 16);
battleRes.heroTagLabels = &heroTagSprite;
+ battleRes.levelLabelCol = 0;
+ battleRes.levelLabelRow = 0;
+ battleRes.healthLabelCol = 0;
+ battleRes.healthLabelRow = 1;
+ battleRes.manaLabelCol = 0;
+ battleRes.manaLabelRow = 2;
+ battleRes.moveLabelCol = 0;
+ battleRes.moveLabelRow = 3;
+ battleRes.ikariLabelCol = 0;
+ battleRes.ikariLabelRow = 4;
+
SDL_Surface *numbersImg(IMG_Load("test-data/numbers.png"));
Sprite numbersSprite(numbersImg, 16, 16);
Font heroTagFont(&numbersSprite);
battleRes.heroTagFrame = &heroTagFrame;
Frame activeHeroTagFrame(tagFramesImg, 16, 16);
battleRes.activeHeroTagFrame = &activeHeroTagFrame;
+ SDL_Surface *smallTagFrameImg(IMG_Load("test-data/small-tag-frame.png"));
+ Frame smallTagFrame(smallTagFrameImg, 8, 16);
+ battleRes.smallHeroTagFrame = &smallTagFrame;
+ Frame lastSmallTagFrame(smallTagFrameImg, 8, 16, 1, 1, 0, 33);
+ battleRes.lastSmallHeroTagFrame = &lastSmallTagFrame;
+ battleRes.heroesBgColor = SDL_MapRGB(screen.Screen()->format, 0x18, 0x28, 0x31);
SDL_Surface *gauges(IMG_Load("test-data/gauges.png"));
Gauge healthGauge(gauges, 0, 16, 0, 0, 16, 6, 1, 6);