diff --git a/data/room/01.room b/data/room/01.room
index 04cc1e2..b9b643c 100644
--- a/data/room/01.room
+++ b/data/room/01.room
@@ -1,4 +1,3 @@
-id=1
name=Test Room
bg_color=black
tileset=room1.png
@@ -6,7 +5,10 @@ room_up=0
room_down=0
room_left=0
room_right=02.room
-tilemap=41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,41,0,0,0,0,41,41,41,41,41,41,41,41,41,41,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,41,0,0,41,41,41,41,41,0,0,0,0,0,0,0,0,0,81,0,0,0,0,0,0,0,0,0,0,0,0,0,41,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,41,0,0,0,0,0,0,0,0,0,0,0,0,41,41,41,41,0,0,0,0,0,0,0,0,0,0,0,41,41,41,41,41,41,41,41,0,0,0,0,0,0,0,0,0,41,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,0,0,0,0,0,41,41,0,0,0,0,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,0,0,0,0,0,41,0,0,0,0,0,0,0,0,0,81,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41
+
+[tilemap]
+room1.tmx
+[tilemap-end]
[enemy]
tileset=enemy01.png
@@ -34,4 +36,9 @@ y2=72
color=yellow
[enemy-end]
-item=1,10,10
\ No newline at end of file
+[item]
+tileset=items.png
+tile=1
+x=10
+y=10
+[item-end]
\ No newline at end of file
diff --git a/data/room/02.room b/data/room/02.room
index 2d6486d..d9bb16b 100644
--- a/data/room/02.room
+++ b/data/room/02.room
@@ -1,4 +1,3 @@
-id=2
name=Test Room 2
bg_color=black
tileset=room1.png
@@ -6,7 +5,7 @@ room_up=0
room_down=0
room_left=01.room
room_right=0
-tilemap=43,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43,43,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43,43,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43,43,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43,43,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43,43,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43,43,0,0,0,0,0,0,0,0,0,0,83,83,83,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43,43,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43,43,43,43,43,0,0,0,0,0,0,0,0,0,43,43,0,0,0,0,0,0,0,0,83,0,0,0,0,0,0,0,0,0,3,0,0,0,0,83,83,0,0,0,0,0,43,43,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,43,43,0,0,0,0,0,0,0,0,83,0,0,0,0,0,0,0,0,0,3,0,0,0,0,83,83,0,0,0,0,0,43,43,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,43,0,0,0,0,0,0,0,83,83,83,83,83,83,0,0,0,0,0,0,3,0,0,0,0,83,83,0,0,0,0,0,0,0,0,0,0,0,83,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,43,43,43,43,43,43,43,43,43,43,43,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63
-enemy=1,0,0,0,1
-enemy=2,10,0,0,1
-item=1,10,10
\ No newline at end of file
+
+[tilemap]
+room2.tmx
+[tilemap-end]
\ No newline at end of file
diff --git a/data/room/room1.tmx b/data/room/room1.tmx
new file mode 100644
index 0000000..5f69ab0
--- /dev/null
+++ b/data/room/room1.tmx
@@ -0,0 +1,24 @@
+
+
diff --git a/data/room/room2.tmx b/data/room/room2.tmx
new file mode 100644
index 0000000..0d8e1e4
--- /dev/null
+++ b/data/room/room2.tmx
@@ -0,0 +1,24 @@
+
+
diff --git a/source/director.cpp b/source/director.cpp
index 412984d..a621b2d 100644
--- a/source/director.cpp
+++ b/source/director.cpp
@@ -198,6 +198,8 @@ void Director::setFileList()
mAsset->add("/data/config.bin", data, false);
mAsset->add("/data/room/01.room", room);
mAsset->add("/data/room/02.room", room);
+ mAsset->add("/data/room/room1.tmx", room);
+ mAsset->add("/data/room/room2.tmx", room);
mAsset->add("/media/tilesets/room1.png", bitmap);
mAsset->add("/media/enemies/enemy01.png", bitmap);
mAsset->add("/media/player/player01.png", bitmap);
diff --git a/source/room.cpp b/source/room.cpp
index 92c5d88..c19c796 100644
--- a/source/room.cpp
+++ b/source/room.cpp
@@ -56,7 +56,7 @@ bool Room::load(std::string _file_path)
printf("Reading file %s\n", filename.c_str());
while (std::getline(file, line))
{
- // Si la linea contiene el texto [enemy] se realiza un proceso distinto
+ // Si la linea contiene el texto [enemy] se realiza el proceso de carga de un enemigo
if (line == "[enemy]")
{
enemy_t enemy;
@@ -80,6 +80,84 @@ bool Room::load(std::string _file_path)
// Añade el enemigo al vector de enemigos
enemy_list.push_back(new Enemy(enemy));
}
+
+ // Si la linea contiene el texto [tilemap] se realiza el proceso de carga del fichero tmx
+ else if (line == "[tilemap]")
+ {
+ //printf("Loading tilemap...\n");
+ do
+ {
+ std::getline(file, line);
+ if (line.find(".tmx") != std::string::npos)
+ {
+ //printf("Reading file %s\n", asset->get(line).c_str());
+ std::ifstream file2(asset->get(line)); // Abre el fichero tmx
+ if (file2.good())
+ {
+ bool data_read = false;
+ while (std::getline(file2, line)) // Lee el fichero linea a linea
+ {
+ if (!data_read)
+ { // Lee lineas hasta que encuentre donde empiezan los datos del mapa
+ int pos = 0;
+ do
+ {
+ std::getline(file2, line);
+ //printf("parsing: %s\n", line.c_str());
+
+ pos = line.find("data encoding");
+ //printf("pos: %i\n", pos);
+
+ } while (pos == std::string::npos);
+
+ do
+ { // Se introducen los valores separados por comas en un vector
+ data_read = true;
+ std::getline(file2, line);
+ if (line != "")
+ {
+ //printf("data: %s\n", line.c_str());
+ std::stringstream ss(line);
+ std::string tmp;
+ while (getline(ss, tmp, ','))
+ {
+ //printf("tile: %s\n", tmp.c_str());
+ tilemap.push_back(std::stoi(tmp));
+ }
+ }
+ } while (line != "");
+ }
+ }
+ }
+ }
+ } while (line != "[tilemap-end]");
+ }
+
+ // Si la linea contiene el texto [item] se realiza el proceso de carga de un item
+ else if (line == "[item]")
+ {
+ // enemy_t enemy;
+ // enemy.asset = asset;
+ // enemy.renderer = renderer;
+
+ do
+ {
+ std::getline(file, line);
+
+ // Encuentra la posición del caracter '='
+ int pos = line.find("=");
+ // Procesa las dos subcadenas
+ // if (!setEnemy(&enemy, line.substr(0, pos), line.substr(pos + 1, line.length())))
+ //{
+ // printf("Warning: file %s\n, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str());
+ // success = false;
+ //}
+ } while (line != "[item-end]");
+
+ // Añade el enemigo al vector de enemigos
+ // enemy_list.push_back(new Enemy(enemy));
+ }
+
// En caso contrario se parsea el fichero para buscar las variables y los valores
else
{
@@ -114,11 +192,7 @@ bool Room::setVars(std::string _var, std::string _value)
// Indicador de éxito en la asignación
bool success = true;
- if (_var == "id")
- {
- id = _value;
- }
- else if (_var == "name")
+ if (_var == "name")
{
name = _value;
}
@@ -156,6 +230,9 @@ bool Room::setVars(std::string _var, std::string _value)
tilemap.push_back(std::stoi(tmp));
}
}
+ else if (_var == "")
+ {
+ }
else
{
success = false;
@@ -210,6 +287,9 @@ bool Room::setEnemy(enemy_t *enemy, std::string _var, std::string _value)
{
enemy->color = stringToColor(_value);
}
+ else if (_var == "[enemy-end]")
+ {
+ }
else
{
success = false;
diff --git a/source/room.h b/source/room.h
index 5bc4923..6327139 100644
--- a/source/room.h
+++ b/source/room.h
@@ -32,7 +32,6 @@ LISTADO DE ITEMS (tipo, posicion)
class Room
{
private:
- std::string id; // Identificador
std::string name; // Nombre de la habitación
color_t bg_color; // Color de fondo de la habitación
std::string room_up; // Identificador de la habitación que se encuentra arriba
diff --git a/todo.txt b/todo.txt
index d4b542b..5f1194e 100644
--- a/todo.txt
+++ b/todo.txt
@@ -1,2 +1,3 @@
[ ] Hacer que deje de poder moverse tras el salto al alcanzar la misma posicion en altura que tenia cuando saltó
-[ ] Leer los mapas directamente del archivo tmx
\ No newline at end of file
+[ ] Leer los mapas directamente del archivo tmx
+[ ] Crear la clase item
\ No newline at end of file