Solucionados bugs en la detección de superficies

This commit is contained in:
2022-10-30 14:25:50 +01:00
parent c11f5d2622
commit c79c25d59d
2 changed files with 37 additions and 28 deletions

View File

@@ -400,6 +400,7 @@ void Game::killPlayer()
// Recarga todas las texturas // Recarga todas las texturas
void Game::reLoadTextures() void Game::reLoadTextures()
{ {
std::cout << "** RELOAD REQUESTED" << std::endl;
player->reLoadTexture(); player->reLoadTexture();
room->reLoadTexture(); room->reLoadTexture();
scoreboard->reLoadTexture(); scoreboard->reLoadTexture();

View File

@@ -55,6 +55,10 @@ std::vector<int> loadRoomTileFile(std::string file_path)
room_t loadRoomFile(std::string file_path) room_t loadRoomFile(std::string file_path)
{ {
room_t room; room_t room;
room.itemColor1 = "yellow";
room.itemColor2 = "magenta";
room.autoSurfaceDirection = 1;
const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1); const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
std::string line; std::string line;
std::ifstream file(file_path); std::ifstream file(file_path);
@@ -63,14 +67,12 @@ room_t loadRoomFile(std::string file_path)
if (file.good()) if (file.good())
{ {
// Procesa el fichero linea a linea // Procesa el fichero linea a linea
//printf("Reading file %s\n\n", filename.c_str());
while (std::getline(file, line)) while (std::getline(file, line))
{ {
// Si la linea contiene el texto [enemy] se realiza el proceso de carga de un enemigo // Si la linea contiene el texto [enemy] se realiza el proceso de carga de un enemigo
if (line == "[enemy]") if (line == "[enemy]")
{ {
enemy_t enemy; enemy_t enemy;
// enemy.renderer = renderer;
enemy.flip = false; enemy.flip = false;
enemy.palette = p_zxspectrum; enemy.palette = p_zxspectrum;
@@ -96,7 +98,6 @@ room_t loadRoomFile(std::string file_path)
else if (line == "[item]") else if (line == "[item]")
{ {
item_t item; item_t item;
// item.renderer = renderer;
item.counter = 0; item.counter = 0;
item.color1 = stringToColor(p_zxspectrum, "yellow"); item.color1 = stringToColor(p_zxspectrum, "yellow");
item.color2 = stringToColor(p_zxspectrum, "magenta"); item.color2 = stringToColor(p_zxspectrum, "magenta");
@@ -116,12 +117,6 @@ room_t loadRoomFile(std::string file_path)
} while (line != "[/item]"); } while (line != "[/item]");
// Añade el item al vector de items
// 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); room.items.push_back(item);
} }
@@ -130,6 +125,7 @@ room_t loadRoomFile(std::string file_path)
{ {
// Encuentra la posición del caracter '=' // Encuentra la posición del caracter '='
int pos = line.find("="); int pos = line.find("=");
// Procesa las dos subcadenas // Procesa las dos subcadenas
if (!setVars(&room, line.substr(0, pos), line.substr(pos + 1, line.length()))) if (!setVars(&room, line.substr(0, pos), line.substr(pos + 1, line.length())))
{ {
@@ -190,14 +186,6 @@ bool setVars(room_t *room, std::string var, std::string value)
else if (var == "tileSetFile") else if (var == "tileSetFile")
{ {
room->tileSetFile = value; room->tileSetFile = value;
/*if (options->palette == p_zxspectrum)
{
tileSetFile = "standard.png";
}
else if (options->palette == p_zxarne)
{
tileSetFile = "standard_zxarne.png";
}*/
} }
else if (var == "roomUp") else if (var == "roomUp")
@@ -913,7 +901,8 @@ void Room::setBottomSurfaces()
// Recorre el vector de tiles buscando tiles consecutivos para localizar las superficies // Recorre el vector de tiles buscando tiles consecutivos para localizar las superficies
int i = 0; int i = 0;
int lastOne = 0; int lastOne = 0;
while (i < (int)tile.size()) // while (i < (int)tile.size())
do
{ {
h_line_t line; h_line_t line;
line.x1 = (tile.at(i) % mapWidth) * tileSize; line.x1 = (tile.at(i) % mapWidth) * tileSize;
@@ -924,6 +913,10 @@ void Room::setBottomSurfaces()
while (tile.at(i) == tile.at(i - 1) + 1) while (tile.at(i) == tile.at(i - 1) + 1)
{ {
lastOne = i; lastOne = i;
if (i == (int)tile.size() - 1)
{
break;
}
i++; i++;
} }
@@ -933,7 +926,7 @@ void Room::setBottomSurfaces()
{ // Si el siguiente elemento es un separador, hay que saltarlo { // Si el siguiente elemento es un separador, hay que saltarlo
i++; i++;
} }
} } while (i < (int)tile.size() - 1);
} }
// Calcula las superficies superiores // Calcula las superficies superiores
@@ -960,7 +953,8 @@ void Room::setTopSurfaces()
// Recorre el vector de tiles buscando tiles consecutivos para localizar las superficies // Recorre el vector de tiles buscando tiles consecutivos para localizar las superficies
int i = 0; int i = 0;
int lastOne = 0; int lastOne = 0;
while (i < (int)tile.size()) // while (i < (int)tile.size())
do
{ {
h_line_t line; h_line_t line;
line.x1 = (tile.at(i) % mapWidth) * tileSize; line.x1 = (tile.at(i) % mapWidth) * tileSize;
@@ -971,6 +965,10 @@ void Room::setTopSurfaces()
while (tile.at(i) == tile.at(i - 1) + 1) while (tile.at(i) == tile.at(i - 1) + 1)
{ {
lastOne = i; lastOne = i;
if (i == (int)tile.size() - 1)
{
break;
}
i++; i++;
} }
@@ -980,7 +978,7 @@ void Room::setTopSurfaces()
{ // Si el siguiente elemento es un separador, hay que saltarlo { // Si el siguiente elemento es un separador, hay que saltarlo
i++; i++;
} }
} } while (i < (int)tile.size() - 1);
} }
// Calcula las superficies laterales izquierdas // Calcula las superficies laterales izquierdas
@@ -1006,19 +1004,24 @@ void Room::setLeftSurfaces()
// (Los tiles de la misma columna, la diferencia entre ellos es de mapWidth) // (Los tiles de la misma columna, la diferencia entre ellos es de mapWidth)
// para localizar las superficies // para localizar las superficies
int i = 0; int i = 0;
while (i < (int)tile.size()) // while (i < (int)tile.size())
do
{ {
v_line_t line; v_line_t line;
line.x = (tile.at(i) % mapWidth) * tileSize; line.x = (tile.at(i) % mapWidth) * tileSize;
line.y1 = ((tile.at(i) / mapWidth) * tileSize); line.y1 = ((tile.at(i) / mapWidth) * tileSize);
while (tile.at(i) + mapWidth == tile[i + 1]) while (tile.at(i) + mapWidth == tile[i + 1])
{ {
if (i == (int)tile.size() - 1)
{
break;
}
i++; i++;
} }
line.y2 = ((tile.at(i) / mapWidth) * tileSize) + tileSize - 1; line.y2 = ((tile.at(i) / mapWidth) * tileSize) + tileSize - 1;
leftSurfaces.push_back(line); leftSurfaces.push_back(line);
i++; i++;
} } while (i < (int)tile.size() - 1);
} }
// Calcula las superficies laterales derechas // Calcula las superficies laterales derechas
@@ -1044,19 +1047,24 @@ void Room::setRightSurfaces()
// (Los tiles de la misma columna, la diferencia entre ellos es de mapWidth) // (Los tiles de la misma columna, la diferencia entre ellos es de mapWidth)
// para localizar las superficies // para localizar las superficies
int i = 0; int i = 0;
while (i < (int)tile.size()) // while (i < (int)tile.size())
do
{ {
v_line_t line; v_line_t line;
line.x = ((tile.at(i) % mapWidth) * tileSize) + tileSize - 1; line.x = ((tile.at(i) % mapWidth) * tileSize) + tileSize - 1;
line.y1 = ((tile.at(i) / mapWidth) * tileSize); line.y1 = ((tile.at(i) / mapWidth) * tileSize);
while (tile.at(i) + mapWidth == tile[i + 1]) while (tile.at(i) + mapWidth == tile[i + 1])
{ {
if (i == (int)tile.size() - 1)
{
break;
}
i++; i++;
} }
line.y2 = ((tile.at(i) / mapWidth) * tileSize) + tileSize - 1; line.y2 = ((tile.at(i) / mapWidth) * tileSize) + tileSize - 1;
rightSurfaces.push_back(line); rightSurfaces.push_back(line);
i++; i++;
} } while (i < (int)tile.size() - 1);
} }
// Encuentra todas las rampas que suben hacia la izquierda // Encuentra todas las rampas que suben hacia la izquierda