Empezando a trabajar con los nuevos mapas

This commit is contained in:
2022-09-20 21:26:37 +02:00
parent 650df9baaf
commit 378f27a01e
36 changed files with 2873 additions and 938 deletions

View File

@@ -7,7 +7,6 @@ Map::Map(std::string file, SDL_Renderer *renderer, Asset *asset, ItemTracker *it
tile_size = 8;
map_width = 40;
map_height = 26;
tileset_width = 34;
name = file.substr(file.find_last_of("\\/") + 1);
enemy_file = "";
bgColor1 = bgColor2 = {0, 0, 0};
@@ -21,6 +20,7 @@ Map::Map(std::string file, SDL_Renderer *renderer, Asset *asset, ItemTracker *it
texture_tile = new LTexture();
load(file);
loadTextureFromFile(texture_tile, asset->get(tileset_img), renderer);
tileset_width = texture_tile->getWidth() / tile_size;
// Crea la textura para el mapa de tiles de la habitación
map_texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
@@ -75,10 +75,11 @@ bool Map::load(std::string file_path)
std::ifstream file2(asset->get(line)); // Abre el fichero tmx
if (file2.good())
{
bool data_read = false;
bool map1_read = false;
bool map2_read = false;
while (std::getline(file2, line)) // Lee el fichero linea a linea
{
if (!data_read)
if (!map1_read)
{ // Lee lineas hasta que encuentre donde empiezan los datos del mapa
int pos = 0;
do
@@ -89,7 +90,7 @@ bool Map::load(std::string file_path)
do
{ // Se introducen los valores separados por comas en un vector
data_read = true;
map1_read = true;
std::getline(file2, line);
if (line != "</data>")
{
@@ -102,6 +103,30 @@ bool Map::load(std::string file_path)
}
} while (line != "</data>");
}
if (!map2_read)
{ // Lee lineas hasta que encuentre donde empiezan los datos del mapa
int pos = 0;
do
{
std::getline(file2, line);
pos = line.find("data encoding");
} while (pos == std::string::npos);
do
{ // Se introducen los valores separados por comas en un vector
map2_read = true;
std::getline(file2, line);
if (line != "</data>")
{
std::stringstream ss(line);
std::string tmp;
while (getline(ss, tmp, ','))
{
collisionmap.push_back(std::stoi(tmp));
}
}
} while (line != "</data>");
}
}
}
}
@@ -424,20 +449,20 @@ e_tile_map Map::getTile(SDL_Point p)
const int y = std::max(getPlayArea(b_top), (std::min(p.y, getPlayArea(b_bottom) - 1)));
// Calcula el tile
const int tile = tilemap[((y / tile_size) * map_width) + (x / tile_size)];
const int tile = collisionmap[((y / tile_size) * map_width) + (x / tile_size)];
// Las 8 primeras filas son tiles de fondo
if (tile >= 0 && tile < 8 * tileset_width)
if (tile == 0)
{
return nothing;
}
// De la fila 8 a la 15 hay tiles de muro
else if (tile >= (8 * tileset_width) && tile < 16 * tileset_width)
else if (tile == 5627)
{
return wall;
}
// A partir de la fila 16 son tiles atravesables
else
else if (tile == 5628)
{
return passable;
}