Arreglos en la estructura i format del codi

This commit is contained in:
2025-03-01 17:01:50 +01:00
parent 3562b139c3
commit 31cded15cc
35 changed files with 496 additions and 755 deletions

View File

@@ -23,12 +23,12 @@ std::vector<int> loadRoomTileFile(const std::string &file_path, bool verbose)
{
std::vector<int> tileMapFile;
const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
std::string line;
std::ifstream file(file_path);
// El fichero se puede abrir
if (file.good())
{
std::string line;
// Procesa el fichero linea a linea
while (std::getline(file, line))
{ // Lee el fichero linea a linea
@@ -81,12 +81,12 @@ RoomData loadRoomFile(const std::string &file_path, bool verbose)
const std::string fileName = file_path.substr(file_path.find_last_of("\\/") + 1);
room.number = fileName.substr(0, fileName.find_last_of("."));
std::string line;
std::ifstream file(file_path);
// El fichero se puede abrir
if (file.good())
{
std::string line;
// Procesa el fichero linea a linea
while (std::getline(file, line))
{
@@ -398,13 +398,14 @@ bool setItem(ItemData *item, const std::string &key, const std::string &value)
}
// Constructor
Room::Room(std::shared_ptr<RoomData> room, std::shared_ptr<ScoreboardData> data)
Room::Room(const std::string &room_path, std::shared_ptr<ScoreboardData> data)
: screen_(Screen::get()),
renderer_(Screen::get()->getRenderer()),
asset_(Asset::get()),
debug_(Debug::get()),
data_(data)
{
auto room = Resource::get()->getRoom(room_path);
number_ = room->number;
name_ = room->name;
bg_color_ = room->bg_color;
@@ -419,11 +420,11 @@ Room::Room(std::shared_ptr<RoomData> room, std::shared_ptr<ScoreboardData> data)
tile_map_file_ = room->tile_map_file;
auto_surface_direction_ = room->auto_surface_direction;
tile_map_ = Resource::get()->getTileMap(room->tile_map_file);
texture_ = (options.video.palette == Palette::ZXSPECTRUM) ? Resource::get()->getTexture(room->tile_set_file) : Resource::get()->getTexture(room->tile_set_file);
texture_ = Resource::get()->getTexture(room->tile_set_file);
// Inicializa variables
tile_set_width_ = texture_->getWidth() / TILE_SIZE_;
paused_ = false;
is_paused_ = false;
counter_ = 0;
// Crea los enemigos
@@ -674,7 +675,7 @@ void Room::renderItems()
// Actualiza las variables y objetos de la habitación
void Room::update()
{
if (paused_)
if (is_paused_)
{ // Si está en modo pausa no se actualiza nada
return;
}
@@ -846,7 +847,7 @@ void Room::reLoadPalette()
screen_->setBorderColor(stringToColor(options.video.palette, border_color_));
// Cambia la textura
//texture_ = (options.video.palette == Palette::ZXSPECTRUM) ? Resource::get()->getTexture(room->tile_set_file) : Resource::get()->getTexture(room->tile_set_file);
// texture_ = (options.video.palette == Palette::ZXSPECTRUM) ? Resource::get()->getTexture(room->tile_set_file) : Resource::get()->getTexture(room->tile_set_file);
// Pone la nueva textura a los tiles animados
for (auto tile : animated_tiles_)
@@ -926,20 +927,19 @@ void Room::setBottomSurfaces()
if ((int)tile.size() > 1)
{
int i = 0;
int lastOne = 0;
do
{
h_line_t line;
line.x1 = (tile[i] % MAP_WIDTH_) * TILE_SIZE_;
line.y = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
lastOne = i;
int last_one = i;
i++;
if (i <= (int)tile.size() - 1)
{
while (tile[i] == tile[i - 1] + 1)
{
lastOne = i;
last_one = i;
if (i == (int)tile.size() - 1)
{
break;
@@ -948,7 +948,7 @@ void Room::setBottomSurfaces()
}
}
line.x2 = ((tile[lastOne] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
line.x2 = ((tile[last_one] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
bottom_surfaces_.push_back(line);
if (i <= (int)tile.size() - 1)
{
@@ -989,20 +989,19 @@ void Room::setTopSurfaces()
if ((int)tile.size() > 1)
{
int i = 0;
int lastOne = 0;
do
{
h_line_t line;
line.x1 = (tile[i] % MAP_WIDTH_) * TILE_SIZE_;
line.y = (tile[i] / MAP_WIDTH_) * TILE_SIZE_;
lastOne = i;
int last_one = i;
i++;
if (i <= (int)tile.size() - 1)
{
while (tile[i] == tile[i - 1] + 1)
{
lastOne = i;
last_one = i;
if (i == (int)tile.size() - 1)
{
break;
@@ -1011,7 +1010,7 @@ void Room::setTopSurfaces()
}
}
line.x2 = ((tile[lastOne] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
line.x2 = ((tile[last_one] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
top_surfaces_.push_back(line);
if (i <= (int)tile.size() - 1)
{
@@ -1224,23 +1223,22 @@ void Room::setAutoSurfaces()
}
// Recorre el vector de tiles buscando tiles consecutivos para localizar las superficies
int i = 0;
int lastOne = 0;
if ((int)tile.size() > 0)
{
int i = 0;
do
{
h_line_t line;
line.x1 = (tile[i] % MAP_WIDTH_) * TILE_SIZE_;
line.y = (tile[i] / MAP_WIDTH_) * TILE_SIZE_;
lastOne = i;
int last_one = i;
i++;
if (i <= (int)tile.size() - 1)
{
while (tile[i] == tile[i - 1] + 1)
{
lastOne = i;
last_one = i;
if (i == (int)tile.size() - 1)
{
break;
@@ -1249,7 +1247,7 @@ void Room::setAutoSurfaces()
}
}
line.x2 = ((tile[lastOne] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
line.x2 = ((tile[last_one] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
auto_surfaces_.push_back(line);
if (i <= (int)tile.size() - 1)
{
@@ -1474,18 +1472,6 @@ bool Room::checkRightSlopes(SDL_Point *p)
return false;
}
// Pone el mapa en modo pausa
void Room::pause()
{
paused_ = true;
}
// Quita el modo pausa del mapa
void Room::resume()
{
paused_ = false;
}
// Obten la direccion de las superficies automaticas
int Room::getAutoSurfaceDirection()
{