Resuelto un bug con la detección de superficies

This commit is contained in:
2022-11-07 17:00:48 +01:00
parent 50309fd30e
commit 8ae821733c
3 changed files with 39 additions and 27 deletions

View File

@@ -796,10 +796,10 @@ bool Room::itemCollision(SDL_Rect &rect)
{
for (int i = 0; i < (int)items.size(); ++i)
{
if (checkCollision(rect, items[i]->getCollider()))
if (checkCollision(rect, items.at(i)->getCollider()))
{
itemTracker->addItem(name, items[i]->getPos());
delete items[i];
itemTracker->addItem(name, items.at(i)->getPos());
delete items.at(i);
items.erase(items.begin() + i);
JA_PlaySound(itemSound);
*itemsPicked = *itemsPicked + 1;
@@ -911,8 +911,11 @@ void Room::setBottomSurfaces()
}
}
// Añade un terminador
tile.push_back(-1);
// Recorre el vector de tiles buscando tiles consecutivos para localizar las superficies
if ((int)tile.size() > 0)
if ((int)tile.size() > 1)
{
int i = 0;
int lastOne = 0;
@@ -937,7 +940,7 @@ void Room::setBottomSurfaces()
}
}
line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1;
line.x2 = ((tile.at(lastOne) % mapWidth) * tileSize) + tileSize - 1;
bottomSurfaces.push_back(line);
if (i <= (int)tile.size() - 1)
{
@@ -971,8 +974,11 @@ void Room::setTopSurfaces()
}
}
// Añade un terminador
tile.push_back(-1);
// Recorre el vector de tiles buscando tiles consecutivos para localizar las superficies
if ((int)tile.size() > 0)
if ((int)tile.size() > 1)
{
int i = 0;
int lastOne = 0;
@@ -997,7 +1003,7 @@ void Room::setTopSurfaces()
}
}
line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1;
line.x2 = ((tile.at(lastOne) % mapWidth) * tileSize) + tileSize - 1;
topSurfaces.push_back(line);
if (i <= (int)tile.size() - 1)
{
@@ -1029,10 +1035,13 @@ void Room::setLeftSurfaces()
}
}
// Añade un terminador
tile.push_back(-1);
// Recorre el vector de tiles buscando tiles consecutivos
// (Los tiles de la misma columna, la diferencia entre ellos es de mapWidth)
// para localizar las superficies
if ((int)tile.size() > 0)
if ((int)tile.size() > 1)
{
int i = 0;
do
@@ -1040,7 +1049,7 @@ void Room::setLeftSurfaces()
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])
while (tile.at(i) + mapWidth == tile.at(i + 1))
{
if (i == (int)tile.size() - 1)
{
@@ -1074,10 +1083,13 @@ void Room::setRightSurfaces()
}
}
// Añade un terminador
tile.push_back(-1);
// Recorre el vector de tiles buscando tiles consecutivos
// (Los tiles de la misma columna, la diferencia entre ellos es de mapWidth)
// para localizar las superficies
if ((int)tile.size() > 0)
if ((int)tile.size() > 1)
{
int i = 0;
do
@@ -1085,7 +1097,7 @@ void Room::setRightSurfaces()
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])
while (tile.at(i) + mapWidth == tile.at(i + 1))
{
if (i == (int)tile.size() - 1)
{
@@ -1120,14 +1132,14 @@ void Room::setLeftSlopes()
while (found.size() > 0)
{
d_line_t line;
line.x1 = (found[0] % mapWidth) * tileSize;
line.y1 = (found[0] / mapWidth) * tileSize;
int lookingFor = found[0] + mapWidth + 1;
int lastOneFound = found[0];
line.x1 = (found.at(0) % mapWidth) * tileSize;
line.y1 = (found.at(0) / mapWidth) * tileSize;
int lookingFor = found.at(0) + mapWidth + 1;
int lastOneFound = found.at(0);
found.erase(found.begin());
for (int i = 0; i < (int)found.size(); ++i)
{
if (found[i] == lookingFor)
if (found.at(i) == lookingFor)
{
lastOneFound = lookingFor;
lookingFor += mapWidth + 1;
@@ -1161,14 +1173,14 @@ void Room::setRightSlopes()
while (found.size() > 0)
{
d_line_t line;
line.x1 = ((found[0] % mapWidth) * tileSize) + tileSize - 1;
line.y1 = (found[0] / mapWidth) * tileSize;
int lookingFor = found[0] + mapWidth - 1;
int lastOneFound = found[0];
line.x1 = ((found.at(0) % mapWidth) * tileSize) + tileSize - 1;
line.y1 = (found.at(0) / mapWidth) * tileSize;
int lookingFor = found.at(0) + mapWidth - 1;
int lastOneFound = found.at(0);
found.erase(found.begin());
for (int i = 0; i < (int)found.size(); ++i)
{
if (found[i] == lookingFor)
if (found.at(i) == lookingFor)
{
lastOneFound = lookingFor;
lookingFor += mapWidth - 1;
@@ -1229,7 +1241,7 @@ void Room::setAutoSurfaces()
}
}
line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1;
line.x2 = ((tile.at(lastOne) % mapWidth) * tileSize) + tileSize - 1;
autoSurfaces.push_back(line);
if (i <= (int)tile.size() - 1)
{