diff --git a/source/cheevos.cpp b/source/cheevos.cpp index e2d3d12..4783686 100644 --- a/source/cheevos.cpp +++ b/source/cheevos.cpp @@ -1,12 +1,11 @@ #include "cheevos.h" -#include // Para SDL_GetError -#include // Para SDL_RWFromFile, SDL_RWclose, SDL_RWwrite -#include // Para NULL -#include // Para basic_ostream, operator<<, cout, endl -#include "notifier.h" // Para Screen -#include "utils.h" // Para options_t -#include "options.h" -#include // Para fstream +#include // for SDL_GetError +#include // for SDL_RWFromFile, SDL_RWclose, SDL_RWwrite +#include // for NULL +#include // for basic_ostream, operator<<, basic_ofstream +#include // for cout, cerr +#include "notifier.h" // for Notifier +#include "options.h" // for Options, options // [SINGLETON] Cheevos *Cheevos::cheevos_ = nullptr; diff --git a/source/cheevos.h b/source/cheevos.h index 2a69c85..5b4a676 100644 --- a/source/cheevos.h +++ b/source/cheevos.h @@ -1,8 +1,7 @@ #pragma once -#include // Para string -#include // Para vector -class Screen; -struct Options; + +#include // for string +#include // for vector // Struct para los logros struct Achievement diff --git a/source/credits.cpp b/source/credits.cpp index 1c6fcd6..28a977d 100644 --- a/source/credits.cpp +++ b/source/credits.cpp @@ -1,22 +1,22 @@ #include "credits.h" -#include // Para SDL_BLENDMODE_BLEND -#include // Para SDL_GetError -#include // Para SDL_PIXELFORMAT_RGBA8888 -#include // Para SDL_Rect -#include // Para SDL_GetTicks -#include // Para min -#include // Para char_traits, basic_ostream, operator<< -#include "animated_sprite.h" // Para AnimatedSprite -#include "defines.h" // Para GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH -#include "input.h" // Para Input, REPEAT_FALSE, inputs_e -#include "resource.h" // Para Resource -#include "screen.h" // Para Screen -#include "text.h" // Para Text, TXT_CENTER, TXT_COLOR -#include "asset.h" -#include "options.h" -#include "global_inputs.h" -#include "global_events.h" -class Asset; +#include // for SDL_BLENDMODE_BLEND +#include // for SDL_GetError +#include // for SDL_PollEvent, SDL_Event +#include // for SDL_PIXELFORMAT_RGBA8888 +#include // for SDL_Rect +#include // for SDL_GetTicks +#include // for min +#include // for basic_ostream, operator<<, cout, endl +#include "animated_sprite.h" // for AnimatedSprite +#include "asset.h" // for Asset +#include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH +#include "global_events.h" // for check +#include "global_inputs.h" // for check +#include "input.h" // for Input +#include "options.h" // for Options, options, OptionsVideo, Sect... +#include "resource.h" // for Resource +#include "screen.h" // for Screen +#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR // Constructor Credits::Credits() diff --git a/source/credits.h b/source/credits.h index f4c4933..b664a51 100644 --- a/source/credits.h +++ b/source/credits.h @@ -1,18 +1,17 @@ #pragma once -#include // Para SDL_Event -#include // Para SDL_Renderer, SDL_Texture -#include // Para Uint32 -#include // Para basic_string, string -#include // Para vector -#include // Para shared_ptr -#include "utils.h" // Para color_t -class AnimatedSprite; -class Asset; -class Input; -class Resource; -class Screen; -class Text; +#include // for SDL_Texture, SDL_Renderer +#include // for Uint32 +#include // for shared_ptr +#include // for string +#include // for vector +#include "utils.h" // for Color +class AnimatedSprite; // lines 10-10 +class Asset; // lines 11-11 +class Input; // lines 12-12 +class Resource; // lines 13-13 +class Screen; // lines 14-14 +class Text; // lines 15-15 class Credits { diff --git a/source/debug.cpp b/source/debug.cpp index 88abda8..18fd618 100644 --- a/source/debug.cpp +++ b/source/debug.cpp @@ -1,11 +1,9 @@ #include "debug.h" -#include // Para max -#include "asset.h" // Para Asset -#include "text.h" // Para Text -#include "texture.h" // Para Texture -#include "utils.h" -#include "screen.h" -#include "resource.h" +#include // for max +#include "resource.h" // for Resource +#include "screen.h" // for Screen +#include "text.h" // for Text +#include "utils.h" // for Color // [SINGLETON] Debug *Debug::debug_ = nullptr; @@ -36,7 +34,7 @@ Debug::Debug() { // Reserva memoria para los punteros texture_ = Resource::get()->getTexture("debug.png"); - text_ = Resource::get()->getText("debug.txt"); + text_ = Resource::get()->getText("debug"); } // Actualiza las variables diff --git a/source/debug.h b/source/debug.h index 106b029..62fd5e6 100644 --- a/source/debug.h +++ b/source/debug.h @@ -1,14 +1,13 @@ #pragma once -#include // Para SDL_Point -#include // Para SDL_Renderer -#include // Para string -#include // Para vector -#include -class Asset; -class Screen; -class Text; -class Texture; +#include // for SDL_Point +#include // for SDL_Renderer +#include // for shared_ptr +#include // for string +#include // for vector +class Screen; // lines 9-9 +class Text; // lines 10-10 +class Texture; // lines 11-11 // Clase Debug class Debug diff --git a/source/demo.cpp b/source/demo.cpp index 6505dc0..119b2a6 100644 --- a/source/demo.cpp +++ b/source/demo.cpp @@ -1,20 +1,21 @@ #include "demo.h" -#include // Para SDL_Rect -#include // Para SDL_GetTicks -#include // Para basic_ostream, basic_ios, operator<<, cout -#include "asset.h" // Para Asset -#include "defines.h" // Para BLOCK, PLAY_AREA_WIDTH, SECTION_DEMO -#include "input.h" // Para Input, REPEAT_FALSE, inputs_e -#include "item_tracker.h" // Para ItemTracker -#include "resource.h" // Para Resource -#include "room.h" // Para Room -#include "screen.h" // Para Screen -#include "text.h" // Para Text, TXT_CENTER, TXT_COLOR -#include "utils.h" // Para color_t, stringToColor, options_t, secti... -#include "options.h" -#include "debug.h" -#include "global_inputs.h" -#include "global_events.h" +#include // for SDL_PollEvent, SDL_Event +#include // for SDL_Rect +#include // for SDL_GetTicks +#include // for basic_ostream, operator<<, cout, endl +#include "asset.h" // for Asset +#include "debug.h" // for Debug +#include "defines.h" // for BLOCK, PLAY_AREA_WIDTH, GAMECANVAS_CENT... +#include "global_events.h" // for check +#include "global_inputs.h" // for check +#include "input.h" // for Input +#include "item_tracker.h" // for ItemTracker +#include "options.h" // for Options, options, OptionsVideo, Section... +#include "resource.h" // for Resource +#include "room.h" // for Room +#include "screen.h" // for Screen +#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR +#include "utils.h" // for Color, stringToColor, colorAreEqual // Constructor Demo::Demo() @@ -43,7 +44,7 @@ Demo::Demo() itemTracker = std::make_shared(); scoreboard = std::make_shared(&board); room = std::make_shared(resource->getRoom(currentRoom), itemTracker, &board.items, false); - text = resource->getText("smb2.txt"); + text = resource->getText("smb2"); // Inicializa el resto de variables counter = 0; diff --git a/source/demo.h b/source/demo.h index 3ded99b..ee393ce 100644 --- a/source/demo.h +++ b/source/demo.h @@ -1,23 +1,19 @@ #pragma once -#include // Para SDL_Event -#include // Para SDL_Renderer -#include // Para Uint32 -#include // Para string, basic_string -#include // Para vector -#include // Para shared_ptr -#include "scoreboard.h" // Para board_t -#include "room.h" -class Asset; -class Debug; -class Input; -class ItemTracker; -class Resource; -class Room; -class Screen; -class Text; -struct Options; -struct SectionState; +#include // for SDL_Renderer +#include // for Uint32 +#include // for shared_ptr +#include // for string +#include // for vector +#include "scoreboard.h" // for board_t +class Asset; // lines 11-11 +class Debug; // lines 12-12 +class Input; // lines 13-13 +class ItemTracker; // lines 14-14 +class Resource; // lines 15-15 +class Room; // lines 16-16 +class Screen; // lines 17-17 +class Text; // lines 18-18 class Demo { diff --git a/source/director.cpp b/source/director.cpp index 2e261e4..721eb1f 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -1,44 +1,42 @@ #include "director.h" -#include // Para SDL_Init, SDL_Quit, SDL_INIT_E... -#include // Para AUDIO_S16 -#include // Para SDL_BLENDMODE_BLEND -#include // Para SDL_GetError -#include // Para SDL_CONTROLLER_BUTTON_B, SDL_C... -#include // Para SDL_SetHint, SDL_HINT_RENDER_D... -#include // Para SDL_SCANCODE_A, SDL_SCANCODE_E... -#include // Para Uint32 -#include // Para SDL_GetTicks -#include // Para errno, EEXIST, EACCES, ENAMETO... -#include // Para printf, perror -#include // Para strcmp -#include // Para mkdir, stat, S_IRWXU -#include // Para getuid -#include // Para exit, EXIT_FAILURE, srand -#include // Para basic_ofstream, basic_ifstream -#include // Para basic_ostream, operator<<, cout -#include // Para basic_string, operator+, char_... -#include // Para vector -#include // Para std::make_unique -#include "asset.h" // Para Asset, assetType -#include "defines.h" // Para Section::LOGO, Section::TITLE -#include "debug.h" // Para Debug -#include "credits.h" // Para Credits -#include "demo.h" // Para Demo -#include "ending.h" // Para Ending -#include "ending2.h" // Para Ending2 -#include "game.h" // Para Game -#include "game_over.h" // Para GameOver -#include "loading_screen.h" // Para LoadingScreen -#include "logo.h" // Para Logo -#include "title.h" // Para Title -#include "input.h" // Para Input, inputs_e -#include "jail_audio.h" // Para JA_GetMusicState, JA_DeleteMusic -#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" -#include "options.h" -#include "cheevos.h" +#include // for SDL_Init, SDL_Quit, SDL_INIT_EV... +#include // for AUDIO_S16 +#include // for SDL_BLENDMODE_BLEND +#include // for SDL_GetError +#include // for SDL_CONTROLLER_BUTTON_B, SDL_CO... +#include // for SDL_SetHint, SDL_HINT_RENDER_DR... +#include // for SDL_SCANCODE_A, SDL_SCANCODE_ES... +#include // for Uint32 +#include // for SDL_GetTicks +#include // for errno, EEXIST, EACCES, ENAMETOO... +#include // for printf, perror +#include // for strcmp +#include // for mkdir, stat, S_IRWXU +#include // for getuid +#include // for exit, EXIT_FAILURE, srand +#include // for basic_ostream, operator<<, cout +#include // for make_unique, unique_ptr +#include // for operator+, allocator, char_traits +#include "asset.h" // for Asset, AssetType +#include "cheevos.h" // for Cheevos +#include "credits.h" // for Credits +#include "debug.h" // for Debug +#include "defines.h" // for WINDOW_CAPTION, borderColor +#include "demo.h" // for Demo +#include "ending.h" // for Ending +#include "ending2.h" // for Ending2 +#include "game.h" // for Game +#include "game_over.h" // for GameOver +#include "input.h" // for Input, inputs_e +#include "jail_audio.h" // for JA_GetMusicState, JA_DeleteMusic +#include "loading_screen.h" // for LoadingScreen +#include "logo.h" // for Logo +#include "notifier.h" // for Notifier +#include "options.h" // for Options, options, Section, Cheat +#include "resource.h" // for Resource +#include "screen.h" // for Screen +#include "title.h" // for Title +#include "utils.h" // for Color #ifndef _WIN32 #include diff --git a/source/director.h b/source/director.h index dbc4e9b..3c471a6 100644 --- a/source/director.h +++ b/source/director.h @@ -1,16 +1,9 @@ #pragma once -#include // for SDL_Renderer -#include // for SDL_Window -#include // for string -class Asset; // lines 6-6 -class Debug; // lines 8-8 -class Input; // lines 14-14 -class Resource; // lines 17-17 -class Screen; // lines 18-18 -struct JA_Music_t; // lines 20-20 -struct Options; // lines 21-21 -struct SectionState; // lines 22-22 +#include // for SDL_Renderer +#include // for SDL_Window +#include // for string +struct JA_Music_t; // lines 11-11 class Director { diff --git a/source/ending.cpp b/source/ending.cpp index a0e446a..a54ea64 100644 --- a/source/ending.cpp +++ b/source/ending.cpp @@ -1,24 +1,25 @@ #include "ending.h" -#include // Para SDL_BLENDMODE_BLEND -#include // Para SDL_GetError -#include // Para SDL_PIXELFORMAT_RGBA8888 -#include // Para SDL_Rect -#include // Para SDL_GetTicks -#include // Para min -#include // Para basic_ostream, operator<<, basic_ios -#include "asset.h" // Para Asset -#include "defines.h" // Para GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH -#include "input.h" // Para Input, REPEAT_FALSE, inputs_e -#include "jail_audio.h" // Para JA_SetVolume, JA_DeleteMusic, JA_Loa... -#include "resource.h" // Para Resource -#include "screen.h" // Para Screen -#include "sprite.h" // Para Sprite -#include "text.h" // Para Text, TEXT_STROKE -#include "texture.h" // Para Texture -#include "utils.h" // Para color_t, stringToColor, options_t -#include "options.h" -#include "global_inputs.h" -#include "global_events.h" +#include // for SDL_BLENDMODE_BLEND +#include // for SDL_GetError +#include // for SDL_PollEvent, SDL_Event +#include // for SDL_PIXELFORMAT_RGBA8888 +#include // for SDL_Rect +#include // for SDL_GetTicks +#include // for min +#include // for basic_ostream, operator<<, cout, endl +#include "asset.h" // for Asset +#include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH +#include "global_events.h" // for check +#include "global_inputs.h" // for check +#include "input.h" // for Input +#include "jail_audio.h" // for JA_SetVolume, JA_PlayMusic, JA_StopM... +#include "options.h" // for Options, options, OptionsVideo, Sect... +#include "resource.h" // for Resource +#include "screen.h" // for Screen +#include "sprite.h" // for Sprite +#include "text.h" // for Text, TEXT_STROKE +#include "texture.h" // for Texture +#include "utils.h" // for Color, stringToColor, Palette // Constructor Ending::Ending() @@ -29,7 +30,7 @@ Ending::Ending() input(Input::get()) { // Reserva memoria para los punteros a objetos - text = resource->getText("smb2.txt"); + text = resource->getText("smb2"); music = resource->getMusic("ending1.ogg"); // Inicializa variables diff --git a/source/ending.h b/source/ending.h index 70d6f0f..183abaf 100644 --- a/source/ending.h +++ b/source/ending.h @@ -1,21 +1,18 @@ #pragma once -#include // Para SDL_Event -#include // Para SDL_Renderer, SDL_Texture -#include // Para Uint32 -#include // Para basic_string, string -#include // Para vector -#include // Para shared_ptr -class Asset; -class Input; -class Resource; -class Screen; -class Sprite; -class Text; -class Texture; -struct JA_Music_t; -struct Options; -struct SectionState; +#include // for SDL_Renderer, SDL_Texture +#include // for Uint32 +#include // for shared_ptr +#include // for string +#include // for vector +class Asset; // lines 9-9 +class Input; // lines 10-10 +class Resource; // lines 11-11 +class Screen; // lines 12-12 +class Sprite; // lines 13-13 +class Text; // lines 14-14 +class Texture; // lines 15-15 +struct JA_Music_t; // lines 16-16 class Ending { diff --git a/source/ending2.cpp b/source/ending2.cpp index 409bf5d..3c8d42d 100644 --- a/source/ending2.cpp +++ b/source/ending2.cpp @@ -1,21 +1,23 @@ #include "ending2.h" -#include // for SDL_BLENDMODE_BLEND -#include // for SDL_GetTicks -#include // for max, min, replace -#include "animated_sprite.h" // for AnimatedSprite -#include "asset.h" // for Asset -#include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_CENTER_X -#include "input.h" // for Input, REPEAT_FALSE, inputs_e -#include "jail_audio.h" // for JA_SetVolume, JA_DeleteMusic, JA_Loa... -#include "moving_sprite.h" // for MovingSprite -#include "resource.h" // for Resource -#include "screen.h" // for Screen -#include "text.h" // for Text -#include "texture.h" // for Texture -#include "utils.h" // for color_t, stringToColor, options_t -#include "options.h" -#include "global_inputs.h" -#include "global_events.h" +#include // for SDL_BLENDMODE_BLEND +#include // for SDL_PollEvent, SDL_Event +#include // for SDL_Rect +#include // for SDL_GetTicks +#include // for max, min, replace +#include "animated_sprite.h" // for AnimatedSprite +#include "asset.h" // for Asset +#include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_CENTER_X +#include "global_events.h" // for check +#include "global_inputs.h" // for check +#include "input.h" // for Input +#include "jail_audio.h" // for JA_SetVolume, JA_PlayMusic, JA_StopM... +#include "moving_sprite.h" // for MovingSprite +#include "options.h" // for Options, options, OptionsVideo, Sect... +#include "resource.h" // for Resource +#include "screen.h" // for Screen +#include "text.h" // for Text +#include "texture.h" // for Texture +#include "utils.h" // for Color, stringToColor // Constructor Ending2::Ending2() @@ -26,7 +28,7 @@ Ending2::Ending2() input(Input::get()) { // Reserva memoria para los punteros a objetos - text = resource->getText("smb2.txt"); + text = resource->getText("smb2"); music = resource->getMusic("ending2.ogg"); // Inicializa variables diff --git a/source/ending2.h b/source/ending2.h index 7216b11..691b6e3 100644 --- a/source/ending2.h +++ b/source/ending2.h @@ -1,22 +1,19 @@ #pragma once -#include // for SDL_Event -#include // for SDL_Renderer -#include // for Uint32 -#include // for string -#include // for vector -#include // for shared_ptr -class AnimatedSprite; // lines 9-9 -class Asset; // lines 10-10 -class Input; // lines 11-11 -class MovingSprite; // lines 12-12 -class Resource; // lines 13-13 -class Screen; // lines 14-14 -class Text; // lines 15-15 -struct JA_Music_t; // lines 16-16 -struct Color; -struct Options; -struct SectionState; +#include // for SDL_Renderer +#include // for Uint32 +#include // for shared_ptr +#include // for string +#include // for vector +#include "utils.h" // for Color +class AnimatedSprite; // lines 9-9 +class Asset; // lines 10-10 +class Input; // lines 11-11 +class MovingSprite; // lines 12-12 +class Resource; // lines 13-13 +class Screen; // lines 14-14 +class Text; // lines 15-15 +struct JA_Music_t; // lines 16-16 class Ending2 { diff --git a/source/enemy.cpp b/source/enemy.cpp index 710c87d..c7aa052 100644 --- a/source/enemy.cpp +++ b/source/enemy.cpp @@ -1,11 +1,10 @@ #include "enemy.h" -#include -#include // Para rand -#include // Para min -#include "animated_sprite.h" // Para AnimatedSprite -#include "texture.h" // Para Texture -#include "resource.h" // Para Resource -#include "options.h" // Para options +#include // for SDL_RendererFlip, SDL_FLIP_NONE, SDL_FL... +#include // for rand +#include "animated_sprite.h" // for AnimatedSprite +#include "options.h" // for Options, OptionsVideo, options +#include "resource.h" // for Resource +#include "texture.h" // for Texture // Constructor Enemy::Enemy(EnemyData enemy) diff --git a/source/enemy.h b/source/enemy.h index 135d429..1a71808 100644 --- a/source/enemy.h +++ b/source/enemy.h @@ -1,11 +1,10 @@ #pragma once -#include // Para SDL_Rect -#include // Para SDL_Renderer -#include // Para basic_string, string -#include "utils.h" // Para palette_e, color_t -#include // Para shared_ptr -#include "animated_sprite.h" // Para AnimatedSprite +#include // for SDL_Rect +#include // for shared_ptr +#include // for string +#include "utils.h" // for Color +class AnimatedSprite; // Estructura para pasar los datos de un enemigo struct EnemyData diff --git a/source/game.cpp b/source/game.cpp index 0f00c73..1d5e1d0 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -59,7 +59,7 @@ Game::Game() const std::string playerANI = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani"; const player_t player = {spawn_point_, playerPNG, playerANI, room_}; player_ = std::make_shared(player); - text_ = resource_->getText("smb2.txt"); + text_ = resource_->getText("smb2"); music_ = resource_->getMusic("game.ogg"); death_sound_ = JA_LoadSound(asset_->get("death.wav").c_str()); stats_ = std::make_shared(asset_->get("stats.csv"), asset_->get("stats_buffer.csv")); @@ -155,19 +155,19 @@ void Game::checkEvents() break; case SDL_SCANCODE_F6: - Notifier::get()->show("ACHIEVEMENT UNLOCKED!", "I LIKE MY MULTICOLOURED FRIENDS", 2); + Notifier::get()->show({"ACHIEVEMENT UNLOCKED!", "I LIKE MY MULTICOLOURED FRIENDS"}, 2); break; case SDL_SCANCODE_F7: - Notifier::get()->show("ACHIEVEMENT UNLOCKED!", "I LIKE MY MULTICOLOURED FRIENDS", 3); + Notifier::get()->show({"ACHIEVEMENT UNLOCKED!", "I LIKE MY MULTICOLOURED FRIENDS"}, 3); break; case SDL_SCANCODE_F8: - Notifier::get()->show("JAILDESIGNER IS LOGGED IN", "", 4); + Notifier::get()->show({"JAILDESIGNER IS LOGGED IN", ""}, 4); break; case SDL_SCANCODE_F9: - Notifier::get()->show("JAILDESIGNER IS LOGGED IN", "", 5); + Notifier::get()->show({"JAILDESIGNER IS LOGGED IN", ""}, 5); break; default: break; diff --git a/source/game_over.cpp b/source/game_over.cpp index 2764a46..123d5c0 100644 --- a/source/game_over.cpp +++ b/source/game_over.cpp @@ -1,19 +1,20 @@ #include "game_over.h" -#include // Para SDL_GetTicks -#include // Para min, max -#include // Para basic_string, operator+, to_string, char... -#include "animated_sprite.h" // Para AnimatedSprite -#include "asset.h" // Para Asset -#include "defines.h" // Para GAMECANVAS_CENTER_X, SECTION_GAME_OVER -#include "input.h" // Para Input, REPEAT_FALSE, inputs_e -#include "jail_audio.h" // Para JA_DeleteMusic, JA_LoadMusic, JA_PlayMusic -#include "resource.h" // Para Resource -#include "screen.h" // Para Screen -#include "text.h" // Para Text, TEXT_CENTER, TEXT_COLOR -#include "texture.h" // Para Texture -#include "options.h" -#include "global_inputs.h" -#include "global_events.h" +#include // for SDL_PollEvent, SDL_Event +#include // for SDL_GetTicks +#include // for min, max +#include // for basic_string, operator+, to_string, cha... +#include "animated_sprite.h" // for AnimatedSprite +#include "asset.h" // for Asset +#include "defines.h" // for GAMECANVAS_CENTER_X +#include "global_events.h" // for check +#include "global_inputs.h" // for check +#include "input.h" // for Input +#include "jail_audio.h" // for JA_PlayMusic +#include "options.h" // for Options, options, OptionsStats, Section... +#include "resource.h" // for Resource +#include "screen.h" // for Screen +#include "text.h" // for TEXT_CENTER, TEXT_COLOR, Text +#include "texture.h" // for Texture // Constructor GameOver::GameOver() @@ -24,7 +25,7 @@ GameOver::GameOver() input(Input::get()) { // Reserva memoria para los punteros a objetos - text = resource->getText("smb2.txt"); + text = resource->getText("smb2"); playerSprite = std::make_shared(resource->getTexture("player_game_over.png"), resource->getAnimation("player_game_over.ani")); tvSprite = std::make_shared(resource->getTexture("tv.png"), resource->getAnimation("tv.ani")); music = resource->getMusic("game_over.ogg"); diff --git a/source/game_over.h b/source/game_over.h index d100c6f..5cf43e6 100644 --- a/source/game_over.h +++ b/source/game_over.h @@ -1,18 +1,17 @@ #pragma once -#include // Para SDL_Event -#include // Para SDL_Renderer -#include // Para Uint32 -#include // Para vector -#include "utils.h" // Para color_t -#include // Para shared_ptr -class AnimatedSprite; -class Asset; -class Input; -class Resource; -class Screen; -class Text; -struct JA_Music_t; +#include // for SDL_Renderer +#include // for Uint32 +#include // for shared_ptr +#include // for vector +#include "utils.h" // for Color +class AnimatedSprite; // lines 9-9 +class Asset; // lines 10-10 +class Input; // lines 11-11 +class Resource; // lines 12-12 +class Screen; // lines 13-13 +class Text; // lines 14-14 +struct JA_Music_t; // lines 15-15 class GameOver { diff --git a/source/global_inputs.cpp b/source/global_inputs.cpp index 8ff0967..f3327e1 100644 --- a/source/global_inputs.cpp +++ b/source/global_inputs.cpp @@ -1,8 +1,11 @@ #include "global_inputs.h" -#include "input.h" // Para Input, InputDeviceToUse, InputType, INPU... -#include "notifier.h" // Para Notifier -#include "options.h" // Para Options, options, OptionsGame, OptionsAudio -#include "screen.h" // Para Screen, ScreenVideoMode +#include // for basic_string +#include // for vector +#include "input.h" // for Input, REPEAT_FALSE, inputs_e +#include "notifier.h" // for Notifier +#include "options.h" // for Section, Options, options, SectionState, Optio... +#include "screen.h" // for Screen +#include "utils.h" // for Palette namespace globalInputs { diff --git a/source/item.h b/source/item.h index fb51e13..88ac3de 100644 --- a/source/item.h +++ b/source/item.h @@ -1,14 +1,13 @@ #pragma once -#include // Para SDL_Rect, SDL_Point -#include // Para SDL_Renderer -#include // Para basic_string, string -#include // Para vector -#include "utils.h" // Para color_t -#include // Para shared_ptr -#include "sprite.h" -#include "texture.h" -class Texture; +#include // for SDL_Rect, SDL_Point +#include // for SDL_Renderer +#include // for shared_ptr, __shared_ptr_access +#include // for string +#include // for vector +#include "sprite.h" // for Sprite +#include "texture.h" // for Texture +#include "utils.h" // for Color struct item_t { diff --git a/source/jail_audio.h b/source/jail_audio.h index cbb73ef..00327d3 100644 --- a/source/jail_audio.h +++ b/source/jail_audio.h @@ -1,9 +1,9 @@ #pragma once -#include // for SDL_AudioFormat -#include // for Uint32, Uint8 -struct JA_Music_t; // lines 8-8 -struct JA_Sound_t; // lines 7-7 +#include // for SDL_AudioFormat +#include // for Uint32, Uint8 +struct JA_Music_t; // lines 5-5 +struct JA_Sound_t; // lines 6-6 enum JA_Channel_state { diff --git a/source/loading_screen.cpp b/source/loading_screen.cpp index 597f481..bda12e9 100644 --- a/source/loading_screen.cpp +++ b/source/loading_screen.cpp @@ -1,18 +1,19 @@ #include "loading_screen.h" -#include // for SDL_GetTicks -#include // for rand -#include "asset.h" // for Asset -#include "defines.h" // for SECTION_LOADING_SCREEN, SECTION_QUIT -#include "input.h" // for Input, REPEAT_FALSE, inputs_e -#include "jail_audio.h" // for JA_DeleteMusic, JA_LoadMusic, JA_PlayMusic -#include "resource.h" // for Resource -#include "screen.h" // for Screen -#include "sprite.h" // for Sprite -#include "texture.h" // for Texture -#include "utils.h" // for options_t, section_t, color_t, stringToC... -#include "options.h" -#include "global_inputs.h" -#include "global_events.h" +#include // for SDL_PollEvent, SDL_Event +#include // for SDL_GetTicks +#include // for rand +#include "asset.h" // for Asset +#include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH +#include "global_events.h" // for check +#include "global_inputs.h" // for check +#include "input.h" // for Input +#include "jail_audio.h" // for JA_PlayMusic, JA_SetVolume, JA_StopMusic +#include "options.h" // for Options, options, OptionsVideo, Section... +#include "resource.h" // for Resource +#include "screen.h" // for Screen +#include "sprite.h" // for Sprite +#include "texture.h" // for Texture +#include "utils.h" // for Color, stringToColor, Palette // Constructor LoadingScreen::LoadingScreen() @@ -66,6 +67,12 @@ LoadingScreen::LoadingScreen() screen_->setBorderColor(stringToColor(options.video.palette, "black")); } +// Destructor +LoadingScreen::~LoadingScreen() +{ + JA_StopMusic(); +} + // Comprueba el manejador de eventos void LoadingScreen::checkEvents() { @@ -88,7 +95,7 @@ void LoadingScreen::updateLoad() // Primera parte de la carga, la parte en blanco y negro if (loading_first_part_) { - // Cada 5 pasos el loadCounter se incrementa en uno + // Cada 5 pasos el load_counter_ se incrementa en uno const int numSteps = 5; const int step = 51; load_counter_ = counter_ / numSteps; @@ -182,18 +189,10 @@ void LoadingScreen::update() // Comprueba que la diferencia de ticks sea mayor a la velocidad del juego if (SDL_GetTicks() - ticks_ > ticks_speed_) { - // Actualiza el contador de ticks ticks_ = SDL_GetTicks(); - - // Comprueba las entradas checkInput(); - - // Gestiona el contador interno updateCounter(); - - // Gestiona el contador de carga updateLoad(); - screen_->update(); } } diff --git a/source/loading_screen.h b/source/loading_screen.h index da82997..a0ae66d 100644 --- a/source/loading_screen.h +++ b/source/loading_screen.h @@ -1,19 +1,16 @@ #pragma once -#include // Para SDL_Event -#include // Para SDL_Rect -#include // Para SDL_Renderer -#include // Para Uint32 -#include // Para shared_ptr -class Asset; -class Input; -class Resource; -class Screen; -class Sprite; -class Texture; -struct JA_Music_t; -struct Options; -struct SectionState; +#include // for SDL_Rect +#include // for SDL_Renderer +#include // for Uint32 +#include // for shared_ptr +class Asset; // lines 8-8 +class Input; // lines 9-9 +class Resource; // lines 10-10 +class Screen; // lines 11-11 +class Sprite; // lines 12-12 +class Texture; // lines 13-13 +struct JA_Music_t; // lines 14-14 class LoadingScreen { @@ -74,7 +71,7 @@ public: LoadingScreen(); // Destructor - ~LoadingScreen() = default; + ~LoadingScreen(); // Bucle principal void run(); diff --git a/source/logo.cpp b/source/logo.cpp index 0faded0..609173c 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -1,19 +1,18 @@ #include "logo.h" -#include // for SDL_GetTicks -#include // for basic_string, string -#include "defines.h" // for SECTION_LOGO, SECTION_TITLE, SUBSECTION_... -#include "input.h" // for Input, REPEAT_FALSE, inputs_e -#include "jail_audio.h" // for JA_StopMusic -#include "resource.h" // for Resource -#include "screen.h" // for Screen -#include "sprite.h" // for Sprite -#include "texture.h" // for Texture -#include "utils.h" // for color_t, section_t, options_t, stringToC... -#include "asset.h" -#include "options.h" -#include "global_inputs.h" -#include "global_events.h" -class Asset; // lines 11-11 +#include // for SDL_PollEvent, SDL_Event +#include // for SDL_GetTicks +#include // for basic_string, string +#include "asset.h" // for Asset +#include "global_events.h" // for check +#include "global_inputs.h" // for check +#include "input.h" // for Input +#include "jail_audio.h" // for JA_StopMusic +#include "options.h" // for Options, options, SectionState, Section +#include "resource.h" // for Resource +#include "screen.h" // for Screen +#include "sprite.h" // for Sprite +#include "texture.h" // for Texture +#include "utils.h" // for Color, stringToColor // Constructor Logo::Logo() diff --git a/source/logo.h b/source/logo.h index 2a91bdd..8493a53 100644 --- a/source/logo.h +++ b/source/logo.h @@ -1,19 +1,16 @@ #pragma once -#include // for SDL_Event -#include // for SDL_Renderer -#include // for Uint32 -#include // for vector -#include // for shared_ptr -class Asset; // lines 8-8 -class Input; // lines 9-9 -class Resource; // lines 10-10 -class Screen; // lines 11-11 -class Sprite; // lines 12-12 -class Texture; // lines 13-13 -struct Color; -struct Options; -struct SectionState; +#include // for SDL_Renderer +#include // for Uint32 +#include // for shared_ptr +#include // for vector +#include "utils.h" // for Color +class Asset; // lines 8-8 +class Input; // lines 9-9 +class Resource; // lines 10-10 +class Screen; // lines 11-11 +class Sprite; // lines 12-12 +class Texture; // lines 13-13 class Logo { diff --git a/source/moving_sprite.cpp b/source/moving_sprite.cpp index 067cf43..5becf1b 100644 --- a/source/moving_sprite.cpp +++ b/source/moving_sprite.cpp @@ -1,6 +1,5 @@ #include "moving_sprite.h" -#include // Para max -#include "texture.h" // Para Texture +#include "texture.h" // for Texture // Constructor MovingSprite::MovingSprite(std::shared_ptr texture, SDL_Rect pos, Rotate rotate, float zoom_w, float zoom_h, SDL_RendererFlip flip) diff --git a/source/moving_sprite.h b/source/moving_sprite.h index 52e7408..3d99e8b 100644 --- a/source/moving_sprite.h +++ b/source/moving_sprite.h @@ -1,12 +1,11 @@ #pragma once -#include // Para SDL_Rect, SDL_Point -#include // Para SDL_RendererFlip -#include // Para shared_ptr -#include "sprite.h" // Para Sprite -#include -#include -class Texture; // lines 8-8 +#include // for SDL_Rect, SDL_Point +#include // for SDL_RendererFlip, SDL_FLIP_HORIZONTAL +#include // for max +#include // for shared_ptr +#include "sprite.h" // for Sprite +class Texture; // lines 9-9 // Clase MovingSprite. Añade movimiento y efectos de rotación, zoom y flip al sprite class MovingSprite : public Sprite diff --git a/source/options.cpp b/source/options.cpp index 2da12be..c74ebfd 100644 --- a/source/options.cpp +++ b/source/options.cpp @@ -1,10 +1,10 @@ #include "options.h" -#include "defines.h" -#include "screen.h" -#include // Para basic_ofstream, basic_ifstream -#include // Para basic_ostream, operator<<, cout -#include // Para unordered_map -#include // Para std::function +#include // for SDL_WINDOW_FULLSCREEN, SDL_WINDOW_FULLSC... +#include // for basic_ostream, operator<<, basic_ofstream +#include // for function +#include // for cout, cerr +#include // for unordered_map, operator==, _Node_const_i... +#include // for pair // Variables Options options; diff --git a/source/options.h b/source/options.h index f21d6e9..b5683e0 100644 --- a/source/options.h +++ b/source/options.h @@ -1,10 +1,9 @@ #pragma once -#include // Para SDL_Rect, SDL_Point -#include // Para Uint8, Uint32 -#include // Para string, basic_string -#include "utils.h" -#include "screen.h" +#include // for Uint32 +#include // for string, basic_string +#include "screen.h" // for ScreenFilter +#include "utils.h" // for Color, Palette // Secciones del programa enum class Section diff --git a/source/player.cpp b/source/player.cpp index 482f4d4..5f437b4 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -123,8 +123,8 @@ void Player::render() { // Pinta los underfeet SDL_SetRenderDrawColor(renderer_, 255, 0, 255, 255); - SDL_RenderDrawPoint(renderer_, underFeet[0].x, underFeet[0].y); - SDL_RenderDrawPoint(renderer_, underFeet[1].x, underFeet[1].y); + SDL_RenderDrawPoint(renderer_, under_feet_[0].x, under_feet_[0].y); + SDL_RenderDrawPoint(renderer_, under_feet_[1].x, under_feet_[1].y); // Pinta rectangulo del jugador SDL_SetRenderDrawColor(renderer_, debugColor.r, debugColor.g, debugColor.b, 192); @@ -135,11 +135,11 @@ void Player::render() // Pinta el rectangulo de movimiento SDL_SetRenderDrawColor(renderer_, 255, 0, 0, 255); - if (vx != 0.0f) + if (vx_ != 0.0f) { SDL_RenderFillRect(renderer_, &rx); } - if (vy != 0.0f) + if (vy_ != 0.0f) { SDL_RenderFillRect(renderer_, &ry); } @@ -177,7 +177,8 @@ void Player::checkInput() } if (!auto_movement_) - { // Comprueba las entradas de desplazamiento lateral solo en el caso de no estar enganchado a una superficie automatica + { + // Comprueba las entradas de desplazamiento lateral solo en el caso de no estar enganchado a una superficie automatica if (input_->checkInput(input_left)) { vx_ = -0.6f; @@ -675,12 +676,12 @@ bool Player::isOnFloor() if (onSlopeL) { - debug_->add("ON_SLOPE_L: " + std::to_string(underFeet[0].x) + "," + std::to_string(underFeet[0].y)); + debug_->add("ON_SLOPE_L: " + std::to_string(under_feet_[0].x) + "," + std::to_string(under_feet_[0].y)); } if (onSlopeR) { - debug_->add("ON_SLOPE_R: " + std::to_string(underFeet[1].x) + "," + std::to_string(underFeet[1].y)); + debug_->add("ON_SLOPE_R: " + std::to_string(under_feet_[1].x) + "," + std::to_string(under_feet_[1].y)); } #endif diff --git a/source/resource.cpp b/source/resource.cpp index 62cd325..d528900 100644 --- a/source/resource.cpp +++ b/source/resource.cpp @@ -1,14 +1,14 @@ #include "resource.h" -#include // Para find_if -#include // Para basic_ostream, operator<<, endl, cout, cerr -#include // Para runtime_error -#include // Para pair -#include "asset.h" // Para Asset, AssetType -#include "jail_audio.h" // Para JA_LoadMusic, JA_LoadSound -#include "screen.h" // Para Screen -#include "text.h" // Para Text, loadTextFile -struct JA_Music_t; // lines 10-10 -struct JA_Sound_t; // lines 11-11 +#include // for find_if +#include // for basic_ostream, operator<<, endl, cout, cerr +#include // for runtime_error +#include "asset.h" // for Asset, AssetType +#include "jail_audio.h" // for JA_DeleteMusic, JA_DeleteSound, JA_LoadMusic +#include "screen.h" // for Screen +#include "text.h" // for Text, loadTextFile +#include "utils.h" // for getFileName, printWithDots +struct JA_Music_t; // lines 10-10 +struct JA_Sound_t; // lines 11-11 // [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado Resource *Resource::resource_ = nullptr; @@ -140,7 +140,7 @@ std::shared_ptr Resource::getText(const std::string &name) } std::cerr << "Error: Text no encontrado " << name << std::endl; - throw std::runtime_error("Text no encontrado: " + name); + throw std::runtime_error("Texto no encontrado: " + name); } // Obtiene la animación a partir de un nombre diff --git a/source/resource.h b/source/resource.h index 3412930..38a5a88 100644 --- a/source/resource.h +++ b/source/resource.h @@ -1,15 +1,14 @@ #pragma once -#include // Para shared_ptr -#include // Para string -#include // Para vector -#include "animated_sprite.h" // Para AnimationsFileBuffer -#include "text.h" // Para TextFile -#include "texture.h" // Para Texture -#include "utils.h" // Para DemoData -#include "room.h" -struct JA_Music_t; -struct JA_Sound_t; +#include // for shared_ptr +#include // for string +#include // for vector +#include "animated_sprite.h" // for AnimationsFileBuffer +#include "room.h" // for room_t +#include "text.h" // for Text, TextFile +#include "texture.h" // for Texture +struct JA_Music_t; // lines 11-11 +struct JA_Sound_t; // lines 12-12 // Estructura para almacenar ficheros de sonido y su nombre struct ResourceSound diff --git a/source/room.h b/source/room.h index de01752..98b53b7 100644 --- a/source/room.h +++ b/source/room.h @@ -1,20 +1,20 @@ #pragma once -#include // Para SDL_Rect, SDL_Point -#include // Para SDL_Renderer, SDL_Texture -#include // Para string, basic_string -#include // Para vector -#include "enemy.h" // Para enemy_t -#include "item.h" // Para item_t -#include "utils.h" // Para h_line_t, color_t, d_line_t, v_line_t -#include "item_tracker.h" // Para ItemTracker -#include // Para shared_ptr -class Asset; -class Debug; -class Screen; -class Sprite; -class Texture; -struct JA_Sound_t; +#include // for SDL_Rect, SDL_Point +#include // for SDL_Renderer, SDL_Texture +#include // for shared_ptr +#include // for string +#include // for vector +#include "enemy.h" // for EnemyData +#include "item.h" // for item_t +#include "utils.h" // for Color +class Asset; // lines 12-12 +class Debug; // lines 13-13 +class ItemTracker; +class Screen; // lines 14-14 +class Sprite; // lines 15-15 +class Texture; // lines 16-16 +struct JA_Sound_t; // lines 17-17 enum tile_e { diff --git a/source/scoreboard.cpp b/source/scoreboard.cpp index ee07913..3f0819f 100644 --- a/source/scoreboard.cpp +++ b/source/scoreboard.cpp @@ -1,16 +1,14 @@ #include "scoreboard.h" -#include // Para SDL_Rect -#include // Para SDL_GetTicks -#include "animated_sprite.h" // Para AnimatedSprite -#include "defines.h" // Para BLOCK, PLAY_AREA_HEIGHT, PLAY_AREA_WIDTH -#include "resource.h" // Para Resource -#include "text.h" // Para Text -#include "texture.h" // Para Texture -#include "options.h" -#include "screen.h" -#include "asset.h" -#include "resource.h" -class Asset; +#include // for SDL_Rect +#include // for SDL_GetTicks +#include "animated_sprite.h" // for AnimatedSprite +#include "asset.h" // for Asset +#include "defines.h" // for BLOCK, GAMECANVAS_HEIGHT, PLAY_AREA_HEIGHT +#include "options.h" // for Options, options, OptionsVideo, Cheat +#include "resource.h" // for Resource +#include "screen.h" // for Screen +#include "text.h" // for Text +#include "texture.h" // for Texture // Constructor Scoreboard::Scoreboard(board_t *board) @@ -21,11 +19,11 @@ Scoreboard::Scoreboard(board_t *board) { // Reserva memoria para los objetos itemTexture = resource->getTexture("items.png"); - const std::string playerJPG = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.jpg" : "player.jpg"; + const std::string playerPNG = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.png" : "player.png"; const std::string playerANI = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani"; - sprite = std::make_shared(resource->getTexture(playerJPG), resource->getAnimation(playerANI)); + sprite = std::make_shared(resource->getTexture(playerPNG), resource->getAnimation(playerANI)); sprite->setCurrentAnimation("walk_menu"); - text = resource->getText("smb2.txt"); + text = resource->getText("smb2"); // Inicializa las variables counter = 0; diff --git a/source/screen.h b/source/screen.h index 9b5f441..fceed05 100644 --- a/source/screen.h +++ b/source/screen.h @@ -1,14 +1,12 @@ #pragma once -#include // Para SDL_BlendMode -#include // Para SDL_Rect -#include // Para SDL_Renderer, SDL_Texture -#include // Para SDL_Window -#include // Para basic_string, string -#include // Para vector -#include "utils.h" // Para color_t -class Asset; -class Notifier; +#include // for SDL_BlendMode +#include // for SDL_Rect +#include // for SDL_Renderer, SDL_Texture +#include // for Uint32 +#include // for SDL_Window +#include // for vector +#include "utils.h" // for Color // Tipos de filtro enum class ScreenFilter : Uint32 diff --git a/source/stats.cpp b/source/stats.cpp index cae4990..b9b448a 100644 --- a/source/stats.cpp +++ b/source/stats.cpp @@ -1,8 +1,7 @@ #include "stats.h" -#include // Para basic_ostream, basic_ifstream, basic_istream, ope... -#include // Para basic_stringstream -#include "utils.h" // Para op_stats_t, options_t -#include "options.h" +#include // for basic_ostream, basic_ifstream, basic_istream +#include // for basic_stringstream +#include "options.h" // for Options, OptionsStats, options // Constructor Stats::Stats(std::string file, std::string buffer) diff --git a/source/stats.h b/source/stats.h index 45e1261..ef3c54c 100644 --- a/source/stats.h +++ b/source/stats.h @@ -1,8 +1,7 @@ #pragma once -#include // Para string, basic_string -#include // Para vector -struct Options; +#include // for string +#include // for vector class Stats { diff --git a/source/text.cpp b/source/text.cpp index 86a7a6d..f919510 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -292,6 +292,6 @@ void Text::setPalette(int number) { auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer()); SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr); - sprite_->getTexture()->setPalette(number); + //sprite_->getTexture()->setPalette(number); SDL_SetRenderTarget(Screen::get()->getRenderer(), temp); } \ No newline at end of file diff --git a/source/texture.cpp b/source/texture.cpp index 20f7dd5..77491bf 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -7,7 +7,6 @@ #include // Para runtime_error #include // Para char_traits, operator<<, operator+ #include // Para vector -#include "gif.c" // Para LoadGif, LoadPalette #include "stb_image.h" // Para stbi_image_free, stbi_load, STBI_rgb_a... #include "utils.h" // Para getFileName, printWithDots @@ -32,7 +31,7 @@ Texture::Texture(SDL_Renderer *renderer, const std::string &path) } // .gif - else if (extension == "gif") + /*else if (extension == "gif") { // Crea la surface desde un fichero surface_ = loadSurface(path_); @@ -45,7 +44,7 @@ Texture::Texture(SDL_Renderer *renderer, const std::string &path) createBlank(width_, height_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING); SDL_SetTextureBlendMode(texture_, SDL_BLENDMODE_BLEND); flipSurface(); - } + }*/ } } @@ -53,7 +52,7 @@ Texture::Texture(SDL_Renderer *renderer, const std::string &path) Texture::~Texture() { unloadTexture(); - unloadSurface(); + //unloadSurface(); palettes_.clear(); } @@ -240,15 +239,15 @@ SDL_Texture *Texture::getSDLTexture() } // Desencadenar la superficie actual -void Texture::unloadSurface() +/*void Texture::unloadSurface() { surface_.reset(); // Resetea el shared_ptr width_ = 0; height_ = 0; -} +}*/ // Crea una surface desde un fichero .gif -std::shared_ptr Texture::loadSurface(const std::string &file_path) +/*std::shared_ptr Texture::loadSurface(const std::string &file_path) { // Desencadenar la superficie actual unloadSurface(); @@ -293,10 +292,10 @@ std::shared_ptr Texture::loadSurface(const std::string &file_path) height_ = h; return surface; -} +}*/ // Vuelca la surface en la textura -void Texture::flipSurface() +/*void Texture::flipSurface() { // Limpia la textura auto temp = SDL_GetRenderTarget(renderer_); @@ -314,16 +313,16 @@ void Texture::flipSurface() pixels[i] = palettes_[current_palette_][surface_->data[i]]; } SDL_UnlockTexture(texture_); -} +}*/ // Establece un color de la paleta -void Texture::setPaletteColor(int palette, int index, Uint32 color) +/*void Texture::setPaletteColor(int palette, int index, Uint32 color) { palettes_.at(palette)[index] = color; -} +}*/ // Carga una paleta desde un fichero -std::vector Texture::loadPaletteFromFile(const std::string &file_path) +/*std::vector Texture::loadPaletteFromFile(const std::string &file_path) { std::vector palette; @@ -360,10 +359,10 @@ std::vector Texture::loadPaletteFromFile(const std::string &file_path) } return palette; -} +}*/ // Añade una paleta a la lista -void Texture::addPaletteFromFile(const std::string &path) +/*void Texture::addPaletteFromFile(const std::string &path) { palettes_.emplace_back(loadPaletteFromFile(path)); setPaletteColor((int)palettes_.size() - 1, 0, 0x00000000); @@ -377,7 +376,7 @@ void Texture::setPalette(int palette) current_palette_ = palette; flipSurface(); } -} +}*/ // Obtiene el renderizador SDL_Renderer *Texture::getRenderer() diff --git a/source/texture.h b/source/texture.h index 22f6790..8a69d46 100644 --- a/source/texture.h +++ b/source/texture.h @@ -37,19 +37,19 @@ private: int current_palette_ = 0; // Indice de la paleta en uso // Crea una surface desde un fichero .gif - std::shared_ptr loadSurface(const std::string &file_name); + //std::shared_ptr loadSurface(const std::string &file_name); // Vuelca la surface en la textura - void flipSurface(); + //void flipSurface(); // Carga una paleta desde un fichero - std::vector loadPaletteFromFile(const std::string &file_name); + //std::vector loadPaletteFromFile(const std::string &file_name); // Libera la memoria de la textura void unloadTexture(); // Desencadenar la superficie actual - void unloadSurface(); + //void unloadSurface(); public: // Constructor @@ -93,13 +93,13 @@ public: SDL_Texture *getSDLTexture(); // Añade una paleta a la lista - void addPaletteFromFile(const std::string &path); + //void addPaletteFromFile(const std::string &path); // Establece un color de la paleta - void setPaletteColor(int palette, int index, Uint32 color); + //void setPaletteColor(int palette, int index, Uint32 color); // Cambia la paleta de la textura - void setPalette(int palette); + //void setPalette(int palette); // Obtiene el renderizador SDL_Renderer *getRenderer(); diff --git a/source/title.cpp b/source/title.cpp index a86e13f..4c52af2 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -1,23 +1,24 @@ #include "title.h" -#include // Para SDL_BLENDMODE_BLEND -#include // Para SDL_GetError -#include // Para SDL_PIXELFORMAT_RGBA8888 -#include // Para SDL_SCANCODE_1, SDL_SCANCODE_2 -#include // Para SDL_GetTicks -#include // Para basic_ostream, operator<<, basic_ios -#include "asset.h" // Para Asset -#include "cheevos.h" // Para cheevos_t, Cheevos -#include "defines.h" // Para PLAY_AREA_CENTER_X, GAMECANVAS_WIDTH -#include "input.h" // Para Input, inputs_e, REPEAT_FALSE, REPEA... -#include "resource.h" // Para Resource -#include "screen.h" // Para Screen -#include "sprite.h" // Para Sprite -#include "text.h" // Para Text, TXT_CENTER, TXT_COLOR -#include "texture.h" // Para Texture -#include "utils.h" // Para color_t, stringToColor, options_t -#include "options.h" -#include "global_inputs.h" -#include "global_events.h" +#include // for SDL_BLENDMODE_BLEND +#include // for SDL_GetError +#include // for SDL_PollEvent, SDL_Event, SDL_KEYDOWN +#include // for SDL_PIXELFORMAT_RGBA8888 +#include // for SDL_SCANCODE_1, SDL_SCANCODE_2 +#include // for SDL_GetTicks +#include // for basic_ostream, operator<<, cout, endl +#include "asset.h" // for Asset +#include "cheevos.h" // for Achievement, Cheevos +#include "defines.h" // for PLAY_AREA_CENTER_X, GAMECANVAS_WIDTH +#include "global_events.h" // for check +#include "global_inputs.h" // for check +#include "input.h" // for Input, inputs_e, REPEAT_FALSE, REPEA... +#include "options.h" // for Options, options, OptionsVideo, Sect... +#include "resource.h" // for Resource +#include "screen.h" // for Screen +#include "sprite.h" // for Sprite +#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR +#include "texture.h" // for Texture +#include "utils.h" // for Color, stringToColor, Palette // Constructor Title::Title() @@ -36,8 +37,8 @@ Title::Title() texture_ = resource_->getTexture("title_logo.png"); } sprite_ = std::make_shared(texture_, 0, 0, texture_->getWidth(), texture_->getHeight()); - text_ = resource_->getText("smb2.txt"); - info_text_ = resource_->getText("subatomic.txt"); + text_ = resource_->getText("smb2"); + info_text_ = resource_->getText("subatomic"); // Crea la textura para los graficos que aparecen en el fondo de la pantalla de titulo bg_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); diff --git a/source/title.h b/source/title.h index df5c7a9..8c52427 100644 --- a/source/title.h +++ b/source/title.h @@ -1,23 +1,18 @@ #pragma once -#include // Para SDL_Event -#include // Para SDL_Rect -#include // Para SDL_Renderer, SDL_Texture -#include // Para Uint32 -#include // Para basic_string, string -#include // Para vector -#include -#include "paleta.h" // Para jSurface -class Asset; -class Cheevos; -class Input; -class Resource; -class Screen; -class Sprite; -class Text; -class Texture; -struct Options; -struct SectionState; +#include // for SDL_Rect +#include // for SDL_Renderer, SDL_Texture +#include // for Uint32 +#include // for shared_ptr +#include // for string +#include // for vector +#include "paleta.h" // for jSurface +class Input; // lines 13-13 +class Resource; // lines 14-14 +class Screen; // lines 15-15 +class Sprite; // lines 16-16 +class Text; // lines 17-17 +class Texture; // lines 18-18 class Title { diff --git a/source/utils.cpp b/source/utils.cpp index 12ae67f..7ea85bf 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -1,10 +1,13 @@ #include "utils.h" -#include // Para path -#include // Para free, malloc, abs -#include // Para round, abs -#include -#include -#include +#include // for free, malloc, abs +#include // for transform +#include // for tolower +#include // for round, abs +#include // for exception +#include // for path +#include // for basic_ostream, cout, basic_ios, ios, endl +#include // for unordered_map +#include // for string // Calcula el cuadrado de la distancia entre dos puntos double distanceSquared(int x1, int y1, int x2, int y2) @@ -352,176 +355,74 @@ bool checkCollision(SDL_Point &p, d_line_t &l) return true; } -// Devuelve un color_t a partir de un string -Color stringToColor(Palette pal, std::string str) +// Convierte una cadena a un color +Color stringToColor(Palette pal, const std::string &str) { + // Mapas de colores para cada paleta + static const std::unordered_map zxSpectrumColors = { + {"black", {0x00, 0x00, 0x00}}, + {"bright_black", {0x00, 0x00, 0x00}}, + {"blue", {0x00, 0x00, 0xD8}}, + {"bright_blue", {0x00, 0x00, 0xFF}}, + {"red", {0xD8, 0x00, 0x00}}, + {"bright_red", {0xFF, 0x00, 0x00}}, + {"magenta", {0xD8, 0x00, 0xD8}}, + {"bright_magenta", {0xFF, 0x00, 0xFF}}, + {"green", {0x00, 0xD8, 0x00}}, + {"bright_green", {0x00, 0xFF, 0x00}}, + {"cyan", {0x00, 0xD8, 0xD8}}, + {"bright_cyan", {0x00, 0xFF, 0xFF}}, + {"yellow", {0xD8, 0xD8, 0x00}}, + {"bright_yellow", {0xFF, 0xFF, 0x00}}, + {"white", {0xD8, 0xD8, 0xD8}}, + {"bright_white", {0xFF, 0xFF, 0xFF}}}; + + static const std::unordered_map zxArneColors = { + {"black", {0x00, 0x00, 0x00}}, + {"bright_black", {0x3C, 0x35, 0x1F}}, + {"blue", {0x31, 0x33, 0x90}}, + {"bright_blue", {0x15, 0x59, 0xDB}}, + {"red", {0xA7, 0x32, 0x11}}, + {"bright_red", {0xD8, 0x55, 0x25}}, + {"magenta", {0xA1, 0x55, 0x89}}, + {"bright_magenta", {0xCD, 0x7A, 0x50}}, + {"green", {0x62, 0x9A, 0x31}}, + {"bright_green", {0x9C, 0xD3, 0x3C}}, + {"cyan", {0x28, 0xA4, 0xCB}}, + {"bright_cyan", {0x65, 0xDC, 0xD6}}, + {"yellow", {0xE8, 0xBC, 0x50}}, + {"bright_yellow", {0xF1, 0xE7, 0x82}}, + {"white", {0xBF, 0xBF, 0xBD}}, + {"bright_white", {0xF2, 0xF1, 0xED}}}; + + // Selecciona el mapa de colores adecuado según la paleta + const std::unordered_map *paletteMap = nullptr; + if (pal == Palette::ZXSPECTRUM) { - if (str == "black") - { - return {0x00, 0x00, 0x00}; - } - - else if (str == "bright_black") - { - return {0x00, 0x00, 0x00}; - } - - else if (str == "blue") - { - return {0x00, 0x00, 0xd8}; - } - - else if (str == "bright_blue") - { - return {0x00, 0x00, 0xFF}; - } - - else if (str == "red") - { - return {0xd8, 0x00, 0x00}; - } - - else if (str == "bright_red") - { - return {0xFF, 0x00, 0x00}; - } - - else if (str == "magenta") - { - return {0xd8, 0x00, 0xd8}; - } - - else if (str == "bright_magenta") - { - return {0xFF, 0x00, 0xFF}; - } - - else if (str == "green") - { - return {0x00, 0xd8, 0x00}; - } - - else if (str == "bright_green") - { - return {0x00, 0xFF, 0x00}; - } - - else if (str == "cyan") - { - return {0x00, 0xd8, 0xd8}; - } - - else if (str == "bright_cyan") - { - return {0x00, 0xFF, 0xFF}; - } - - else if (str == "yellow") - { - return {0xd8, 0xd8, 0x00}; - } - - else if (str == "bright_yellow") - { - return {0xFF, 0xFF, 0x00}; - } - - else if (str == "white") - { - return {0xd8, 0xd8, 0xd8}; - } - - else if (str == "bright_white") - { - return {0xFF, 0xFF, 0xFF}; - } + paletteMap = &zxSpectrumColors; } - else if (pal == Palette::ZXARNE) { - if (str == "black") - { - return {0x00, 0x00, 0x00}; - } - - else if (str == "bright_black") - { - return {0x3C, 0x35, 0x1F}; - } - - else if (str == "blue") - { - return {0x31, 0x33, 0x90}; - } - - else if (str == "bright_blue") - { - return {0x15, 0x59, 0xDB}; - } - - else if (str == "red") - { - return {0xA7, 0x32, 0x11}; - } - - else if (str == "bright_red") - { - return {0xD8, 0x55, 0x25}; - } - - else if (str == "magenta") - { - return {0xA1, 0x55, 0x89}; - } - - else if (str == "bright_magenta") - { - return {0xCD, 0x7A, 0x50}; - } - - else if (str == "green") - { - return {0x62, 0x9A, 0x31}; - } - - else if (str == "bright_green") - { - return {0x9C, 0xD3, 0x3C}; - } - - else if (str == "cyan") - { - return {0x28, 0xA4, 0xCB}; - } - - else if (str == "bright_cyan") - { - return {0x65, 0xDC, 0xD6}; - } - - else if (str == "yellow") - { - return {0xE8, 0xBC, 0x50}; - } - - else if (str == "bright_yellow") - { - return {0xF1, 0xE7, 0x82}; - } - - else if (str == "white") - { - return {0xBF, 0xBF, 0xBD}; - } - - else if (str == "bright_white") - { - return {0xF2, 0xF1, 0xED}; - } + paletteMap = &zxArneColors; + } + else + { + // Paleta desconocida, devolvemos negro por defecto + return {0x00, 0x00, 0x00}; } - return {0x00, 0x00, 0x00}; + // Busca el color en el mapa + auto it = paletteMap->find(str); + if (it != paletteMap->end()) + { + return it->second; + } + else + { + // Si no se encuentra el color, devolvemos negro por defecto + return {0x00, 0x00, 0x00}; + } } // Convierte una cadena a un entero de forma segura diff --git a/source/utils.h b/source/utils.h index 345f719..05638a3 100644 --- a/source/utils.h +++ b/source/utils.h @@ -1,9 +1,8 @@ #pragma once -#include // Para SDL_Rect, SDL_Point -#include // Para Uint8, Uint32 -#include // Para string, basic_string -#include // Para vector +#include // for SDL_Rect, SDL_Point +#include // for Uint8 +#include // for string // Tipos de paleta enum class Palette : int @@ -95,8 +94,8 @@ bool checkCollision(SDL_Point &p, d_line_t &l); // Normaliza una linea diagonal void normalizeLine(d_line_t &l); -// Devuelve un color_t a partir de un string -Color stringToColor(Palette pal, std::string str); +// Devuelve un Color a partir de un string +Color stringToColor(Palette pal, const std::string &str); // Convierte una cadena a un entero de forma segura int safeStoi(const std::string &value, int defaultValue = 0);