forked from jaildesigner-jailgames/jaildoctors_dilemma
Eliminados la mayor parte de accesos a vector mediante at()
This commit is contained in:
102
source/room.cpp
102
source/room.cpp
@@ -548,13 +548,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.at(index) >= 18 * tileSetWidth) && (tileMap.at(index) < 19 * tileSetWidth);
|
||||
const bool b = tileMap.at(index) > -1;
|
||||
const bool a = (tileMap[index] >= 18 * tileSetWidth) && (tileMap[index] < 19 * tileSetWidth);
|
||||
const bool b = tileMap[index] > -1;
|
||||
|
||||
if (b && !a)
|
||||
{
|
||||
clip.x = (tileMap.at(index) % tileSetWidth) * tileSize;
|
||||
clip.y = (tileMap.at(index) / tileSetWidth) * tileSize;
|
||||
clip.x = (tileMap[index] % tileSetWidth) * tileSize;
|
||||
clip.y = (tileMap[index] / tileSetWidth) * tileSize;
|
||||
texture->render(renderer, x * tileSize, y * tileSize, &clip);
|
||||
|
||||
#ifdef DEBUG
|
||||
@@ -763,37 +763,37 @@ tile_e Room::getTile(int index)
|
||||
if (onRange)
|
||||
{
|
||||
// Las filas 0-8 son de tiles t_wall
|
||||
if ((tileMap.at(index) >= 0) && (tileMap.at(index) < 9 * tileSetWidth))
|
||||
if ((tileMap[index] >= 0) && (tileMap[index] < 9 * tileSetWidth))
|
||||
{
|
||||
return t_wall;
|
||||
}
|
||||
|
||||
// Las filas 9-17 son de tiles t_passable
|
||||
else if ((tileMap.at(index) >= 9 * tileSetWidth) && (tileMap.at(index) < 18 * tileSetWidth))
|
||||
else if ((tileMap[index] >= 9 * tileSetWidth) && (tileMap[index] < 18 * tileSetWidth))
|
||||
{
|
||||
return t_passable;
|
||||
}
|
||||
|
||||
// Las filas 18-20 es de tiles t_animated
|
||||
else if ((tileMap.at(index) >= 18 * tileSetWidth) && (tileMap.at(index) < 21 * tileSetWidth))
|
||||
else if ((tileMap[index] >= 18 * tileSetWidth) && (tileMap[index] < 21 * tileSetWidth))
|
||||
{
|
||||
return t_animated;
|
||||
}
|
||||
|
||||
// La fila 21 es de tiles t_slope_r
|
||||
else if ((tileMap.at(index) >= 21 * tileSetWidth) && (tileMap.at(index) < 22 * tileSetWidth))
|
||||
else if ((tileMap[index] >= 21 * tileSetWidth) && (tileMap[index] < 22 * tileSetWidth))
|
||||
{
|
||||
return t_slope_r;
|
||||
}
|
||||
|
||||
// La fila 22 es de tiles t_slope_l
|
||||
else if ((tileMap.at(index) >= 22 * tileSetWidth) && (tileMap.at(index) < 23 * tileSetWidth))
|
||||
else if ((tileMap[index] >= 22 * tileSetWidth) && (tileMap[index] < 23 * tileSetWidth))
|
||||
{
|
||||
return t_slope_l;
|
||||
}
|
||||
|
||||
// La fila 23 es de tiles t_kill
|
||||
else if ((tileMap.at(index) >= 23 * tileSetWidth) && (tileMap.at(index) < 24 * tileSetWidth))
|
||||
else if ((tileMap[index] >= 23 * tileSetWidth) && (tileMap[index] < 24 * tileSetWidth))
|
||||
{
|
||||
return t_kill;
|
||||
}
|
||||
@@ -820,10 +820,10 @@ bool Room::itemCollision(SDL_Rect &rect)
|
||||
{
|
||||
for (int i = 0; i < (int)items.size(); ++i)
|
||||
{
|
||||
if (checkCollision(rect, items.at(i)->getCollider()))
|
||||
if (checkCollision(rect, items[i]->getCollider()))
|
||||
{
|
||||
itemTracker->addItem(name, items.at(i)->getPos());
|
||||
delete items.at(i);
|
||||
itemTracker->addItem(name, items[i]->getPos());
|
||||
delete items[i];
|
||||
items.erase(items.begin() + i);
|
||||
JA_PlaySound(itemSound);
|
||||
*itemsPicked = *itemsPicked + 1;
|
||||
@@ -955,14 +955,14 @@ void Room::setBottomSurfaces()
|
||||
do
|
||||
{
|
||||
h_line_t line;
|
||||
line.x1 = (tile.at(i) % mapWidth) * tileSize;
|
||||
line.y = ((tile.at(i) / mapWidth) * tileSize) + tileSize - 1;
|
||||
line.x1 = (tile[i] % mapWidth) * tileSize;
|
||||
line.y = ((tile[i] / mapWidth) * tileSize) + tileSize - 1;
|
||||
lastOne = i;
|
||||
i++;
|
||||
|
||||
if (i <= (int)tile.size() - 1)
|
||||
{
|
||||
while (tile.at(i) == tile.at(i - 1) + 1)
|
||||
while (tile[i] == tile[i - 1] + 1)
|
||||
{
|
||||
lastOne = i;
|
||||
if (i == (int)tile.size() - 1)
|
||||
@@ -973,11 +973,11 @@ void Room::setBottomSurfaces()
|
||||
}
|
||||
}
|
||||
|
||||
line.x2 = ((tile.at(lastOne) % mapWidth) * tileSize) + tileSize - 1;
|
||||
line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1;
|
||||
bottomSurfaces.push_back(line);
|
||||
if (i <= (int)tile.size() - 1)
|
||||
{
|
||||
if (tile.at(i) == -1)
|
||||
if (tile[i] == -1)
|
||||
{ // Si el siguiente elemento es un separador, hay que saltarlo
|
||||
i++;
|
||||
}
|
||||
@@ -1018,14 +1018,14 @@ void Room::setTopSurfaces()
|
||||
do
|
||||
{
|
||||
h_line_t line;
|
||||
line.x1 = (tile.at(i) % mapWidth) * tileSize;
|
||||
line.y = (tile.at(i) / mapWidth) * tileSize;
|
||||
line.x1 = (tile[i] % mapWidth) * tileSize;
|
||||
line.y = (tile[i] / mapWidth) * tileSize;
|
||||
lastOne = i;
|
||||
i++;
|
||||
|
||||
if (i <= (int)tile.size() - 1)
|
||||
{
|
||||
while (tile.at(i) == tile.at(i - 1) + 1)
|
||||
while (tile[i] == tile[i - 1] + 1)
|
||||
{
|
||||
lastOne = i;
|
||||
if (i == (int)tile.size() - 1)
|
||||
@@ -1036,11 +1036,11 @@ void Room::setTopSurfaces()
|
||||
}
|
||||
}
|
||||
|
||||
line.x2 = ((tile.at(lastOne) % mapWidth) * tileSize) + tileSize - 1;
|
||||
line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1;
|
||||
topSurfaces.push_back(line);
|
||||
if (i <= (int)tile.size() - 1)
|
||||
{
|
||||
if (tile.at(i) == -1)
|
||||
if (tile[i] == -1)
|
||||
{ // Si el siguiente elemento es un separador, hay que saltarlo
|
||||
i++;
|
||||
}
|
||||
@@ -1080,9 +1080,9 @@ void Room::setLeftSurfaces()
|
||||
do
|
||||
{
|
||||
v_line_t line;
|
||||
line.x = (tile.at(i) % mapWidth) * tileSize;
|
||||
line.y1 = ((tile.at(i) / mapWidth) * tileSize);
|
||||
while (tile.at(i) + mapWidth == tile.at(i + 1))
|
||||
line.x = (tile[i] % mapWidth) * tileSize;
|
||||
line.y1 = ((tile[i] / mapWidth) * tileSize);
|
||||
while (tile[i] + mapWidth == tile[i + 1])
|
||||
{
|
||||
if (i == (int)tile.size() - 1)
|
||||
{
|
||||
@@ -1090,7 +1090,7 @@ void Room::setLeftSurfaces()
|
||||
}
|
||||
i++;
|
||||
}
|
||||
line.y2 = ((tile.at(i) / mapWidth) * tileSize) + tileSize - 1;
|
||||
line.y2 = ((tile[i] / mapWidth) * tileSize) + tileSize - 1;
|
||||
leftSurfaces.push_back(line);
|
||||
i++;
|
||||
} while (i < (int)tile.size() - 1);
|
||||
@@ -1128,9 +1128,9 @@ void Room::setRightSurfaces()
|
||||
do
|
||||
{
|
||||
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.at(i + 1))
|
||||
line.x = ((tile[i] % mapWidth) * tileSize) + tileSize - 1;
|
||||
line.y1 = ((tile[i] / mapWidth) * tileSize);
|
||||
while (tile[i] + mapWidth == tile[i + 1])
|
||||
{
|
||||
if (i == (int)tile.size() - 1)
|
||||
{
|
||||
@@ -1138,7 +1138,7 @@ void Room::setRightSurfaces()
|
||||
}
|
||||
i++;
|
||||
}
|
||||
line.y2 = ((tile.at(i) / mapWidth) * tileSize) + tileSize - 1;
|
||||
line.y2 = ((tile[i] / mapWidth) * tileSize) + tileSize - 1;
|
||||
rightSurfaces.push_back(line);
|
||||
i++;
|
||||
} while (i < (int)tile.size() - 1);
|
||||
@@ -1165,14 +1165,14 @@ void Room::setLeftSlopes()
|
||||
while (found.size() > 0)
|
||||
{
|
||||
d_line_t line;
|
||||
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);
|
||||
line.x1 = (found[0] % mapWidth) * tileSize;
|
||||
line.y1 = (found[0] / mapWidth) * tileSize;
|
||||
int lookingFor = found[0] + mapWidth + 1;
|
||||
int lastOneFound = found[0];
|
||||
found.erase(found.begin());
|
||||
for (int i = 0; i < (int)found.size(); ++i)
|
||||
{
|
||||
if (found.at(i) == lookingFor)
|
||||
if (found[i] == lookingFor)
|
||||
{
|
||||
lastOneFound = lookingFor;
|
||||
lookingFor += mapWidth + 1;
|
||||
@@ -1206,14 +1206,14 @@ void Room::setRightSlopes()
|
||||
while (found.size() > 0)
|
||||
{
|
||||
d_line_t line;
|
||||
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);
|
||||
line.x1 = ((found[0] % mapWidth) * tileSize) + tileSize - 1;
|
||||
line.y1 = (found[0] / mapWidth) * tileSize;
|
||||
int lookingFor = found[0] + mapWidth - 1;
|
||||
int lastOneFound = found[0];
|
||||
found.erase(found.begin());
|
||||
for (int i = 0; i < (int)found.size(); ++i)
|
||||
{
|
||||
if (found.at(i) == lookingFor)
|
||||
if (found[i] == lookingFor)
|
||||
{
|
||||
lastOneFound = lookingFor;
|
||||
lookingFor += mapWidth - 1;
|
||||
@@ -1256,14 +1256,14 @@ void Room::setAutoSurfaces()
|
||||
do
|
||||
{
|
||||
h_line_t line;
|
||||
line.x1 = (tile.at(i) % mapWidth) * tileSize;
|
||||
line.y = (tile.at(i) / mapWidth) * tileSize;
|
||||
line.x1 = (tile[i] % mapWidth) * tileSize;
|
||||
line.y = (tile[i] / mapWidth) * tileSize;
|
||||
lastOne = i;
|
||||
i++;
|
||||
|
||||
if (i <= (int)tile.size() - 1)
|
||||
{
|
||||
while (tile.at(i) == tile.at(i - 1) + 1)
|
||||
while (tile[i] == tile[i - 1] + 1)
|
||||
{
|
||||
lastOne = i;
|
||||
if (i == (int)tile.size() - 1)
|
||||
@@ -1274,11 +1274,11 @@ void Room::setAutoSurfaces()
|
||||
}
|
||||
}
|
||||
|
||||
line.x2 = ((tile.at(lastOne) % mapWidth) * tileSize) + tileSize - 1;
|
||||
line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1;
|
||||
autoSurfaces.push_back(line);
|
||||
if (i <= (int)tile.size() - 1)
|
||||
{
|
||||
if (tile.at(i) == -1)
|
||||
if (tile[i] == -1)
|
||||
{ // Si el siguiente elemento es un separador, hay que saltarlo
|
||||
i++;
|
||||
}
|
||||
@@ -1299,9 +1299,9 @@ void Room::setAnimatedTiles()
|
||||
const int x = (i % mapWidth) * tileSize;
|
||||
const int y = (i / mapWidth) * 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;
|
||||
// TileMap[i] es el tile a poner
|
||||
const int xc = (tileMap[i] % tileSetWidth) * tileSize;
|
||||
const int yc = (tileMap[i] / tileSetWidth) * tileSize;
|
||||
|
||||
aTile_t at;
|
||||
at.sprite = new Sprite(x, y, 8, 8, texture, renderer);
|
||||
@@ -1532,7 +1532,7 @@ void Room::openTheJail()
|
||||
// Abre las puertas
|
||||
const int tileA = 16 + (13 * 32);
|
||||
const int tileB = 16 + (14 * 32);
|
||||
tileMap.at(tileA) = -1;
|
||||
tileMap.at(tileB) = -1;
|
||||
tileMap[tileA] = -1;
|
||||
tileMap[tileB] = -1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user