forked from jaildesigner-jailgames/jaildoctors_dilemma
Arreglos en la estructura i format del codi
This commit is contained in:
132
source/room.cpp
132
source/room.cpp
@@ -399,11 +399,7 @@ bool setItem(ItemData *item, const std::string &key, const std::string &value)
|
||||
|
||||
// Constructor
|
||||
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)
|
||||
: data_(data)
|
||||
{
|
||||
auto room = Resource::get()->getRoom(room_path);
|
||||
number_ = room->number;
|
||||
@@ -468,7 +464,7 @@ Room::Room(const std::string &room_path, std::shared_ptr<ScoreboardData> data)
|
||||
setAnimatedTiles();
|
||||
|
||||
// Crea la textura para el mapa de tiles de la habitación
|
||||
map_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT);
|
||||
map_texture_ = SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT);
|
||||
if (map_texture_ == nullptr)
|
||||
{
|
||||
if (options.console)
|
||||
@@ -482,7 +478,7 @@ Room::Room(const std::string &room_path, std::shared_ptr<ScoreboardData> data)
|
||||
fillMapTexture();
|
||||
|
||||
// Establece el color del borde
|
||||
screen_->setBorderColor(stringToColor(options.video.palette, room->border_color));
|
||||
Screen::get()->setBorderColor(stringToColor(options.video.palette, room->border_color));
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -514,9 +510,9 @@ Color Room::getBorderColor()
|
||||
void Room::fillMapTexture()
|
||||
{
|
||||
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_);
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), map_texture_);
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF);
|
||||
SDL_RenderClear(Screen::get()->getRenderer());
|
||||
|
||||
// Los tileSetFiles son de 20x20 tiles. El primer tile es el 0. Cuentan hacia la derecha y hacia abajo
|
||||
|
||||
@@ -538,14 +534,14 @@ void Room::fillMapTexture()
|
||||
texture_->render(x * TILE_SIZE_, y * TILE_SIZE_, &clip);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (debug_->getEnabled())
|
||||
if (Debug::get()->getEnabled())
|
||||
{
|
||||
if (clip.x != -TILE_SIZE_)
|
||||
{
|
||||
clip.x = x * TILE_SIZE_;
|
||||
clip.y = y * TILE_SIZE_;
|
||||
SDL_SetRenderDrawColor(renderer_, 64, 64, 64, 224);
|
||||
SDL_RenderFillRect(renderer_, &clip);
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 64, 64, 64, 224);
|
||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &clip);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -553,16 +549,16 @@ void Room::fillMapTexture()
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if (debug_->getEnabled())
|
||||
if (Debug::get()->getEnabled())
|
||||
{
|
||||
// BottomSurfaces
|
||||
if (true)
|
||||
{
|
||||
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(Screen::get()->getRenderer(), (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 255, 0, 0, 0xFF);
|
||||
SDL_RenderDrawLine(Screen::get()->getRenderer(), l.x1, l.y, l.x2, l.y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -571,9 +567,9 @@ void Room::fillMapTexture()
|
||||
{
|
||||
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(Screen::get()->getRenderer(), (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 255, 0, 0xFF);
|
||||
SDL_RenderDrawLine(Screen::get()->getRenderer(), l.x1, l.y, l.x2, l.y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -582,9 +578,9 @@ void Room::fillMapTexture()
|
||||
{
|
||||
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(Screen::get()->getRenderer(), (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 128, 128, 255, 0xFF);
|
||||
SDL_RenderDrawLine(Screen::get()->getRenderer(), l.x, l.y1, l.x, l.y2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -593,9 +589,9 @@ void Room::fillMapTexture()
|
||||
{
|
||||
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(Screen::get()->getRenderer(), (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 255, 255, 0, 0xFF);
|
||||
SDL_RenderDrawLine(Screen::get()->getRenderer(), l.x, l.y1, l.x, l.y2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -604,9 +600,9 @@ void Room::fillMapTexture()
|
||||
{
|
||||
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(Screen::get()->getRenderer(), (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 255, 255, 0xFF);
|
||||
SDL_RenderDrawLine(Screen::get()->getRenderer(), l.x1, l.y1, l.x2, l.y2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -615,9 +611,9 @@ void Room::fillMapTexture()
|
||||
{
|
||||
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(Screen::get()->getRenderer(), (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 255, 0, 255, 0xFF);
|
||||
SDL_RenderDrawLine(Screen::get()->getRenderer(), l.x1, l.y1, l.x2, l.y2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -626,14 +622,14 @@ void Room::fillMapTexture()
|
||||
{
|
||||
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(Screen::get()->getRenderer(), (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
|
||||
SDL_RenderDrawLine(Screen::get()->getRenderer(), l.x1, l.y, l.x2, l.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_SetRenderTarget(renderer_, nullptr);
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr);
|
||||
}
|
||||
|
||||
// Dibuja el mapa en pantalla
|
||||
@@ -641,11 +637,11 @@ 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_, map_texture_, nullptr, &dest);
|
||||
SDL_RenderCopy(Screen::get()->getRenderer(), map_texture_, nullptr, &dest);
|
||||
|
||||
// Dibuja los tiles animados
|
||||
#ifdef DEBUG
|
||||
if (!debug_->getEnabled())
|
||||
if (!Debug::get()->getEnabled())
|
||||
{
|
||||
renderAnimatedTiles();
|
||||
}
|
||||
@@ -811,73 +807,19 @@ bool Room::itemCollision(SDL_Rect &rect)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Recarga la textura
|
||||
void Room::reLoadTexture()
|
||||
{
|
||||
texture_->reLoad();
|
||||
fillMapTexture();
|
||||
|
||||
for (auto enemy : enemies_)
|
||||
{
|
||||
enemy->reLoadTexture();
|
||||
}
|
||||
|
||||
for (auto item : items_)
|
||||
{
|
||||
item->reLoadTexture();
|
||||
}
|
||||
}
|
||||
|
||||
// Recarga la paleta
|
||||
void Room::reLoadPalette()
|
||||
{
|
||||
// Cambia el color de los items
|
||||
for (auto item : items_)
|
||||
{
|
||||
item->setColors(stringToColor(options.video.palette, item_color1_), stringToColor(options.video.palette, item_color2_));
|
||||
}
|
||||
|
||||
// Cambia el color de los enemigos
|
||||
for (auto enemy : enemies_)
|
||||
{
|
||||
enemy->setPalette(options.video.palette);
|
||||
}
|
||||
|
||||
// Establece el color del borde
|
||||
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);
|
||||
|
||||
// Pone la nueva textura a los tiles animados
|
||||
for (auto tile : animated_tiles_)
|
||||
{
|
||||
tile.sprite->setTexture(texture_);
|
||||
}
|
||||
|
||||
// Recarga las texturas
|
||||
reLoadTexture();
|
||||
}
|
||||
|
||||
// Obten el tamaño del tile
|
||||
int Room::getTileSize()
|
||||
{
|
||||
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_;
|
||||
#ifdef DEBUG
|
||||
debug_->add("BASE = " + std::to_string(base));
|
||||
Debug::get()->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
|
||||
#ifdef DEBUG
|
||||
debug_->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
|
||||
@@ -885,14 +827,14 @@ int Room::getSlopeHeight(SDL_Point p, tile_e slope)
|
||||
{
|
||||
base -= pos + 1;
|
||||
#ifdef DEBUG
|
||||
debug_->add("BASE_R = " + std::to_string(base));
|
||||
Debug::get()->add("BASE_R = " + std::to_string(base));
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
base -= (TILE_SIZE_ - pos);
|
||||
#ifdef DEBUG
|
||||
debug_->add("BASE_L = " + std::to_string(base));
|
||||
Debug::get()->add("BASE_L = " + std::to_string(base));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user