canvi de pc

This commit is contained in:
2025-02-27 07:37:39 +01:00
parent e6fd4225a2
commit c6474cb2da
26 changed files with 903 additions and 991 deletions

View File

@@ -19,43 +19,42 @@
// Constructor
Demo::Demo()
: screen(Screen::get()),
renderer(Screen::get()->getRenderer()),
resource(Resource::get()),
asset(Asset::get()),
input(Input::get()),
debug(Debug::get())
: screen_(Screen::get()),
renderer_(Screen::get()->getRenderer()),
resource_(Resource::get()),
asset_(Asset::get()),
input_(Input::get()),
debug_(Debug::get())
{
// Inicia algunas variables
board.ini_clock = SDL_GetTicks();
rooms.push_back("04.room");
rooms.push_back("54.room");
rooms.push_back("20.room");
rooms.push_back("09.room");
rooms.push_back("05.room");
rooms.push_back("11.room");
rooms.push_back("31.room");
rooms.push_back("44.room");
board_.ini_clock = SDL_GetTicks();
rooms_.push_back("04.room");
rooms_.push_back("54.room");
rooms_.push_back("20.room");
rooms_.push_back("09.room");
rooms_.push_back("05.room");
rooms_.push_back("11.room");
rooms_.push_back("31.room");
rooms_.push_back("44.room");
roomIndex = 0;
currentRoom = rooms[roomIndex];
room_index_ = 0;
current_room_ = rooms_[room_index_];
// Crea los objetos
ItemTracker::init();
scoreboard = std::make_shared<Scoreboard>(&board);
room = std::make_shared<Room>(resource->getRoom(currentRoom), &board.items, false);
text = resource->getText("smb2");
scoreboard_ = std::make_shared<Scoreboard>(&board_);
room_ = std::make_shared<Room>(resource_->getRoom(current_room_), &board_.items, false);
text_ = resource_->getText("smb2");
// Inicializa el resto de variables
counter = 0;
roomTime = 400;
ticks = 0;
ticksSpeed = 15;
board.lives = 9;
board.items = 0;
board.rooms = 1;
board.jail_is_open = false;
board.music = true;
counter_ = 0;
room_time_ = 400;
ticks_ = 0;
board_.lives = 9;
board_.items = 0;
board_.rooms = 1;
board_.jail_is_open = false;
board_.music = true;
setScoreBoardColor();
options.section.section = Section::DEMO;
@@ -99,21 +98,21 @@ void Demo::run()
void Demo::update()
{
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
if (SDL_GetTicks() - ticks > ticksSpeed)
if (SDL_GetTicks() - ticks_ > GAME_SPEED)
{
// Actualiza el contador de ticks
ticks = SDL_GetTicks();
ticks_ = SDL_GetTicks();
// Comprueba las entradas
checkInput();
// Actualiza los objetos
room->update();
scoreboard->update();
screen->updateFX();
room_->update();
scoreboard_->update();
screen_->updateFX();
checkRoomChange();
screen->update();
screen_->update();
}
}
@@ -121,18 +120,18 @@ void Demo::update()
void Demo::render()
{
// Prepara para dibujar el frame
screen->start();
screen_->start();
// Dibuja los elementos del juego en orden
room->renderMap();
room->renderEnemies();
room->renderItems();
room_->renderMap();
room_->renderEnemies();
room_->renderItems();
renderRoomName();
scoreboard->render();
screen->renderFX();
scoreboard_->render();
screen_->renderFX();
// Actualiza la pantalla
screen->render();
screen_->render();
}
// Escribe el nombre de la pantalla
@@ -141,10 +140,10 @@ void Demo::renderRoomName()
// Texto en el centro de la pantalla
SDL_Rect rect = {0, 16 * BLOCK, PLAY_AREA_WIDTH, BLOCK * 2};
Color color = stringToColor(options.video.palette, "white");
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 0xFF);
SDL_RenderFillRect(renderer, &rect);
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF);
SDL_RenderFillRect(renderer_, &rect);
text->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, 16 * 8 + 4, room->getName(), 1, room->getBGColor());
text_->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, 16 * 8 + 4, room_->getName(), 1, room_->getBGColor());
}
// Recarga todas las texturas
@@ -154,9 +153,9 @@ void Demo::reLoadTextures()
{
std::cout << "** RELOAD REQUESTED" << std::endl;
}
room->reLoadTexture();
scoreboard->reLoadTexture();
text->reLoadTexture();
room_->reLoadTexture();
scoreboard_->reLoadTexture();
text_->reLoadTexture();
}
// Cambia la paleta
@@ -172,8 +171,8 @@ void Demo::switchPalette()
options.video.palette = Palette::ZXSPECTRUM;
}
room->reLoadPalette();
scoreboard->reLoadPalette();
room_->reLoadPalette();
scoreboard_->reLoadPalette();
// Pone el color del marcador en función del color del borde de la habitación
setScoreBoardColor();
@@ -186,10 +185,10 @@ bool Demo::changeRoom(std::string file)
if (file != "0")
{
// Verifica que exista el fichero que se va a cargar
if (asset->get(file) != "")
if (asset_->get(file) != "")
{
// Crea un objeto habitación a partir del fichero
room = std::make_shared<Room>(resource->getRoom(file), &board.items, false);
room_ = std::make_shared<Room>(resource_->getRoom(file), &board_.items, false);
// Pone el color del marcador en función del color del borde de la habitación
setScoreBoardColor();
@@ -204,19 +203,19 @@ bool Demo::changeRoom(std::string file)
// Comprueba si se ha de cambiar de habitación
void Demo::checkRoomChange()
{
counter++;
if (counter == roomTime)
counter_++;
if (counter_ == room_time_)
{
counter = 0;
roomIndex++;
if (roomIndex == (int)rooms.size())
counter_ = 0;
room_index_++;
if (room_index_ == (int)rooms_.size())
{
options.section.section = Section::LOGO;
options.section.subsection = Subsection::LOGO_TO_TITLE;
}
else
{
changeRoom(rooms[roomIndex]);
changeRoom(rooms_[room_index_]);
}
}
}
@@ -225,13 +224,13 @@ void Demo::checkRoomChange()
void Demo::setScoreBoardColor()
{
// Obtiene el color del borde
const Color color = room->getBorderColor();
const Color color = room_->getBorderColor();
// Si el color es negro lo cambia a blanco
const Color black_color = stringToColor(options.video.palette, "black");
board.color = colorAreEqual(color, black_color) ? stringToColor(options.video.palette, "white") : color;
board_.color = colorAreEqual(color, black_color) ? stringToColor(options.video.palette, "white") : color;
// Si el color es negro brillante lo cambia a blanco
const Color bright_blac_color = stringToColor(options.video.palette, "bright_black");
board.color = colorAreEqual(color, bright_blac_color) ? stringToColor(options.video.palette, "white") : color;
board_.color = colorAreEqual(color, bright_blac_color) ? stringToColor(options.video.palette, "white") : color;
}