Ja torna a deixar jugar

Encara queden bugs per corregir
Trencat el sistema de triar la paleta, de moment
This commit is contained in:
2025-02-26 20:37:29 +01:00
parent 85ab5ea03f
commit e6fd4225a2
7 changed files with 362 additions and 384 deletions

View File

@@ -15,9 +15,11 @@
#include "sprite.h" // Para Sprite
#include "texture.h" // Para Texture
#include "options.h"
#include "utils.h" // Para stringToBool, stringToColor
#include "resource.h"
// Carga las variables y texturas desde un fichero de mapa de tiles
std::vector<int> loadRoomTileFile(std::string file_path, bool verbose)
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);
@@ -69,7 +71,7 @@ std::vector<int> loadRoomTileFile(std::string file_path, bool verbose)
}
// Carga las variables desde un fichero de mapa
RoomData loadRoomFile(std::string file_path, bool verbose)
RoomData loadRoomFile(const std::string &file_path, bool verbose)
{
RoomData room;
room.item_color1 = "yellow";
@@ -104,13 +106,13 @@ RoomData loadRoomFile(std::string file_path, bool verbose)
int pos = line.find("=");
// Procesa las dos subcadenas
if (!setEnemy(&enemy, line.substr(0, pos), line.substr(pos + 1, line.length())))
{
std::string key = line.substr(0, pos);
std::string value = line.substr(pos + 1, line.length());
if (!setEnemy(&enemy, key, value))
if (verbose)
{
std::cout << "Warning: file " << fileName.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
}
}
} while (line != "[/enemy]");
// Añade el enemigo al vector de enemigos
@@ -120,7 +122,7 @@ RoomData loadRoomFile(std::string file_path, bool verbose)
// Si la linea contiene el texto [item] se realiza el proceso de carga de un item
else if (line == "[item]")
{
item_t item;
ItemData item;
item.counter = 0;
item.color1 = stringToColor(Palette::ZXSPECTRUM, "yellow");
item.color2 = stringToColor(Palette::ZXSPECTRUM, "magenta");
@@ -133,7 +135,9 @@ RoomData loadRoomFile(std::string file_path, bool verbose)
int pos = line.find("=");
// Procesa las dos subcadenas
if (!setItem(&item, line.substr(0, pos), line.substr(pos + 1, line.length())))
std::string key = line.substr(0, pos);
std::string value = line.substr(pos + 1, line.length());
if (!setItem(&item, key, value))
{
if (verbose)
{
@@ -153,7 +157,9 @@ RoomData loadRoomFile(std::string file_path, bool verbose)
int pos = line.find("=");
// Procesa las dos subcadenas
if (!setVars(&room, line.substr(0, pos), line.substr(pos + 1, line.length())))
std::string key = line.substr(0, pos);
std::string value = line.substr(pos + 1, line.length());
if (!setRoom(&room, key, value))
{
if (verbose)
{
@@ -181,226 +187,210 @@ RoomData loadRoomFile(std::string file_path, bool verbose)
return room;
}
// Asigna variables a partir de dos cadenas
bool setVars(RoomData *room, std::string var, std::string value)
// Asigna variables a una estructura RoomData
bool setRoom(RoomData *room, const std::string &key, const std::string &value)
{
// Indicador de éxito en la asignación
bool success = true;
if (var == "tileMapFile")
try
{
room->tile_map_file = value;
}
else if (var == "name")
{
room->name = value;
}
else if (var == "bgColor")
{
room->bg_color = value;
}
else if (var == "border")
{
room->border_color = value;
}
else if (var == "itemColor1")
{
room->item_color1 = value;
}
else if (var == "itemColor2")
{
room->item_color2 = value;
}
else if (var == "tileSetFile")
{
room->tile_set_file = value;
}
else if (var == "roomUp")
{
room->room_top = value;
}
else if (var == "roomDown")
{
room->room_bottom = value;
}
else if (var == "roomLeft")
{
room->room_left = value;
}
else if (var == "roomRight")
{
room->room_right = value;
}
else if (var == "autoSurface")
{
if (value == "right")
if (key == "tileMapFile")
{
room->auto_surface_direction = 1;
room->tile_map_file = value;
}
else if (key == "name")
{
room->name = value;
}
else if (key == "bgColor")
{
room->bg_color = value;
}
else if (key == "border")
{
room->border_color = value;
}
else if (key == "itemColor1")
{
room->item_color1 = value;
}
else if (key == "itemColor2")
{
room->item_color2 = value;
}
else if (key == "tileSetFile")
{
room->tile_set_file = value;
}
else if (key == "roomUp")
{
room->room_top = value;
}
else if (key == "roomDown")
{
room->room_bottom = value;
}
else if (key == "roomLeft")
{
room->room_left = value;
}
else if (key == "roomRight")
{
room->room_right = value;
}
else if (key == "autoSurface")
{
room->auto_surface_direction = (value == "right") ? 1 : -1;
}
else if (key == "" || key.substr(0, 1) == "#")
{
// No se realiza ninguna acción para estas claves
}
else
{
room->auto_surface_direction = -1;
success = false;
}
}
else if (var == "" || var.substr(0, 1) == "#")
{
}
else
catch (const std::exception &e)
{
std::cerr << "Error al asignar la clave " << key << " con valor " << value << ": " << e.what() << std::endl;
success = false;
}
return success;
}
// Asigna variables a una estructura enemy_t
bool setEnemy(EnemyData *enemy, std::string var, std::string value)
// Asigna variables a una estructura EnemyData
bool setEnemy(EnemyData *enemy, const std::string &key, const std::string &value)
{
// Indicador de éxito en la asignación
bool success = true;
if (var == "tileSetFile")
try
{
enemy->texture_path = value;
if (key == "tileSetFile")
{
enemy->texture_path = value;
}
else if (key == "animation")
{
enemy->animation_path = value;
}
else if (key == "width")
{
enemy->w = std::stoi(value);
}
else if (key == "height")
{
enemy->h = std::stoi(value);
}
else if (key == "x")
{
enemy->x = std::stof(value) * BLOCK;
}
else if (key == "y")
{
enemy->y = std::stof(value) * BLOCK;
}
else if (key == "vx")
{
enemy->vx = std::stof(value);
}
else if (key == "vy")
{
enemy->vy = std::stof(value);
}
else if (key == "x1")
{
enemy->x1 = std::stoi(value) * BLOCK;
}
else if (key == "x2")
{
enemy->x2 = std::stoi(value) * BLOCK;
}
else if (key == "y1")
{
enemy->y1 = std::stoi(value) * BLOCK;
}
else if (key == "y2")
{
enemy->y2 = std::stoi(value) * BLOCK;
}
else if (key == "flip")
{
enemy->flip = stringToBool(value);
}
else if (key == "mirror")
{
enemy->mirror = stringToBool(value);
}
else if (key == "color")
{
enemy->color = value;
}
else if (key == "frame")
{
enemy->frame = std::stoi(value);
}
else if (key == "[/enemy]" || key == "tileSetFile" || key.substr(0, 1) == "#")
{
// No se realiza ninguna acción para estas claves
}
else
{
success = false;
}
}
else if (var == "animation")
{
enemy->animation_path = value;
}
else if (var == "width")
{
enemy->w = std::stof(value);
}
else if (var == "height")
{
enemy->h = std::stof(value);
}
else if (var == "x")
{
enemy->x = std::stof(value) * BLOCK;
}
else if (var == "y")
{
enemy->y = std::stof(value) * BLOCK;
}
else if (var == "vx")
{
enemy->vx = std::stof(value);
}
else if (var == "vy")
{
enemy->vy = std::stof(value);
}
else if (var == "x1")
{
enemy->x1 = std::stoi(value) * BLOCK;
}
else if (var == "x2")
{
enemy->x2 = std::stoi(value) * BLOCK;
}
else if (var == "y1")
{
enemy->y1 = std::stoi(value) * BLOCK;
}
else if (var == "y2")
{
enemy->y2 = std::stoi(value) * BLOCK;
}
else if (var == "flip")
{
enemy->flip = stringToBool(value);
}
else if (var == "mirror")
{
enemy->mirror = stringToBool(value);
}
else if (var == "color")
{
enemy->color = value;
}
else if (var == "frame")
{
enemy->frame = std::stoi(value);
}
else if (var == "[/enemy]" || var == "tileSetFile" || var.substr(0, 1) == "#")
{
}
else
catch (const std::exception &e)
{
std::cerr << "Error al asignar la clave " << key << " con valor " << value << ": " << e.what() << std::endl;
success = false;
}
return success;
}
// Asigna variables a una estructura item_t
bool setItem(item_t *item, std::string var, std::string value)
// Asigna variables a una estructura ItemData
bool setItem(ItemData *item, const std::string &key, const std::string &value)
{
// Indicador de éxito en la asignación
bool success = true;
if (var == "tileSetFile")
try
{
item->tileSetFile = value;
if (key == "tileSetFile")
{
item->tile_set_file = value;
}
else if (key == "counter")
{
item->counter = std::stoi(value);
}
else if (key == "x")
{
item->x = std::stof(value) * BLOCK;
}
else if (key == "y")
{
item->y = std::stof(value) * BLOCK;
}
else if (key == "tile")
{
item->tile = std::stof(value);
}
else if (key == "[/item]")
{
// No se realiza ninguna acción para esta clave
}
else
{
success = false;
}
}
else if (var == "counter")
{
item->counter = std::stoi(value);
}
else if (var == "x")
{
item->x = std::stof(value) * BLOCK;
}
else if (var == "y")
{
item->y = std::stof(value) * BLOCK;
}
else if (var == "tile")
{
item->tile = std::stof(value);
}
else if (var == "[/item]")
{
}
else
catch (const std::exception &e)
{
std::cerr << "Error al asignar la clave " << key << " con valor " << value << ": " << e.what() << std::endl;
success = false;
}
@@ -408,7 +398,7 @@ bool setItem(item_t *item, std::string var, std::string value)
}
// Constructor
Room::Room(std::shared_ptr<RoomData> room, int *itemsPicked, bool jailEnabled)
Room::Room(std::shared_ptr<RoomData> room, int *itemsPicked, bool jail_is_open)
: screen_(Screen::get()),
renderer_(Screen::get()->getRenderer()),
asset_(Asset::get()),
@@ -428,17 +418,12 @@ Room::Room(std::shared_ptr<RoomData> room, int *itemsPicked, bool jailEnabled)
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;
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);
jail_is_open_ = jail_is_open;
// Inicializa variables
tile_size_ = 8;
tile_set_width_ = texture_->getWidth() / tile_size_;
map_width_ = 32;
map_height_ = 16;
tile_set_width_ = texture_->getWidth() / TILE_SIZE_;
paused_ = false;
counter_ = 0;
@@ -455,7 +440,6 @@ Room::Room(std::shared_ptr<RoomData> room, int *itemsPicked, bool jailEnabled)
if (!ItemTracker::get()->hasBeenPicked(room->name, itemPos))
{
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));
@@ -466,7 +450,7 @@ Room::Room(std::shared_ptr<RoomData> room, int *itemsPicked, bool jailEnabled)
item_sound_ = JA_LoadSound(asset_->get("item.wav").c_str());
// Abre la jail para poder entrar
if (jailEnabled)
if (jail_is_open)
{
openTheJail();
}
@@ -536,121 +520,117 @@ void Room::fillMapTexture()
// Los tileSetFiles son de 20x20 tiles. El primer tile es el 0. Cuentan hacia la derecha y hacia abajo
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)
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 * map_width_) + x;
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 = (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);
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
// ****
if (debug->getEnabled())
if (debug_->getEnabled())
{
if (clip.x != -tileSize)
if (clip.x != -TILE_SIZE_)
{
clip.x = x * tileSize;
clip.y = y * tileSize;
SDL_SetRenderDrawColor(renderer, 64, 64, 64, 224);
SDL_RenderFillRect(renderer, &clip);
clip.x = x * TILE_SIZE_;
clip.y = y * TILE_SIZE_;
SDL_SetRenderDrawColor(renderer_, 64, 64, 64, 224);
SDL_RenderFillRect(renderer_, &clip);
}
}
// ****
#endif
}
}
#ifdef DEBUG
// ****
if (debug->getEnabled())
if (debug_->getEnabled())
{
// BottomSurfaces
if (true)
{
for (auto l : bottomSurfaces)
for (auto l : bottom_surfaces_)
{
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 0xFF);
SDL_RenderDrawLine(renderer, l.x1, l.y, l.x2, l.y);
SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer_, 255, 0, 0, 0xFF);
SDL_RenderDrawLine(renderer_, l.x1, l.y, l.x2, l.y);
}
}
// TopSurfaces
if (true)
{
for (auto l : topSurfaces)
for (auto l : top_surfaces_)
{
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 0xFF);
SDL_RenderDrawLine(renderer, l.x1, l.y, l.x2, l.y);
SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer_, 0, 255, 0, 0xFF);
SDL_RenderDrawLine(renderer_, l.x1, l.y, l.x2, l.y);
}
}
// LeftSurfaces
if (true)
{
for (auto l : leftSurfaces)
for (auto l : left_surfaces_)
{
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer, 128, 128, 255, 0xFF);
SDL_RenderDrawLine(renderer, l.x, l.y1, l.x, l.y2);
SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer_, 128, 128, 255, 0xFF);
SDL_RenderDrawLine(renderer_, l.x, l.y1, l.x, l.y2);
}
}
// RightSurfaces
if (true)
{
for (auto l : rightSurfaces)
for (auto l : right_surfaces_)
{
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer, 255, 255, 0, 0xFF);
SDL_RenderDrawLine(renderer, l.x, l.y1, l.x, l.y2);
SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer_, 255, 255, 0, 0xFF);
SDL_RenderDrawLine(renderer_, l.x, l.y1, l.x, l.y2);
}
}
// LeftSlopes
if (true)
{
for (auto l : leftSlopes)
for (auto l : left_slopes_)
{
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer, 0, 255, 255, 0xFF);
SDL_RenderDrawLine(renderer, l.x1, l.y1, l.x2, l.y2);
SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer_, 0, 255, 255, 0xFF);
SDL_RenderDrawLine(renderer_, l.x1, l.y1, l.x2, l.y2);
}
}
// RightSlopes
if (true)
{
for (auto l : rightSlopes)
for (auto l : right_slopes_)
{
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer, 255, 0, 255, 0xFF);
SDL_RenderDrawLine(renderer, l.x1, l.y1, l.x2, l.y2);
SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer_, 255, 0, 255, 0xFF);
SDL_RenderDrawLine(renderer_, l.x1, l.y1, l.x2, l.y2);
}
}
// AutoSurfaces
if (true)
{
for (auto l : autoSurfaces)
for (auto l : auto_surfaces_)
{
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_RenderDrawLine(renderer, l.x1, l.y, l.x2, l.y);
SDL_SetRenderDrawColor(renderer_, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_RenderDrawLine(renderer_, l.x1, l.y, l.x2, l.y);
}
}
}
// ****
#endif
SDL_SetRenderTarget(renderer_, nullptr);
@@ -665,7 +645,7 @@ void Room::renderMap()
// Dibuja los tiles animados
#ifdef DEBUG
if (!debug->getEnabled())
if (!debug_->getEnabled())
{
renderAnimatedTiles();
}
@@ -747,7 +727,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 / tile_size_) * map_width_) + (point.x / tile_size_);
const int pos = ((point.y / TILE_SIZE_) * MAP_WIDTH_) + (point.x / TILE_SIZE_);
return getTile(pos);
}
@@ -867,7 +847,7 @@ void Room::reLoadPalette()
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) ? 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_)
@@ -882,22 +862,22 @@ void Room::reLoadPalette()
// Obten el tamaño del tile
int Room::getTileSize()
{
return tile_size_;
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 / tile_size_) * tile_size_) + tile_size_;
int base = ((p.y / TILE_SIZE_) * TILE_SIZE_) + TILE_SIZE_;
#ifdef DEBUG
debug->add("BASE = " + std::to_string(base));
debug_->add("BASE = " + std::to_string(base));
#endif
// Calcula cuanto se ha entrado en el tile horizontalmente
const int pos = (p.x % tile_size_); // 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));
debug_->add("POS = " + std::to_string(pos));
#endif
// Se resta a la base la cantidad de pixeles pos en funcion de la rampa
@@ -905,14 +885,14 @@ int Room::getSlopeHeight(SDL_Point p, tile_e slope)
{
base -= pos + 1;
#ifdef DEBUG
debug->add("BASE_R = " + std::to_string(base));
debug_->add("BASE_R = " + std::to_string(base));
#endif
}
else
{
base -= (tile_size_ - pos);
base -= (TILE_SIZE_ - pos);
#ifdef DEBUG
debug->add("BASE_L = " + std::to_string(base));
debug_->add("BASE_L = " + std::to_string(base));
#endif
}
@@ -926,14 +906,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)tile_map_.size() - map_width_; ++i)
for (int i = 0; i < (int)tile_map_.size() - MAP_WIDTH_; ++i)
{
if (getTile(i) == t_wall && getTile(i + map_width_) != 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 % map_width_ == map_width_ - 1)
if (i % MAP_WIDTH_ == MAP_WIDTH_ - 1)
{
tile.push_back(-1);
}
@@ -951,8 +931,8 @@ void Room::setBottomSurfaces()
do
{
h_line_t line;
line.x1 = (tile[i] % map_width_) * tile_size_;
line.y = ((tile[i] / map_width_) * tile_size_) + tile_size_ - 1;
line.x1 = (tile[i] % MAP_WIDTH_) * TILE_SIZE_;
line.y = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
lastOne = i;
i++;
@@ -969,7 +949,7 @@ void Room::setBottomSurfaces()
}
}
line.x2 = ((tile[lastOne] % map_width_) * tile_size_) + tile_size_ - 1;
line.x2 = ((tile[lastOne] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
bottom_surfaces_.push_back(line);
if (i <= (int)tile.size() - 1)
{
@@ -989,14 +969,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 = map_width_; i < (int)tile_map_.size(); ++i)
for (int i = MAP_WIDTH_; i < (int)tile_map_.size(); ++i)
{
if ((getTile(i) == t_wall || getTile(i) == t_passable) && getTile(i - map_width_) != 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 % map_width_ == map_width_ - 1)
if (i % MAP_WIDTH_ == MAP_WIDTH_ - 1)
{
tile.push_back(-1);
}
@@ -1014,8 +994,8 @@ void Room::setTopSurfaces()
do
{
h_line_t line;
line.x1 = (tile[i] % map_width_) * tile_size_;
line.y = (tile[i] / map_width_) * tile_size_;
line.x1 = (tile[i] % MAP_WIDTH_) * TILE_SIZE_;
line.y = (tile[i] / MAP_WIDTH_) * TILE_SIZE_;
lastOne = i;
i++;
@@ -1032,7 +1012,7 @@ void Room::setTopSurfaces()
}
}
line.x2 = ((tile[lastOne] % map_width_) * tile_size_) + tile_size_ - 1;
line.x2 = ((tile[lastOne] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
top_surfaces_.push_back(line);
if (i <= (int)tile.size() - 1)
{
@@ -1052,11 +1032,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 < map_width_; ++i)
for (int i = 1; i < MAP_WIDTH_; ++i)
{
for (int j = 0; j < map_height_; ++j)
for (int j = 0; j < MAP_HEIGHT_; ++j)
{
const int pos = (j * map_width_ + i);
const int pos = (j * MAP_WIDTH_ + i);
if (getTile(pos) == t_wall && getTile(pos - 1) != t_wall)
{
tile.push_back(pos);
@@ -1076,9 +1056,9 @@ void Room::setLeftSurfaces()
do
{
v_line_t line;
line.x = (tile[i] % map_width_) * tile_size_;
line.y1 = ((tile[i] / map_width_) * tile_size_);
while (tile[i] + map_width_ == 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)
{
@@ -1086,7 +1066,7 @@ void Room::setLeftSurfaces()
}
i++;
}
line.y2 = ((tile[i] / map_width_) * tile_size_) + tile_size_ - 1;
line.y2 = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
left_surfaces_.push_back(line);
i++;
} while (i < (int)tile.size() - 1);
@@ -1100,11 +1080,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 < map_width_ - 1; ++i)
for (int i = 0; i < MAP_WIDTH_ - 1; ++i)
{
for (int j = 0; j < map_height_; ++j)
for (int j = 0; j < MAP_HEIGHT_; ++j)
{
const int pos = (j * map_width_ + i);
const int pos = (j * MAP_WIDTH_ + i);
if (getTile(pos) == t_wall && getTile(pos + 1) != t_wall)
{
tile.push_back(pos);
@@ -1124,9 +1104,9 @@ void Room::setRightSurfaces()
do
{
v_line_t line;
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])
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)
{
@@ -1134,7 +1114,7 @@ void Room::setRightSurfaces()
}
i++;
}
line.y2 = ((tile[i] / map_width_) * tile_size_) + tile_size_ - 1;
line.y2 = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
right_surfaces_.push_back(line);
i++;
} while (i < (int)tile.size() - 1);
@@ -1161,9 +1141,9 @@ void Room::setLeftSlopes()
while (found.size() > 0)
{
d_line_t line;
line.x1 = (found[0] % map_width_) * tile_size_;
line.y1 = (found[0] / map_width_) * tile_size_;
int lookingFor = found[0] + map_width_ + 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)
@@ -1171,13 +1151,13 @@ void Room::setLeftSlopes()
if (found[i] == lookingFor)
{
lastOneFound = lookingFor;
lookingFor += map_width_ + 1;
lookingFor += MAP_WIDTH_ + 1;
found.erase(found.begin() + i);
i--;
}
}
line.x2 = ((lastOneFound % map_width_) * tile_size_) + tile_size_ - 1;
line.y2 = ((lastOneFound / map_width_) * tile_size_) + tile_size_ - 1;
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);
}
}
@@ -1202,9 +1182,9 @@ void Room::setRightSlopes()
while (found.size() > 0)
{
d_line_t line;
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;
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)
@@ -1212,13 +1192,13 @@ void Room::setRightSlopes()
if (found[i] == lookingFor)
{
lastOneFound = lookingFor;
lookingFor += map_width_ - 1;
lookingFor += MAP_WIDTH_ - 1;
found.erase(found.begin() + i);
i--;
}
}
line.x2 = (lastOneFound % map_width_) * tile_size_;
line.y2 = ((lastOneFound / map_width_) * tile_size_) + tile_size_ - 1;
line.x2 = (lastOneFound % MAP_WIDTH_) * TILE_SIZE_;
line.y2 = ((lastOneFound / MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
right_slopes_.push_back(line);
}
}
@@ -1230,14 +1210,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 = map_width_; i < (int)tile_map_.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 % map_width_ == map_width_ - 1)
if (i % MAP_WIDTH_ == MAP_WIDTH_ - 1)
{
tile.push_back(-1);
}
@@ -1252,8 +1232,8 @@ void Room::setAutoSurfaces()
do
{
h_line_t line;
line.x1 = (tile[i] % map_width_) * tile_size_;
line.y = (tile[i] / map_width_) * tile_size_;
line.x1 = (tile[i] % MAP_WIDTH_) * TILE_SIZE_;
line.y = (tile[i] / MAP_WIDTH_) * TILE_SIZE_;
lastOne = i;
i++;
@@ -1270,7 +1250,7 @@ void Room::setAutoSurfaces()
}
}
line.x2 = ((tile[lastOne] % map_width_) * tile_size_) + tile_size_ - 1;
line.x2 = ((tile[lastOne] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
auto_surfaces_.push_back(line);
if (i <= (int)tile.size() - 1)
{
@@ -1292,12 +1272,12 @@ void Room::setAnimatedTiles()
if (getTile(i) == t_animated)
{
// La i es la ubicación
const int x = (i % map_width_) * tile_size_;
const int y = (i / map_width_) * tile_size_;
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 = (tile_map_[i] % tile_set_width_) * tile_size_;
const int yc = (tile_map_[i] / tile_set_width_) * tile_size_;
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);
@@ -1315,11 +1295,11 @@ void Room::updateAnimatedTiles()
int offset = 0;
if (auto_surface_direction_ == -1)
{
offset = ((counter_ / 3) % numFrames * tile_size_);
offset = ((counter_ / 3) % numFrames * TILE_SIZE_);
}
else
{
offset = ((numFrames - 1 - ((counter_ / 3) % numFrames)) * tile_size_);
offset = ((numFrames - 1 - ((counter_ / 3) % numFrames)) * TILE_SIZE_);
}
for (auto &a : animated_tiles_)