diff --git a/Makefile b/Makefile
index 42bcb3e..2304ad7 100644
--- a/Makefile
+++ b/Makefile
@@ -9,12 +9,15 @@ SRCS := $(shell find $(SRC_DIRS) -name *.cpp -or -name *.c -or -name *.s)
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
+LIBXML_ROOT ?= /usr/include/libxml2
+#LIBRARY_PATH=. ./lib/
+
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
-CPPFLAGS ?= $(INC_FLAGS) -MMD -MP -w
+CPPFLAGS ?= $(INC_FLAGS) -Ilibtmx-parser/src -Ilibtmx-parser/libs/tinyxml2 -MMD -MP -w -I$(LIBXML_ROOT)
-LINKER_FLAGS = -lSDL2 -lSDL2_image -lSDL2_mixer
+LINKER_FLAGS = -lSDL2 -lSDL2_image -lSDL2_mixer -lxml2 -ltmxparser
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
# $(CC) $(OBJS) -o $@ $(LDFLAGS)
diff --git a/assets/maps/br-tiles.png b/assets/maps/br-tiles.png
new file mode 100644
index 0000000..8e80265
Binary files /dev/null and b/assets/maps/br-tiles.png differ
diff --git a/assets/maps/br-tiles.tsx b/assets/maps/br-tiles.tsx
new file mode 100644
index 0000000..561ba45
--- /dev/null
+++ b/assets/maps/br-tiles.tsx
@@ -0,0 +1,103 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/assets/maps/testmap.tmx b/assets/maps/testmap.tmx
new file mode 100644
index 0000000..20ae09e
--- /dev/null
+++ b/assets/maps/testmap.tmx
@@ -0,0 +1,96 @@
+
+
diff --git a/assets/maps/testmapb64.tmx b/assets/maps/testmapb64.tmx
new file mode 100644
index 0000000..f744aa4
--- /dev/null
+++ b/assets/maps/testmapb64.tmx
@@ -0,0 +1,9 @@
+
+
diff --git a/assets/textures/tiles/br-tiles.tsx b/assets/textures/tiles/br-tiles.tsx
new file mode 100644
index 0000000..561ba45
--- /dev/null
+++ b/assets/textures/tiles/br-tiles.tsx
@@ -0,0 +1,103 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build/BeagleRescue b/build/BeagleRescue
index 842d19f..c60dac7 100755
Binary files a/build/BeagleRescue and b/build/BeagleRescue differ
diff --git a/libtmx-parser b/libtmx-parser
new file mode 160000
index 0000000..a2b8ca0
--- /dev/null
+++ b/libtmx-parser
@@ -0,0 +1 @@
+Subproject commit a2b8ca09efbcaff4c423580a633b2e7787ba7405
diff --git a/rungame.sh b/rungame.sh
new file mode 100755
index 0000000..fc34db1
--- /dev/null
+++ b/rungame.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+LD_LIBRARY_PATH=./libtmx-parser/ ./build/BeagleRescue
diff --git a/src/assetmgr/Map.cpp b/src/assetmgr/Map.cpp.bak
similarity index 96%
rename from src/assetmgr/Map.cpp
rename to src/assetmgr/Map.cpp.bak
index a2aeb32..a3e1c44 100644
--- a/src/assetmgr/Map.cpp
+++ b/src/assetmgr/Map.cpp.bak
@@ -33,7 +33,7 @@ void Map::LoadMap(std::string path, int sizeX, int sizeY, int scale)
std::fstream mapFile;
mapFile.open(path);
int srcX, srcY;
-
+
width = tSize*scale*sizeX;
height = tSize*scale*sizeY;
@@ -45,7 +45,6 @@ void Map::LoadMap(std::string path, int sizeX, int sizeY, int scale)
srcY = atoi(&c) * tileSize;
mapFile.get(c);
srcX = atoi(&c) * tileSize;
- AddTile(srcX, srcY, x*scaledSize, y*scaledSize);
mapFile.ignore(2,',');
}
}
diff --git a/src/assetmgr/Map.h b/src/assetmgr/Map.h.bak
similarity index 100%
rename from src/assetmgr/Map.h
rename to src/assetmgr/Map.h.bak
diff --git a/src/config/credits.json b/src/config/credits.json
index db7738a..15ba458 100644
--- a/src/config/credits.json
+++ b/src/config/credits.json
@@ -1,6 +1,6 @@
{
"GameName":"Beagle Rescue",
"Developers": "Alan Youngblood, Simon Zaleski, Daniel Rinaldi",
-"LibraryDevelopers": "Sam Lantinga, Dave Gamble, Carl Birch, Job Vranish, David Lafreniere",
+"LibraryDevelopers": "Sam Lantinga, Dave Gamble, Carl Birch, Job Vranish, David Lafreniere, Bayle Jonathan",
"SpecialThanks":"Nic Allen, Brian Lhota, Rodrigo Monteiro"
}
diff --git a/src/ecs/Components.h b/src/ecs/Components.h
index 4e9dba6..5f27a78 100644
--- a/src/ecs/Components.h
+++ b/src/ecs/Components.h
@@ -16,6 +16,7 @@
#include "PlayerController.h"
#include "ProjectileComponent.h"
#include "TileComponent.h"
+#include "TileMapComponent.h"
#include "UITextComponent.h"
#endif /* SRC_COMPONENTS_H_ */
diff --git a/src/ecs/TileMapComponent.h b/src/ecs/TileMapComponent.h
new file mode 100644
index 0000000..c879755
--- /dev/null
+++ b/src/ecs/TileMapComponent.h
@@ -0,0 +1,79 @@
+/*
+ * TileMapComponent.h
+ *
+ * Created on: Mar 21, 2020
+ * Author: ayoungblood
+ */
+
+#ifndef SRC_ECS_TILEMAPCOMPONENT_H_
+#define SRC_ECS_TILEMAPCOMPONENT_H_
+
+#include "ECS.h"
+#include "SDL2/SDL.h"
+#include "../assetmgr/AssetManager.h"
+#include
+#include
+#include
+#include
+
+class TileMapComponent : public Component
+{
+public:
+ TransformComponent *transform;
+ SDL_Texture* texture;
+ SDL_Rect srcRect, destRect;
+ Vector2D position;
+ std::tuple tile;
+
+ TileMapComponent() = default;
+
+ ~TileMapComponent()
+ {
+ SDL_DestroyTexture(texture);
+ }
+
+ TileMapComponent(std::string id, int tsize, int tscale)
+ {
+ setTex(id);
+// position.x = xpos;
+// position.y = ypos;
+//
+// srcRect.x = srcX;
+// srcRect.y = srcY;
+ srcRect.w = srcRect.h = tsize;
+
+// destRect.x = xpos;
+// destRect.y = ypos;
+ destRect.w = destRect.h = tsize * tscale;
+ }
+
+ void update() override
+ {
+ destRect.x = position.x - Game::camera.x;
+ destRect.y = position.y - Game::camera.y;
+ }
+
+ void draw() override
+ {
+ //iterate through rows and columns of the map to draw the tiles
+
+ TextureManager::Draw(texture, srcRect, destRect, SDL_FLIP_NONE);
+ }
+
+ std::tuple getTile(char currentTile, int i)
+ {
+ std::tuple tileTuple;
+
+
+ tileTuple = std::make_tuple(srcRect,destRect);
+ return tileTuple;
+ }
+
+ void setTex(std::string id)
+ {
+ texture = Game::assets->GetTexture(id);
+ }
+};
+
+#endif /* SRC_ECS_TILEMAPCOMPONENT_H_ */
+
diff --git a/src/ecs/UITextComponent.h b/src/ecs/UITextComponent.h
index f676a2f..151b524 100644
--- a/src/ecs/UITextComponent.h
+++ b/src/ecs/UITextComponent.h
@@ -34,9 +34,7 @@ private:
SDL_RendererFlip spriteFlip = SDL_FLIP_NONE;
std::tuple letter;
-public:
-
-
+public:
UITextComponent(std::string id, std::string textToPrint, int letterW, int letterH, int letterScale)
{
setTex(id);
diff --git a/src/game/Game.cpp b/src/game/Game.cpp
index 866bf99..2cca2a7 100644
--- a/src/game/Game.cpp
+++ b/src/game/Game.cpp
@@ -10,7 +10,7 @@
#include "Game.hpp"
#include "../assetmgr/TextureManager.h"
-#include "../assetmgr/Map.h"
+// #include "../assetmgr/Map.h"
#include "../ecs/Components.h"
#include "Collision.h"
#include
@@ -21,8 +21,10 @@
// #include "../ui/UIText.h"
#include "../ui/UINineSlice.h"
#include "../cjson/cJSON.h"
+#include "tmxparser.h"
-Map* map;
+
+// Map* map;
Manager manager;
UINineSlice* my9Slice;
UINineSlice* scoreboard9Slice;
@@ -117,7 +119,17 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Couldn't initialize SDL audio mixer!, Error: %s", SDL_GetError());
}
+
+// Trying out the halsafar/libtmx-parser
+ tmxparser::TmxReturn error;
+ tmxparser::TmxMap map;
+ error = tmxparser::parseFromFile("assets/maps/testmap.tmx", &map, "assets/textures/tiles/");
// current_time = SDL_GetTicks();
+ if (!error)
+ {
+ printf("Yay! Tile map loaded with no errors.\n");
+ std::cout << "Map width: " << map.width << " tiles wide by: " << map.height << " tiles high" << std::endl;
+ }
assets->AddTexture("terrain", "assets/textures/tiles/br-tiles.png");
assets->AddTexture("player", "assets/textures/actors/firefighter.png");
@@ -133,7 +145,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
assets->AddSoundClip("bark1","assets/audio/sfx/Bark1.wav");
assets->AddSoundClip("bark2","assets/audio/sfx/Bark2.wav");
- map = new Map("terrain",globalScale,16);
+// map = new Map("terrain",globalScale,16);
// std::string myText = "Find lost puppies!\nThey need your help!";
std::string myText = "Press U to Start";
@@ -171,7 +183,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
//ecs implementation
- map->LoadMap("assets/maps/br-map-color.txt",70,45, globalScale);
+// map->LoadMap("assets/maps/br-map-color.txt",70,45, globalScale);
player.addComponent(860*globalScale,640*globalScale,22,42,globalScale);
player.addComponent("player", SpriteComponent::spriteAnimation, "assets/textures/actors/firefighter.json");
@@ -298,10 +310,10 @@ void Game::update()
camera.x = 0;
if (camera.y < 0)
camera.y = 0;
- if (camera.x > map->width-camera.w)
- camera.x = map->width-camera.w;
- if (camera.y > map->height-camera.h)
- camera.y = map->height-camera.h;
+// if (camera.x > map->width-camera.w)
+// camera.x = map->width-camera.w;
+// if (camera.y > map->height-camera.h)
+// camera.y = map->height-camera.h;
if (Game::debugCollisionBoxes)
{
for (auto& c: colliders)