PETA QUE NI EL PEPE KARTS
This commit is contained in:
486
source/game.cpp
486
source/game.cpp
@@ -22,52 +22,50 @@
|
||||
#include "utils.h" // for options_t, cheat_t, stringToColor
|
||||
|
||||
// Constructor
|
||||
Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Input *input, section_t *section, Debug *debug)
|
||||
Game::Game(Resource *resource, options_t *options, section_t *section, Debug *debug)
|
||||
: screen_(Screen::get()),
|
||||
renderer_(Screen::get()->getRenderer()),
|
||||
asset_(Asset::get()),
|
||||
input_(Input::get()),
|
||||
resource_(resource),
|
||||
debug_(debug),
|
||||
options_(options),
|
||||
section_(section)
|
||||
{
|
||||
// Copia los punteros
|
||||
this->resource = resource;
|
||||
this->renderer = renderer;
|
||||
this->asset = asset;
|
||||
this->screen = screen;
|
||||
this->input = input;
|
||||
this->debug = debug;
|
||||
this->options = options;
|
||||
this->section = section;
|
||||
|
||||
// Inicia algunas variables
|
||||
board.iniClock = SDL_GetTicks();
|
||||
board_.iniClock = SDL_GetTicks();
|
||||
#ifdef DEBUG
|
||||
currentRoom = "03.room";
|
||||
current_room_ = "03.room";
|
||||
const int x = 25;
|
||||
const int y = 13;
|
||||
spawnPoint = {x * 8, y * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
|
||||
spawn_point_ = {x * 8, y * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
|
||||
debug->setEnabled(false);
|
||||
#else
|
||||
currentRoom = "03.room";
|
||||
current_room_ = "03.room";
|
||||
const int x = 25;
|
||||
const int y = 13;
|
||||
spawnPoint = {x * 8, y * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
|
||||
spawn_point_ = {x * 8, y * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
|
||||
#endif
|
||||
|
||||
// Crea los objetos
|
||||
cheevos = new Cheevos(screen, options, asset->get("cheevos.bin"));
|
||||
scoreboard = new ScoreBoard(renderer, resource, asset, options, &board);
|
||||
itemTracker = new ItemTracker();
|
||||
roomTracker = new RoomTracker();
|
||||
room = new Room(resource->getRoom(currentRoom), renderer, screen, asset, options, itemTracker, &board.items, false, debug);
|
||||
cheevos_ = new Cheevos(screen_, options, asset_->get("cheevos.bin"));
|
||||
scoreboard_ = new ScoreBoard(renderer_, resource, asset_, options, &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 = {spawnPoint, playerPNG, playerANI, renderer, resource, asset, options, input, room, debug};
|
||||
this->player = new Player(player);
|
||||
eventHandler = new SDL_Event();
|
||||
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
|
||||
music = JA_LoadMusic(asset->get("game.ogg").c_str());
|
||||
deathSound = JA_LoadSound(asset->get("death.wav").c_str());
|
||||
stats = new Stats(asset->get("stats.csv"), asset->get("stats_buffer.csv"), options);
|
||||
const player_t player = {spawn_point_, playerPNG, playerANI, renderer_, resource, asset_, options, 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);
|
||||
|
||||
// Crea la textura para poner el nombre de la habitación
|
||||
roomNameTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, text->getCharacterSize() * 2);
|
||||
if (roomNameTexture == nullptr)
|
||||
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)
|
||||
{
|
||||
@@ -76,35 +74,35 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
|
||||
}
|
||||
|
||||
// Establece el blend mode de la textura
|
||||
SDL_SetTextureBlendMode(roomNameTexture, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetTextureBlendMode(room_name_texture_, SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Establece el destino de la textura
|
||||
roomNameRect = {0, PLAY_AREA_HEIGHT, GAMECANVAS_WIDTH, text->getCharacterSize() * 2};
|
||||
room_name_rect_ = {0, PLAY_AREA_HEIGHT, GAMECANVAS_WIDTH, text_->getCharacterSize() * 2};
|
||||
|
||||
// Pone el nombre de la habitación en la textura
|
||||
fillRoomNameTexture();
|
||||
|
||||
// Inicializa el resto de variables
|
||||
ticks = 0;
|
||||
ticksSpeed = 15;
|
||||
board.lives = 9;
|
||||
ticks_ = 0;
|
||||
ticks_speed_ = 15;
|
||||
board_.lives = 9;
|
||||
#ifdef DEBUG
|
||||
board.lives = 9;
|
||||
board_.lives = 9;
|
||||
#endif
|
||||
board.items = 0;
|
||||
board.rooms = 1;
|
||||
board.music = true;
|
||||
board.jailEnabled = options->cheat.jailEnabled;
|
||||
board_.items = 0;
|
||||
board_.rooms = 1;
|
||||
board_.music = true;
|
||||
board_.jailEnabled = options->cheat.jailEnabled;
|
||||
setScoreBoardColor();
|
||||
roomTracker->addRoom(currentRoom);
|
||||
paused = false;
|
||||
blackScreen = false;
|
||||
blackScreenCounter = 0;
|
||||
totalItems = getTotalItems();
|
||||
room_tracker_->addRoom(current_room_);
|
||||
paused_ = false;
|
||||
black_screen_ = false;
|
||||
black_screen_counter_ = 0;
|
||||
total_items_ = getTotalItems();
|
||||
initStats();
|
||||
stats->addVisit(room->getName());
|
||||
stats_->addVisit(room_->getName());
|
||||
const bool cheats = options->cheat.infiniteLives || options->cheat.invincible || options->cheat.jailEnabled;
|
||||
cheevos->enable(!cheats); // Deshabilita los logros si hay trucos activados
|
||||
cheevos_->enable(!cheats); // Deshabilita los logros si hay trucos activados
|
||||
|
||||
section->name = SECTION_GAME;
|
||||
section->subsection = 0;
|
||||
@@ -113,55 +111,55 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
|
||||
Game::~Game()
|
||||
{
|
||||
// Libera la memoria de los objetos
|
||||
delete cheevos;
|
||||
delete scoreboard;
|
||||
delete itemTracker;
|
||||
delete roomTracker;
|
||||
delete room;
|
||||
delete player;
|
||||
delete eventHandler;
|
||||
delete text;
|
||||
delete stats;
|
||||
delete cheevos_;
|
||||
delete scoreboard_;
|
||||
delete item_tracker_;
|
||||
delete room_tracker_;
|
||||
delete room_;
|
||||
delete player_;
|
||||
delete event_handler_;
|
||||
delete text_;
|
||||
delete stats_;
|
||||
|
||||
SDL_DestroyTexture(roomNameTexture);
|
||||
SDL_DestroyTexture(room_name_texture_);
|
||||
|
||||
JA_DeleteMusic(music);
|
||||
JA_DeleteSound(deathSound);
|
||||
JA_DeleteMusic(music_);
|
||||
JA_DeleteSound(death_sound_);
|
||||
}
|
||||
|
||||
// Comprueba los eventos de la cola
|
||||
void Game::checkEvents()
|
||||
{
|
||||
// Comprueba los eventos que hay en la cola
|
||||
while (SDL_PollEvent(eventHandler) != 0)
|
||||
while (SDL_PollEvent(event_handler_) != 0)
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (eventHandler->type == SDL_QUIT)
|
||||
if (event_handler_->type == SDL_QUIT)
|
||||
{
|
||||
section->name = SECTION_QUIT;
|
||||
screen->setBorderColor(stringToColor(options->palette, "black"));
|
||||
section_->name = SECTION_QUIT;
|
||||
screen_->setBorderColor(stringToColor(options_->palette, "black"));
|
||||
break;
|
||||
}
|
||||
|
||||
if (eventHandler->type == SDL_RENDER_DEVICE_RESET || eventHandler->type == SDL_RENDER_TARGETS_RESET)
|
||||
if (event_handler_->type == SDL_RENDER_DEVICE_RESET || event_handler_->type == SDL_RENDER_TARGETS_RESET)
|
||||
{
|
||||
reLoadTextures();
|
||||
}
|
||||
|
||||
if (eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0)
|
||||
if (event_handler_->type == SDL_KEYDOWN && event_handler_->key.repeat == 0)
|
||||
{
|
||||
switch (eventHandler->key.keysym.scancode)
|
||||
switch (event_handler_->key.keysym.scancode)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
case SDL_SCANCODE_G:
|
||||
debug->switchEnabled();
|
||||
options->cheat.invincible = debug->getEnabled();
|
||||
board.music = !debug->getEnabled();
|
||||
board.music ? JA_ResumeMusic() : JA_PauseMusic();
|
||||
debug_->switchEnabled();
|
||||
options_->cheat.invincible = debug_->getEnabled();
|
||||
board_.music = !debug_->getEnabled();
|
||||
board_.music ? JA_ResumeMusic() : JA_PauseMusic();
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_R:
|
||||
resource->reLoad();
|
||||
resource_->reLoad();
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_W:
|
||||
@@ -181,19 +179,19 @@ void Game::checkEvents()
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F6:
|
||||
screen->showNotification("ACHIEVEMENT UNLOCKED!", "I LIKE MY MULTICOLOURED FRIENDS", 2);
|
||||
screen_->showNotification("ACHIEVEMENT UNLOCKED!", "I LIKE MY MULTICOLOURED FRIENDS", 2);
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F7:
|
||||
screen->showNotification("ACHIEVEMENT UNLOCKED!", "I LIKE MY MULTICOLOURED FRIENDS", 3);
|
||||
screen_->showNotification("ACHIEVEMENT UNLOCKED!", "I LIKE MY MULTICOLOURED FRIENDS", 3);
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F8:
|
||||
screen->showNotification("JAILDESIGNER IS LOGGED IN", "", 4);
|
||||
screen_->showNotification("JAILDESIGNER IS LOGGED IN", "", 4);
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F9:
|
||||
screen->showNotification("JAILDESIGNER IS LOGGED IN", "", 5);
|
||||
screen_->showNotification("JAILDESIGNER IS LOGGED IN", "", 5);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
@@ -206,52 +204,52 @@ void Game::checkEvents()
|
||||
// Comprueba el teclado
|
||||
void Game::checkInput()
|
||||
{
|
||||
if (input->checkInput(input_exit, REPEAT_FALSE))
|
||||
if (input_->checkInput(input_exit, REPEAT_FALSE))
|
||||
{
|
||||
section->name = SECTION_TITLE;
|
||||
section_->name = SECTION_TITLE;
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_toggle_music, REPEAT_FALSE))
|
||||
else if (input_->checkInput(input_toggle_music, REPEAT_FALSE))
|
||||
{
|
||||
board.music = !board.music;
|
||||
board.music ? JA_ResumeMusic() : JA_PauseMusic();
|
||||
board_.music = !board_.music;
|
||||
board_.music ? JA_ResumeMusic() : JA_PauseMusic();
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_pause, REPEAT_FALSE))
|
||||
else if (input_->checkInput(input_pause, REPEAT_FALSE))
|
||||
{
|
||||
switchPause();
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_toggle_border, REPEAT_FALSE))
|
||||
else if (input_->checkInput(input_toggle_border, REPEAT_FALSE))
|
||||
{
|
||||
screen->toggleBorder();
|
||||
screen_->toggleBorder();
|
||||
reLoadTextures();
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_toggle_videomode, REPEAT_FALSE))
|
||||
else if (input_->checkInput(input_toggle_videomode, REPEAT_FALSE))
|
||||
{
|
||||
screen->toggleVideoMode();
|
||||
screen_->toggleVideoMode();
|
||||
reLoadTextures();
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_toggle_shaders, REPEAT_FALSE))
|
||||
else if (input_->checkInput(input_toggle_shaders, REPEAT_FALSE))
|
||||
{
|
||||
screen->toggleShaders();
|
||||
screen_->toggleShaders();
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
|
||||
else if (input_->checkInput(input_window_dec_size, REPEAT_FALSE))
|
||||
{
|
||||
screen->decWindowSize();
|
||||
screen_->decWindowSize();
|
||||
reLoadTextures();
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
|
||||
else if (input_->checkInput(input_window_inc_size, REPEAT_FALSE))
|
||||
{
|
||||
screen->incWindowSize();
|
||||
screen_->incWindowSize();
|
||||
reLoadTextures();
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_toggle_palette, REPEAT_FALSE))
|
||||
else if (input_->checkInput(input_toggle_palette, REPEAT_FALSE))
|
||||
{
|
||||
switchPalette();
|
||||
}
|
||||
@@ -260,13 +258,13 @@ void Game::checkInput()
|
||||
// Bucle para el juego
|
||||
void Game::run()
|
||||
{
|
||||
JA_PlayMusic(music);
|
||||
if (!board.music)
|
||||
JA_PlayMusic(music_);
|
||||
if (!board_.music)
|
||||
{
|
||||
JA_PauseMusic();
|
||||
}
|
||||
|
||||
while (section->name == SECTION_GAME)
|
||||
while (section_->name == SECTION_GAME)
|
||||
{
|
||||
update();
|
||||
checkEvents();
|
||||
@@ -280,21 +278,21 @@ void Game::run()
|
||||
void Game::update()
|
||||
{
|
||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||
if (SDL_GetTicks() - ticks > ticksSpeed)
|
||||
if (SDL_GetTicks() - ticks_ > ticks_speed_)
|
||||
{
|
||||
// Actualiza el contador de ticks
|
||||
ticks = SDL_GetTicks();
|
||||
ticks_ = SDL_GetTicks();
|
||||
|
||||
// Comprueba el teclado
|
||||
checkInput();
|
||||
|
||||
#ifdef DEBUG
|
||||
debug->clear();
|
||||
debug_->clear();
|
||||
#endif
|
||||
|
||||
// Actualiza los objetos
|
||||
room->update();
|
||||
player->update();
|
||||
room_->update();
|
||||
player_->update();
|
||||
checkPlayerOnBorder();
|
||||
checkPlayerAndItems();
|
||||
checkPlayerAndEnemies();
|
||||
@@ -303,13 +301,13 @@ void Game::update()
|
||||
checkEndGame();
|
||||
checkRestoringJail();
|
||||
checkSomeCheevos();
|
||||
scoreboard->update();
|
||||
input->update();
|
||||
scoreboard_->update();
|
||||
input_->update();
|
||||
|
||||
updateBlackScreen();
|
||||
|
||||
// Actualiza las notificaciones
|
||||
screen->updateNotifier();
|
||||
screen_->updateNotifier();
|
||||
|
||||
#ifdef DEBUG
|
||||
updateDebugInfo();
|
||||
@@ -321,15 +319,15 @@ void Game::update()
|
||||
void Game::render()
|
||||
{
|
||||
// Prepara para dibujar el frame
|
||||
screen->start();
|
||||
screen_->start();
|
||||
|
||||
// Dibuja los elementos del juego en orden
|
||||
room->renderMap();
|
||||
room->renderEnemies();
|
||||
room->renderItems();
|
||||
player->render();
|
||||
room_->renderMap();
|
||||
room_->renderEnemies();
|
||||
room_->renderItems();
|
||||
player_->render();
|
||||
renderRoomName();
|
||||
scoreboard->render();
|
||||
scoreboard_->render();
|
||||
renderBlackScreen();
|
||||
|
||||
#ifdef DEBUG
|
||||
@@ -338,45 +336,45 @@ void Game::render()
|
||||
#endif
|
||||
|
||||
// Actualiza la pantalla
|
||||
screen->render();
|
||||
screen_->render();
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
// Pasa la información de debug
|
||||
void Game::updateDebugInfo()
|
||||
{
|
||||
debug->add("X = " + std::to_string((int)player->x) + ", Y = " + std::to_string((int)player->y));
|
||||
debug->add("VX = " + std::to_string(player->vx).substr(0, 4) + ", VY = " + std::to_string(player->vy).substr(0, 4));
|
||||
debug->add("STATE = " + std::to_string(player->state));
|
||||
debug_->add("X = " + std::to_string(static_cast<int>(player_->x)) + ", Y = " + std::to_string(static_cast<int>(player_->y)));
|
||||
debug_->add("VX = " + std::to_string(player_->vx).substr(0, 4) + ", VY = " + std::to_string(player_->vy).substr(0, 4));
|
||||
debug_->add("STATE = " + std::to_string(player_->state));
|
||||
}
|
||||
|
||||
// Pone la información de debug en pantalla
|
||||
void Game::renderDebugInfo()
|
||||
{
|
||||
if (!debug->getEnabled())
|
||||
if (!debug_->getEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Borra el marcador
|
||||
SDL_Rect rect = {0, 18 * BLOCK, PLAY_AREA_WIDTH, GAMECANVAS_HEIGHT - PLAY_AREA_HEIGHT};
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 255);
|
||||
SDL_RenderFillRect(renderer_, &rect);
|
||||
|
||||
// Pinta la rejilla
|
||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 32);
|
||||
SDL_SetRenderDrawColor(renderer_, 255, 255, 255, 32);
|
||||
for (int i = 0; i < PLAY_AREA_BOTTOM; i += 8)
|
||||
{ // Lineas horizontales
|
||||
SDL_RenderDrawLine(renderer, 0, i, PLAY_AREA_RIGHT, i);
|
||||
SDL_RenderDrawLine(renderer_, 0, i, PLAY_AREA_RIGHT, i);
|
||||
}
|
||||
for (int i = 0; i < PLAY_AREA_RIGHT; i += 8)
|
||||
{ // Lineas verticales
|
||||
SDL_RenderDrawLine(renderer, i, 0, i, PLAY_AREA_BOTTOM - 1);
|
||||
SDL_RenderDrawLine(renderer_, i, 0, i, PLAY_AREA_BOTTOM - 1);
|
||||
}
|
||||
|
||||
// Pinta el texto
|
||||
debug->setPos({1, 18 * 8});
|
||||
debug->render();
|
||||
debug_->setPos({1, 18 * 8});
|
||||
debug_->render();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -384,7 +382,7 @@ void Game::renderDebugInfo()
|
||||
void Game::renderRoomName()
|
||||
{
|
||||
// Dibuja la textura con el nombre de la habitación
|
||||
SDL_RenderCopy(renderer, roomNameTexture, nullptr, &roomNameRect);
|
||||
SDL_RenderCopy(renderer_, room_name_texture_, nullptr, &room_name_rect_);
|
||||
}
|
||||
|
||||
// Cambia de habitación
|
||||
@@ -397,14 +395,14 @@ bool Game::changeRoom(std::string file)
|
||||
}
|
||||
|
||||
// Verifica que exista el fichero que se va a cargar
|
||||
if (asset->get(file) != "")
|
||||
if (asset_->get(file) != "")
|
||||
{
|
||||
// Elimina la habitación actual
|
||||
delete room;
|
||||
room = nullptr;
|
||||
delete room_;
|
||||
room_ = nullptr;
|
||||
|
||||
// Crea un objeto habitación nuevo a partir del fichero
|
||||
room = new Room(resource->getRoom(file), renderer, screen, asset, options, itemTracker, &board.items, board.jailEnabled, debug);
|
||||
room_ = new Room(resource_->getRoom(file), renderer_, screen_, asset_, options_, item_tracker_, &board_.items, board_.jailEnabled, debug_);
|
||||
|
||||
// Pone el nombre de la habitación en la textura
|
||||
fillRoomNameTexture();
|
||||
@@ -412,18 +410,18 @@ bool Game::changeRoom(std::string file)
|
||||
// Pone el color del marcador en función del color del borde de la habitación
|
||||
setScoreBoardColor();
|
||||
|
||||
if (roomTracker->addRoom(file))
|
||||
if (room_tracker_->addRoom(file))
|
||||
{
|
||||
// Incrementa el contador de habitaciones visitadas
|
||||
board.rooms++;
|
||||
options->stats.rooms = board.rooms;
|
||||
board_.rooms++;
|
||||
options_->stats.rooms = board_.rooms;
|
||||
|
||||
// Actualiza las estadisticas
|
||||
stats->addVisit(room->getName());
|
||||
stats_->addVisit(room_->getName());
|
||||
}
|
||||
|
||||
// Pasa la nueva habitación al jugador
|
||||
player->setRoom(room);
|
||||
player_->setRoom(room_);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -434,14 +432,14 @@ bool Game::changeRoom(std::string file)
|
||||
// Comprueba si el jugador esta en el borde de la pantalla
|
||||
void Game::checkPlayerOnBorder()
|
||||
{
|
||||
if (player->getOnBorder())
|
||||
if (player_->getOnBorder())
|
||||
{
|
||||
const std::string roomName = room->getRoom(player->getBorder());
|
||||
const std::string roomName = room_->getRoom(player_->getBorder());
|
||||
if (changeRoom(roomName))
|
||||
{
|
||||
player->switchBorders();
|
||||
currentRoom = roomName;
|
||||
spawnPoint = player->getSpawnParams();
|
||||
player_->switchBorders();
|
||||
current_room_ = roomName;
|
||||
spawn_point_ = player_->getSpawnParams();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -449,7 +447,7 @@ void Game::checkPlayerOnBorder()
|
||||
// Comprueba las colisiones del jugador con los enemigos
|
||||
bool Game::checkPlayerAndEnemies()
|
||||
{
|
||||
const bool death = room->enemyCollision(player->getCollider());
|
||||
const bool death = room_->enemyCollision(player_->getCollider());
|
||||
if (death)
|
||||
{
|
||||
killPlayer();
|
||||
@@ -460,13 +458,13 @@ bool Game::checkPlayerAndEnemies()
|
||||
// Comprueba las colisiones del jugador con los objetos
|
||||
void Game::checkPlayerAndItems()
|
||||
{
|
||||
room->itemCollision(player->getCollider());
|
||||
room_->itemCollision(player_->getCollider());
|
||||
}
|
||||
|
||||
// Comprueba si el jugador esta vivo
|
||||
void Game::checkIfPlayerIsAlive()
|
||||
{
|
||||
if (!player->isAlive())
|
||||
if (!player_->isAlive())
|
||||
{
|
||||
killPlayer();
|
||||
}
|
||||
@@ -475,82 +473,82 @@ void Game::checkIfPlayerIsAlive()
|
||||
// Comprueba si ha terminado la partida
|
||||
void Game::checkGameOver()
|
||||
{
|
||||
if (board.lives < 0 && blackScreenCounter > 17)
|
||||
if (board_.lives < 0 && black_screen_counter_ > 17)
|
||||
{
|
||||
section->name = SECTION_GAME_OVER;
|
||||
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--;
|
||||
board_.lives--;
|
||||
}
|
||||
|
||||
// Actualiza las estadisticas
|
||||
stats->addDeath(room->getName());
|
||||
stats_->addDeath(room_->getName());
|
||||
|
||||
// Invalida el logro de pasarse el juego sin morir
|
||||
cheevos->invalidate(11);
|
||||
cheevos_->invalidate(11);
|
||||
|
||||
// Destruye la habitacion y el jugador
|
||||
delete room;
|
||||
delete this->player;
|
||||
delete room_;
|
||||
delete this->player_;
|
||||
|
||||
// Sonido
|
||||
JA_PlaySound(deathSound);
|
||||
JA_PlaySound(death_sound_);
|
||||
|
||||
// Pone la pantalla en negro un tiempo
|
||||
setBlackScreen();
|
||||
|
||||
// Crea la nueva habitación y el nuevo jugador
|
||||
room = new Room(resource->getRoom(currentRoom), renderer, screen, asset, options, itemTracker, &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 = {spawnPoint, playerPNG, playerANI, renderer, resource, asset, options, input, room, debug};
|
||||
this->player = new Player(player);
|
||||
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_};
|
||||
this->player_ = new Player(player);
|
||||
|
||||
// Pone los objetos en pausa mientras esta la habitación en negro
|
||||
room->pause();
|
||||
this->player->pause();
|
||||
room_->pause();
|
||||
this->player_->pause();
|
||||
}
|
||||
|
||||
// Recarga todas las texturas
|
||||
void Game::reLoadTextures()
|
||||
{
|
||||
if (options->console)
|
||||
if (options_->console)
|
||||
{
|
||||
std::cout << "** RELOAD REQUESTED" << std::endl;
|
||||
}
|
||||
player->reLoadTexture();
|
||||
room->reLoadTexture();
|
||||
scoreboard->reLoadTexture();
|
||||
text->reLoadTexture();
|
||||
player_->reLoadTexture();
|
||||
room_->reLoadTexture();
|
||||
scoreboard_->reLoadTexture();
|
||||
text_->reLoadTexture();
|
||||
}
|
||||
|
||||
// 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();
|
||||
player->reLoadPalette();
|
||||
scoreboard->reLoadPalette();
|
||||
room_->reLoadPalette();
|
||||
player_->reLoadPalette();
|
||||
scoreboard_->reLoadPalette();
|
||||
|
||||
// Pone el color del marcador en función del color del borde de la habitación
|
||||
setScoreBoardColor();
|
||||
@@ -559,23 +557,23 @@ void Game::switchPalette()
|
||||
// Establece la pantalla en negro
|
||||
void Game::setBlackScreen()
|
||||
{
|
||||
blackScreen = true;
|
||||
black_screen_ = true;
|
||||
}
|
||||
|
||||
// Actualiza las variables relativas a la pantalla en negro
|
||||
void Game::updateBlackScreen()
|
||||
{
|
||||
if (blackScreen)
|
||||
if (black_screen_)
|
||||
{
|
||||
blackScreenCounter++;
|
||||
if (blackScreenCounter > 20)
|
||||
black_screen_counter_++;
|
||||
if (black_screen_counter_ > 20)
|
||||
{
|
||||
blackScreen = false;
|
||||
blackScreenCounter = 0;
|
||||
black_screen_ = false;
|
||||
black_screen_counter_ = 0;
|
||||
|
||||
player->resume();
|
||||
room->resume();
|
||||
screen->setBorderColor(room->getBorderColor());
|
||||
player_->resume();
|
||||
room_->resume();
|
||||
screen_->setBorderColor(room_->getBorderColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -583,10 +581,10 @@ void Game::updateBlackScreen()
|
||||
// Dibuja la pantalla negra
|
||||
void Game::renderBlackScreen()
|
||||
{
|
||||
if (blackScreen)
|
||||
if (black_screen_)
|
||||
{
|
||||
screen->clean();
|
||||
screen->setBorderColor(stringToColor(options->palette, "black"));
|
||||
screen_->clean();
|
||||
screen_->setBorderColor(stringToColor(options_->palette, "black"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -594,25 +592,25 @@ void Game::renderBlackScreen()
|
||||
void Game::setScoreBoardColor()
|
||||
{
|
||||
// Obtiene el color del borde
|
||||
const color_t colorBorder = room->getBorderColor();
|
||||
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(totalItems * 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)
|
||||
{
|
||||
board.jailEnabled = true;
|
||||
board_.jailEnabled = true;
|
||||
}
|
||||
|
||||
if (haveTheItems && isOnTheRoom && isOnTheDoor)
|
||||
@@ -620,7 +618,7 @@ bool Game::checkEndGame()
|
||||
// Comprueba los logros de completar el juego
|
||||
checkEndGameCheevos();
|
||||
|
||||
section->name = SECTION_ENDING;
|
||||
section_->name = SECTION_ENDING;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -632,7 +630,7 @@ int Game::getTotalItems()
|
||||
{
|
||||
int items = 0;
|
||||
std::vector<res_room_t> *rooms = new std::vector<res_room_t>;
|
||||
rooms = resource->getAllRooms();
|
||||
rooms = resource_->getAllRooms();
|
||||
|
||||
for (auto room : *rooms)
|
||||
{
|
||||
@@ -645,43 +643,43 @@ int Game::getTotalItems()
|
||||
// Va a la habitación designada
|
||||
void Game::goToRoom(int border)
|
||||
{
|
||||
const std::string roomName = room->getRoom(border);
|
||||
const std::string roomName = room_->getRoom(border);
|
||||
if (changeRoom(roomName))
|
||||
{
|
||||
currentRoom = roomName;
|
||||
current_room_ = roomName;
|
||||
}
|
||||
}
|
||||
|
||||
// Pone el juego en pausa
|
||||
void Game::switchPause()
|
||||
{
|
||||
if (paused)
|
||||
if (paused_)
|
||||
{
|
||||
player->resume();
|
||||
room->resume();
|
||||
scoreboard->resume();
|
||||
paused = false;
|
||||
player_->resume();
|
||||
room_->resume();
|
||||
scoreboard_->resume();
|
||||
paused_ = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
player->pause();
|
||||
room->pause();
|
||||
scoreboard->pause();
|
||||
paused = true;
|
||||
player_->pause();
|
||||
room_->pause();
|
||||
scoreboard_->pause();
|
||||
paused_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Da vidas al jugador cuando está en la Jail
|
||||
void Game::checkRestoringJail()
|
||||
{
|
||||
if (room->getName() != "THE JAIL" || board.lives == 9)
|
||||
if (room_->getName() != "THE JAIL" || board_.lives == 9)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static int counter = 0;
|
||||
|
||||
if (!paused)
|
||||
if (!paused_)
|
||||
{
|
||||
counter++;
|
||||
}
|
||||
@@ -690,14 +688,14 @@ void Game::checkRestoringJail()
|
||||
if (counter == 100)
|
||||
{
|
||||
counter = 0;
|
||||
board.lives++;
|
||||
JA_PlaySound(deathSound);
|
||||
board_.lives++;
|
||||
JA_PlaySound(death_sound_);
|
||||
|
||||
// Invalida el logro de completar el juego sin entrar a la jail
|
||||
const bool haveTheItems = board.items >= int(totalItems * 0.9f);
|
||||
const bool haveTheItems = board_.items >= int(total_items_ * 0.9f);
|
||||
if (!haveTheItems)
|
||||
{
|
||||
cheevos->invalidate(9);
|
||||
cheevos_->invalidate(9);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -706,76 +704,76 @@ void Game::checkRestoringJail()
|
||||
void Game::initStats()
|
||||
{
|
||||
std::vector<res_room_t> *rooms = new std::vector<res_room_t>;
|
||||
rooms = resource->getAllRooms();
|
||||
rooms = resource_->getAllRooms();
|
||||
|
||||
for (auto room : *rooms)
|
||||
{
|
||||
stats->addDictionary(room.room->number, room.room->name);
|
||||
stats_->addDictionary(room.room->number, room.room->name);
|
||||
}
|
||||
|
||||
stats->init();
|
||||
stats_->init();
|
||||
}
|
||||
|
||||
// Crea la textura con el nombre de la habitación
|
||||
void Game::fillRoomNameTexture()
|
||||
{
|
||||
// Pone la textura como destino de renderizado
|
||||
SDL_SetRenderTarget(renderer, roomNameTexture);
|
||||
SDL_SetRenderTarget(renderer_, room_name_texture_);
|
||||
|
||||
// Rellena la textura de color
|
||||
const color_t color = stringToColor(options->palette, "white");
|
||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
const color_t color = stringToColor(options_->palette, "white");
|
||||
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF);
|
||||
SDL_RenderClear(renderer_);
|
||||
|
||||
// Escribe el texto en la textura
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, text->getCharacterSize() / 2, room->getName(), 1, room->getBGColor());
|
||||
text_->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, text_->getCharacterSize() / 2, room_->getName(), 1, room_->getBGColor());
|
||||
|
||||
// Deja el renderizador por defecto
|
||||
SDL_SetRenderTarget(renderer, nullptr);
|
||||
SDL_SetRenderTarget(renderer_, nullptr);
|
||||
}
|
||||
|
||||
// Comprueba algunos logros
|
||||
void Game::checkSomeCheevos()
|
||||
{
|
||||
// Logros sobre la cantidad de items
|
||||
if (board.items == totalItems)
|
||||
if (board_.items == total_items_)
|
||||
{
|
||||
cheevos->unlock(4);
|
||||
cheevos->unlock(3);
|
||||
cheevos->unlock(2);
|
||||
cheevos->unlock(1);
|
||||
cheevos_->unlock(4);
|
||||
cheevos_->unlock(3);
|
||||
cheevos_->unlock(2);
|
||||
cheevos_->unlock(1);
|
||||
}
|
||||
else if (board.items >= totalItems * 0.75f)
|
||||
else if (board_.items >= total_items_ * 0.75f)
|
||||
{
|
||||
cheevos->unlock(3);
|
||||
cheevos->unlock(2);
|
||||
cheevos->unlock(1);
|
||||
cheevos_->unlock(3);
|
||||
cheevos_->unlock(2);
|
||||
cheevos_->unlock(1);
|
||||
}
|
||||
else if (board.items >= totalItems * 0.5f)
|
||||
else if (board_.items >= total_items_ * 0.5f)
|
||||
{
|
||||
cheevos->unlock(2);
|
||||
cheevos->unlock(1);
|
||||
cheevos_->unlock(2);
|
||||
cheevos_->unlock(1);
|
||||
}
|
||||
else if (board.items >= totalItems * 0.25f)
|
||||
else if (board_.items >= total_items_ * 0.25f)
|
||||
{
|
||||
cheevos->unlock(1);
|
||||
cheevos_->unlock(1);
|
||||
}
|
||||
|
||||
// Logros sobre las habitaciones visitadas
|
||||
if (board.rooms >= 60)
|
||||
if (board_.rooms >= 60)
|
||||
{
|
||||
cheevos->unlock(7);
|
||||
cheevos->unlock(6);
|
||||
cheevos->unlock(5);
|
||||
cheevos_->unlock(7);
|
||||
cheevos_->unlock(6);
|
||||
cheevos_->unlock(5);
|
||||
}
|
||||
else if (board.rooms >= 40)
|
||||
else if (board_.rooms >= 40)
|
||||
{
|
||||
cheevos->unlock(6);
|
||||
cheevos->unlock(5);
|
||||
cheevos_->unlock(6);
|
||||
cheevos_->unlock(5);
|
||||
}
|
||||
else if (board.rooms >= 20)
|
||||
else if (board_.rooms >= 20)
|
||||
{
|
||||
cheevos->unlock(5);
|
||||
cheevos_->unlock(5);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -783,23 +781,23 @@ void Game::checkSomeCheevos()
|
||||
void Game::checkEndGameCheevos()
|
||||
{
|
||||
// "Complete the game"
|
||||
cheevos->unlock(8);
|
||||
cheevos_->unlock(8);
|
||||
|
||||
// "Complete the game without entering the jail"
|
||||
cheevos->unlock(9);
|
||||
cheevos_->unlock(9);
|
||||
|
||||
// "Complete the game with all items"
|
||||
if (board.items == totalItems)
|
||||
if (board_.items == total_items_)
|
||||
{
|
||||
cheevos->unlock(10);
|
||||
cheevos_->unlock(10);
|
||||
}
|
||||
|
||||
// "Complete the game without dying"
|
||||
cheevos->unlock(11);
|
||||
cheevos_->unlock(11);
|
||||
|
||||
// "Complete the game in under 30 minutes"
|
||||
if (scoreboard->getMinutes() < 30)
|
||||
if (scoreboard_->getMinutes() < 30)
|
||||
{
|
||||
cheevos->unlock(12);
|
||||
cheevos_->unlock(12);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user