Trabajando en la precarga de habitaciones

This commit is contained in:
2022-10-30 13:27:30 +01:00
parent d1c27c4639
commit c11f5d2622
74 changed files with 1028 additions and 754 deletions

View File

@@ -3,92 +3,10 @@
#include <fstream>
#include <sstream>
// Constructor
Room::Room(std::string file, SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, ItemTracker *itemTracker, int *items, Debug *debug)
{
// Copia los punteros a objetos
this->resource = resource;
this->renderer = renderer;
this->asset = asset;
this->screen = screen;
this->itemTracker = itemTracker;
this->itemsPicked = items;
this->debug = debug;
this->options = options;
// Inicializa variables
tileSize = 8;
mapWidth = 32;
mapHeight = 16;
paused = false;
itemColor1 = "magenta";
itemColor2 = "yellow";
autoSurfaceDirection = 1;
counter = 0;
// Crea los objetos
loadMapFile(file);
//texture = new Texture(renderer, asset->get(tileset));
texture = resource->getTexture(tileset);
tilesetWidth = texture->getWidth() / tileSize;
itemSound = JA_LoadSound(asset->get("item.wav").c_str());
loadMapTileFile(asset->get(tileMapFile));
// Calcula las superficies
setBottomSurfaces();
setTopSurfaces();
setLeftSurfaces();
setRightSurfaces();
setLeftSlopes();
setRightSlopes();
setAutoSurfaces();
// Busca los tiles animados
setAnimatedTiles();
// Crea la textura para el mapa de tiles de la habitación
mapTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
if (mapTexture == nullptr)
{
printf("Error: mapTexture could not be created!\nSDL Error: %s\n", SDL_GetError());
}
SDL_SetTextureBlendMode(mapTexture, SDL_BLENDMODE_BLEND);
// Pinta el mapa de la habitación en la textura
fillMapTexture();
// Establece el color del borde
screen->setBorderColor(stringToColor(options->palette, borderColor));
}
// Destructor
Room::~Room()
{
// Reclama la memoria utilizada por los objetos
//delete texture;
JA_DeleteSound(itemSound);
SDL_DestroyTexture(mapTexture);
for (auto enemy : enemies)
{
delete enemy;
}
for (auto item : items)
{
delete item;
}
for (auto a : aTile)
{
delete a.sprite;
}
}
// Carga las variables desde un fichero de mapa
bool Room::loadMapFile(std::string file_path)
// Carga las variables y texturas desde un fichero de mapa de tiles
std::vector<int> loadRoomTileFile(std::string file_path)
{
std::vector<int> tileMapFile;
const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
std::string line;
std::ifstream file(file_path);
@@ -97,18 +15,64 @@ bool Room::loadMapFile(std::string file_path)
if (file.good())
{
// Procesa el fichero linea a linea
printf("Reading file %s\n\n", filename.c_str());
//printf("Reading file %s\n", filename.c_str());
while (std::getline(file, line))
{ // Lee el fichero linea a linea
if (line.find("data encoding") != std::string::npos)
{
// Lee la primera linea
std::getline(file, line);
while (line != "</data>")
{ // Procesa lineas mientras haya
std::stringstream ss(line);
std::string tmp;
while (getline(ss, tmp, ','))
{
tileMapFile.push_back(std::stoi(tmp) - 1);
}
// Lee la siguiente linea
std::getline(file, line);
}
}
}
// Cierra el fichero
printf("TileMap loaded: %s\n", filename.c_str());
file.close();
}
else
{ // El fichero no se puede abrir
printf("Warning: Unable to open %s file\n", filename.c_str());
}
return tileMapFile;
}
// Carga las variables desde un fichero de mapa
room_t loadRoomFile(std::string file_path)
{
room_t room;
const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
std::string line;
std::ifstream file(file_path);
// El fichero se puede abrir
if (file.good())
{
// Procesa el fichero linea a linea
//printf("Reading file %s\n\n", filename.c_str());
while (std::getline(file, line))
{
// Si la linea contiene el texto [enemy] se realiza el proceso de carga de un enemigo
if (line == "[enemy]")
{
enemy_t enemy;
enemy.resource = resource;
enemy.asset = asset;
enemy.renderer = renderer;
// enemy.renderer = renderer;
enemy.flip = false;
enemy.palette = options->palette;
enemy.palette = p_zxspectrum;
do
{
@@ -116,7 +80,7 @@ bool Room::loadMapFile(std::string file_path)
// 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())))
{
@@ -125,19 +89,17 @@ bool Room::loadMapFile(std::string file_path)
} while (line != "[/enemy]");
// Añade el enemigo al vector de enemigos
enemies.push_back(new Enemy(enemy));
room.enemies.push_back(enemy);
}
// Si la linea contiene el texto [item] se realiza el proceso de carga de un item
else if (line == "[item]")
{
item_t item;
item.resource = resource;
item.asset = asset;
item.renderer = renderer;
// item.renderer = renderer;
item.counter = 0;
item.color1 = stringToColor(options->palette, itemColor1);
item.color2 = stringToColor(options->palette, itemColor2);
item.color1 = stringToColor(p_zxspectrum, "yellow");
item.color2 = stringToColor(p_zxspectrum, "magenta");
do
{
@@ -155,11 +117,12 @@ bool Room::loadMapFile(std::string file_path)
} while (line != "[/item]");
// Añade el item al vector de items
const SDL_Point itemPos = {item.x, item.y};
if (!itemTracker->hasBeenPicked(name, itemPos))
{
items.push_back(new Item(item));
}
// const SDL_Point itemPos = {item.x, item.y};
// if (!itemTracker->hasBeenPicked(room.name, itemPos))
//{
// room.items.push_back(new Item(item));
// }
room.items.push_back(item);
}
// En caso contrario se parsea el fichero para buscar las variables y los valores
@@ -168,7 +131,7 @@ bool Room::loadMapFile(std::string file_path)
// Encuentra la posición del caracter '='
int pos = line.find("=");
// Procesa las dos subcadenas
if (!setVars(line.substr(0, pos), line.substr(pos + 1, line.length())))
if (!setVars(&room, line.substr(0, pos), line.substr(pos + 1, line.length())))
{
printf("Warning: file %s, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str());
}
@@ -176,149 +139,100 @@ bool Room::loadMapFile(std::string file_path)
}
// Cierra el fichero
printf("Closing file %s\n\n", filename.c_str());
printf("Room loaded: %s\n", filename.c_str());
file.close();
}
// El fichero no se puede abrir
else
{
printf("Warning: Unable to open %s file\n", filename.c_str());
return false;
}
return true;
}
// Carga las variables y texturas desde un fichero de mapa de tiles
bool Room::loadMapTileFile(std::string file_path)
{
const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
std::string line;
std::ifstream file(file_path);
// El fichero se puede abrir
if (file.good())
{
// Procesa el fichero linea a linea
printf("Reading file %s\n", filename.c_str());
while (std::getline(file, line))
{ // Lee el fichero linea a linea
if (line.find("data encoding") != std::string::npos)
{
// Lee la primera linea
std::getline(file, line);
while (line != "</data>")
{ // Procesa lineas mientras haya
std::stringstream ss(line);
std::string tmp;
while (getline(ss, tmp, ','))
{
tilemap.push_back(std::stoi(tmp) - 1);
}
// Lee la siguiente linea
std::getline(file, line);
}
}
}
// Cierra el fichero
printf("Closing file %s\n\n", filename.c_str());
file.close();
}
else
{ // El fichero no se puede abrir
printf("Warning: Unable to open %s file\n", filename.c_str());
return false;
}
return true;
return room;
}
// Asigna variables a partir de dos cadenas
bool Room::setVars(std::string var, std::string value)
bool setVars(room_t *room, std::string var, std::string value)
{
// Indicador de éxito en la asignación
bool success = true;
if (var == "tilemap")
if (var == "tileMapFile")
{
tileMapFile = value;
room->tileMapFile = value;
}
else if (var == "name")
{
name = value;
room->name = value;
}
else if (var == "bgColor")
{
bgColor = value;
room->bgColor = value;
}
else if (var == "border")
{
borderColor = value;
room->borderColor = value;
}
else if (var == "itemColor1")
{
itemColor1 = value;
room->itemColor1 = value;
}
else if (var == "itemColor2")
{
itemColor2 = value;
room->itemColor2 = value;
}
else if (var == "tileset")
else if (var == "tileSetFile")
{
tileset = value;
if (options->palette == p_zxspectrum)
room->tileSetFile = value;
/*if (options->palette == p_zxspectrum)
{
tileset = "standard.png";
tileSetFile = "standard.png";
}
else if (options->palette == p_zxarne)
{
tileset = "standard_zxarne.png";
}
tileSetFile = "standard_zxarne.png";
}*/
}
else if (var == "roomUp")
{
roomUp = value;
room->roomUp = value;
}
else if (var == "roomDown")
{
roomDown = value;
room->roomDown = value;
}
else if (var == "roomLeft")
{
roomLeft = value;
room->roomLeft = value;
}
else if (var == "roomRight")
{
roomRight = value;
room->roomRight = value;
}
else if (var == "autoSurface")
{
if (value == "right")
{
autoSurfaceDirection = 1;
room->autoSurfaceDirection = 1;
}
else
{
autoSurfaceDirection = -1;
room->autoSurfaceDirection = -1;
}
}
else if (var == "")
else if (var == "" || var.substr(0, 1) == "#")
{
}
@@ -331,19 +245,14 @@ bool Room::setVars(std::string var, std::string value)
}
// Asigna variables a una estructura enemy_t
bool Room::setEnemy(enemy_t *enemy, std::string var, std::string value)
bool setEnemy(enemy_t *enemy, std::string var, std::string value)
{
// Indicador de éxito en la asignación
bool success = true;
if (var == "tileset")
if (var == "animation")
{
enemy->tileset = value;
}
else if (var == "animation")
{
enemy->animation = value;
enemy->animationString = value;
}
else if (var == "width")
@@ -406,7 +315,7 @@ bool Room::setEnemy(enemy_t *enemy, std::string var, std::string value)
enemy->color = value;
}
else if (var == "[/enemy]")
else if (var == "[/enemy]" || var == "tileSetFile" || var.substr(0, 1) == "#")
{
}
@@ -419,14 +328,14 @@ bool Room::setEnemy(enemy_t *enemy, std::string var, std::string value)
}
// Asigna variables a una estructura item_t
bool Room::setItem(item_t *item, std::string var, std::string value)
bool setItem(item_t *item, std::string var, std::string value)
{
// Indicador de éxito en la asignación
bool success = true;
if (var == "tileset")
if (var == "tileSetFile")
{
item->tileset = value;
item->tileSetFile = value;
}
else if (var == "counter")
@@ -461,6 +370,132 @@ bool Room::setItem(item_t *item, std::string var, std::string value)
return success;
}
// Constructor
Room::Room(room_t *room, SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options, ItemTracker *itemTracker, int *itemsPicked, Debug *debug)
{
// Copia los punteros a objetos
this->renderer = renderer;
this->asset = asset;
this->screen = screen;
this->itemTracker = itemTracker;
this->itemsPicked = itemsPicked;
this->debug = debug;
this->options = options;
name = room->name;
bgColor = room->bgColor;
borderColor = room->borderColor;
itemColor1 = room->itemColor1 == ""?"yellow":room->itemColor1;
itemColor2 = room->itemColor2 == ""?"magenta":room->itemColor2;
roomUp = room->roomUp;
roomDown = room->roomDown;
roomLeft = room->roomLeft;
roomRight = room->roomRight;
tileSetFile = room->tileSetFile;
tileMapFile = room->tileMapFile;
autoSurfaceDirection = room->autoSurfaceDirection;
textureA = room->textureA;
textureB = room->textureB;
tileMap = room->tileMap;
// Inicializa variables
tileSize = 8;
mapWidth = 32;
mapHeight = 16;
paused = false;
counter = 0;
// itemColor1 = "magenta";
// itemColor2 = "yellow";
// autoSurfaceDirection = 1;
// Crea los enemigos
for (auto &enemy : room->enemies)
{
enemy.renderer = renderer;
enemies.push_back(new Enemy(enemy));
}
// Crea los items
for (auto &item : room->items)
{
const SDL_Point itemPos = {item.x, item.y};
if (!itemTracker->hasBeenPicked(room->name, itemPos))
{
item.renderer = renderer;
items.push_back(new Item(item));
}
}
// Crea los objetos
// loadRoomFile(file);
// texture = new Texture(renderer, asset->get(tileSetFile));
// texture = resource->getTexture(tileSetFile);
if (options->palette == p_zxspectrum)
{
texture = textureA;
}
else
{
texture = textureB;
}
tileSetWidth = texture->getWidth() / tileSize;
itemSound = JA_LoadSound(asset->get("item.wav").c_str());
// loadRoomTileFile(asset->get(tileMapFile));
// Calcula las superficies
setBottomSurfaces();
setTopSurfaces();
setLeftSurfaces();
setRightSurfaces();
setLeftSlopes();
setRightSlopes();
setAutoSurfaces();
// Busca los tiles animados
setAnimatedTiles();
// Crea la textura para el mapa de tiles de la habitación
mapTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
if (mapTexture == nullptr)
{
printf("Error: mapTexture could not be created!\nSDL Error: %s\n", SDL_GetError());
}
SDL_SetTextureBlendMode(mapTexture, SDL_BLENDMODE_BLEND);
// Pinta el mapa de la habitación en la textura
fillMapTexture();
// Establece el color del borde
screen->setBorderColor(stringToColor(options->palette, room->borderColor));
}
// Destructor
Room::~Room()
{
// Reclama la memoria utilizada por los objetos
// delete texture;
JA_DeleteSound(itemSound);
SDL_DestroyTexture(mapTexture);
for (auto enemy : enemies)
{
delete enemy;
}
for (auto item : items)
{
delete item;
}
for (auto a : aTile)
{
delete a.sprite;
}
}
// Devuelve el nombre de la habitación
std::string Room::getName()
{
@@ -486,7 +521,7 @@ void Room::fillMapTexture()
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00);
SDL_RenderClear(renderer);
// Los tilesets son de 20x20 tiles. El primer tile es el 0. Cuentan hacia la derecha y hacia abajo
// Los tileSetFiles son de 20x20 tiles. El primer tile es el 0. Cuentan hacia la derecha y hacia abajo
SDL_Rect clip = {0, 0, tileSize, tileSize};
for (int y = 0; y < mapHeight; ++y)
@@ -496,13 +531,13 @@ void Room::fillMapTexture()
// Al cargar el mapa en memoria, se resta uno, por tanto los tiles vacios son -1
// Tampoco hay que dibujar los tiles animados que estan en la fila 19 (indices)
const int index = (y * mapWidth) + x;
const bool a = (tilemap[index] >= 18 * tilesetWidth) && (tilemap[index] < 19 * tilesetWidth);
const bool b = tilemap[index] > -1;
const bool a = (tileMap->at(index) >= 18 * tileSetWidth) && (tileMap->at(index) < 19 * tileSetWidth);
const bool b = tileMap->at(index) > -1;
if (b && !a)
{
clip.x = (tilemap[index] % tilesetWidth) * tileSize;
clip.y = (tilemap[index] / tilesetWidth) * tileSize;
clip.x = (tileMap->at(index) % tileSetWidth) * tileSize;
clip.y = (tileMap->at(index) / tileSetWidth) * tileSize;
texture->render(renderer, x * tileSize, y * tileSize, &clip);
// ****
@@ -702,37 +737,37 @@ tile_e Room::getTile(int index)
if (index < maxTile)
{
// Las filas 0-8 son de tiles t_wall
if ((tilemap[index] >= 0) && (tilemap[index] < 9 * tilesetWidth))
if ((tileMap->at(index) >= 0) && (tileMap->at(index) < 9 * tileSetWidth))
{
return t_wall;
}
// Las filas 9-17 son de tiles t_passable
else if ((tilemap[index] >= 9 * tilesetWidth) && (tilemap[index] < 18 * tilesetWidth))
else if ((tileMap->at(index) >= 9 * tileSetWidth) && (tileMap->at(index) < 18 * tileSetWidth))
{
return t_passable;
}
// Las filas 18-20 es de tiles t_animated
else if ((tilemap[index] >= 18 * tilesetWidth) && (tilemap[index] < 21 * tilesetWidth))
else if ((tileMap->at(index) >= 18 * tileSetWidth) && (tileMap->at(index) < 21 * tileSetWidth))
{
return t_animated;
}
// La fila 21 es de tiles t_slope_r
else if ((tilemap[index] >= 21 * tilesetWidth) && (tilemap[index] < 22 * tilesetWidth))
else if ((tileMap->at(index) >= 21 * tileSetWidth) && (tileMap->at(index) < 22 * tileSetWidth))
{
return t_slope_r;
}
// La fila 22 es de tiles t_slope_l
else if ((tilemap[index] >= 22 * tilesetWidth) && (tilemap[index] < 23 * tilesetWidth))
else if ((tileMap->at(index) >= 22 * tileSetWidth) && (tileMap->at(index) < 23 * tileSetWidth))
{
return t_slope_l;
}
// La fila 23 es de tiles t_kill
else if ((tilemap[index] >= 23 * tilesetWidth) && (tilemap[index] < 24 * tilesetWidth))
else if ((tileMap->at(index) >= 23 * tileSetWidth) && (tileMap->at(index) < 24 * tileSetWidth))
{
return t_kill;
}
@@ -776,19 +811,7 @@ bool Room::itemCollision(SDL_Rect &rect)
// Recarga la textura
void Room::reLoadTexture()
{
if (options->palette == p_zxspectrum)
{
//texture->loadFromFile(asset->get("standard.png"), renderer);
texture = resource->getTexture("standard.png");
texture->reLoad();
}
else if (options->palette == p_zxarne)
{
//texture->loadFromFile(asset->get("standard_zxarne.png"), renderer);
texture = resource->getTexture("standard_zxarne.png");
texture->reLoad();
}
texture->reLoad();
fillMapTexture();
for (auto enemy : enemies)
@@ -806,20 +829,30 @@ void Room::reLoadTexture()
void Room::reLoadPalette()
{
// Cambia el color de los items
for (auto item:items)
for (auto item : items)
{
item->setColors(stringToColor(options->palette, itemColor1), stringToColor(options->palette, itemColor2));
}
// Cambia el color de los enemigos
for (auto enemy:enemies)
for (auto enemy : enemies)
{
enemy->setPalette(options->palette);
}
// Establece el color del borde
screen->setBorderColor(stringToColor(options->palette, borderColor));
// Cambia la textura
if (options->palette == p_zxspectrum)
{
texture = textureA;
}
else
{
texture = textureB;
}
// Recarga las texturas
reLoadTexture();
}
@@ -863,7 +896,7 @@ void Room::setBottomSurfaces()
// Busca todos los tiles de tipo muro que no tengan debajo otro muro
// Hay que recorrer la habitación por filas (excepto los de la última fila)
for (int i = 0; i < (int)tilemap.size() - mapWidth; ++i)
for (int i = 0; i < (int)tileMap->size() - mapWidth; ++i)
{
if (getTile(i) == t_wall && getTile(i + mapWidth) != t_wall)
{
@@ -883,12 +916,12 @@ void Room::setBottomSurfaces()
while (i < (int)tile.size())
{
h_line_t line;
line.x1 = (tile[i] % mapWidth) * tileSize;
line.y = ((tile[i] / mapWidth) * tileSize) + tileSize - 1;
line.x1 = (tile.at(i) % mapWidth) * tileSize;
line.y = ((tile.at(i) / mapWidth) * tileSize) + tileSize - 1;
lastOne = i;
i++;
while (tile[i] == tile[i - 1] + 1)
while (tile.at(i) == tile.at(i - 1) + 1)
{
lastOne = i;
i++;
@@ -896,7 +929,7 @@ void Room::setBottomSurfaces()
line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1;
bottomSurfaces.push_back(line);
if (tile[i] == -1)
if (tile.at(i) == -1)
{ // Si el siguiente elemento es un separador, hay que saltarlo
i++;
}
@@ -910,7 +943,7 @@ void Room::setTopSurfaces()
// Busca todos los tiles de tipo muro o pasable que no tengan encima un muro
// Hay que recorrer la habitación por filas (excepto los de la primera fila)
for (int i = mapWidth; i < (int)tilemap.size(); ++i)
for (int i = mapWidth; i < (int)tileMap->size(); ++i)
{
if ((getTile(i) == t_wall || getTile(i) == t_passable) && getTile(i - mapWidth) != t_wall)
{
@@ -930,12 +963,12 @@ void Room::setTopSurfaces()
while (i < (int)tile.size())
{
h_line_t line;
line.x1 = (tile[i] % mapWidth) * tileSize;
line.y = (tile[i] / mapWidth) * tileSize;
line.x1 = (tile.at(i) % mapWidth) * tileSize;
line.y = (tile.at(i) / mapWidth) * tileSize;
lastOne = i;
i++;
while (tile[i] == tile[i - 1] + 1)
while (tile.at(i) == tile.at(i - 1) + 1)
{
lastOne = i;
i++;
@@ -943,7 +976,7 @@ void Room::setTopSurfaces()
line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1;
topSurfaces.push_back(line);
if (tile[i] == -1)
if (tile.at(i) == -1)
{ // Si el siguiente elemento es un separador, hay que saltarlo
i++;
}
@@ -976,13 +1009,13 @@ void Room::setLeftSurfaces()
while (i < (int)tile.size())
{
v_line_t line;
line.x = (tile[i] % mapWidth) * tileSize;
line.y1 = ((tile[i] / mapWidth) * tileSize);
while (tile[i] + mapWidth == tile[i + 1])
line.x = (tile.at(i) % mapWidth) * tileSize;
line.y1 = ((tile.at(i) / mapWidth) * tileSize);
while (tile.at(i) + mapWidth == tile[i + 1])
{
i++;
}
line.y2 = ((tile[i] / mapWidth) * tileSize) + tileSize - 1;
line.y2 = ((tile.at(i) / mapWidth) * tileSize) + tileSize - 1;
leftSurfaces.push_back(line);
i++;
}
@@ -1014,13 +1047,13 @@ void Room::setRightSurfaces()
while (i < (int)tile.size())
{
v_line_t line;
line.x = ((tile[i] % mapWidth) * tileSize) + tileSize - 1;
line.y1 = ((tile[i] / mapWidth) * tileSize);
while (tile[i] + mapWidth == tile[i + 1])
line.x = ((tile.at(i) % mapWidth) * tileSize) + tileSize - 1;
line.y1 = ((tile.at(i) / mapWidth) * tileSize);
while (tile.at(i) + mapWidth == tile[i + 1])
{
i++;
}
line.y2 = ((tile[i] / mapWidth) * tileSize) + tileSize - 1;
line.y2 = ((tile.at(i) / mapWidth) * tileSize) + tileSize - 1;
rightSurfaces.push_back(line);
i++;
}
@@ -1031,7 +1064,7 @@ void Room::setLeftSlopes()
{
// Recorre la habitación entera por filas buscando tiles de tipo t_slope_l
std::vector<int> found;
for (int i = 0; i < (int)tilemap.size(); ++i)
for (int i = 0; i < (int)tileMap->size(); ++i)
{
if (getTile(i) == t_slope_l)
{
@@ -1072,7 +1105,7 @@ void Room::setRightSlopes()
{
// Recorre la habitación entera por filas buscando tiles de tipo t_slope_r
std::vector<int> found;
for (int i = 0; i < (int)tilemap.size(); ++i)
for (int i = 0; i < (int)tileMap->size(); ++i)
{
if (getTile(i) == t_slope_r)
{
@@ -1115,7 +1148,7 @@ void Room::setAutoSurfaces()
// Busca todos los tiles de tipo animado
// Hay que recorrer la habitación por filas (excepto los de la primera fila)
for (int i = mapWidth; i < (int)tilemap.size(); ++i)
for (int i = mapWidth; i < (int)tileMap->size(); ++i)
{
if (getTile(i) == t_animated)
{
@@ -1135,12 +1168,12 @@ void Room::setAutoSurfaces()
while (i < (int)tile.size())
{
h_line_t line;
line.x1 = (tile[i] % mapWidth) * tileSize;
line.y = (tile[i] / mapWidth) * tileSize;
line.x1 = (tile.at(i) % mapWidth) * tileSize;
line.y = (tile.at(i) / mapWidth) * tileSize;
lastOne = i;
i++;
while (tile[i] == tile[i - 1] + 1)
while (tile.at(i) == tile.at(i - 1) + 1)
{
lastOne = i;
i++;
@@ -1148,7 +1181,7 @@ void Room::setAutoSurfaces()
line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1;
autoSurfaces.push_back(line);
if (tile[i] == -1)
if (tile.at(i) == -1)
{ // Si el siguiente elemento es un separador, hay que saltarlo
i++;
}
@@ -1159,17 +1192,17 @@ void Room::setAutoSurfaces()
void Room::setAnimatedTiles()
{
// Recorre la habitación entera por filas buscando tiles de tipo t_animated
for (int i = 0; i < (int)tilemap.size(); ++i)
for (int i = 0; i < (int)tileMap->size(); ++i)
{
if (getTile(i) == t_animated)
{
// la i me da la ubicación
// La i es la ubicación
const int x = (i % mapWidth) * tileSize;
const int y = (i / mapWidth) * tileSize;
// tilemap[i] me da el tile a poner
const int xc = (tilemap[i] % tilesetWidth) * tileSize;
const int yc = (tilemap[i] / tilesetWidth) * tileSize;
// TileMap->at(i) es el tile a poner
const int xc = (tileMap->at(i) % tileSetWidth) * tileSize;
const int yc = (tileMap->at(i) / tileSetWidth) * tileSize;
aTile_t at;
at.sprite = new Sprite(x, y, 8, 8, texture, renderer);