]> git.localhorst.tv Git - l2e.git/commitdiff
added basic map classes
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 29 Sep 2012 16:45:01 +0000 (18:45 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 29 Sep 2012 17:19:14 +0000 (19:19 +0200)
13 files changed:
Debug/makefile
Debug/sources.mk
Debug/src/map/subdir.mk [new file with mode: 0644]
Release/makefile
Release/sources.mk
Release/src/map/subdir.mk [new file with mode: 0644]
src/main.cpp
src/map/Area.cpp [new file with mode: 0644]
src/map/Area.h [new file with mode: 0644]
src/map/Map.cpp [new file with mode: 0644]
src/map/Map.h [new file with mode: 0644]
src/map/Tile.cpp [new file with mode: 0644]
src/map/Tile.h [new file with mode: 0644]

index 13878f316e329a04cd70183f468b17dd1ae5ccd1..fb78d77000c341cfe3be76ba5c445c9aa748eea4 100644 (file)
@@ -9,6 +9,7 @@ RM := rm -rf
 # 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
index 7aaa6cfb7a6cbee251461aacc619ec53c1a97322..ccb0eebe5d0f5e4132e4e8157d776dc6722fd187 100644 (file)
@@ -24,6 +24,7 @@ C_UPPER_DEPS :=
 # Every subdirectory with source files must be described here
 SUBDIRS := \
 src/sdl \
+src/map \
 src \
 src/loader \
 src/graphics \
diff --git a/Debug/src/map/subdir.mk b/Debug/src/map/subdir.mk
new file mode 100644 (file)
index 0000000..5f0138c
--- /dev/null
@@ -0,0 +1,30 @@
+################################################################################
+# 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 ' '
+
+
index 13878f316e329a04cd70183f468b17dd1ae5ccd1..fb78d77000c341cfe3be76ba5c445c9aa748eea4 100644 (file)
@@ -9,6 +9,7 @@ RM := rm -rf
 # 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
index 7aaa6cfb7a6cbee251461aacc619ec53c1a97322..ccb0eebe5d0f5e4132e4e8157d776dc6722fd187 100644 (file)
@@ -24,6 +24,7 @@ C_UPPER_DEPS :=
 # Every subdirectory with source files must be described here
 SUBDIRS := \
 src/sdl \
+src/map \
 src \
 src/loader \
 src/graphics \
diff --git a/Release/src/map/subdir.mk b/Release/src/map/subdir.mk
new file mode 100644 (file)
index 0000000..384a876
--- /dev/null
@@ -0,0 +1,30 @@
+################################################################################
+# 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 ' '
+
+
index 965da00e56eb871bd7e5345dd101c40668cf81ad..a2cdae9da96f38112252ece108446c12c9153dc4 100644 (file)
@@ -84,6 +84,8 @@ int main(int argc, char **argv) {
        const int width = 800;
        const int height = 480;
 
+       const bool battle(false);
+
 //     std::srand(std::time(0));
 
        try {
@@ -224,29 +226,33 @@ int main(int argc, char **argv) {
 
                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) {
diff --git a/src/map/Area.cpp b/src/map/Area.cpp
new file mode 100644 (file)
index 0000000..a1ae680
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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());
+       }
+}
+
+}
diff --git a/src/map/Area.h b/src/map/Area.h
new file mode 100644 (file)
index 0000000..9bca341
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * 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_ */
diff --git a/src/map/Map.cpp b/src/map/Map.cpp
new file mode 100644 (file)
index 0000000..450c004
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * 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);
+       }
+}
+
+}
diff --git a/src/map/Map.h b/src/map/Map.h
new file mode 100644 (file)
index 0000000..9fb24af
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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_ */
diff --git a/src/map/Tile.cpp b/src/map/Tile.cpp
new file mode 100644 (file)
index 0000000..7b77fb1
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Tile.cpp
+ *
+ *  Created on: Sep 29, 2012
+ *      Author: holy
+ */
+
+#include "Tile.h"
+
+namespace map {
+
+Tile::Tile()
+: flags(0) {
+
+}
+
+}
diff --git a/src/map/Tile.h b/src/map/Tile.h
new file mode 100644 (file)
index 0000000..d21de56
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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_ */