# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
+../src/graphics/Frame.cpp \
../src/graphics/Sprite.cpp
OBJS += \
+./src/graphics/Frame.o \
./src/graphics/Sprite.o
CPP_DEPS += \
+./src/graphics/Frame.d \
./src/graphics/Sprite.d
# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
+../src/graphics/Frame.cpp \
../src/graphics/Sprite.cpp
OBJS += \
+./src/graphics/Frame.o \
./src/graphics/Sprite.o
CPP_DEPS += \
+./src/graphics/Frame.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], HeroTag::Alignment((i + 1) % 2)));
+ heroTags.push_back(HeroTag(&heroes[i], &attackChoices[i], heroTagFrame, activeHeroTagFrame, HeroTag::Alignment((i + 1) % 2)));
}
}
#include <SDL.h>
namespace app { class Input; }
-namespace graphics { class Sprite; }
+namespace graphics {
+ class Frame;
+ class Sprite;
+}
namespace battle {
: public app::State {
public:
- BattleState(SDL_Surface *background, const PartyLayout &monstersLayout, const PartyLayout &heroesLayout, const graphics::Sprite *attackIcons, const graphics::Sprite *moveIcons)
+ 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)
: background(background)
, monstersLayout(&monstersLayout)
, heroesLayout(&heroesLayout)
+ , heroTagFrame(heroTagFrame)
+ , activeHeroTagFrame(activeHeroTagFrame)
, attackTypeMenu(attackIcons)
, moveMenu(moveIcons)
, activeHero(-1) { }
SDL_Surface *background;
const PartyLayout *monstersLayout;
const PartyLayout *heroesLayout;
+ const graphics::Frame *heroTagFrame;
+ const graphics::Frame *activeHeroTagFrame;
AttackTypeMenu attackTypeMenu;
MoveMenu moveMenu;
std::vector<geometry::Point<int> > monsterPositions;
#include "Hero.h"
#include "../geometry/operators.h"
#include "../geometry/Vector.h"
+#include "../graphics/Frame.h"
#include "../graphics/Sprite.h"
using geometry::Point;
namespace battle {
void HeroTag::Render(SDL_Surface *screen, int width, int height, Point<int> position, bool active) const {
- SDL_Rect destRect;
- destRect.x = position.X();
- destRect.y = position.Y();
- destRect.w = width;
- destRect.h = height;
-
- destRect.x += 1;
- destRect.y += 1;
- destRect.w -= 2;
- destRect.h -= 2;
- SDL_FillRect(screen, &destRect, SDL_MapRGB(screen->format, 0xFF, active ? 0 : 0xFF, active ? 0 : 0xFF));
-
- destRect.x += 1;
- destRect.y += 1;
- destRect.w -= 2;
- destRect.h -= 2;
- SDL_FillRect(screen, &destRect, SDL_MapRGB(screen->format, 0, 0, 0));
+ if (active) {
+ activeFrame->Draw(screen, position, width, height);
+ } else {
+ frame->Draw(screen, position, width, height);
+ }
Vector<int> heroOffset(
(align == LEFT) ? 3 : width - hero->Sprite()->Width() - 3,
#include <SDL.h>
+namespace graphics { class Frame; }
+
namespace battle {
class AttackChoice;
};
public:
- HeroTag(const Hero *hero, const AttackChoice *choice, Alignment align) : hero(hero), choice(choice), align(align) { }
+ HeroTag(const Hero *hero, const AttackChoice *choice, const graphics::Frame *frame, const graphics::Frame *activeFrame, Alignment align)
+ : hero(hero), choice(choice), frame(frame), activeFrame(activeFrame), align(align) { }
~HeroTag() { }
public:
private:
const Hero *hero;
const AttackChoice *choice;
+ const graphics::Frame *frame;
+ const graphics::Frame *activeFrame;
Alignment align;
};
--- /dev/null
+/*
+ * Frame.cpp
+ *
+ * Created on: Aug 7, 2012
+ * Author: holy
+ */
+
+#include "Frame.h"
+
+using geometry::Point;
+
+namespace graphics {
+
+// TODO: maybe create a cache for frames?
+void Frame::Draw(SDL_Surface *dest, Point<int> position, int width, int height) const {
+ // top-left corner
+ SDL_Rect srcRect;
+ srcRect.x = xOffset;
+ srcRect.y = yOffset;
+ srcRect.w = borderWidth;
+ srcRect.h = borderHeight;
+ SDL_Rect destRect;
+ destRect.x = position.X();
+ destRect.y = position.Y();
+ SDL_BlitSurface(surface, &srcRect, dest, &destRect);
+
+ // top border
+ srcRect.x += borderWidth;
+ srcRect.w = repeatWidth;
+ destRect.x += borderWidth;
+ int fullRepeatWidth(width - (2 * borderWidth));
+ int repeatCursor(0);
+ while (repeatCursor < fullRepeatWidth) {
+ SDL_BlitSurface(surface, &srcRect, dest, &destRect);
+ destRect.x += repeatWidth;
+ repeatCursor += repeatWidth;
+ }
+
+ // top-right corner
+ srcRect.x += repeatWidth;
+ srcRect.w = borderWidth;
+ SDL_BlitSurface(surface, &srcRect, dest, &destRect);
+
+ // middle
+ destRect.y += borderHeight;
+ int fullRepeatHeight(height - (2 * borderHeight));
+ int hRepeatCursor(0);
+ while (hRepeatCursor < fullRepeatHeight) {
+
+ // left border
+ srcRect.x = xOffset;
+ srcRect.y = yOffset + borderHeight;
+ srcRect.w = borderWidth;
+ srcRect.h = repeatHeight;
+ destRect.x = position.X();
+ SDL_BlitSurface(surface, &srcRect, dest, &destRect);
+
+ // fill
+ repeatCursor = 0;
+ srcRect.x += borderWidth;
+ srcRect.w = repeatWidth;
+ destRect.x += borderWidth;
+ while (repeatCursor < fullRepeatWidth) {
+ SDL_BlitSurface(surface, &srcRect, dest, &destRect);
+ destRect.x += repeatWidth;
+ repeatCursor += repeatWidth;
+ }
+
+ // right border
+ srcRect.x += repeatWidth;
+ srcRect.w = borderWidth;
+ SDL_BlitSurface(surface, &srcRect, dest, &destRect);
+
+ destRect.y += repeatHeight;
+ hRepeatCursor += repeatHeight;
+ }
+
+ // bottom-left corner
+ srcRect.x = xOffset;
+ srcRect.y = yOffset + borderHeight + repeatHeight;
+ srcRect.w = borderWidth;
+ srcRect.h = borderHeight;
+ destRect.x = position.X();
+ SDL_BlitSurface(surface, &srcRect, dest, &destRect);
+
+ // bottom border
+ srcRect.x += borderWidth;
+ srcRect.w = repeatWidth;
+ destRect.x += borderWidth;
+ repeatCursor = 0;
+ while (repeatCursor < fullRepeatWidth) {
+ SDL_BlitSurface(surface, &srcRect, dest, &destRect);
+ destRect.x += repeatWidth;
+ repeatCursor += repeatWidth;
+ }
+ if (fullRepeatWidth < fullRepeatWidth) {
+ srcRect.w = fullRepeatWidth - fullRepeatWidth;
+ SDL_BlitSurface(surface, &srcRect, dest, &destRect);
+ destRect.x += fullRepeatWidth - fullRepeatWidth;
+ }
+
+ // bottom-right corner
+ srcRect.x += repeatWidth;
+ srcRect.w = borderWidth;
+ SDL_BlitSurface(surface, &srcRect, dest, &destRect);
+}
+
+}
--- /dev/null
+/*
+ * Frame.h
+ *
+ * Created on: Aug 7, 2012
+ * Author: holy
+ */
+
+#ifndef GRAPHICS_FRAME_H_
+#define GRAPHICS_FRAME_H_
+
+#include "../geometry/Point.h"
+
+#include <SDL.h>
+
+namespace graphics {
+
+class Frame {
+
+public:
+ Frame(SDL_Surface *s, int borderWidth, int borderHeight, int repeatWidth = 1, int repeatHeight = 1, int xOffset = 0, int yOffset = 0)
+ : surface(s), borderWidth(borderWidth), borderHeight(borderHeight), repeatWidth(repeatWidth), repeatHeight(repeatHeight), xOffset(xOffset), yOffset(yOffset) { }
+
+public:
+ int MinWidth() const { return 2 * borderWidth; }
+ int MinHeight() const { return 2 * borderHeight; }
+ void Draw(SDL_Surface *dest, geometry::Point<int> position, int width, int height) const;
+
+private:
+ SDL_Surface *surface;
+ int borderWidth;
+ int borderHeight;
+ int repeatWidth;
+ int repeatHeight;
+ int xOffset;
+ int yOffset;
+
+};
+
+}
+
+#endif /* GRAPHICS_FRAME_H_ */
void Sprite::Draw(SDL_Surface *dest, Point<int> position, int col, int row) const {
SDL_Rect srcRect, destRect;
- srcRect.x = col * Width();
- srcRect.y = row * Height();
+ srcRect.x = xOffset + col * Width();
+ srcRect.y = yOffset + row * Height();
srcRect.w = Width();
srcRect.h = Height();
destRect.x = position.X();
destRect.y = position.Y();
- destRect.w = Width();
- destRect.h = Height();
if (surface) {
SDL_BlitSurface(surface, &srcRect, dest, &destRect);
} else {
+ destRect.w = Width();
+ destRect.h = Height();
bool red(true);
while (destRect.w > 1 && destRect.h > 1) {
SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, red ? 0xFF : 0, 0, 0));
class Sprite {
public:
- Sprite(SDL_Surface *s, int width, int height)
- : surface(s), width(width), height(height) { }
+ Sprite(SDL_Surface *s, int width, int height, int xOffset = 0, int yOffset = 0)
+ : surface(s), width(width), height(height), xOffset(xOffset), yOffset(yOffset) { }
public:
int Width() const { return width; }
SDL_Surface *surface;
int width;
int height;
+ int xOffset;
+ int yOffset;
};
#include "battle/Monster.h"
#include "battle/PartyLayout.h"
#include "geometry/Point.h"
+#include "graphics/Frame.h"
#include "graphics/Sprite.h"
#include "sdl/InitImage.h"
#include "sdl/InitScreen.h"
using battle::Monster;
using battle::PartyLayout;
using geometry::Point;
+using graphics::Frame;
using graphics::Sprite;
using sdl::InitImage;
using sdl::InitScreen;
Sprite attackIconsSprite(attackIcons, 32, 32);
SDL_Surface *moveIcons(IMG_Load("test-data/move-icons.png"));
Sprite moveIconsSprite(moveIcons, 32, 32);
+ SDL_Surface *tagFrames(IMG_Load("test-data/tag-frames.png"));
+ Frame heroTagFrame(tagFrames, 8, 8, 1, 1, 17);
+ Frame activeHeroTagFrame(tagFrames, 8, 8);
- BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &attackIconsSprite, &moveIconsSprite));
+ BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &attackIconsSprite, &moveIconsSprite, &heroTagFrame, &activeHeroTagFrame));
battleState->AddMonster(monster);
battleState->AddMonster(monster);
battleState->AddMonster(monster);