forked from jaildesigner-jailgames/jaildoctors_dilemma
Resueltos muchos bugs de vector out of range en la busqueda de superficies
This commit is contained in:
@@ -11,6 +11,68 @@ Demo::Demo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
|
|||||||
rooms.push_back("45.room");
|
rooms.push_back("45.room");
|
||||||
rooms.push_back("60.room");
|
rooms.push_back("60.room");
|
||||||
rooms.push_back("58.room");
|
rooms.push_back("58.room");
|
||||||
|
|
||||||
|
//rooms.push_back("01.room");
|
||||||
|
//rooms.push_back("02.room");
|
||||||
|
//rooms.push_back("03.room");
|
||||||
|
//rooms.push_back("04.room");
|
||||||
|
//rooms.push_back("05.room");
|
||||||
|
//rooms.push_back("06.room");
|
||||||
|
//rooms.push_back("07.room");
|
||||||
|
//rooms.push_back("08.room");
|
||||||
|
//rooms.push_back("09.room");
|
||||||
|
//rooms.push_back("10.room");
|
||||||
|
//rooms.push_back("11.room");
|
||||||
|
//rooms.push_back("12.room");
|
||||||
|
//rooms.push_back("13.room");
|
||||||
|
//rooms.push_back("14.room");
|
||||||
|
//rooms.push_back("15.room");
|
||||||
|
//rooms.push_back("16.room");
|
||||||
|
//rooms.push_back("17.room");
|
||||||
|
//rooms.push_back("18.room");
|
||||||
|
//rooms.push_back("19.room");
|
||||||
|
//rooms.push_back("20.room");
|
||||||
|
//rooms.push_back("21.room");
|
||||||
|
//rooms.push_back("22.room");
|
||||||
|
//rooms.push_back("23.room");
|
||||||
|
//rooms.push_back("24.room");
|
||||||
|
//rooms.push_back("25.room");
|
||||||
|
//rooms.push_back("26.room");
|
||||||
|
//rooms.push_back("27.room");
|
||||||
|
//rooms.push_back("28.room");
|
||||||
|
//rooms.push_back("29.room");
|
||||||
|
//rooms.push_back("30.room");
|
||||||
|
//rooms.push_back("31.room");
|
||||||
|
//rooms.push_back("32.room");
|
||||||
|
//rooms.push_back("33.room");
|
||||||
|
//rooms.push_back("34.room");
|
||||||
|
//rooms.push_back("35.room");
|
||||||
|
//rooms.push_back("36.room");
|
||||||
|
//rooms.push_back("37.room");
|
||||||
|
//rooms.push_back("38.room");
|
||||||
|
//rooms.push_back("39.room");
|
||||||
|
//rooms.push_back("40.room");
|
||||||
|
//rooms.push_back("41.room");
|
||||||
|
//rooms.push_back("42.room");
|
||||||
|
//rooms.push_back("43.room");
|
||||||
|
//rooms.push_back("44.room");
|
||||||
|
//rooms.push_back("45.room");
|
||||||
|
//rooms.push_back("46.room");
|
||||||
|
//rooms.push_back("47.room");
|
||||||
|
//rooms.push_back("48.room");
|
||||||
|
//rooms.push_back("49.room");
|
||||||
|
//rooms.push_back("50.room");
|
||||||
|
//rooms.push_back("51.room");
|
||||||
|
//rooms.push_back("52.room");
|
||||||
|
//rooms.push_back("53.room");
|
||||||
|
//rooms.push_back("54.room");
|
||||||
|
//rooms.push_back("55.room");
|
||||||
|
//rooms.push_back("56.room");
|
||||||
|
//rooms.push_back("57.room");
|
||||||
|
//rooms.push_back("58.room");
|
||||||
|
//rooms.push_back("59.room");
|
||||||
|
//rooms.push_back("60.room");
|
||||||
|
|
||||||
roomIndex = 0;
|
roomIndex = 0;
|
||||||
currentRoom = rooms.at(roomIndex);
|
currentRoom = rooms.at(roomIndex);
|
||||||
|
|
||||||
@@ -31,6 +93,8 @@ Demo::Demo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
|
|||||||
|
|
||||||
// Inicializa el resto de variables
|
// Inicializa el resto de variables
|
||||||
counter = 0;
|
counter = 0;
|
||||||
|
roomTime = 400;
|
||||||
|
roomTime = 200;
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
ticksSpeed = 15;
|
ticksSpeed = 15;
|
||||||
board.lives = 9;
|
board.lives = 9;
|
||||||
@@ -240,7 +304,7 @@ bool Demo::changeRoom(std::string file)
|
|||||||
void Demo::checkRoomChange()
|
void Demo::checkRoomChange()
|
||||||
{
|
{
|
||||||
counter++;
|
counter++;
|
||||||
if (counter == 400)
|
if (counter == roomTime)
|
||||||
{
|
{
|
||||||
counter = 0;
|
counter = 0;
|
||||||
roomIndex++;
|
roomIndex++;
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ private:
|
|||||||
std::string currentRoom; // Fichero de la habitación actual
|
std::string currentRoom; // Fichero de la habitación actual
|
||||||
board_t board; // Estructura con los datos del marcador
|
board_t board; // Estructura con los datos del marcador
|
||||||
int counter; // Contador para el modo demo
|
int counter; // Contador para el modo demo
|
||||||
|
int roomTime; // Tiempo que se muestra cada habitacion
|
||||||
int roomIndex; // Indice para el vector de habitaciones
|
int roomIndex; // Indice para el vector de habitaciones
|
||||||
std::vector<std::string> rooms; // Listado con los mapas de la demo
|
std::vector<std::string> rooms; // Listado con los mapas de la demo
|
||||||
|
|
||||||
|
|||||||
207
source/room.cpp
207
source/room.cpp
@@ -882,33 +882,42 @@ 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;
|
if ((int)tile.size() > 0)
|
||||||
int lastOne = 0;
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
h_line_t line;
|
int i = 0;
|
||||||
line.x1 = (tile.at(i) % mapWidth) * tileSize;
|
int lastOne = 0;
|
||||||
line.y = ((tile.at(i) / mapWidth) * tileSize) + tileSize - 1;
|
do
|
||||||
lastOne = i;
|
|
||||||
i++;
|
|
||||||
|
|
||||||
while (tile.at(i) == tile.at(i - 1) + 1)
|
|
||||||
{
|
{
|
||||||
|
h_line_t line;
|
||||||
|
line.x1 = (tile.at(i) % mapWidth) * tileSize;
|
||||||
|
line.y = ((tile.at(i) / mapWidth) * tileSize) + tileSize - 1;
|
||||||
lastOne = i;
|
lastOne = i;
|
||||||
if (i == (int)tile.size() - 1)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
i++;
|
||||||
}
|
|
||||||
|
|
||||||
line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1;
|
if (i < (int)tile.size() - 1)
|
||||||
bottomSurfaces.push_back(line);
|
{
|
||||||
if (tile.at(i) == -1)
|
while (tile.at(i) == tile.at(i - 1) + 1)
|
||||||
{ // Si el siguiente elemento es un separador, hay que saltarlo
|
{
|
||||||
i++;
|
lastOne = i;
|
||||||
}
|
if (i == (int)tile.size() - 1)
|
||||||
} while (i < (int)tile.size() - 1);
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1;
|
||||||
|
bottomSurfaces.push_back(line);
|
||||||
|
if (i < (int)tile.size() - 1)
|
||||||
|
{
|
||||||
|
if (tile.at(i) == -1)
|
||||||
|
{ // Si el siguiente elemento es un separador, hay que saltarlo
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (i < (int)tile.size() - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calcula las superficies superiores
|
// Calcula las superficies superiores
|
||||||
@@ -933,33 +942,42 @@ 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;
|
if ((int)tile.size() > 0)
|
||||||
int lastOne = 0;
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
h_line_t line;
|
int i = 0;
|
||||||
line.x1 = (tile.at(i) % mapWidth) * tileSize;
|
int lastOne = 0;
|
||||||
line.y = (tile.at(i) / mapWidth) * tileSize;
|
do
|
||||||
lastOne = i;
|
|
||||||
i++;
|
|
||||||
|
|
||||||
while (tile.at(i) == tile.at(i - 1) + 1)
|
|
||||||
{
|
{
|
||||||
|
h_line_t line;
|
||||||
|
line.x1 = (tile.at(i) % mapWidth) * tileSize;
|
||||||
|
line.y = (tile.at(i) / mapWidth) * tileSize;
|
||||||
lastOne = i;
|
lastOne = i;
|
||||||
if (i == (int)tile.size() - 1)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
i++;
|
||||||
}
|
|
||||||
|
|
||||||
line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1;
|
if (i < (int)tile.size() - 1)
|
||||||
topSurfaces.push_back(line);
|
{
|
||||||
if (tile.at(i) == -1)
|
while (tile.at(i) == tile.at(i - 1) + 1)
|
||||||
{ // Si el siguiente elemento es un separador, hay que saltarlo
|
{
|
||||||
i++;
|
lastOne = i;
|
||||||
}
|
if (i == (int)tile.size() - 1)
|
||||||
} while (i < (int)tile.size() - 1);
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1;
|
||||||
|
topSurfaces.push_back(line);
|
||||||
|
if (i < (int)tile.size() - 1)
|
||||||
|
{
|
||||||
|
if (tile.at(i) == -1)
|
||||||
|
{ // Si el siguiente elemento es un separador, hay que saltarlo
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (i < (int)tile.size() - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calcula las superficies laterales izquierdas
|
// Calcula las superficies laterales izquierdas
|
||||||
@@ -984,24 +1002,27 @@ void Room::setLeftSurfaces()
|
|||||||
// Recorre el vector de tiles buscando tiles consecutivos
|
// Recorre el vector de tiles buscando tiles consecutivos
|
||||||
// (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;
|
if ((int)tile.size() > 0)
|
||||||
do
|
|
||||||
{
|
{
|
||||||
v_line_t line;
|
int i = 0;
|
||||||
line.x = (tile.at(i) % mapWidth) * tileSize;
|
do
|
||||||
line.y1 = ((tile.at(i) / mapWidth) * tileSize);
|
|
||||||
while (tile.at(i) + mapWidth == tile[i + 1])
|
|
||||||
{
|
{
|
||||||
if (i == (int)tile.size() - 1)
|
v_line_t line;
|
||||||
|
line.x = (tile.at(i) % mapWidth) * tileSize;
|
||||||
|
line.y1 = ((tile.at(i) / mapWidth) * tileSize);
|
||||||
|
while (tile.at(i) + mapWidth == tile[i + 1])
|
||||||
{
|
{
|
||||||
break;
|
if (i == (int)tile.size() - 1)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
line.y2 = ((tile.at(i) / mapWidth) * tileSize) + tileSize - 1;
|
||||||
|
leftSurfaces.push_back(line);
|
||||||
i++;
|
i++;
|
||||||
}
|
} while (i < (int)tile.size() - 1);
|
||||||
line.y2 = ((tile.at(i) / mapWidth) * tileSize) + tileSize - 1;
|
}
|
||||||
leftSurfaces.push_back(line);
|
|
||||||
i++;
|
|
||||||
} while (i < (int)tile.size() - 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calcula las superficies laterales derechas
|
// Calcula las superficies laterales derechas
|
||||||
@@ -1026,24 +1047,27 @@ void Room::setRightSurfaces()
|
|||||||
// Recorre el vector de tiles buscando tiles consecutivos
|
// Recorre el vector de tiles buscando tiles consecutivos
|
||||||
// (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;
|
if ((int)tile.size() > 0)
|
||||||
do
|
|
||||||
{
|
{
|
||||||
v_line_t line;
|
int i = 0;
|
||||||
line.x = ((tile.at(i) % mapWidth) * tileSize) + tileSize - 1;
|
do
|
||||||
line.y1 = ((tile.at(i) / mapWidth) * tileSize);
|
|
||||||
while (tile.at(i) + mapWidth == tile[i + 1])
|
|
||||||
{
|
{
|
||||||
if (i == (int)tile.size() - 1)
|
v_line_t line;
|
||||||
|
line.x = ((tile.at(i) % mapWidth) * tileSize) + tileSize - 1;
|
||||||
|
line.y1 = ((tile.at(i) / mapWidth) * tileSize);
|
||||||
|
while (tile.at(i) + mapWidth == tile[i + 1])
|
||||||
{
|
{
|
||||||
break;
|
if (i == (int)tile.size() - 1)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
line.y2 = ((tile.at(i) / mapWidth) * tileSize) + tileSize - 1;
|
||||||
|
rightSurfaces.push_back(line);
|
||||||
i++;
|
i++;
|
||||||
}
|
} while (i < (int)tile.size() - 1);
|
||||||
line.y2 = ((tile.at(i) / mapWidth) * tileSize) + tileSize - 1;
|
}
|
||||||
rightSurfaces.push_back(line);
|
|
||||||
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
|
||||||
@@ -1152,26 +1176,39 @@ void Room::setAutoSurfaces()
|
|||||||
// 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())
|
if ((int)tile.size() > 0)
|
||||||
{
|
{
|
||||||
h_line_t line;
|
do
|
||||||
line.x1 = (tile.at(i) % mapWidth) * tileSize;
|
|
||||||
line.y = (tile.at(i) / mapWidth) * tileSize;
|
|
||||||
lastOne = i;
|
|
||||||
i++;
|
|
||||||
|
|
||||||
while (tile.at(i) == tile.at(i - 1) + 1)
|
|
||||||
{
|
{
|
||||||
|
h_line_t line;
|
||||||
|
line.x1 = (tile.at(i) % mapWidth) * tileSize;
|
||||||
|
line.y = (tile.at(i) / mapWidth) * tileSize;
|
||||||
lastOne = i;
|
lastOne = i;
|
||||||
i++;
|
i++;
|
||||||
}
|
|
||||||
|
|
||||||
line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1;
|
if (i < (int)tile.size() - 1)
|
||||||
autoSurfaces.push_back(line);
|
{
|
||||||
if (tile.at(i) == -1)
|
while (tile.at(i) == tile.at(i - 1) + 1)
|
||||||
{ // Si el siguiente elemento es un separador, hay que saltarlo
|
{
|
||||||
i++;
|
lastOne = i;
|
||||||
}
|
if (i == (int)tile.size() - 1)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1;
|
||||||
|
autoSurfaces.push_back(line);
|
||||||
|
if (i < (int)tile.size() - 1)
|
||||||
|
{
|
||||||
|
if (tile.at(i) == -1)
|
||||||
|
{ // Si el siguiente elemento es un separador, hay que saltarlo
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (i < (int)tile.size() - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user