# All of the sources participating in the build are defined here
-include sources.mk
-include src/sdl/subdir.mk
+-include src/map/subdir.mk
-include src/loader/subdir.mk
-include src/graphics/subdir.mk
-include src/common/subdir.mk
# Every subdirectory with source files must be described here
SUBDIRS := \
src/sdl \
+src/map \
src \
src/loader \
src/graphics \
--- /dev/null
+################################################################################
+# Automatically-generated file. Do not edit!
+################################################################################
+
+# Add inputs and outputs from these tool invocations to the build variables
+CPP_SRCS += \
+../src/map/Area.cpp \
+../src/map/Map.cpp \
+../src/map/Tile.cpp
+
+OBJS += \
+./src/map/Area.o \
+./src/map/Map.o \
+./src/map/Tile.o
+
+CPP_DEPS += \
+./src/map/Area.d \
+./src/map/Map.d \
+./src/map/Tile.d
+
+
+# Each subdirectory must supply rules for building sources it contributes
+src/map/%.o: ../src/map/%.cpp
+ @echo 'Building file: $<'
+ @echo 'Invoking: GCC C++ Compiler'
+ g++ -I/usr/include/SDL -O0 -g3 -Wall -Werror -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
+ @echo 'Finished building: $<'
+ @echo ' '
+
+
# All of the sources participating in the build are defined here
-include sources.mk
-include src/sdl/subdir.mk
+-include src/map/subdir.mk
-include src/loader/subdir.mk
-include src/graphics/subdir.mk
-include src/common/subdir.mk
# Every subdirectory with source files must be described here
SUBDIRS := \
src/sdl \
+src/map \
src \
src/loader \
src/graphics \
--- /dev/null
+################################################################################
+# Automatically-generated file. Do not edit!
+################################################################################
+
+# Add inputs and outputs from these tool invocations to the build variables
+CPP_SRCS += \
+../src/map/Area.cpp \
+../src/map/Map.cpp \
+../src/map/Tile.cpp
+
+OBJS += \
+./src/map/Area.o \
+./src/map/Map.o \
+./src/map/Tile.o
+
+CPP_DEPS += \
+./src/map/Area.d \
+./src/map/Map.d \
+./src/map/Tile.d
+
+
+# Each subdirectory must supply rules for building sources it contributes
+src/map/%.o: ../src/map/%.cpp
+ @echo 'Building file: $<'
+ @echo 'Invoking: GCC C++ Compiler'
+ g++ -DNDEBUG -I/usr/include/SDL -O3 -Wall -Werror -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
+ @echo 'Finished building: $<'
+ @echo ' '
+
+
const int width = 800;
const int height = 480;
+ const bool battle(false);
+
// std::srand(std::time(0));
try {
InitScreen screen(width, height);
- BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, battleRes));
- battleState->AddMonster(monster);
- battleState->AddMonster(monster);
- battleState->AddMonster(monster);
- battleState->AddMonster(monster);
- battleState->AddHero(maxim);
- battleState->AddHero(selan);
- battleState->AddHero(guy);
- battleState->AddHero(dekar);
- Application app(&screen, battleState);
- app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
- app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
- app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
- app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
- app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
- app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
- app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
- app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
- app.Buttons().MapKey(SDLK_RETURN, Input::START);
- app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
- app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
- app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
- app.Run();
+ if (battle) {
+ BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, battleRes));
+ battleState->AddMonster(monster);
+ battleState->AddMonster(monster);
+ battleState->AddMonster(monster);
+ battleState->AddMonster(monster);
+ battleState->AddHero(maxim);
+ battleState->AddHero(selan);
+ battleState->AddHero(guy);
+ battleState->AddHero(dekar);
+ Application app(&screen, battleState);
+ app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
+ app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
+ app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
+ app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
+ app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
+ app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
+ app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
+ app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
+ app.Buttons().MapKey(SDLK_RETURN, Input::START);
+ app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
+ app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
+ app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
+ app.Run();
+ } else {
+
+ }
return 0;
} catch (Parser::Error &e) {
--- /dev/null
+/*
+ * Area.cpp
+ *
+ * Created on: Sep 26, 2012
+ * Author: holy
+ */
+
+#include "Area.h"
+
+#include "Tile.h"
+#include "../graphics/Sprite.h"
+
+using geometry::Vector;
+
+namespace map {
+
+Area::Area()
+: tiles(0)
+, numTiles(0)
+, width(0) {
+
+}
+
+void Area::Render(SDL_Surface *dest, const graphics::Sprite *tileset, const Vector<int> &inOffset) const {
+ for (int i(0); i < numTiles; ++i) {
+ Vector<int> offset(
+ inOffset.X() + (i % width) * tileset->Width(),
+ inOffset.Y() + (i / width) * tileset->Height());
+ const Tile &tile(tiles[i]);
+ tileset->Draw(dest, offset, tile.Offset().X(), tile.Offset().Y());
+ }
+}
+
+}
--- /dev/null
+/*
+ * Area.h
+ *
+ * Created on: Sep 26, 2012
+ * Author: holy
+ */
+
+#ifndef MAP_AREA_H_
+#define MAP_AREA_H_
+
+#include "../geometry/Vector.h"
+
+#include <SDL.h>
+
+namespace graphics {
+ class Sprite;
+}
+
+namespace map {
+
+class Tile;
+
+class Area {
+
+public:
+ Area();
+ ~Area() { }
+
+public:
+ int Width() const { return width; }
+ int Height() const { return numTiles / width + (numTiles % width ? 1 : 0); }
+
+ void Render(SDL_Surface *dest, const graphics::Sprite *tileset, const geometry::Vector<int> &offset) const;
+
+// temporary setters
+public:
+ void SetTiles(const Tile *t, int num) { tiles = t; numTiles = num; }
+ void SetWidth(int w) { width = w; }
+
+private:
+ const Tile *tiles;
+ int numTiles;
+ int width;
+
+};
+
+}
+
+#endif /* MAP_AREA_H_ */
--- /dev/null
+/*
+ * Map.cpp
+ *
+ * Created on: Sep 29, 2012
+ * Author: holy
+ */
+
+#include "Map.h"
+
+#include "Area.h"
+#include "../graphics/Sprite.h"
+
+using geometry::Vector;
+
+namespace map {
+
+Map::Map()
+: tileset(0)
+, areas(0)
+, numAreas(0)
+, width(0) {
+
+}
+
+
+void Map::Render(SDL_Surface *dest, const Vector<int> &inOffset) const {
+ // TODO: skip invisible areas
+ for (int i(0); i < numAreas; ++i) {
+ const Area &area(areas[i]);
+ Vector<int> offset(
+ inOffset.X() + (i % width) * area.Width() * tileset->Width(),
+ inOffset.Y() + (i / width) * area.Height() * tileset->Height());
+ area.Render(dest, tileset, offset);
+ }
+}
+
+}
--- /dev/null
+/*
+ * Map.h
+ *
+ * Created on: Sep 29, 2012
+ * Author: holy
+ */
+
+#ifndef MAP_MAP_H_
+#define MAP_MAP_H_
+
+#include "../geometry/Vector.h"
+
+#include <SDL.h>
+
+namespace graphics {
+ class Sprite;
+}
+
+namespace map {
+
+class Area;
+
+class Map {
+
+public:
+ Map();
+ ~Map() { }
+
+public:
+ void Render(SDL_Surface *dest, const geometry::Vector<int> &offset) const;
+
+// temporary setters
+public:
+ void SetTileset(const graphics::Sprite *t) { tileset = t; }
+ void SetAreas(const Area *a, int num) { areas = a; numAreas = num; }
+ void SetWidth(int w) { width = w; }
+
+private:
+ const graphics::Sprite *tileset;
+ const Area *areas;
+ int numAreas;
+ int width;
+
+};
+
+}
+
+#endif /* MAP_MAP_H_ */
--- /dev/null
+/*
+ * Tile.cpp
+ *
+ * Created on: Sep 29, 2012
+ * Author: holy
+ */
+
+#include "Tile.h"
+
+namespace map {
+
+Tile::Tile()
+: flags(0) {
+
+}
+
+}
--- /dev/null
+/*
+ * Tile.h
+ *
+ * Created on: Sep 29, 2012
+ * Author: holy
+ */
+
+#ifndef MAP_TILE_H_
+#define MAP_TILE_H_
+
+#include "../geometry/Vector.h"
+
+#include <SDL.h>
+
+namespace map {
+
+class Tile {
+
+public:
+ Tile();
+ ~Tile() { }
+
+public:
+ enum Flag {
+ BLOCK_NORTH = 0x01,
+ BLOCK_EAST = 0x02,
+ BLOCK_SOUTH = 0x04,
+ BLOCK_WEST = 0x08,
+ };
+
+ const geometry::Vector<int> &Offset() const { return offset; }
+
+ bool BlocksNorth() const { return flags & BLOCK_NORTH; }
+ bool BlocksEast() const { return flags & BLOCK_EAST; }
+ bool BlocksSouth() const { return flags & BLOCK_SOUTH; }
+ bool BlocksWest() const { return flags & BLOCK_WEST; }
+
+// temporary setters
+public:
+ void SetOffset(const geometry::Vector<int> &o) { offset = o; }
+ void SetFlags(Uint32 f) { flags = f; }
+
+private:
+ geometry::Vector<int> offset;
+ Uint32 flags;
+
+};
+
+}
+
+#endif /* MAP_TILE_H_ */