Singleton de ItemTracker

Arreglos menors
This commit is contained in:
2025-02-26 13:07:41 +01:00
parent 2457517f2b
commit 85ab5ea03f
13 changed files with 466 additions and 442 deletions

View File

@@ -69,12 +69,12 @@ std::vector<int> loadRoomTileFile(std::string file_path, bool verbose)
}
// Carga las variables desde un fichero de mapa
room_t loadRoomFile(std::string file_path, bool verbose)
RoomData loadRoomFile(std::string file_path, bool verbose)
{
room_t room;
room.itemColor1 = "yellow";
room.itemColor2 = "magenta";
room.autoSurfaceDirection = 1;
RoomData room;
room.item_color1 = "yellow";
room.item_color2 = "magenta";
room.auto_surface_direction = 1;
const std::string fileName = file_path.substr(file_path.find_last_of("\\/") + 1);
room.number = fileName.substr(0, fileName.find_last_of("."));
@@ -182,14 +182,14 @@ room_t loadRoomFile(std::string file_path, bool verbose)
}
// Asigna variables a partir de dos cadenas
bool setVars(room_t *room, std::string var, std::string value)
bool setVars(RoomData *room, std::string var, std::string value)
{
// Indicador de éxito en la asignación
bool success = true;
if (var == "tileMapFile")
{
room->tileMapFile = value;
room->tile_map_file = value;
}
else if (var == "name")
@@ -199,58 +199,58 @@ bool setVars(room_t *room, std::string var, std::string value)
else if (var == "bgColor")
{
room->bgColor = value;
room->bg_color = value;
}
else if (var == "border")
{
room->borderColor = value;
room->border_color = value;
}
else if (var == "itemColor1")
{
room->itemColor1 = value;
room->item_color1 = value;
}
else if (var == "itemColor2")
{
room->itemColor2 = value;
room->item_color2 = value;
}
else if (var == "tileSetFile")
{
room->tileSetFile = value;
room->tile_set_file = value;
}
else if (var == "roomUp")
{
room->roomUp = value;
room->room_top = value;
}
else if (var == "roomDown")
{
room->roomDown = value;
room->room_bottom = value;
}
else if (var == "roomLeft")
{
room->roomLeft = value;
room->room_left = value;
}
else if (var == "roomRight")
{
room->roomRight = value;
room->room_right = value;
}
else if (var == "autoSurface")
{
if (value == "right")
{
room->autoSurfaceDirection = 1;
room->auto_surface_direction = 1;
}
else
{
room->autoSurfaceDirection = -1;
room->auto_surface_direction = -1;
}
}
@@ -408,45 +408,44 @@ bool setItem(item_t *item, std::string var, std::string value)
}
// Constructor
Room::Room(std::shared_ptr<room_t> room, std::shared_ptr<ItemTracker> itemTracker, int *itemsPicked, bool jailEnabled)
: screen(Screen::get()),
renderer(Screen::get()->getRenderer()),
asset(Asset::get()),
debug(Debug::get()),
itemTracker(itemTracker),
itemsPicked(itemsPicked)
Room::Room(std::shared_ptr<RoomData> room, int *itemsPicked, bool jailEnabled)
: screen_(Screen::get()),
renderer_(Screen::get()->getRenderer()),
asset_(Asset::get()),
debug_(Debug::get()),
items_picked_(itemsPicked)
{
number = room->number;
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;
texture = (options.video.palette == Palette::ZXSPECTRUM) ? textureA : textureB;
this->jailEnabled = jailEnabled;
number_ = room->number;
name_ = room->name;
bg_color_ = room->bg_color;
border_color_ = room->border_color;
item_color1_ = room->item_color1 == "" ? "yellow" : room->item_color1;
item_color2_ = room->item_color2 == "" ? "magenta" : room->item_color2;
room_top_ = room->room_top;
room_bottom_ = room->room_bottom;
room_left_ = room->room_left;
room_right_ = room->room_right;
tile_set_file_ = room->tile_set_file;
tile_map_file_ = room->tile_map_file;
auto_surface_direction_ = room->auto_surface_direction;
textureA_ = room->textureA;
textureB_ = room->textureB;
tile_map_ = room->tile_map;
texture_ = (options.video.palette == Palette::ZXSPECTRUM) ? textureA_ : textureB_;
jail_is_open_ = jailEnabled;
// Inicializa variables
tileSize = 8;
tileSetWidth = texture->getWidth() / tileSize;
mapWidth = 32;
mapHeight = 16;
paused = false;
counter = 0;
tile_size_ = 8;
tile_set_width_ = texture_->getWidth() / tile_size_;
map_width_ = 32;
map_height_ = 16;
paused_ = false;
counter_ = 0;
// Crea los enemigos
for (auto &enemy_data : room->enemies)
{
enemies.emplace_back(std::make_shared<Enemy>(enemy_data));
enemies_.emplace_back(std::make_shared<Enemy>(enemy_data));
}
// Crea los items
@@ -454,17 +453,17 @@ Room::Room(std::shared_ptr<room_t> room, std::shared_ptr<ItemTracker> itemTracke
{
const SDL_Point itemPos = {item.x, item.y};
if (!itemTracker->hasBeenPicked(room->name, itemPos))
if (!ItemTracker::get()->hasBeenPicked(room->name, itemPos))
{
item.renderer = renderer;
item.color1 = stringToColor(options.video.palette, itemColor1);
item.color2 = stringToColor(options.video.palette, itemColor2);
items.emplace_back(std::make_shared<Item>(item));
item.renderer = renderer_;
item.color1 = stringToColor(options.video.palette, item_color1_);
item.color2 = stringToColor(options.video.palette, item_color2_);
items_.emplace_back(std::make_shared<Item>(item));
}
}
// Carga los sonidos
itemSound = JA_LoadSound(asset->get("item.wav").c_str());
item_sound_ = JA_LoadSound(asset_->get("item.wav").c_str());
// Abre la jail para poder entrar
if (jailEnabled)
@@ -485,74 +484,74 @@ Room::Room(std::shared_ptr<room_t> room, std::shared_ptr<ItemTracker> itemTracke
setAnimatedTiles();
// Crea la textura para el mapa de tiles de la habitación
mapTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT);
if (mapTexture == nullptr)
map_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT);
if (map_texture_ == nullptr)
{
if (options.console)
{
std::cout << "Error: mapTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
SDL_SetTextureBlendMode(mapTexture, SDL_BLENDMODE_BLEND);
SDL_SetTextureBlendMode(map_texture_, SDL_BLENDMODE_BLEND);
// Pinta el mapa de la habitación en la textura
fillMapTexture();
// Establece el color del borde
screen->setBorderColor(stringToColor(options.video.palette, room->borderColor));
screen_->setBorderColor(stringToColor(options.video.palette, room->border_color));
}
// Destructor
Room::~Room()
{
// Reclama la memoria utilizada por los objetos
SDL_DestroyTexture(mapTexture);
SDL_DestroyTexture(map_texture_);
}
// Devuelve el nombre de la habitación
std::string Room::getName()
{
return name;
return name_;
}
// Devuelve el color de la habitación
Color Room::getBGColor()
{
return stringToColor(options.video.palette, bgColor);
return stringToColor(options.video.palette, bg_color_);
}
// Devuelve el color del borde
Color Room::getBorderColor()
{
return stringToColor(options.video.palette, borderColor);
return stringToColor(options.video.palette, border_color_);
}
// Crea la textura con el mapeado de la habitación
void Room::fillMapTexture()
{
const Color color = stringToColor(options.video.palette, bgColor);
SDL_SetRenderTarget(renderer, mapTexture);
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 0xFF);
SDL_RenderClear(renderer);
const Color color = stringToColor(options.video.palette, bg_color_);
SDL_SetRenderTarget(renderer_, map_texture_);
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF);
SDL_RenderClear(renderer_);
// 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)
for (int x = 0; x < mapWidth; ++x)
SDL_Rect clip = {0, 0, tile_size_, tile_size_};
for (int y = 0; y < map_height_; ++y)
for (int x = 0; x < map_width_; ++x)
{
// Tiled pone los tiles vacios del mapa como cero y empieza a contar de 1 a n.
// 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 int index = (y * map_width_) + x;
const bool a = (tile_map_[index] >= 18 * tile_set_width_) && (tile_map_[index] < 19 * tile_set_width_);
const bool b = tile_map_[index] > -1;
if (b && !a)
{
clip.x = (tileMap[index] % tileSetWidth) * tileSize;
clip.y = (tileMap[index] / tileSetWidth) * tileSize;
texture->render(x * tileSize, y * tileSize, &clip);
clip.x = (tile_map_[index] % tile_set_width_) * tile_size_;
clip.y = (tile_map_[index] / tile_set_width_) * tile_size_;
texture_->render(x * tile_size_, y * tile_size_, &clip);
#ifdef DEBUG
// ****
@@ -654,7 +653,7 @@ void Room::fillMapTexture()
// ****
#endif
SDL_SetRenderTarget(renderer, nullptr);
SDL_SetRenderTarget(renderer_, nullptr);
}
// Dibuja el mapa en pantalla
@@ -662,7 +661,7 @@ void Room::renderMap()
{
// Dibuja la textura con el mapa en pantalla
SDL_Rect dest = {0, 0, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT};
SDL_RenderCopy(renderer, mapTexture, nullptr, &dest);
SDL_RenderCopy(renderer_, map_texture_, nullptr, &dest);
// Dibuja los tiles animados
#ifdef DEBUG
@@ -678,7 +677,7 @@ void Room::renderMap()
// Dibuja los enemigos en pantalla
void Room::renderEnemies()
{
for (auto enemy : enemies)
for (auto enemy : enemies_)
{
enemy->render();
}
@@ -687,7 +686,7 @@ void Room::renderEnemies()
// Dibuja los objetos en pantalla
void Room::renderItems()
{
for (auto item : items)
for (auto item : items_)
{
item->render();
}
@@ -696,23 +695,23 @@ void Room::renderItems()
// Actualiza las variables y objetos de la habitación
void Room::update()
{
if (paused)
if (paused_)
{ // Si está en modo pausa no se actualiza nada
return;
}
// Actualiza el contador
counter++;
counter_++;
// Actualiza los tiles animados
updateAnimatedTiles();
for (auto enemy : enemies)
for (auto enemy : enemies_)
{ // Actualiza los enemigos
enemy->update();
}
for (auto item : items)
for (auto item : items_)
{ // Actualiza los items
item->update();
}
@@ -724,19 +723,19 @@ std::string Room::getRoom(int border)
switch (border)
{
case BORDER_TOP:
return roomUp;
return room_top_;
break;
case BORDER_BOTTOM:
return roomDown;
return room_bottom_;
break;
case BORDER_RIGHT:
return roomRight;
return room_right_;
break;
case BORDER_LEFT:
return roomLeft;
return room_left_;
break;
default:
@@ -748,7 +747,7 @@ std::string Room::getRoom(int border)
// Devuelve el tipo de tile que hay en ese pixel
tile_e Room::getTile(SDL_Point point)
{
const int pos = ((point.y / tileSize) * mapWidth) + (point.x / tileSize);
const int pos = ((point.y / tile_size_) * map_width_) + (point.x / tile_size_);
return getTile(pos);
}
@@ -756,42 +755,42 @@ tile_e Room::getTile(SDL_Point point)
tile_e Room::getTile(int index)
{
// const bool onRange = (index > -1) && (index < mapWidth * mapHeight);
const bool onRange = (index > -1) && (index < (int)tileMap.size());
const bool onRange = (index > -1) && (index < (int)tile_map_.size());
if (onRange)
{
// Las filas 0-8 son de tiles t_wall
if ((tileMap[index] >= 0) && (tileMap[index] < 9 * tileSetWidth))
if ((tile_map_[index] >= 0) && (tile_map_[index] < 9 * tile_set_width_))
{
return t_wall;
}
// Las filas 9-17 son de tiles t_passable
else if ((tileMap[index] >= 9 * tileSetWidth) && (tileMap[index] < 18 * tileSetWidth))
else if ((tile_map_[index] >= 9 * tile_set_width_) && (tile_map_[index] < 18 * tile_set_width_))
{
return t_passable;
}
// Las filas 18-20 es de tiles t_animated
else if ((tileMap[index] >= 18 * tileSetWidth) && (tileMap[index] < 21 * tileSetWidth))
else if ((tile_map_[index] >= 18 * tile_set_width_) && (tile_map_[index] < 21 * tile_set_width_))
{
return t_animated;
}
// La fila 21 es de tiles t_slope_r
else if ((tileMap[index] >= 21 * tileSetWidth) && (tileMap[index] < 22 * tileSetWidth))
else if ((tile_map_[index] >= 21 * tile_set_width_) && (tile_map_[index] < 22 * tile_set_width_))
{
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 ((tile_map_[index] >= 22 * tile_set_width_) && (tile_map_[index] < 23 * tile_set_width_))
{
return t_slope_l;
}
// La fila 23 es de tiles t_kill
else if ((tileMap[index] >= 23 * tileSetWidth) && (tileMap[index] < 24 * tileSetWidth))
else if ((tile_map_[index] >= 23 * tile_set_width_) && (tile_map_[index] < 24 * tile_set_width_))
{
return t_kill;
}
@@ -805,7 +804,7 @@ bool Room::enemyCollision(SDL_Rect &rect)
{
bool collision = false;
for (auto enemy : enemies)
for (auto enemy : enemies_)
{
collision |= checkCollision(rect, enemy->getCollider());
}
@@ -816,15 +815,15 @@ bool Room::enemyCollision(SDL_Rect &rect)
// Indica si hay colision con un objeto a partir de un rectangulo
bool Room::itemCollision(SDL_Rect &rect)
{
for (int i = 0; i < (int)items.size(); ++i)
for (int i = 0; i < (int)items_.size(); ++i)
{
if (checkCollision(rect, items[i]->getCollider()))
if (checkCollision(rect, items_[i]->getCollider()))
{
itemTracker->addItem(name, items[i]->getPos());
items.erase(items.begin() + i);
JA_PlaySound(itemSound);
*itemsPicked = *itemsPicked + 1;
options.stats.items = *itemsPicked;
ItemTracker::get()->addItem(name_, items_[i]->getPos());
items_.erase(items_.begin() + i);
JA_PlaySound(item_sound_);
*items_picked_ = *items_picked_ + 1;
options.stats.items = *items_picked_;
return true;
}
}
@@ -835,15 +834,15 @@ bool Room::itemCollision(SDL_Rect &rect)
// Recarga la textura
void Room::reLoadTexture()
{
texture->reLoad();
texture_->reLoad();
fillMapTexture();
for (auto enemy : enemies)
for (auto enemy : enemies_)
{
enemy->reLoadTexture();
}
for (auto item : items)
for (auto item : items_)
{
item->reLoadTexture();
}
@@ -853,27 +852,27 @@ void Room::reLoadTexture()
void Room::reLoadPalette()
{
// Cambia el color de los items
for (auto item : items)
for (auto item : items_)
{
item->setColors(stringToColor(options.video.palette, itemColor1), stringToColor(options.video.palette, itemColor2));
item->setColors(stringToColor(options.video.palette, item_color1_), stringToColor(options.video.palette, item_color2_));
}
// Cambia el color de los enemigos
for (auto enemy : enemies)
for (auto enemy : enemies_)
{
enemy->setPalette(options.video.palette);
}
// Establece el color del borde
screen->setBorderColor(stringToColor(options.video.palette, borderColor));
screen_->setBorderColor(stringToColor(options.video.palette, border_color_));
// Cambia la textura
texture = (options.video.palette == Palette::ZXSPECTRUM) ? textureA : textureB;
texture_ = (options.video.palette == Palette::ZXSPECTRUM) ? textureA_ : textureB_;
// Pone la nueva textura a los tiles animados
for (auto tile : aTile)
for (auto tile : animated_tiles_)
{
tile.sprite->setTexture(texture);
tile.sprite->setTexture(texture_);
}
// Recarga las texturas
@@ -883,20 +882,20 @@ void Room::reLoadPalette()
// Obten el tamaño del tile
int Room::getTileSize()
{
return tileSize;
return tile_size_;
}
// Obten la coordenada de la cuesta a partir de un punto perteneciente a ese tile
int Room::getSlopeHeight(SDL_Point p, tile_e slope)
{
// Calcula la base del tile
int base = ((p.y / tileSize) * tileSize) + tileSize;
int base = ((p.y / tile_size_) * tile_size_) + tile_size_;
#ifdef DEBUG
debug->add("BASE = " + std::to_string(base));
#endif
// Calcula cuanto se ha entrado en el tile horizontalmente
const int pos = (p.x % tileSize); // Esto da un valor entre 0 y 7
const int pos = (p.x % tile_size_); // Esto da un valor entre 0 y 7
#ifdef DEBUG
debug->add("POS = " + std::to_string(pos));
#endif
@@ -911,7 +910,7 @@ int Room::getSlopeHeight(SDL_Point p, tile_e slope)
}
else
{
base -= (tileSize - pos);
base -= (tile_size_ - pos);
#ifdef DEBUG
debug->add("BASE_L = " + std::to_string(base));
#endif
@@ -927,14 +926,14 @@ 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)tile_map_.size() - map_width_; ++i)
{
if (getTile(i) == t_wall && getTile(i + mapWidth) != t_wall)
if (getTile(i) == t_wall && getTile(i + map_width_) != t_wall)
{
tile.push_back(i);
// Si llega al final de la fila, introduce un separador
if (i % mapWidth == mapWidth - 1)
if (i % map_width_ == map_width_ - 1)
{
tile.push_back(-1);
}
@@ -952,8 +951,8 @@ void Room::setBottomSurfaces()
do
{
h_line_t line;
line.x1 = (tile[i] % mapWidth) * tileSize;
line.y = ((tile[i] / mapWidth) * tileSize) + tileSize - 1;
line.x1 = (tile[i] % map_width_) * tile_size_;
line.y = ((tile[i] / map_width_) * tile_size_) + tile_size_ - 1;
lastOne = i;
i++;
@@ -970,8 +969,8 @@ void Room::setBottomSurfaces()
}
}
line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1;
bottomSurfaces.push_back(line);
line.x2 = ((tile[lastOne] % map_width_) * tile_size_) + tile_size_ - 1;
bottom_surfaces_.push_back(line);
if (i <= (int)tile.size() - 1)
{
if (tile[i] == -1)
@@ -990,14 +989,14 @@ 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 = map_width_; i < (int)tile_map_.size(); ++i)
{
if ((getTile(i) == t_wall || getTile(i) == t_passable) && getTile(i - mapWidth) != t_wall)
if ((getTile(i) == t_wall || getTile(i) == t_passable) && getTile(i - map_width_) != t_wall)
{
tile.push_back(i);
// Si llega al final de la fila, introduce un separador
if (i % mapWidth == mapWidth - 1)
if (i % map_width_ == map_width_ - 1)
{
tile.push_back(-1);
}
@@ -1015,8 +1014,8 @@ void Room::setTopSurfaces()
do
{
h_line_t line;
line.x1 = (tile[i] % mapWidth) * tileSize;
line.y = (tile[i] / mapWidth) * tileSize;
line.x1 = (tile[i] % map_width_) * tile_size_;
line.y = (tile[i] / map_width_) * tile_size_;
lastOne = i;
i++;
@@ -1033,8 +1032,8 @@ void Room::setTopSurfaces()
}
}
line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1;
topSurfaces.push_back(line);
line.x2 = ((tile[lastOne] % map_width_) * tile_size_) + tile_size_ - 1;
top_surfaces_.push_back(line);
if (i <= (int)tile.size() - 1)
{
if (tile[i] == -1)
@@ -1053,11 +1052,11 @@ void Room::setLeftSurfaces()
// Busca todos los tiles de tipo muro que no tienen a su izquierda un tile de tipo muro
// Hay que recorrer la habitación por columnas (excepto los de la primera columna)
for (int i = 1; i < mapWidth; ++i)
for (int i = 1; i < map_width_; ++i)
{
for (int j = 0; j < mapHeight; ++j)
for (int j = 0; j < map_height_; ++j)
{
const int pos = (j * mapWidth + i);
const int pos = (j * map_width_ + i);
if (getTile(pos) == t_wall && getTile(pos - 1) != t_wall)
{
tile.push_back(pos);
@@ -1077,9 +1076,9 @@ void Room::setLeftSurfaces()
do
{
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[i] % map_width_) * tile_size_;
line.y1 = ((tile[i] / map_width_) * tile_size_);
while (tile[i] + map_width_ == tile[i + 1])
{
if (i == (int)tile.size() - 1)
{
@@ -1087,8 +1086,8 @@ void Room::setLeftSurfaces()
}
i++;
}
line.y2 = ((tile[i] / mapWidth) * tileSize) + tileSize - 1;
leftSurfaces.push_back(line);
line.y2 = ((tile[i] / map_width_) * tile_size_) + tile_size_ - 1;
left_surfaces_.push_back(line);
i++;
} while (i < (int)tile.size() - 1);
}
@@ -1101,11 +1100,11 @@ void Room::setRightSurfaces()
// Busca todos los tiles de tipo muro que no tienen a su derecha un tile de tipo muro
// Hay que recorrer la habitación por columnas (excepto los de la última columna)
for (int i = 0; i < mapWidth - 1; ++i)
for (int i = 0; i < map_width_ - 1; ++i)
{
for (int j = 0; j < mapHeight; ++j)
for (int j = 0; j < map_height_; ++j)
{
const int pos = (j * mapWidth + i);
const int pos = (j * map_width_ + i);
if (getTile(pos) == t_wall && getTile(pos + 1) != t_wall)
{
tile.push_back(pos);
@@ -1125,9 +1124,9 @@ void Room::setRightSurfaces()
do
{
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[i] % map_width_) * tile_size_) + tile_size_ - 1;
line.y1 = ((tile[i] / map_width_) * tile_size_);
while (tile[i] + map_width_ == tile[i + 1])
{
if (i == (int)tile.size() - 1)
{
@@ -1135,8 +1134,8 @@ void Room::setRightSurfaces()
}
i++;
}
line.y2 = ((tile[i] / mapWidth) * tileSize) + tileSize - 1;
rightSurfaces.push_back(line);
line.y2 = ((tile[i] / map_width_) * tile_size_) + tile_size_ - 1;
right_surfaces_.push_back(line);
i++;
} while (i < (int)tile.size() - 1);
}
@@ -1147,7 +1146,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)tile_map_.size(); ++i)
{
if (getTile(i) == t_slope_l)
{
@@ -1162,9 +1161,9 @@ 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;
line.x1 = (found[0] % map_width_) * tile_size_;
line.y1 = (found[0] / map_width_) * tile_size_;
int lookingFor = found[0] + map_width_ + 1;
int lastOneFound = found[0];
found.erase(found.begin());
for (int i = 0; i < (int)found.size(); ++i)
@@ -1172,14 +1171,14 @@ void Room::setLeftSlopes()
if (found[i] == lookingFor)
{
lastOneFound = lookingFor;
lookingFor += mapWidth + 1;
lookingFor += map_width_ + 1;
found.erase(found.begin() + i);
i--;
}
}
line.x2 = ((lastOneFound % mapWidth) * tileSize) + tileSize - 1;
line.y2 = ((lastOneFound / mapWidth) * tileSize) + tileSize - 1;
leftSlopes.push_back(line);
line.x2 = ((lastOneFound % map_width_) * tile_size_) + tile_size_ - 1;
line.y2 = ((lastOneFound / map_width_) * tile_size_) + tile_size_ - 1;
left_slopes_.push_back(line);
}
}
@@ -1188,7 +1187,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)tile_map_.size(); ++i)
{
if (getTile(i) == t_slope_r)
{
@@ -1203,9 +1202,9 @@ 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;
line.x1 = ((found[0] % map_width_) * tile_size_) + tile_size_ - 1;
line.y1 = (found[0] / map_width_) * tile_size_;
int lookingFor = found[0] + map_width_ - 1;
int lastOneFound = found[0];
found.erase(found.begin());
for (int i = 0; i < (int)found.size(); ++i)
@@ -1213,14 +1212,14 @@ void Room::setRightSlopes()
if (found[i] == lookingFor)
{
lastOneFound = lookingFor;
lookingFor += mapWidth - 1;
lookingFor += map_width_ - 1;
found.erase(found.begin() + i);
i--;
}
}
line.x2 = (lastOneFound % mapWidth) * tileSize;
line.y2 = ((lastOneFound / mapWidth) * tileSize) + tileSize - 1;
rightSlopes.push_back(line);
line.x2 = (lastOneFound % map_width_) * tile_size_;
line.y2 = ((lastOneFound / map_width_) * tile_size_) + tile_size_ - 1;
right_slopes_.push_back(line);
}
}
@@ -1231,14 +1230,14 @@ 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 = map_width_; i < (int)tile_map_.size(); ++i)
{
if (getTile(i) == t_animated)
{
tile.push_back(i);
// Si llega al final de la fila, introduce un separador
if (i % mapWidth == mapWidth - 1)
if (i % map_width_ == map_width_ - 1)
{
tile.push_back(-1);
}
@@ -1253,8 +1252,8 @@ void Room::setAutoSurfaces()
do
{
h_line_t line;
line.x1 = (tile[i] % mapWidth) * tileSize;
line.y = (tile[i] / mapWidth) * tileSize;
line.x1 = (tile[i] % map_width_) * tile_size_;
line.y = (tile[i] / map_width_) * tile_size_;
lastOne = i;
i++;
@@ -1271,8 +1270,8 @@ void Room::setAutoSurfaces()
}
}
line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1;
autoSurfaces.push_back(line);
line.x2 = ((tile[lastOne] % map_width_) * tile_size_) + tile_size_ - 1;
auto_surfaces_.push_back(line);
if (i <= (int)tile.size() - 1)
{
if (tile[i] == -1)
@@ -1288,23 +1287,23 @@ 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)tile_map_.size(); ++i)
{
if (getTile(i) == t_animated)
{
// La i es la ubicación
const int x = (i % mapWidth) * tileSize;
const int y = (i / mapWidth) * tileSize;
const int x = (i % map_width_) * tile_size_;
const int y = (i / map_width_) * tile_size_;
// TileMap[i] es el tile a poner
const int xc = (tileMap[i] % tileSetWidth) * tileSize;
const int yc = (tileMap[i] / tileSetWidth) * tileSize;
const int xc = (tile_map_[i] % tile_set_width_) * tile_size_;
const int yc = (tile_map_[i] / tile_set_width_) * tile_size_;
aTile_t at;
at.sprite = std::make_shared<Sprite>(texture, x, y, 8, 8);
at.sprite = std::make_shared<Sprite>(texture_, x, y, 8, 8);
at.sprite->setClip(xc, yc, 8, 8);
at.xcOrig = xc;
aTile.push_back(at);
at.x_orig = xc;
animated_tiles_.push_back(at);
}
}
}
@@ -1314,19 +1313,19 @@ void Room::updateAnimatedTiles()
{
const int numFrames = 4;
int offset = 0;
if (autoSurfaceDirection == -1)
if (auto_surface_direction_ == -1)
{
offset = ((counter / 3) % numFrames * tileSize);
offset = ((counter_ / 3) % numFrames * tile_size_);
}
else
{
offset = ((numFrames - 1 - ((counter / 3) % numFrames)) * tileSize);
offset = ((numFrames - 1 - ((counter_ / 3) % numFrames)) * tile_size_);
}
for (auto &a : aTile)
for (auto &a : animated_tiles_)
{
SDL_Rect rect = a.sprite->getClip();
rect.x = a.xcOrig + offset;
rect.x = a.x_orig + offset;
a.sprite->setClip(rect);
}
}
@@ -1334,7 +1333,7 @@ void Room::updateAnimatedTiles()
// Pinta los tiles animados en pantalla
void Room::renderAnimatedTiles()
{
for (auto a : aTile)
for (auto a : animated_tiles_)
{
a.sprite->render();
}
@@ -1343,7 +1342,7 @@ void Room::renderAnimatedTiles()
// Comprueba las colisiones
int Room::checkRightSurfaces(SDL_Rect *rect)
{
for (auto s : rightSurfaces)
for (auto s : right_surfaces_)
{
if (checkCollision(s, *rect))
{
@@ -1357,7 +1356,7 @@ int Room::checkRightSurfaces(SDL_Rect *rect)
// Comprueba las colisiones
int Room::checkLeftSurfaces(SDL_Rect *rect)
{
for (auto s : leftSurfaces)
for (auto s : left_surfaces_)
{
if (checkCollision(s, *rect))
{
@@ -1371,7 +1370,7 @@ int Room::checkLeftSurfaces(SDL_Rect *rect)
// Comprueba las colisiones
int Room::checkTopSurfaces(SDL_Rect *rect)
{
for (auto s : topSurfaces)
for (auto s : top_surfaces_)
{
if (checkCollision(s, *rect))
{
@@ -1385,7 +1384,7 @@ int Room::checkTopSurfaces(SDL_Rect *rect)
// Comprueba las colisiones
int Room::checkBottomSurfaces(SDL_Rect *rect)
{
for (auto s : bottomSurfaces)
for (auto s : bottom_surfaces_)
{
if (checkCollision(s, *rect))
{
@@ -1399,7 +1398,7 @@ int Room::checkBottomSurfaces(SDL_Rect *rect)
// Comprueba las colisiones
int Room::checkAutoSurfaces(SDL_Rect *rect)
{
for (auto s : autoSurfaces)
for (auto s : auto_surfaces_)
{
if (checkCollision(s, *rect))
{
@@ -1413,7 +1412,7 @@ int Room::checkAutoSurfaces(SDL_Rect *rect)
// Comprueba las colisiones
bool Room::checkTopSurfaces(SDL_Point *p)
{
for (auto s : topSurfaces)
for (auto s : top_surfaces_)
{
if (checkCollision(s, *p))
{
@@ -1427,7 +1426,7 @@ bool Room::checkTopSurfaces(SDL_Point *p)
// Comprueba las colisiones
bool Room::checkAutoSurfaces(SDL_Point *p)
{
for (auto s : autoSurfaces)
for (auto s : auto_surfaces_)
{
if (checkCollision(s, *p))
{
@@ -1441,7 +1440,7 @@ bool Room::checkAutoSurfaces(SDL_Point *p)
// Comprueba las colisiones
int Room::checkLeftSlopes(v_line_t *line)
{
for (auto s : leftSlopes)
for (auto s : left_slopes_)
{
const SDL_Point p = checkCollision(s, *line);
if (p.x != -1)
@@ -1456,7 +1455,7 @@ int Room::checkLeftSlopes(v_line_t *line)
// Comprueba las colisiones
bool Room::checkLeftSlopes(SDL_Point *p)
{
for (auto s : leftSlopes)
for (auto s : left_slopes_)
{
if (checkCollision(*p, s))
{
@@ -1470,7 +1469,7 @@ bool Room::checkLeftSlopes(SDL_Point *p)
// Comprueba las colisiones
int Room::checkRightSlopes(v_line_t *line)
{
for (auto s : rightSlopes)
for (auto s : right_slopes_)
{
const SDL_Point p = checkCollision(s, *line);
if (p.x != -1)
@@ -1485,7 +1484,7 @@ int Room::checkRightSlopes(v_line_t *line)
// Comprueba las colisiones
bool Room::checkRightSlopes(SDL_Point *p)
{
for (auto s : rightSlopes)
for (auto s : right_slopes_)
{
if (checkCollision(*p, s))
{
@@ -1499,33 +1498,33 @@ bool Room::checkRightSlopes(SDL_Point *p)
// Pone el mapa en modo pausa
void Room::pause()
{
paused = true;
paused_ = true;
}
// Quita el modo pausa del mapa
void Room::resume()
{
paused = false;
paused_ = false;
}
// Obten la direccion de las superficies automaticas
int Room::getAutoSurfaceDirection()
{
return autoSurfaceDirection;
return auto_surface_direction_;
}
// Abre la jail para poder entrar
void Room::openTheJail()
{
if (name == "THE JAIL")
if (name_ == "THE JAIL")
{
// Elimina el último enemigo (Bry debe ser el ultimo enemigo definido en el fichero)
enemies.pop_back();
enemies_.pop_back();
// Abre las puertas
const int tileA = 16 + (13 * 32);
const int tileB = 16 + (14 * 32);
tileMap[tileA] = -1;
tileMap[tileB] = -1;
tile_map_[tileA] = -1;
tile_map_[tileB] = -1;
}
}