JA VA! Nomes s'havia de fer les coses be i no ser un ansias

This commit is contained in:
2025-02-22 00:30:32 +01:00
parent f6098a479b
commit e361d295c1
39 changed files with 1053 additions and 1098 deletions

View File

@@ -20,17 +20,16 @@
#include "stats.h" // for Stats
#include "text.h" // for Text, TXT_CENTER, TXT_COLOR
#include "utils.h" // for options_t, cheat_t, stringToColor
#include "options.h"
// Constructor
Game::Game(Resource *resource, options_t *options, section_t *section, Debug *debug)
Game::Game(Resource *resource, Debug *debug)
: screen_(Screen::get()),
renderer_(Screen::get()->getRenderer()),
asset_(Asset::get()),
input_(Input::get()),
resource_(resource),
debug_(debug),
options_(options),
section_(section)
debug_(debug)
{
// Inicia algunas variables
board_.iniClock = SDL_GetTicks();
@@ -48,26 +47,26 @@ Game::Game(Resource *resource, options_t *options, section_t *section, Debug *de
#endif
// Crea los objetos
cheevos_ = new Cheevos(screen_, options, asset_->get("cheevos.bin"));
scoreboard_ = new ScoreBoard(renderer_, resource, asset_, options, &board_);
cheevos_ = new Cheevos(screen_, asset_->get("cheevos.bin"));
scoreboard_ = new ScoreBoard(renderer_, resource, asset_, &board_);
item_tracker_ = new ItemTracker();
room_tracker_ = new RoomTracker();
room_ = new Room(resource->getRoom(current_room_), renderer_, screen_, asset_, options, item_tracker_, &board_.items, false, debug);
const std::string playerPNG = options->cheat.altSkin ? "player2.png" : "player.png";
const std::string playerANI = options->cheat.altSkin ? "player2.ani" : "player.ani";
const player_t player = {spawn_point_, playerPNG, playerANI, renderer_, resource, asset_, options, input_, room_, debug};
room_ = new Room(resource->getRoom(current_room_), renderer_, screen_, asset_, item_tracker_, &board_.items, false, debug);
const std::string playerPNG = options.cheat.altSkin ? "player2.png" : "player.png";
const std::string playerANI = options.cheat.altSkin ? "player2.ani" : "player.ani";
const player_t player = {spawn_point_, playerPNG, playerANI, renderer_, resource, asset_, input_, room_, debug};
this->player_ = new Player(player);
event_handler_ = new SDL_Event();
text_ = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer_);
music_ = JA_LoadMusic(asset_->get("game.ogg").c_str());
death_sound_ = JA_LoadSound(asset_->get("death.wav").c_str());
stats_ = new Stats(asset_->get("stats.csv"), asset_->get("stats_buffer.csv"), options);
stats_ = new Stats(asset_->get("stats.csv"), asset_->get("stats_buffer.csv"));
// Crea la textura para poner el nombre de la habitación
room_name_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, text_->getCharacterSize() * 2);
if (room_name_texture_ == nullptr)
{
if (options->console)
if (options.console)
{
std::cout << "Error: roomNameTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
@@ -92,7 +91,7 @@ Game::Game(Resource *resource, options_t *options, section_t *section, Debug *de
board_.items = 0;
board_.rooms = 1;
board_.music = true;
board_.jailEnabled = options->cheat.jailEnabled;
board_.jailEnabled = options.cheat.jailEnabled;
setScoreBoardColor();
room_tracker_->addRoom(current_room_);
paused_ = false;
@@ -101,11 +100,11 @@ Game::Game(Resource *resource, options_t *options, section_t *section, Debug *de
total_items_ = getTotalItems();
initStats();
stats_->addVisit(room_->getName());
const bool cheats = options->cheat.infiniteLives || options->cheat.invincible || options->cheat.jailEnabled;
const bool cheats = options.cheat.infiniteLives || options.cheat.invincible || options.cheat.jailEnabled;
cheevos_->enable(!cheats); // Deshabilita los logros si hay trucos activados
section->name = SECTION_GAME;
section->subsection = 0;
options.section.name = SECTION_GAME;
options.section.subsection = 0;
}
Game::~Game()
@@ -136,8 +135,8 @@ void Game::checkEvents()
// Evento de salida de la aplicación
if (event_handler_->type == SDL_QUIT)
{
section_->name = SECTION_QUIT;
screen_->setBorderColor(stringToColor(options_->palette, "black"));
options.section.name = SECTION_QUIT;
screen_->setBorderColor(stringToColor(options.palette, "black"));
break;
}
@@ -153,7 +152,7 @@ void Game::checkEvents()
#ifdef DEBUG
case SDL_SCANCODE_G:
debug_->switchEnabled();
options_->cheat.invincible = debug_->getEnabled();
options.cheat.invincible = debug_->getEnabled();
board_.music = !debug_->getEnabled();
board_.music ? JA_ResumeMusic() : JA_PauseMusic();
break;
@@ -206,7 +205,7 @@ void Game::checkInput()
{
if (input_->checkInput(input_exit, REPEAT_FALSE))
{
section_->name = SECTION_TITLE;
options.section.name = SECTION_TITLE;
}
else if (input_->checkInput(input_toggle_music, REPEAT_FALSE))
@@ -264,7 +263,7 @@ void Game::run()
JA_PauseMusic();
}
while (section_->name == SECTION_GAME)
while (options.section.name == SECTION_GAME)
{
update();
checkEvents();
@@ -402,7 +401,7 @@ bool Game::changeRoom(std::string file)
room_ = nullptr;
// Crea un objeto habitación nuevo a partir del fichero
room_ = new Room(resource_->getRoom(file), renderer_, screen_, asset_, options_, item_tracker_, &board_.items, board_.jailEnabled, debug_);
room_ = new Room(resource_->getRoom(file), renderer_, screen_, asset_, item_tracker_, &board_.items, board_.jailEnabled, debug_);
// Pone el nombre de la habitación en la textura
fillRoomNameTexture();
@@ -414,7 +413,7 @@ bool Game::changeRoom(std::string file)
{
// Incrementa el contador de habitaciones visitadas
board_.rooms++;
options_->stats.rooms = board_.rooms;
options.stats.rooms = board_.rooms;
// Actualiza las estadisticas
stats_->addVisit(room_->getName());
@@ -475,20 +474,20 @@ void Game::checkGameOver()
{
if (board_.lives < 0 && black_screen_counter_ > 17)
{
section_->name = SECTION_GAME_OVER;
options.section.name = SECTION_GAME_OVER;
}
}
// Mata al jugador
void Game::killPlayer()
{
if (options_->cheat.invincible)
if (options.cheat.invincible)
{
return;
}
// Resta una vida al jugador
if (!options_->cheat.infiniteLives)
if (!options.cheat.infiniteLives)
{
board_.lives--;
}
@@ -510,10 +509,10 @@ void Game::killPlayer()
setBlackScreen();
// Crea la nueva habitación y el nuevo jugador
room_ = new Room(resource_->getRoom(current_room_), renderer_, screen_, asset_, options_, item_tracker_, &board_.items, board_.jailEnabled, debug_);
const std::string playerPNG = options_->cheat.altSkin ? "player2.png" : "player.png";
const std::string playerANI = options_->cheat.altSkin ? "player2.ani" : "player.ani";
const player_t player = {spawn_point_, playerPNG, playerANI, renderer_, resource_, asset_, options_, input_, room_, debug_};
room_ = new Room(resource_->getRoom(current_room_), renderer_, screen_, asset_, item_tracker_, &board_.items, board_.jailEnabled, debug_);
const std::string playerPNG = options.cheat.altSkin ? "player2.png" : "player.png";
const std::string playerANI = options.cheat.altSkin ? "player2.ani" : "player.ani";
const player_t player = {spawn_point_, playerPNG, playerANI, renderer_, resource_, asset_, input_, room_, debug_};
this->player_ = new Player(player);
// Pone los objetos en pausa mientras esta la habitación en negro
@@ -524,7 +523,7 @@ void Game::killPlayer()
// Recarga todas las texturas
void Game::reLoadTextures()
{
if (options_->console)
if (options.console)
{
std::cout << "** RELOAD REQUESTED" << std::endl;
}
@@ -537,13 +536,13 @@ void Game::reLoadTextures()
// Cambia la paleta
void Game::switchPalette()
{
if (options_->console)
if (options.console)
{
std::cout << "** PALETTE SWITCH REQUESTED" << std::endl;
}
// Modifica la variable
options_->palette = (options_->palette == p_zxspectrum) ? p_zxarne : p_zxspectrum;
options.palette = (options.palette == p_zxspectrum) ? p_zxarne : p_zxspectrum;
// Recarga las paletas
room_->reLoadPalette();
@@ -584,7 +583,7 @@ void Game::renderBlackScreen()
if (black_screen_)
{
screen_->clean();
screen_->setBorderColor(stringToColor(options_->palette, "black"));
screen_->setBorderColor(stringToColor(options.palette, "black"));
}
}
@@ -594,19 +593,19 @@ void Game::setScoreBoardColor()
// Obtiene el color del borde
const color_t colorBorder = room_->getBorderColor();
const bool isBlack = colorAreEqual(colorBorder, stringToColor(options_->palette, "black"));
const bool isBrightBlack = colorAreEqual(colorBorder, stringToColor(options_->palette, "bright_black"));
const bool isBlack = colorAreEqual(colorBorder, stringToColor(options.palette, "black"));
const bool isBrightBlack = colorAreEqual(colorBorder, stringToColor(options.palette, "bright_black"));
// Si el color del borde es negro o negro brillante cambia el texto del marcador a blanco
board_.color = isBlack || isBrightBlack ? stringToColor(options_->palette, "white") : colorBorder;
board_.color = isBlack || isBrightBlack ? stringToColor(options.palette, "white") : colorBorder;
}
// Comprueba si ha finalizado el juego
bool Game::checkEndGame()
{
const bool isOnTheRoom = room_->getName() == "THE JAIL"; // Estar en la habitación que toca
const bool haveTheItems = board_.items >= int(total_items_ * 0.9f) || options_->cheat.jailEnabled; // Con mas del 90% de los items recogidos
const bool isOnTheDoor = player_->getRect().x <= 128; // Y en la ubicación que toca (En la puerta)
const bool isOnTheRoom = room_->getName() == "THE JAIL"; // Estar en la habitación que toca
const bool haveTheItems = board_.items >= int(total_items_ * 0.9f) || options.cheat.jailEnabled; // Con mas del 90% de los items recogidos
const bool isOnTheDoor = player_->getRect().x <= 128; // Y en la ubicación que toca (En la puerta)
if (haveTheItems)
{
@@ -618,7 +617,7 @@ bool Game::checkEndGame()
// Comprueba los logros de completar el juego
checkEndGameCheevos();
section_->name = SECTION_ENDING;
options.section.name = SECTION_ENDING;
return true;
}
@@ -721,7 +720,7 @@ void Game::fillRoomNameTexture()
SDL_SetRenderTarget(renderer_, room_name_texture_);
// Rellena la textura de color
const color_t color = stringToColor(options_->palette, "white");
const color_t color = stringToColor(options.palette, "white");
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF);
SDL_RenderClear(renderer_);