USER_OBJS :=
-LIBS := -lSDL
+LIBS := -lSDL -lSDL_image
# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
+../src/battle/AttackTypeMenu.cpp \
../src/battle/BattleState.cpp \
../src/battle/Hero.cpp \
../src/battle/Monster.cpp \
../src/battle/PartyLayout.cpp
OBJS += \
+./src/battle/AttackTypeMenu.o \
./src/battle/BattleState.o \
./src/battle/Hero.o \
./src/battle/Monster.o \
./src/battle/PartyLayout.o
CPP_DEPS += \
+./src/battle/AttackTypeMenu.d \
./src/battle/BattleState.d \
./src/battle/Hero.d \
./src/battle/Monster.d \
# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
+../src/sdl/InitImage.cpp \
../src/sdl/InitSDL.cpp \
../src/sdl/InitScreen.cpp
OBJS += \
+./src/sdl/InitImage.o \
./src/sdl/InitSDL.o \
./src/sdl/InitScreen.o
CPP_DEPS += \
+./src/sdl/InitImage.d \
./src/sdl/InitSDL.d \
./src/sdl/InitScreen.d
USER_OBJS :=
-LIBS := -lSDL
+LIBS := -lSDL -lSDL_image
# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
+../src/battle/AttackTypeMenu.cpp \
../src/battle/BattleState.cpp \
../src/battle/Hero.cpp \
../src/battle/Monster.cpp \
../src/battle/PartyLayout.cpp
OBJS += \
+./src/battle/AttackTypeMenu.o \
./src/battle/BattleState.o \
./src/battle/Hero.o \
./src/battle/Monster.o \
./src/battle/PartyLayout.o
CPP_DEPS += \
+./src/battle/AttackTypeMenu.d \
./src/battle/BattleState.d \
./src/battle/Hero.d \
./src/battle/Monster.d \
# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
+../src/sdl/InitImage.cpp \
../src/sdl/InitSDL.cpp \
../src/sdl/InitScreen.cpp
OBJS += \
+./src/sdl/InitImage.o \
./src/sdl/InitSDL.o \
./src/sdl/InitScreen.o
CPP_DEPS += \
+./src/sdl/InitImage.d \
./src/sdl/InitSDL.d \
./src/sdl/InitScreen.d
--- /dev/null
+/*
+ * AttackTypeMenu.cpp
+ *
+ * Created on: Aug 6, 2012
+ * Author: holy
+ */
+
+#include "AttackTypeMenu.h"
+
+#include "../app/Input.h"
+#include "../geometry/operators.h"
+#include "../geometry/Vector.h"
+#include "../graphics/Sprite.h"
+
+using app::Input;
+using geometry::Point;
+using geometry::Vector;
+
+namespace battle {
+
+void AttackTypeMenu::ReadInput(const Input &input) {
+ if (input.IsDown(Input::PAD_UP)) {
+ selected = MAGIC;
+ } else if (input.IsDown(Input::PAD_RIGHT)) {
+ selected = DEFEND;
+ } else if (input.IsDown(Input::PAD_DOWN)) {
+ selected = IKARI;
+ } else if (input.IsDown(Input::PAD_LEFT)) {
+ selected = ITEM;
+ } else {
+ selected = SWORD;
+ }
+}
+
+void AttackTypeMenu::Render(SDL_Surface *screen, const geometry::Point<int> ¢er) {
+ Vector<int> swordOffset(icons->Width() / -2, icons->Height() / -2);
+ Vector<int> magicOffset(swordOffset.X(), swordOffset.Y() - icons->Height());
+ Vector<int> defendOffset(swordOffset.X() + icons->Width(), swordOffset.Y());
+ Vector<int> ikariOffset(swordOffset.X(), swordOffset.Y() + icons->Height());
+ Vector<int> itemOffset(swordOffset.X() - icons->Width(), swordOffset.Y());
+
+ icons->Draw(screen, center + swordOffset, SWORD, (selected == SWORD) ? 1 : 0);
+ icons->Draw(screen, center + magicOffset, MAGIC, (selected == MAGIC) ? 1 : 0);
+ icons->Draw(screen, center + defendOffset, DEFEND, (selected == DEFEND) ? 1 : 0);
+ icons->Draw(screen, center + ikariOffset, IKARI, (selected == IKARI) ? 1 : 0);
+ icons->Draw(screen, center + itemOffset, ITEM, (selected == ITEM) ? 1 : 0);
+}
+
+}
--- /dev/null
+/*
+ * AttackTypeMenu.h
+ *
+ * Created on: Aug 6, 2012
+ * Author: holy
+ */
+
+#ifndef BATTLE_ATTACKTYPEMENU_H_
+#define BATTLE_ATTACKTYPEMENU_H_
+
+namespace app { class Input; }
+namespace graphics { class Sprite; }
+
+#include "../geometry/Point.h"
+
+#include <SDL.h>
+
+namespace battle {
+
+class AttackTypeMenu {
+
+public:
+ enum Icon {
+ SWORD,
+ MAGIC,
+ DEFEND,
+ IKARI,
+ ITEM
+ };
+
+public:
+ explicit AttackTypeMenu(const graphics::Sprite *icons)
+ : icons(icons), selected(SWORD) { }
+
+public:
+ void ReadInput(const app::Input &);
+ Icon Selected() const { return selected; }
+ void Render(SDL_Surface *screen, const geometry::Point<int> ¢er);
+
+private:
+ const graphics::Sprite *icons;
+ Icon selected;
+
+};
+
+}
+
+#endif /* BATTLE_ATTACKTYPEMENU_H_ */
void BattleState::HandleInput(const Input &input) {
-
+ attackTypeMenu.ReadInput(input);
}
void BattleState::UpdateWorld(float deltaT) {
RenderBackground(screen, offset);
RenderMonsters(screen, offset);
- RenderHeroes(screen, offset);
+// RenderHeroes(screen, offset);
+ attackTypeMenu.Render(screen, Point<int>(background->w / 2, background->h * 3 / 4));
}
void BattleState::RenderBackground(SDL_Surface *screen, const Vector<int> &offset) {
#ifndef BATTLE_BATTLESTATE_H_
#define BATTLE_BATTLESTATE_H_
+#include "AttackTypeMenu.h"
#include "Hero.h"
#include "Monster.h"
#include "../app/State.h"
#include <SDL.h>
namespace app { class Input; }
+namespace graphics { class Sprite; }
namespace battle {
class PartyLayout;
+// TODO: maybe split battle state into substates for each menu?
class BattleState
: public app::State {
public:
- BattleState(SDL_Surface *background, const PartyLayout &monstersLayout, const PartyLayout &heroesLayout)
+ BattleState(SDL_Surface *background, const PartyLayout &monstersLayout, const PartyLayout &heroesLayout, const graphics::Sprite *attackIcons)
: background(background)
, monstersLayout(&monstersLayout)
- , heroesLayout(&heroesLayout) { }
+ , heroesLayout(&heroesLayout)
+ , attackTypeMenu(attackIcons) { }
public:
void AddMonster(const Monster &);
SDL_Surface *background;
const PartyLayout *monstersLayout;
const PartyLayout *heroesLayout;
+ AttackTypeMenu attackTypeMenu;
std::vector<geometry::Point<int> > monsterPositions;
std::vector<geometry::Point<int> > heroesPositions;
std::vector<Monster> monsters;
#include "battle/PartyLayout.h"
#include "geometry/Point.h"
#include "graphics/Sprite.h"
+#include "sdl/InitImage.h"
#include "sdl/InitScreen.h"
#include "sdl/InitSDL.h"
#include <exception>
#include <iostream>
+#include <SDL.h>
+#include <SDL_image.h>
using app::Application;
using app::Input;
using battle::PartyLayout;
using geometry::Point;
using graphics::Sprite;
+using sdl::InitImage;
using sdl::InitScreen;
using sdl::InitSDL;
const int width = 800;
const int height = 480;
- // temporary test data
- SDL_Surface *bg(SDL_CreateRGBSurface(0, width, height, 32, 0xFF000000, 0xFF0000, 0xFF00, 0xFF));
- SDL_FillRect(bg, 0, SDL_MapRGB(bg->format, 0xFF, 0xFF, 0xFF));
- SDL_Rect r;
- r.x = 1;
- r.y = 1;
- r.w = width - 2;
- r.h = height - 2;
- SDL_FillRect(bg, &r, SDL_MapRGB(bg->format, 0, 0, 0));
- PartyLayout monstersLayout;
- monstersLayout.AddPosition(Point<Uint8>(50, 100));
- monstersLayout.AddPosition(Point<Uint8>(100, 100));
- monstersLayout.AddPosition(Point<Uint8>(150, 100));
- monstersLayout.AddPosition(Point<Uint8>(200, 100));
- PartyLayout heroesLayout;
- heroesLayout.AddPosition(Point<Uint8>(27, 219));
- heroesLayout.AddPosition(Point<Uint8>(104, 227));
- heroesLayout.AddPosition(Point<Uint8>(66, 238));
- heroesLayout.AddPosition(Point<Uint8>(143, 246));
- SDL_Surface *white96(SDL_CreateRGBSurface(0, 96, 96, 32, 0xFF000000, 0xFF0000, 0xFF00, 0xFF));
- SDL_FillRect(white96, 0, SDL_MapRGB(bg->format, 0xFF, 0xFF, 0xFF));
- Sprite dummySprite(white96, 96, 96);
- Monster monster;
- monster.SetSprite(&dummySprite);
- Hero hero;
- hero.SetSprite(&dummySprite);
-
try {
InitSDL sdl;
+ InitImage image(IMG_INIT_PNG);
InitScreen screen(width, height);
- BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout));
+ // temporary test data
+ SDL_Surface *bg(SDL_CreateRGBSurface(0, width, height, 32, 0xFF000000, 0xFF0000, 0xFF00, 0xFF));
+ SDL_FillRect(bg, 0, SDL_MapRGB(bg->format, 0xFF, 0xFF, 0xFF));
+ SDL_Rect r;
+ r.x = 1;
+ r.y = 1;
+ r.w = width - 2;
+ r.h = height - 2;
+ SDL_FillRect(bg, &r, SDL_MapRGB(bg->format, 0, 0, 0));
+ PartyLayout monstersLayout;
+ monstersLayout.AddPosition(Point<Uint8>(50, 100));
+ monstersLayout.AddPosition(Point<Uint8>(100, 100));
+ monstersLayout.AddPosition(Point<Uint8>(150, 100));
+ monstersLayout.AddPosition(Point<Uint8>(200, 100));
+ PartyLayout heroesLayout;
+ heroesLayout.AddPosition(Point<Uint8>(27, 219));
+ heroesLayout.AddPosition(Point<Uint8>(104, 227));
+ heroesLayout.AddPosition(Point<Uint8>(66, 238));
+ heroesLayout.AddPosition(Point<Uint8>(143, 246));
+ SDL_Surface *white96(SDL_CreateRGBSurface(0, 96, 96, 32, 0xFF000000, 0xFF0000, 0xFF00, 0xFF));
+ SDL_FillRect(white96, 0, SDL_MapRGB(bg->format, 0xFF, 0xFF, 0xFF));
+ Sprite dummySprite(white96, 96, 96);
+ Monster monster;
+ monster.SetSprite(&dummySprite);
+ Hero hero;
+ hero.SetSprite(&dummySprite);
+
+ SDL_Surface *attackIcons(IMG_Load("test-data/attack-type-icons.png"));
+ Sprite attackIconsSprite(attackIcons, 32, 32);
+
+ BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &attackIconsSprite));
battleState->AddMonster(monster);
battleState->AddMonster(monster);
battleState->AddMonster(monster);
--- /dev/null
+/*
+ * InitImage.cpp
+ *
+ * Created on: Aug 6, 2012
+ * Author: holy
+ */
+
+#include "InitImage.h"
+
+#include <SDL_image.h>
+#include <stdexcept>
+
+using std::runtime_error;
+
+namespace sdl {
+
+InitImage::InitImage(int flags) {
+ if (IMG_Init(flags) != flags) {
+ throw runtime_error(IMG_GetError());
+ }
+}
+
+InitImage::~InitImage() {
+ IMG_Quit();
+}
+
+}
--- /dev/null
+/*
+ * InitImage.h
+ *
+ * Created on: Aug 6, 2012
+ * Author: holy
+ */
+
+#ifndef SDL_INITIMAGE_H_
+#define SDL_INITIMAGE_H_
+
+namespace sdl {
+
+class InitImage {
+
+public:
+ explicit InitImage(int flags);
+ ~InitImage();
+private:
+ InitImage(const InitImage &);
+ InitImage &operator =(const InitImage &);
+
+};
+
+}
+
+#endif /* SDL_INITIMAGE_H_ */