forked from jaildesigner-jailgames/jaildoctors_dilemma
PETA QUE NI EL PEPE KARTS
This commit is contained in:
14
Makefile
14
Makefile
@@ -52,10 +52,10 @@ windows_release:
|
||||
powershell if (Test-Path "$(releaseFolder)") {Remove-Item "$(releaseFolder)" -Recurse -Force}
|
||||
|
||||
macos:
|
||||
clang++ $(source) -std=$(cpp_standard) -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -o "$(executable)"
|
||||
clang++ $(source) -std=$(cpp_standard) -Wall -Os -lSDL2 -framework OpenGL -Wno-deprecated -ffunction-sections -fdata-sections -o "$(executable)"
|
||||
|
||||
macos_debug:
|
||||
clang++ $(source) -D DEBUG -std=$(cpp_standard) -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -o "$(executable)_debug"
|
||||
clang++ $(source) -D DEBUG -std=$(cpp_standard) -Wall -Os -lSDL2 -framework OpenGL -Wno-deprecated -ffunction-sections -fdata-sections -o "$(executable)_debug"
|
||||
|
||||
macos_release:
|
||||
# Remove data and possible data from previous builds
|
||||
@@ -90,7 +90,7 @@ macos_release:
|
||||
ln -s /Applications "$(releaseFolder)"/Applications
|
||||
|
||||
# Build INTEL
|
||||
clang++ $(source) -D MACOS_BUNDLE -std=$(cpp_standard) -Wall -Os -framework SDL2 -F ./Frameworks -ffunction-sections -fdata-sections -o "$(releaseFolder)/$(appName).app/Contents/MacOS/$(executable)" -rpath @executable_path/../Frameworks/ -target x86_64-apple-macos10.12
|
||||
clang++ $(source) -D MACOS_BUNDLE -std=$(cpp_standard) -Wall -Os -framework SDL2 -F ./Frameworks -framework OpenGL -Wno-deprecated -ffunction-sections -fdata-sections -o "$(releaseFolder)/$(appName).app/Contents/MacOS/$(executable)" -rpath @executable_path/../Frameworks/ -target x86_64-apple-macos10.12
|
||||
|
||||
# Build INTEL DMG
|
||||
hdiutil create tmp.dmg -ov -volname "$(appName)" -fs HFS+ -srcfolder "$(releaseFolder)"
|
||||
@@ -98,7 +98,7 @@ macos_release:
|
||||
rm -f tmp.dmg
|
||||
|
||||
# Build APPLE SILICON
|
||||
clang++ $(source) -D MACOS_BUNDLE -std=$(cpp_standard) -Wall -Os -framework SDL2 -F ./Frameworks -ffunction-sections -fdata-sections -o "$(releaseFolder)/$(appName).app/Contents/MacOS/$(executable)" -rpath @executable_path/../Frameworks/ -target arm64-apple-macos11
|
||||
clang++ $(source) -D MACOS_BUNDLE -std=$(cpp_standard) -Wall -Os -framework SDL2 -F ./Frameworks -framework OpenGL -Wno-deprecated -ffunction-sections -fdata-sections -o "$(releaseFolder)/$(appName).app/Contents/MacOS/$(executable)" -rpath @executable_path/../Frameworks/ -target arm64-apple-macos11
|
||||
|
||||
# Build APPLE SILICON DMG
|
||||
hdiutil create tmp.dmg -ov -volname "$(appName)" -fs HFS+ -srcfolder "$(releaseFolder)"
|
||||
@@ -110,11 +110,11 @@ macos_release:
|
||||
rm -rdf "$(releaseFolder)"
|
||||
|
||||
linux:
|
||||
g++ $(source) -std=$(cpp_standard) -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)"
|
||||
g++ $(source) -std=$(cpp_standard) -Wall -Os -lSDL2 -lGL -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)"
|
||||
strip -s -R .comment -R .gnu.version "$(executable)" --strip-unneeded
|
||||
|
||||
linux_debug:
|
||||
g++ $(source) -D DEBUG -std=$(cpp_standard) -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)_debug"
|
||||
g++ $(source) -D DEBUG -std=$(cpp_standard) -Wall -Os -lSDL2 -lGL -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)_debug"
|
||||
strip -s -R .comment -R .gnu.version "$(executable)_debug" --strip-unneeded
|
||||
|
||||
linux_release:
|
||||
@@ -134,7 +134,7 @@ linux_release:
|
||||
rm -f "$(releaseFolder)/data/room/standard.tsx"
|
||||
|
||||
# Build
|
||||
g++ $(source) -std=$(cpp_standard) -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(releaseFolder)/$(executable)"
|
||||
g++ $(source) -std=$(cpp_standard) -Wall -Os -lSDL2 -lGL -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(releaseFolder)/$(executable)"
|
||||
strip -s -R .comment -R .gnu.version "$(releaseFolder)/$(executable)" --strip-unneeded
|
||||
|
||||
# Pack files
|
||||
|
||||
@@ -28,8 +28,8 @@ Credits::Credits(Resource *resource, options_t *options, section_t *section)
|
||||
{
|
||||
// Reserva memoria para los punteros
|
||||
event_handler_ = new SDL_Event();
|
||||
text_ = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer_);
|
||||
sprite_ = new AnimatedSprite(renderer_, resource->getAnimation("shine.ani"));
|
||||
text_ = new Text(resource_->getOffset("smb2.txt"), resource_->getTexture("smb2.png"), renderer_);
|
||||
sprite_ = new AnimatedSprite(renderer_, resource_->getAnimation("shine.ani"));
|
||||
|
||||
// Inicializa variables
|
||||
section->name = SECTION_CREDITS;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
class Debug;
|
||||
|
||||
// Constructor
|
||||
Demo::Demo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section, Debug *debug)
|
||||
Demo::Demo(Resource *resource, options_t *options, section_t *section, Debug *debug)
|
||||
{
|
||||
// Inicia algunas variables
|
||||
board.iniClock = SDL_GetTicks();
|
||||
@@ -31,11 +31,11 @@ Demo::Demo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
|
||||
currentRoom = rooms[roomIndex];
|
||||
|
||||
// Copia los punteros
|
||||
this->renderer = renderer;
|
||||
this->screen = screen;
|
||||
this->resource = resource;
|
||||
this->asset = asset;
|
||||
this->input = input;
|
||||
this->screen = Screen::get();
|
||||
this->renderer = Screen::get()->getRenderer();
|
||||
this->asset = Asset::get();
|
||||
this->input = Input::get();
|
||||
this->options = options;
|
||||
this->section = section;
|
||||
this->debug = debug;
|
||||
|
||||
@@ -77,7 +77,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Demo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section, Debug *debug);
|
||||
Demo(Resource *resource, options_t *options, section_t *section, Debug *debug);
|
||||
|
||||
// Destructor
|
||||
~Demo();
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "resource.h" // Para Resource
|
||||
#include "screen.h" // Para Screen, FILTER_NEAREST, FILTER...
|
||||
#include "utils.h" // Para options_t, section_t, op_notif...
|
||||
#include "notifier.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <pwd.h>
|
||||
@@ -53,15 +54,16 @@ Director::Director(int argc, const char *argv[])
|
||||
#ifdef DEBUG
|
||||
section->name = SECTION_TITLE;
|
||||
#endif
|
||||
|
||||
Asset::init(argv[0]); // Crea el objeto que controla los ficheros de recursos
|
||||
|
||||
// Crea e inicializa las opciones del programa
|
||||
initOptions();
|
||||
|
||||
// Comprueba los parametros del programa
|
||||
checkProgramArguments(argc, argv);
|
||||
|
||||
// Crea el objeto que controla los ficheros de recursos
|
||||
Asset::init(executable_path_);
|
||||
Asset::get()->setVerbose(options->console);
|
||||
|
||||
// Crea la carpeta del sistema donde guardar datos
|
||||
createSystemFolder("jailgames");
|
||||
#ifndef DEBUG
|
||||
@@ -70,9 +72,6 @@ Director::Director(int argc, const char *argv[])
|
||||
createSystemFolder("jailgames/jaildoctors_dilemma_debug");
|
||||
#endif
|
||||
|
||||
// Crea el objeto que controla los ficheros de recursos
|
||||
Asset::get()->setVerbose(options->console);
|
||||
|
||||
// Si falta algún fichero no inicia el programa
|
||||
if (!setFileList())
|
||||
{
|
||||
@@ -91,6 +90,7 @@ Director::Director(int argc, const char *argv[])
|
||||
// Crea los objetos
|
||||
Screen::init(window_, renderer_);
|
||||
Screen::get()->setBorderColor(borderColor);
|
||||
Notifier::init(Asset::get()->get("notify.png"), Asset::get()->get("smb2.png"), Asset::get()->get("smb2.txt"), Asset::get()->get("notify.wav"), options);
|
||||
resource_ = new Resource(options);
|
||||
Input::init(Asset::get()->get("gamecontrollerdb.txt"));
|
||||
initInput();
|
||||
@@ -104,6 +104,10 @@ Director::~Director()
|
||||
saveConfig();
|
||||
|
||||
// Libera la memoria
|
||||
Asset::destroy();
|
||||
Input::destroy();
|
||||
Screen::destroy();
|
||||
Notifier::destroy();
|
||||
delete section;
|
||||
delete options;
|
||||
delete debug_;
|
||||
@@ -416,11 +420,11 @@ void Director::createSystemFolder(const std::string &folder)
|
||||
#elif __APPLE__
|
||||
struct passwd *pw = getpwuid(getuid());
|
||||
const char *homedir = pw->pw_dir;
|
||||
systemFolder = std::string(homedir) + "/Library/Application Support" + "/" + folder;
|
||||
system_folder_ = std::string(homedir) + "/Library/Application Support" + "/" + folder;
|
||||
#elif __linux__
|
||||
struct passwd *pw = getpwuid(getuid());
|
||||
const char *homedir = pw->pw_dir;
|
||||
systemFolder = std::string(homedir) + "/.config/" + folder;
|
||||
system_folder_ = std::string(homedir) + "/.config/" + folder;
|
||||
|
||||
{
|
||||
// Intenta crear ".config", per si no existeix
|
||||
@@ -441,7 +445,7 @@ void Director::createSystemFolder(const std::string &folder)
|
||||
#ifdef _WIN32
|
||||
int ret = mkdir(system_folder_.c_str());
|
||||
#else
|
||||
int ret = mkdir(systemFolder.c_str(), S_IRWXU);
|
||||
int ret = mkdir(system_folder_.c_str(), S_IRWXU);
|
||||
#endif
|
||||
|
||||
if (ret == -1)
|
||||
|
||||
@@ -18,14 +18,14 @@
|
||||
#include "utils.h" // Para color_t, stringToColor, options_t
|
||||
|
||||
// Constructor
|
||||
Ending::Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section)
|
||||
Ending::Ending(Resource *resource, options_t *options, section_t *section)
|
||||
{
|
||||
// Copia los punteros
|
||||
this->renderer = renderer;
|
||||
this->screen = screen;
|
||||
this->screen = Screen::get();
|
||||
this->renderer = Screen::get()->getRenderer();
|
||||
this->resource = resource;
|
||||
this->asset = asset;
|
||||
this->input = input;
|
||||
this->asset = Asset::get();
|
||||
this->input = Input::get();
|
||||
this->options = options;
|
||||
this->section = section;
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section);
|
||||
Ending(Resource *resource, options_t *options, section_t *section);
|
||||
|
||||
// Destructor
|
||||
~Ending();
|
||||
|
||||
@@ -15,14 +15,14 @@
|
||||
#include "utils.h" // for color_t, stringToColor, options_t
|
||||
|
||||
// Constructor
|
||||
Ending2::Ending2(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section)
|
||||
Ending2::Ending2(Resource *resource, options_t *options, section_t *section)
|
||||
{
|
||||
// Copia los punteros
|
||||
this->renderer = renderer;
|
||||
this->screen = screen;
|
||||
this->screen = Screen::get();
|
||||
this->renderer = Screen::get()->getRenderer();
|
||||
this->resource = resource;
|
||||
this->asset = asset;
|
||||
this->input = input;
|
||||
this->asset = Asset::get();
|
||||
this->input = Input::get();
|
||||
this->options = options;
|
||||
this->section = section;
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Ending2(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section);
|
||||
Ending2(Resource *resource, options_t *options, section_t *section);
|
||||
|
||||
// Destructor
|
||||
~Ending2();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -27,38 +27,38 @@ class Game
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
SDL_Event *eventHandler; // Manejador de eventos
|
||||
Screen *screen; // Objeto encargado de manejar el renderizador
|
||||
Room *room; // Objeto encargado de gestionar cada habitación del juego
|
||||
Player *player; // Objeto con el jugador
|
||||
ItemTracker *itemTracker; // Lleva el control de los objetos recogidos
|
||||
RoomTracker *roomTracker; // Lleva el control de las habitaciones visitadas
|
||||
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
|
||||
Input *input; // Objeto pata gestionar la entrada
|
||||
Text *text; // Objeto para los textos del juego
|
||||
ScoreBoard *scoreboard; // Objeto encargado de gestionar el marcador
|
||||
Cheevos *cheevos; // Objeto encargado de gestionar los logros del juego
|
||||
Resource *resource; // Objeto con los recursos
|
||||
Debug *debug; // Objeto para gestionar la información de debug
|
||||
options_t *options; // Puntero a las opciones del juego
|
||||
Stats *stats; // Objeto encargado de gestionar las estadísticas
|
||||
SDL_Texture *roomNameTexture; // Textura para escribir el nombre de la habitación
|
||||
section_t *section; // Seccion actual dentro del juego
|
||||
Screen *screen_; // Objeto encargado de manejar el renderizador
|
||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||
SDL_Event *event_handler_; // Manejador de eventos
|
||||
Room *room_; // Objeto encargado de gestionar cada habitación del juego
|
||||
Player *player_; // Objeto con el jugador
|
||||
ItemTracker *item_tracker_; // Lleva el control de los objetos recogidos
|
||||
RoomTracker *room_tracker_; // Lleva el control de las habitaciones visitadas
|
||||
Asset *asset_; // Objeto con la ruta a todos los ficheros de recursos
|
||||
Input *input_; // Objeto pata gestionar la entrada
|
||||
Text *text_; // Objeto para los textos del juego
|
||||
ScoreBoard *scoreboard_; // Objeto encargado de gestionar el marcador
|
||||
Cheevos *cheevos_; // Objeto encargado de gestionar los logros del juego
|
||||
Resource *resource_; // Objeto con los recursos
|
||||
Debug *debug_; // Objeto para gestionar la información de debug
|
||||
options_t *options_; // Puntero a las opciones del juego
|
||||
Stats *stats_; // Objeto encargado de gestionar las estadísticas
|
||||
SDL_Texture *room_name_texture_; // Textura para escribir el nombre de la habitación
|
||||
section_t *section_; // Seccion actual dentro del juego
|
||||
|
||||
// Variables
|
||||
JA_Music_t *music; // Musica que suena durante el juego
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
std::string currentRoom; // Fichero de la habitación actual
|
||||
playerSpawn_t spawnPoint; // Lugar de la habitación donde aparece el jugador
|
||||
JA_Sound_t *deathSound; // Sonido a reproducir cuando muere el jugador
|
||||
board_t board; // Estructura con los datos del marcador
|
||||
bool paused; // Indica si el juego se encuentra en pausa
|
||||
bool blackScreen; // Indica si la pantalla está en negro. Se utiliza para la muerte del jugador
|
||||
int blackScreenCounter; // Contador para temporizar la pantalla en negro
|
||||
int totalItems; // Cantidad total de items que hay en el mapeado del juego
|
||||
SDL_Rect roomNameRect; // Rectangulo donde pintar la textura con el nombre de la habitación
|
||||
JA_Music_t *music_; // Musica que suena durante el juego
|
||||
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticks_speed_; // Velocidad a la que se repiten los bucles del programa
|
||||
std::string current_room_; // Fichero de la habitación actual
|
||||
playerSpawn_t spawn_point_; // Lugar de la habitación donde aparece el jugador
|
||||
JA_Sound_t *death_sound_; // Sonido a reproducir cuando muere el jugador
|
||||
board_t board_; // Estructura con los datos del marcador
|
||||
bool paused_; // Indica si el juego se encuentra en pausa
|
||||
bool black_screen_; // Indica si la pantalla está en negro. Se utiliza para la muerte del jugador
|
||||
int black_screen_counter_; // Contador para temporizar la pantalla en negro
|
||||
int total_items_; // Cantidad total de items que hay en el mapeado del juego
|
||||
SDL_Rect room_name_rect_; // Rectangulo donde pintar la textura con el nombre de la habitación
|
||||
|
||||
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
||||
void update();
|
||||
@@ -151,7 +151,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Input *input, section_t *section, Debug *debug);
|
||||
Game(Resource *resource, options_t *options, section_t *section, Debug *debug);
|
||||
|
||||
// Destructor
|
||||
~Game();
|
||||
|
||||
@@ -13,14 +13,14 @@
|
||||
#include "texture.h" // Para Texture
|
||||
|
||||
// Constructor
|
||||
GameOver::GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section)
|
||||
GameOver::GameOver(Resource *resource, options_t *options, section_t *section)
|
||||
{
|
||||
// Copia los punteros
|
||||
this->renderer = renderer;
|
||||
this->screen = screen;
|
||||
this->screen = Screen::get();
|
||||
this->renderer = Screen::get()->getRenderer();
|
||||
this->resource = resource;
|
||||
this->asset = asset;
|
||||
this->input = input;
|
||||
this->asset = Asset::get();
|
||||
this->input = Input::get();
|
||||
this->options = options;
|
||||
this->section = section;
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section);
|
||||
GameOver(Resource *resource, options_t *options, section_t *section);
|
||||
|
||||
// Destructor
|
||||
~GameOver();
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
|
||||
// Constructor
|
||||
LoadingScreen::LoadingScreen(Resource *resource, options_t *options, section_t *section)
|
||||
: resource_(resource),
|
||||
screen_(Screen::get()),
|
||||
: screen_(Screen::get()),
|
||||
renderer_(Screen::get()->getRenderer()),
|
||||
resource_(resource),
|
||||
asset_(Asset::get()),
|
||||
input_(Input::get()),
|
||||
options_(options),
|
||||
|
||||
@@ -18,8 +18,8 @@ class LoadingScreen
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||
Screen *screen_; // Objeto encargado de dibujar en pantalla
|
||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||
Resource *resource_; // Objeto con los recursos
|
||||
Asset *asset_; // Objeto con los ficheros de recursos
|
||||
Input *input_; // Objeto pata gestionar la entrada
|
||||
|
||||
@@ -14,9 +14,9 @@ class Asset; // lines 11-11
|
||||
|
||||
// Constructor
|
||||
Logo::Logo(Resource *resource, options_t *options, section_t *section)
|
||||
: resource_(resource),
|
||||
screen_(Screen::get()),
|
||||
: screen_(Screen::get()),
|
||||
renderer_(Screen::get()->getRenderer()),
|
||||
resource_(resource),
|
||||
asset_(Asset::get()),
|
||||
input_(Input::get()),
|
||||
options_(options),
|
||||
@@ -24,8 +24,8 @@ Logo::Logo(Resource *resource, options_t *options, section_t *section)
|
||||
{
|
||||
// Reserva memoria para los punteros
|
||||
event_handler_ = new SDL_Event();
|
||||
jailgames_texture_ = resource->getTexture("jailgames.png");
|
||||
since_1998_texture_ = resource->getTexture("since_1998.png");
|
||||
jailgames_texture_ = resource_->getTexture("jailgames.png");
|
||||
since_1998_texture_ = resource_->getTexture("since_1998.png");
|
||||
since_1998_sprite_ = new Sprite((256 - since_1998_texture_->getWidth()) / 2, 83 + jailgames_texture_->getHeight() + 5, since_1998_texture_->getWidth(), since_1998_texture_->getHeight(), since_1998_texture_, renderer_);
|
||||
since_1998_sprite_->setSpriteClip(0, 0, since_1998_texture_->getWidth(), since_1998_texture_->getHeight());
|
||||
since_1998_texture_->setColor(0, 0, 0);
|
||||
|
||||
@@ -18,8 +18,8 @@ class Logo
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||
Screen *screen_; // Objeto encargado de dibujar en pantalla
|
||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||
Resource *resource_; // Objeto con los recursos
|
||||
Asset *asset_; // Objeto con los ficheros de recursos
|
||||
Input *input_; // Objeto pata gestionar la entrada
|
||||
|
||||
@@ -1,16 +1,38 @@
|
||||
#include "notify.h"
|
||||
#include "notifier.h"
|
||||
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
|
||||
#include <string> // Para basic_string, string, char_traits
|
||||
#include "jail_audio.h" // Para JA_DeleteSound, JA_LoadSound, JA_Pla...
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "text.h" // Para Text
|
||||
#include "texture.h" // Para Texture
|
||||
#include "screen.h"
|
||||
|
||||
// [SINGLETON]
|
||||
Notifier *Notifier::notifier_ = nullptr;
|
||||
|
||||
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||
void Notifier::init(std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile, options_t *options)
|
||||
{
|
||||
Notifier::notifier_ = new Notifier(iconFile, bitmapFile, textFile, soundFile, options);
|
||||
}
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||
void Notifier::destroy()
|
||||
{
|
||||
delete Notifier::notifier_;
|
||||
}
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||
Notifier *Notifier::get()
|
||||
{
|
||||
return Notifier::notifier_;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile, options_t *options)
|
||||
Notifier::Notifier(std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile, options_t *options)
|
||||
{
|
||||
// Inicializa variables
|
||||
this->renderer = renderer;
|
||||
this->renderer = Screen::get()->getRenderer();
|
||||
this->options = options;
|
||||
bgColor = options->notifications.color;
|
||||
waitTime = 300;
|
||||
@@ -23,7 +45,7 @@ Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapF
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Notify::~Notify()
|
||||
Notifier::~Notifier()
|
||||
{
|
||||
// Libera la memoria de los objetos
|
||||
delete textTexture;
|
||||
@@ -39,7 +61,7 @@ Notify::~Notify()
|
||||
}
|
||||
|
||||
// Dibuja las notificaciones por pantalla
|
||||
void Notify::render()
|
||||
void Notifier::render()
|
||||
{
|
||||
for (int i = (int)notifications.size() - 1; i >= 0; --i)
|
||||
{
|
||||
@@ -48,7 +70,7 @@ void Notify::render()
|
||||
}
|
||||
|
||||
// Actualiza el estado de las notificaiones
|
||||
void Notify::update()
|
||||
void Notifier::update()
|
||||
{
|
||||
for (int i = 0; i < (int)notifications.size(); ++i)
|
||||
{
|
||||
@@ -136,7 +158,7 @@ void Notify::update()
|
||||
}
|
||||
|
||||
// Elimina las notificaciones finalizadas
|
||||
void Notify::clearFinishedNotifications()
|
||||
void Notifier::clearFinishedNotifications()
|
||||
{
|
||||
for (int i = (int)notifications.size() - 1; i >= 0; --i)
|
||||
{
|
||||
@@ -150,7 +172,7 @@ void Notify::clearFinishedNotifications()
|
||||
}
|
||||
|
||||
// Muestra una notificación de texto por pantalla;
|
||||
void Notify::showText(std::string text1, std::string text2, int icon)
|
||||
void Notifier::showText(std::string text1, std::string text2, int icon)
|
||||
{
|
||||
// Inicializa variables
|
||||
const int iconSize = 16;
|
||||
@@ -277,7 +299,7 @@ void Notify::showText(std::string text1, std::string text2, int icon)
|
||||
}
|
||||
|
||||
// Indica si hay notificaciones activas
|
||||
bool Notify::active()
|
||||
bool Notifier::active()
|
||||
{
|
||||
if ((int)notifications.size() > 0)
|
||||
{
|
||||
@@ -10,9 +10,12 @@ class Text;
|
||||
class Texture;
|
||||
struct JA_Sound_t;
|
||||
|
||||
class Notify
|
||||
class Notifier
|
||||
{
|
||||
private:
|
||||
// [SINGLETON] Objeto notifier
|
||||
static Notifier *notifier_;
|
||||
|
||||
enum notification_state_e
|
||||
{
|
||||
ns_rising,
|
||||
@@ -63,19 +66,28 @@ private:
|
||||
// Elimina las notificaciones finalizadas
|
||||
void clearFinishedNotifications();
|
||||
|
||||
// Constructor
|
||||
Notifier(std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile, options_t *options);
|
||||
|
||||
// Destructor
|
||||
~Notifier();
|
||||
|
||||
public:
|
||||
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||
static void init(std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile, options_t *options);
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||
static void destroy();
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||
static Notifier *get();
|
||||
|
||||
// Dibuja las notificaciones por pantalla
|
||||
void render();
|
||||
|
||||
// Actualiza el estado de las notificaiones
|
||||
void update();
|
||||
|
||||
// Constructor
|
||||
Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile, options_t *options);
|
||||
|
||||
// Destructor
|
||||
~Notify();
|
||||
|
||||
// Muestra una notificación de texto por pantalla;
|
||||
void showText(std::string text1 = "", std::string text2 = "", int icon = -1);
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <string> // Para basic_string, char_traits, string
|
||||
#include "asset.h" // Para Asset
|
||||
#include "jail_shader.h" // Para init, render
|
||||
#include "notify.h" // Para Notify
|
||||
#include "notifier.h" // Para Notify
|
||||
|
||||
// [SINGLETON]
|
||||
Screen *Screen::screen_ = nullptr;
|
||||
@@ -36,12 +36,8 @@ Screen *Screen::get()
|
||||
// Constructor
|
||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
||||
: window_(window),
|
||||
renderer_(renderer),
|
||||
asset_(Asset::get())
|
||||
renderer_(renderer)
|
||||
{
|
||||
// Crea los objetos
|
||||
notify_ = new Notify(renderer, asset_->get("notify.png"), asset_->get("smb2.png"), asset_->get("smb2.txt"), asset_->get("notify.wav"), options_);
|
||||
|
||||
game_canvas_width_ = options_->gameWidth;
|
||||
game_canvas_height_ = options_->gameHeight;
|
||||
notification_logical_width_ = game_canvas_width_;
|
||||
@@ -77,9 +73,6 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
||||
// Establece el modo de video
|
||||
setVideoMode(options_->videoMode);
|
||||
|
||||
// Inicializa variables
|
||||
notify_active_ = false;
|
||||
|
||||
// Muestra la ventana
|
||||
SDL_ShowWindow(window);
|
||||
}
|
||||
@@ -87,7 +80,6 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
||||
// Destructor
|
||||
Screen::~Screen()
|
||||
{
|
||||
delete notify_;
|
||||
SDL_DestroyTexture(game_canvas_);
|
||||
SDL_DestroyTexture(border_canvas_);
|
||||
}
|
||||
@@ -217,14 +209,11 @@ void Screen::setVideoMode(int videoMode)
|
||||
options_->screen.windowWidth = window_width_;
|
||||
options_->screen.windowHeight = window_height_;
|
||||
|
||||
// Establece el tamaño de las notificaciones
|
||||
setNotificationSize();
|
||||
|
||||
// Reinicia los shaders
|
||||
if (options_->shaders)
|
||||
{
|
||||
const std::string glsl_file = options_->screen.windowHeight == 192 ? "crtpi_192.glsl" : "crtpi_240.glsl";
|
||||
std::ifstream f(asset_->get(glsl_file).c_str());
|
||||
std::ifstream f(Asset::get()->get(glsl_file).c_str());
|
||||
std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
||||
|
||||
if (options_->borderEnabled)
|
||||
@@ -448,46 +437,21 @@ void Screen::renderFX()
|
||||
// Actualiza el notificador
|
||||
void Screen::updateNotifier()
|
||||
{
|
||||
notify_->update();
|
||||
notify_active_ = notify_->active();
|
||||
Notifier::get()->update();
|
||||
}
|
||||
|
||||
// Muestra una notificación de texto por pantalla;
|
||||
void Screen::showNotification(std::string text1, std::string text2, int icon)
|
||||
{
|
||||
notify_->showText(text1, text2, icon);
|
||||
Notifier::get()->showText(text1, text2, icon);
|
||||
}
|
||||
|
||||
// Dibuja las notificaciones
|
||||
void Screen::renderNotifications()
|
||||
{
|
||||
if (notify_active_)
|
||||
if (Notifier::get()->active())
|
||||
{
|
||||
notify_->render();
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el tamaño de las notificaciones
|
||||
void Screen::setNotificationSize()
|
||||
{
|
||||
if (options_->videoMode == 0)
|
||||
{
|
||||
if (options_->windowSize == 3)
|
||||
{
|
||||
notification_logical_width_ = (window_width_ * 3) / 2;
|
||||
notification_logical_height_ = (window_height_ * 3) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
notification_logical_width_ = window_width_ * 2;
|
||||
notification_logical_height_ = window_height_ * 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (options_->videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
|
||||
{
|
||||
notification_logical_width_ = window_width_ / 3;
|
||||
notification_logical_height_ = window_height_ / 3;
|
||||
Notifier::get()->render();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <vector> // Para vector
|
||||
#include "utils.h" // Para color_t
|
||||
class Asset;
|
||||
class Notify;
|
||||
class Notifier;
|
||||
|
||||
constexpr int FILTER_NEAREST = 0;
|
||||
constexpr int FILTER_LINEAR = 1;
|
||||
@@ -22,11 +22,9 @@ private:
|
||||
// Objetos y punteros
|
||||
SDL_Window *window_; // Ventana de la aplicación
|
||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||
Asset *asset_; // Objeto con el listado de recursos
|
||||
SDL_Texture *game_canvas_; // Textura donde se dibuja el juego
|
||||
SDL_Texture *border_canvas_; // Textura donde se dibuja el borde del juego
|
||||
options_t *options_; // Variable con todas las opciones del programa
|
||||
Notify *notify_; // Dibuja notificaciones por pantalla
|
||||
|
||||
// Variables
|
||||
int window_width_; // Ancho de la pantalla o ventana
|
||||
@@ -35,7 +33,6 @@ private:
|
||||
int game_canvas_height_; // Resolución interna del juego. Es el alto de la textura donde se dibuja el juego
|
||||
SDL_Rect dest_; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
|
||||
color_t border_color_; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
||||
bool notify_active_; // Indica si hay notificaciones activas
|
||||
int notification_logical_width_; // Ancho lógico de las notificaciones en relación al tamaño de pantalla
|
||||
int notification_logical_height_; // Alto lógico de las notificaciones en relación al tamaño de pantalla
|
||||
|
||||
@@ -69,9 +66,6 @@ private:
|
||||
// Dibuja las notificaciones
|
||||
void renderNotifications();
|
||||
|
||||
// Establece el tamaño de las notificaciones
|
||||
void setNotificationSize();
|
||||
|
||||
// Copia el gameCanvas en el borderCanvas
|
||||
void gameCanvasToBorderCanvas();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user