forked from jaildesigner-jailgames/jaildoctors_dilemma
linter
This commit is contained in:
@@ -19,8 +19,8 @@
|
||||
|
||||
// Carga las variables y texturas desde un fichero de mapa de tiles
|
||||
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::vector<int> tile_map_file;
|
||||
const std::string FILENAME = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
std::ifstream file(file_path);
|
||||
|
||||
// El fichero se puede abrir
|
||||
@@ -35,7 +35,7 @@ std::vector<int> loadRoomTileFile(const std::string& file_path, bool verbose) {
|
||||
std::stringstream ss(line);
|
||||
std::string tmp;
|
||||
while (getline(ss, tmp, ',')) {
|
||||
tileMapFile.push_back(std::stoi(tmp) - 1);
|
||||
tile_map_file.push_back(std::stoi(tmp) - 1);
|
||||
}
|
||||
|
||||
// Lee la siguiente linea
|
||||
@@ -46,18 +46,18 @@ std::vector<int> loadRoomTileFile(const std::string& file_path, bool verbose) {
|
||||
|
||||
// Cierra el fichero
|
||||
if (verbose) {
|
||||
std::cout << "TileMap loaded: " << filename.c_str() << std::endl;
|
||||
std::cout << "TileMap loaded: " << FILENAME.c_str() << std::endl;
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
else { // El fichero no se puede abrir
|
||||
if (verbose) {
|
||||
std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl;
|
||||
std::cout << "Warning: Unable to open " << FILENAME.c_str() << " file" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return tileMapFile;
|
||||
return tile_map_file;
|
||||
}
|
||||
|
||||
// Carga las variables desde un fichero de mapa
|
||||
@@ -67,8 +67,8 @@ RoomData loadRoomFile(const std::string& file_path, bool verbose) {
|
||||
room.item_color2 = "magenta";
|
||||
room.conveyor_belt_direction = 1;
|
||||
|
||||
const std::string fileName = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
room.number = fileName.substr(0, fileName.find_last_of("."));
|
||||
const std::string FILE_NAME = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
room.number = FILE_NAME.substr(0, FILE_NAME.find_last_of("."));
|
||||
|
||||
std::ifstream file(file_path);
|
||||
|
||||
@@ -93,10 +93,11 @@ RoomData loadRoomFile(const std::string& file_path, bool verbose) {
|
||||
// Procesa las dos subcadenas
|
||||
std::string key = line.substr(0, pos);
|
||||
std::string value = line.substr(pos + 1, line.length());
|
||||
if (!setEnemy(&enemy, key, value))
|
||||
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;
|
||||
std::cout << "Warning: file " << FILE_NAME.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||
}
|
||||
}
|
||||
} while (line != "[/enemy]");
|
||||
|
||||
// Añade el enemigo al vector de enemigos
|
||||
@@ -121,7 +122,7 @@ RoomData loadRoomFile(const std::string& file_path, bool verbose) {
|
||||
std::string value = line.substr(pos + 1, line.length());
|
||||
if (!setItem(&item, key, value)) {
|
||||
if (verbose) {
|
||||
std::cout << "Warning: file " << fileName.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||
std::cout << "Warning: file " << FILE_NAME.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +141,7 @@ RoomData loadRoomFile(const std::string& file_path, bool verbose) {
|
||||
std::string value = line.substr(pos + 1, line.length());
|
||||
if (!setRoom(&room, key, value)) {
|
||||
if (verbose) {
|
||||
std::cout << "Warning: file " << fileName.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||
std::cout << "Warning: file " << FILE_NAME.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -148,14 +149,14 @@ RoomData loadRoomFile(const std::string& file_path, bool verbose) {
|
||||
|
||||
// Cierra el fichero
|
||||
if (verbose) {
|
||||
std::cout << "Room loaded: " << fileName.c_str() << std::endl;
|
||||
std::cout << "Room loaded: " << FILE_NAME.c_str() << std::endl;
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
// El fichero no se puede abrir
|
||||
else {
|
||||
{
|
||||
std::cout << "Warning: Unable to open " << fileName.c_str() << " file" << std::endl;
|
||||
std::cout << "Warning: Unable to open " << FILE_NAME.c_str() << " file" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,7 +193,7 @@ bool setRoom(RoomData* room, const std::string& key, const std::string& value) {
|
||||
room->right_room = value;
|
||||
} else if (key == "autoSurface") {
|
||||
room->conveyor_belt_direction = (value == "right") ? 1 : -1;
|
||||
} else if (key == "" || key.substr(0, 1) == "#") {
|
||||
} else if (key.empty() || key.substr(0, 1) == "#") {
|
||||
// No se realiza ninguna acción para estas claves
|
||||
} else {
|
||||
success = false;
|
||||
@@ -327,56 +328,57 @@ void Room::initializeRoom(const RoomData& room) {
|
||||
conveyor_belt_direction_ = room.conveyor_belt_direction;
|
||||
tile_map_ = Resource::get()->getTileMap(room.tile_map_file);
|
||||
surface_ = Resource::get()->getSurface(room.tile_set_file);
|
||||
tile_set_width_ = surface_->getWidth() / TILE_SIZE_;
|
||||
tile_set_width_ = surface_->getWidth() / TILE_SIZE;
|
||||
is_paused_ = false;
|
||||
counter_ = 0;
|
||||
|
||||
// Crear los enemigos
|
||||
for (auto& enemy_data : room.enemies) {
|
||||
for (const auto& enemy_data : room.enemies) {
|
||||
enemies_.emplace_back(std::make_shared<Enemy>(enemy_data));
|
||||
}
|
||||
|
||||
// Crear los items
|
||||
for (const auto& item : room.items) {
|
||||
const SDL_FPoint itemPos = {item.x, item.y};
|
||||
const SDL_FPoint ITEM_POS = {item.x, item.y};
|
||||
|
||||
if (!ItemTracker::get()->hasBeenPicked(room.name, itemPos)) {
|
||||
if (!ItemTracker::get()->hasBeenPicked(room.name, ITEM_POS)) {
|
||||
// Crear una copia local de los datos del item
|
||||
ItemData itemCopy = item;
|
||||
itemCopy.color1 = stringToColor(item_color1_);
|
||||
itemCopy.color2 = stringToColor(item_color2_);
|
||||
ItemData item_copy = item;
|
||||
item_copy.color1 = stringToColor(item_color1_);
|
||||
item_copy.color2 = stringToColor(item_color2_);
|
||||
|
||||
// Crear el objeto Item usando la copia modificada
|
||||
items_.emplace_back(std::make_shared<Item>(itemCopy));
|
||||
items_.emplace_back(std::make_shared<Item>(item_copy));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Crea la textura con el mapeado de la habitación
|
||||
void Room::fillMapTexture() {
|
||||
const Uint8 color = stringToColor(bg_color_);
|
||||
const Uint8 COLOR = stringToColor(bg_color_);
|
||||
auto previuos_renderer = Screen::get()->getRendererSurface();
|
||||
Screen::get()->setRendererSurface(map_surface_);
|
||||
map_surface_->clear(color);
|
||||
map_surface_->clear(COLOR);
|
||||
|
||||
// Los tileSetFiles son de 20x20 tiles. El primer tile es el 0. Cuentan hacia la derecha y hacia abajo
|
||||
|
||||
SDL_FRect clip = {0, 0, TILE_SIZE_, TILE_SIZE_};
|
||||
for (int y = 0; y < MAP_HEIGHT_; ++y)
|
||||
for (int x = 0; x < MAP_WIDTH_; ++x) {
|
||||
SDL_FRect 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_;
|
||||
surface_->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;
|
||||
surface_->render(x * TILE_SIZE, y * TILE_SIZE, &clip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
if (Debug::get()->getEnabled()) {
|
||||
@@ -517,23 +519,23 @@ std::string Room::getRoom(RoomBorder border) {
|
||||
|
||||
// Devuelve el tipo de tile que hay en ese pixel
|
||||
TileType Room::getTile(SDL_FPoint point) {
|
||||
const int pos = ((point.y / TILE_SIZE_) * MAP_WIDTH_) + (point.x / TILE_SIZE_);
|
||||
return getTile(pos);
|
||||
const int POS = ((point.y / TILE_SIZE) * MAP_WIDTH) + (point.x / TILE_SIZE);
|
||||
return getTile(POS);
|
||||
}
|
||||
|
||||
// Devuelve el tipo de tile que hay en ese indice
|
||||
TileType Room::getTile(int index) {
|
||||
// const bool onRange = (index > -1) && (index < mapWidth * mapHeight);
|
||||
const bool onRange = (index > -1) && (index < (int)tile_map_.size());
|
||||
const bool ON_RANGE = (index > -1) && (index < (int)tile_map_.size());
|
||||
|
||||
if (onRange) {
|
||||
if (ON_RANGE) {
|
||||
// Las filas 0-8 son de tiles t_wall
|
||||
if ((tile_map_[index] >= 0) && (tile_map_[index] < 9 * tile_set_width_)) {
|
||||
return TileType::WALL;
|
||||
}
|
||||
|
||||
// Las filas 9-17 son de tiles t_passable
|
||||
else if ((tile_map_[index] >= 9 * tile_set_width_) && (tile_map_[index] < 18 * tile_set_width_)) {
|
||||
if ((tile_map_[index] >= 9 * tile_set_width_) && (tile_map_[index] < 18 * tile_set_width_)) {
|
||||
return TileType::PASSABLE;
|
||||
}
|
||||
|
||||
@@ -590,25 +592,25 @@ bool Room::itemCollision(SDL_FRect& rect) {
|
||||
// Obten la coordenada de la cuesta a partir de un punto perteneciente a ese tile
|
||||
int Room::getSlopeHeight(SDL_FPoint p, TileType 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::get()->add("BASE = " + std::to_string(base));
|
||||
#endif
|
||||
|
||||
// Calcula cuanto se ha entrado en el tile horizontalmente
|
||||
const int pos = (static_cast<int>(p.x) % TILE_SIZE_); // Esto da un valor entre 0 y 7
|
||||
const int POS = (static_cast<int>(p.x) % TILE_SIZE); // Esto da un valor entre 0 y 7
|
||||
#ifdef _DEBUG
|
||||
Debug::get()->add("POS = " + std::to_string(pos));
|
||||
Debug::get()->add("POS = " + std::to_string(POS));
|
||||
#endif
|
||||
|
||||
// Se resta a la base la cantidad de pixeles pos en funcion de la rampa
|
||||
if (slope == TileType::SLOPE_R) {
|
||||
base -= pos + 1;
|
||||
base -= POS + 1;
|
||||
#ifdef _DEBUG
|
||||
Debug::get()->add("BASE_R = " + std::to_string(base));
|
||||
#endif
|
||||
} else {
|
||||
base -= (TILE_SIZE_ - pos);
|
||||
base -= (TILE_SIZE - POS);
|
||||
#ifdef _DEBUG
|
||||
Debug::get()->add("BASE_L = " + std::to_string(base));
|
||||
#endif
|
||||
@@ -623,12 +625,12 @@ 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) {
|
||||
if (getTile(i) == TileType::WALL && getTile(i + MAP_WIDTH_) != TileType::WALL) {
|
||||
for (int i = 0; i < (int)tile_map_.size() - MAP_WIDTH; ++i) {
|
||||
if (getTile(i) == TileType::WALL && getTile(i + MAP_WIDTH) != TileType::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);
|
||||
}
|
||||
}
|
||||
@@ -642,8 +644,8 @@ void Room::setBottomSurfaces() {
|
||||
int i = 0;
|
||||
do {
|
||||
LineHorizontal 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;
|
||||
int last_one = i;
|
||||
i++;
|
||||
|
||||
@@ -657,7 +659,7 @@ void Room::setBottomSurfaces() {
|
||||
}
|
||||
}
|
||||
|
||||
line.x2 = ((tile[last_one] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
|
||||
line.x2 = ((tile[last_one] % MAP_WIDTH) * TILE_SIZE) + TILE_SIZE - 1;
|
||||
bottom_floors_.push_back(line);
|
||||
if (i <= (int)tile.size() - 1) {
|
||||
if (tile[i] == -1) { // Si el siguiente elemento es un separador, hay que saltarlo
|
||||
@@ -674,12 +676,12 @@ 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) {
|
||||
if ((getTile(i) == TileType::WALL || getTile(i) == TileType::PASSABLE) && getTile(i - MAP_WIDTH_) != TileType::WALL) {
|
||||
for (int i = MAP_WIDTH; i < (int)tile_map_.size(); ++i) {
|
||||
if ((getTile(i) == TileType::WALL || getTile(i) == TileType::PASSABLE) && getTile(i - MAP_WIDTH) != TileType::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);
|
||||
}
|
||||
}
|
||||
@@ -693,8 +695,8 @@ void Room::setTopSurfaces() {
|
||||
int i = 0;
|
||||
do {
|
||||
LineHorizontal 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;
|
||||
int last_one = i;
|
||||
i++;
|
||||
|
||||
@@ -708,7 +710,7 @@ void Room::setTopSurfaces() {
|
||||
}
|
||||
}
|
||||
|
||||
line.x2 = ((tile[last_one] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
|
||||
line.x2 = ((tile[last_one] % MAP_WIDTH) * TILE_SIZE) + TILE_SIZE - 1;
|
||||
top_floors_.push_back(line);
|
||||
if (i <= (int)tile.size() - 1) {
|
||||
if (tile[i] == -1) { // Si el siguiente elemento es un separador, hay que saltarlo
|
||||
@@ -725,11 +727,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 j = 0; j < MAP_HEIGHT_; ++j) {
|
||||
const int pos = (j * MAP_WIDTH_ + i);
|
||||
if (getTile(pos) == TileType::WALL && getTile(pos - 1) != TileType::WALL) {
|
||||
tile.push_back(pos);
|
||||
for (int i = 1; i < MAP_WIDTH; ++i) {
|
||||
for (int j = 0; j < MAP_HEIGHT; ++j) {
|
||||
const int POS = ((j * MAP_WIDTH) + i);
|
||||
if (getTile(POS) == TileType::WALL && getTile(POS - 1) != TileType::WALL) {
|
||||
tile.push_back(POS);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -744,15 +746,15 @@ void Room::setLeftSurfaces() {
|
||||
int i = 0;
|
||||
do {
|
||||
LineVertical 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) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
line.y2 = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
|
||||
line.y2 = ((tile[i] / MAP_WIDTH) * TILE_SIZE) + TILE_SIZE - 1;
|
||||
left_walls_.push_back(line);
|
||||
i++;
|
||||
} while (i < (int)tile.size() - 1);
|
||||
@@ -765,11 +767,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 j = 0; j < MAP_HEIGHT_; ++j) {
|
||||
const int pos = (j * MAP_WIDTH_ + i);
|
||||
if (getTile(pos) == TileType::WALL && getTile(pos + 1) != TileType::WALL) {
|
||||
tile.push_back(pos);
|
||||
for (int i = 0; i < MAP_WIDTH - 1; ++i) {
|
||||
for (int j = 0; j < MAP_HEIGHT; ++j) {
|
||||
const int POS = ((j * MAP_WIDTH) + i);
|
||||
if (getTile(POS) == TileType::WALL && getTile(POS + 1) != TileType::WALL) {
|
||||
tile.push_back(POS);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -784,15 +786,15 @@ void Room::setRightSurfaces() {
|
||||
int i = 0;
|
||||
do {
|
||||
LineVertical 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) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
line.y2 = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
|
||||
line.y2 = ((tile[i] / MAP_WIDTH) * TILE_SIZE) + TILE_SIZE - 1;
|
||||
right_walls_.push_back(line);
|
||||
i++;
|
||||
} while (i < (int)tile.size() - 1);
|
||||
@@ -813,23 +815,23 @@ void Room::setLeftSlopes() {
|
||||
// que seran i + mapWidth + 1. Conforme se añaden se eliminan y se vuelve a escudriñar el vector de
|
||||
// tiles encontrados hasta que esté vacío
|
||||
|
||||
while (found.size() > 0) {
|
||||
while (!found.empty()) {
|
||||
LineDiagonal line;
|
||||
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];
|
||||
line.x1 = (found[0] % MAP_WIDTH) * TILE_SIZE;
|
||||
line.y1 = (found[0] / MAP_WIDTH) * TILE_SIZE;
|
||||
int looking_for = found[0] + MAP_WIDTH + 1;
|
||||
int last_one_found = found[0];
|
||||
found.erase(found.begin());
|
||||
for (int i = 0; i < (int)found.size(); ++i) {
|
||||
if (found[i] == lookingFor) {
|
||||
lastOneFound = lookingFor;
|
||||
lookingFor += MAP_WIDTH_ + 1;
|
||||
if (found[i] == looking_for) {
|
||||
last_one_found = looking_for;
|
||||
looking_for += 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 = ((last_one_found % MAP_WIDTH) * TILE_SIZE) + TILE_SIZE - 1;
|
||||
line.y2 = ((last_one_found / MAP_WIDTH) * TILE_SIZE) + TILE_SIZE - 1;
|
||||
left_slopes_.push_back(line);
|
||||
}
|
||||
}
|
||||
@@ -848,23 +850,23 @@ void Room::setRightSlopes() {
|
||||
// que seran i + mapWidth - 1. Conforme se añaden se eliminan y se vuelve a escudriñar el vector de
|
||||
// tiles encontrados hasta que esté vacío
|
||||
|
||||
while (found.size() > 0) {
|
||||
while (!found.empty()) {
|
||||
LineDiagonal 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;
|
||||
int lastOneFound = found[0];
|
||||
line.x1 = ((found[0] % MAP_WIDTH) * TILE_SIZE) + TILE_SIZE - 1;
|
||||
line.y1 = (found[0] / MAP_WIDTH) * TILE_SIZE;
|
||||
int looking_for = found[0] + MAP_WIDTH - 1;
|
||||
int last_one_found = found[0];
|
||||
found.erase(found.begin());
|
||||
for (int i = 0; i < (int)found.size(); ++i) {
|
||||
if (found[i] == lookingFor) {
|
||||
lastOneFound = lookingFor;
|
||||
lookingFor += MAP_WIDTH_ - 1;
|
||||
if (found[i] == looking_for) {
|
||||
last_one_found = looking_for;
|
||||
looking_for += 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 = (last_one_found % MAP_WIDTH) * TILE_SIZE;
|
||||
line.y2 = ((last_one_found / MAP_WIDTH) * TILE_SIZE) + TILE_SIZE - 1;
|
||||
right_slopes_.push_back(line);
|
||||
}
|
||||
}
|
||||
@@ -875,12 +877,12 @@ 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) == TileType::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);
|
||||
}
|
||||
}
|
||||
@@ -891,8 +893,8 @@ void Room::setAutoSurfaces() {
|
||||
int i = 0;
|
||||
do {
|
||||
LineHorizontal 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;
|
||||
int last_one = i;
|
||||
i++;
|
||||
|
||||
@@ -906,7 +908,7 @@ void Room::setAutoSurfaces() {
|
||||
}
|
||||
}
|
||||
|
||||
line.x2 = ((tile[last_one] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
|
||||
line.x2 = ((tile[last_one] % MAP_WIDTH) * TILE_SIZE) + TILE_SIZE - 1;
|
||||
conveyor_belt_floors_.push_back(line);
|
||||
if (i <= (int)tile.size() - 1) {
|
||||
if (tile[i] == -1) { // Si el siguiente elemento es un separador, hay que saltarlo
|
||||
@@ -923,17 +925,17 @@ void Room::setAnimatedTiles() {
|
||||
for (int i = 0; i < (int)tile_map_.size(); ++i) {
|
||||
if (getTile(i) == TileType::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;
|
||||
|
||||
AnimatedTile at;
|
||||
at.sprite = std::make_shared<SurfaceSprite>(surface_, x, y, 8, 8);
|
||||
at.sprite->setClip(xc, yc, 8, 8);
|
||||
at.x_orig = xc;
|
||||
at.sprite = std::make_shared<SurfaceSprite>(surface_, X, Y, 8, 8);
|
||||
at.sprite->setClip(XC, YC, 8, 8);
|
||||
at.x_orig = XC;
|
||||
animated_tiles_.push_back(at);
|
||||
}
|
||||
}
|
||||
@@ -941,12 +943,12 @@ void Room::setAnimatedTiles() {
|
||||
|
||||
// Actualiza los tiles animados
|
||||
void Room::updateAnimatedTiles() {
|
||||
const int numFrames = 4;
|
||||
const int NUM_FRAMES = 4;
|
||||
int offset = 0;
|
||||
if (conveyor_belt_direction_ == -1) {
|
||||
offset = ((counter_ / 3) % numFrames * TILE_SIZE_);
|
||||
offset = ((counter_ / 3) % NUM_FRAMES * TILE_SIZE);
|
||||
} else {
|
||||
offset = ((numFrames - 1 - ((counter_ / 3) % numFrames)) * TILE_SIZE_);
|
||||
offset = ((NUM_FRAMES - 1 - ((counter_ / 3) % NUM_FRAMES)) * TILE_SIZE);
|
||||
}
|
||||
|
||||
for (auto& a : animated_tiles_) {
|
||||
@@ -1043,9 +1045,9 @@ bool Room::checkAutoSurfaces(SDL_FPoint* p) {
|
||||
// Comprueba las colisiones
|
||||
int Room::checkLeftSlopes(const LineVertical* line) {
|
||||
for (const auto& slope : left_slopes_) {
|
||||
const auto p = checkCollision(slope, *line);
|
||||
if (p.x != -1) {
|
||||
return p.y;
|
||||
const auto P = checkCollision(slope, *line);
|
||||
if (P.x != -1) {
|
||||
return P.y;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1066,9 +1068,9 @@ bool Room::checkLeftSlopes(SDL_FPoint* p) {
|
||||
// Comprueba las colisiones
|
||||
int Room::checkRightSlopes(const LineVertical* line) {
|
||||
for (const auto& slope : right_slopes_) {
|
||||
const auto p = checkCollision(slope, *line);
|
||||
if (p.x != -1) {
|
||||
return p.y;
|
||||
const auto P = checkCollision(slope, *line);
|
||||
if (P.x != -1) {
|
||||
return P.y;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user