diff --git a/source/credits.cpp b/source/credits.cpp index 56105db..95820c1 100644 --- a/source/credits.cpp +++ b/source/credits.cpp @@ -1,22 +1,20 @@ #include "credits.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 "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 +#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 "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH +#include "global_events.h" // for check +#include "global_inputs.h" // for check +#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 b0ceb7e..45fd76a 100644 --- a/source/credits.h +++ b/source/credits.h @@ -1,17 +1,12 @@ #pragma once -#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 +#include // for SDL_Texture +#include // for Uint32 +#include // for shared_ptr +#include // for string +#include // for vector +#include "utils.h" // for Color +class AnimatedSprite; // lines 9-9 class Credits { diff --git a/source/debug.cpp b/source/debug.cpp index 0752979..2093b2f 100644 --- a/source/debug.cpp +++ b/source/debug.cpp @@ -1,9 +1,9 @@ #include "debug.h" -#include // for max -#include "resource.h" // for Resource -#include "screen.h" // for Screen -#include "text.h" // for Text -#include "utils.h" // for Color +#include // for max +#include // for __shared_ptr_access, shared_ptr +#include "resource.h" // for Resource +#include "text.h" // for Text +#include "utils.h" // for Color // [SINGLETON] Debug *Debug::debug_ = nullptr; diff --git a/source/debug.h b/source/debug.h index e09d579..537a804 100644 --- a/source/debug.h +++ b/source/debug.h @@ -1,13 +1,8 @@ #pragma once -#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 +#include // for SDL_Point +#include // for string +#include // for vector // Clase Debug class Debug diff --git a/source/demo.cpp b/source/demo.cpp index 5869a77..70f5a2d 100644 --- a/source/demo.cpp +++ b/source/demo.cpp @@ -1,21 +1,20 @@ #include "demo.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 +#include // for SDL_PollEvent, SDL_Event +#include // for SDL_Rect +#include // for SDL_RenderFillRect, SDL_SetRenderDrawColor +#include // for SDL_GetTicks +#include "asset.h" // for Asset +#include "defines.h" // for BLOCK, PLAY_AREA_WIDTH, GAMECANVAS_CENT... +#include "global_events.h" // for check +#include "global_inputs.h" // for check +#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 "scoreboard.h" // for ScoreboardData, Scoreboard +#include "screen.h" // for Screen +#include "text.h" // for TEXT_CENTER, TEXT_COLOR, Text +#include "utils.h" // for Color, stringToColor, colorAreEqual // Constructor Demo::Demo() diff --git a/source/demo.h b/source/demo.h index af9192f..5531ac5 100644 --- a/source/demo.h +++ b/source/demo.h @@ -1,19 +1,12 @@ #pragma once -#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 +#include // for Uint32 +#include // for shared_ptr +#include // for string +#include // for vector +class Room; // lines 14-14 +class Scoreboard; +struct ScoreboardData; class Demo { diff --git a/source/director.h b/source/director.h index 316c403..897f9b5 100644 --- a/source/director.h +++ b/source/director.h @@ -3,7 +3,6 @@ #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 c82fee9..aeb9418 100644 --- a/source/ending.cpp +++ b/source/ending.cpp @@ -1,25 +1,23 @@ #include "ending.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 +#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 "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH +#include "global_events.h" // for check +#include "global_inputs.h" // for check +#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() diff --git a/source/ending.h b/source/ending.h index 1483a88..65c4a5b 100644 --- a/source/ending.h +++ b/source/ending.h @@ -1,18 +1,12 @@ #pragma once -#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 +#include // for SDL_Texture +#include // for Uint32 +#include // for shared_ptr +#include // for string +#include // for vector +class Sprite; // lines 12-12 +class Texture; // lines 14-14 class Ending { diff --git a/source/ending2.cpp b/source/ending2.cpp index 392ed57..9b5ed68 100644 --- a/source/ending2.cpp +++ b/source/ending2.cpp @@ -1,23 +1,22 @@ #include "ending2.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 +#include // for SDL_BLENDMODE_BLEND +#include // for SDL_PollEvent, SDL_Event +#include // for SDL_Rect +#include // for SDL_RenderDrawPoint, SDL_SetRenderDr... +#include // for SDL_GetTicks +#include // for max, min, replace +#include "animated_sprite.h" // for AnimatedSprite +#include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_CENTER_X +#include "global_events.h" // for check +#include "global_inputs.h" // for check +#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() diff --git a/source/ending2.h b/source/ending2.h index cd9f438..920610d 100644 --- a/source/ending2.h +++ b/source/ending2.h @@ -1,20 +1,13 @@ #pragma once -#include // for SDL_Renderer -#include // for Uint32 -#include // for shared_ptr -#include // for string -#include // for vector -#include "utils.h" // for Color -#include "defines.h" // for GAMECANVAS_FIRST_QUARTER_X, GAMECANVAS_THIRD_QUARTER_X, GAMECANVAS_WIDTH -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 +#include // for Uint32 +#include // for shared_ptr +#include // for string +#include // for vector +#include "defines.h" // for GAMECANVAS_WIDTH, GAMECANVAS_FIRST_QUAR... +#include "utils.h" // for Color +class AnimatedSprite; // lines 10-10 +class MovingSprite; // lines 13-13 class Ending2 { diff --git a/source/game.cpp b/source/game.cpp index 8eea285..74a8f0f 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -1,30 +1,30 @@ #include "game.h" -#include // for SDL_BLENDMODE_BLEND -#include // for SDL_GetError -#include // for SDL_PIXELFORMAT_RGBA8888 -#include // for SDL_SCANCODE_A, SDL_SCANCODE_D, SDL_... -#include // for SDL_GetTicks -#include // for basic_ostream, operator<<, cout, endl -#include // for vector -#include "asset.h" // for Asset -#include "cheevos.h" // for Cheevos -#include "defines.h" // for PLAY_AREA_HEIGHT, GAMECANVAS_WIDTH -#include "debug.h" // for Debug -#include "input.h" // for Input, REPEAT_FALSE, inputs_e -#include "item_tracker.h" // for ItemTracker -#include "jail_audio.h" // for JA_PauseMusic, JA_PlaySound, JA_Resu... -#include "resource.h" // for Resource, res_room_t -#include "room.h" // for Room, room_t -#include "room_tracker.h" // for RoomTracker -#include "screen.h" // for Screen -#include "stats.h" // for Stats -#include "text.h" // for Text, TXT_CENTER, TXT_COLOR -#include "utils.h" // for options_t, cheat_t, stringToColor -#include "options.h" -#include "notifier.h" -#include "global_inputs.h" -#include "global_events.h" -// #include "surface.h" +#include // for SDL_BLENDMODE_BLEND +#include // for SDL_GetError +#include // for SDL_PIXELFORMAT_RGBA8888 +#include // for SDL_SCANCODE_A, SDL_SCANCODE_D, SDL_... +#include // for SDL_GetTicks +#include // for basic_ostream, operator<<, cout, endl +#include // for vector +#include "asset.h" // for Asset +#include "cheevos.h" // for Cheevos +#include "debug.h" // for Debug +#include "defines.h" // for BLOCK, PLAY_AREA_HEIGHT, GAMECANVAS_... +#include "global_events.h" // for check +#include "global_inputs.h" // for check +#include "input.h" // for Input, InputAction, REPEAT_FALSE +#include "item_tracker.h" // for ItemTracker +#include "jail_audio.h" // for JA_PauseMusic, JA_PlaySound, JA_Resu... +#include "notifier.h" // for Notifier, NotificationText +#include "options.h" // for Options, options, Cheat, OptionsVideo +#include "resource.h" // for ResourceRoom, Resource +#include "room.h" // for Room, RoomData +#include "room_tracker.h" // for RoomTracker +#include "scoreboard.h" // for ScoreboardData, Scoreboard +#include "screen.h" // for Screen +#include "stats.h" // for Stats +#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR +#include "utils.h" // for Color, stringToColor, colorAreEqual // Constructor Game::Game() diff --git a/source/game.h b/source/game.h index 990ab38..cfb92a1 100644 --- a/source/game.h +++ b/source/game.h @@ -1,28 +1,17 @@ #pragma once -#include // Para SDL_Event -#include // Para SDL_Rect -#include // Para SDL_Renderer, SDL_Texture -#include // Para Uint32 -#include // Para string, basic_string -#include "player.h" // Para playerSpawn_t -#include "scoreboard.h" // Para board_t -#include "room.h" -class Asset; -class Cheevos; -class Debug; -class Input; -class ItemTracker; -class Resource; -class Room; -class RoomTracker; -class Screen; -class Stats; -class Text; -struct JA_Music_t; -struct JA_Sound_t; -struct Options; -struct SectionState; +#include // for SDL_Event +#include // for SDL_Rect +#include // for SDL_Texture +#include // for Uint32 +#include // for shared_ptr +#include // for string +#include "player.h" // for PlayerSpawn +class Room; // lines 17-17 +class RoomTracker; // lines 18-18 +class Scoreboard; +class Stats; // lines 20-20 +struct ScoreboardData; class Game { diff --git a/source/game_over.cpp b/source/game_over.cpp index 53e1318..7959db2 100644 --- a/source/game_over.cpp +++ b/source/game_over.cpp @@ -1,20 +1,18 @@ #include "game_over.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 +#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 "defines.h" // for GAMECANVAS_CENTER_X, GAME_SPEED +#include "global_events.h" // for check +#include "global_inputs.h" // for check +#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() diff --git a/source/game_over.h b/source/game_over.h index ccb9fdf..1a26d57 100644 --- a/source/game_over.h +++ b/source/game_over.h @@ -1,17 +1,10 @@ #pragma once -#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 +#include // for Uint32 +#include // for shared_ptr +#include // for vector +#include "utils.h" // for Color +class AnimatedSprite; // lines 8-8 class GameOver { diff --git a/source/gif.cpp b/source/gif.cpp index f0f6fbb..4d495f9 100644 --- a/source/gif.cpp +++ b/source/gif.cpp @@ -1,8 +1,6 @@ #include "gif.h" -#include -#include -#include -#include +#include // for NULL, fprintf, stderr +#include // for malloc, realloc, exit, calloc, free void uncompress( int code_length, const unsigned char *input, diff --git a/source/gif.h b/source/gif.h index ba6f670..5e6641f 100644 --- a/source/gif.h +++ b/source/gif.h @@ -1,6 +1,7 @@ #pragma once -#include +#include // for uint32_t +#include // for memcpy #define EXTENSION_INTRODUCER 0x21 #define IMAGE_DESCRIPTOR 0x2C diff --git a/source/input.cpp b/source/input.cpp index 2bf0ff8..4e901e7 100644 --- a/source/input.cpp +++ b/source/input.cpp @@ -32,12 +32,12 @@ Input::Input(const std::string &game_controller_db_path) : db_path_(game_controller_db_path) { // Inicializa las variables - keyBindings_t kb; + KeyBindings kb; kb.scancode = 0; kb.active = false; key_bindings_.resize(static_cast(InputAction::SIZE), kb); - GameControllerBindings_t gcb; + GameControllerBindings gcb; gcb.button = SDL_CONTROLLER_BUTTON_INVALID; gcb.active = false; game_controller_bindings_.resize(static_cast(InputAction::SIZE), gcb); diff --git a/source/input.h b/source/input.h index 174543f..e94e7b0 100644 --- a/source/input.h +++ b/source/input.h @@ -48,13 +48,13 @@ private: // [SINGLETON] Objeto privado static Input *input_; - struct keyBindings_t + struct KeyBindings { Uint8 scancode; // Scancode asociado bool active; // Indica si está activo }; - struct GameControllerBindings_t + struct GameControllerBindings { SDL_GameControllerButton button; // GameControllerButton asociado bool active; // Indica si está activo @@ -64,13 +64,13 @@ private: std::vector connected_controllers_; // Vector con todos los mandos conectados // Variables - std::vector key_bindings_; // Vector con las teclas asociadas a los inputs predefinidos - std::vector game_controller_bindings_; // Vector con las teclas asociadas a los inputs predefinidos - std::vector controller_names_; // Vector con los nombres de los mandos - int num_gamepads_ = 0; // Numero de mandos conectados - std::string db_path_; // Ruta al archivo gamecontrollerdb.txt - bool verbose_ = true; // Indica si ha de mostrar mensajes - bool enabled_ = true; // Indica si está habilitado + std::vector key_bindings_; // Vector con las teclas asociadas a los inputs predefinidos + std::vector game_controller_bindings_; // Vector con las teclas asociadas a los inputs predefinidos + std::vector controller_names_; // Vector con los nombres de los mandos + int num_gamepads_ = 0; // Numero de mandos conectados + std::string db_path_; // Ruta al archivo gamecontrollerdb.txt + bool verbose_ = true; // Indica si ha de mostrar mensajes + bool enabled_ = true; // Indica si está habilitado // Constructor explicit Input(const std::string &game_controller_db_path); diff --git a/source/item.h b/source/item.h index 9e6137d..723e103 100644 --- a/source/item.h +++ b/source/item.h @@ -1,13 +1,12 @@ #pragma once -#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 +#include // for SDL_Rect, SDL_Point +#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 ItemData { diff --git a/source/loading_screen.cpp b/source/loading_screen.cpp index 0bd8257..03e0a4f 100644 --- a/source/loading_screen.cpp +++ b/source/loading_screen.cpp @@ -1,20 +1,20 @@ #include "loading_screen.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 -#include +#include // for SDL_GetError +#include // for SDL_PollEvent, SDL_Event +#include // for SDL_PIXELFORMAT_RGBA8888 +#include // for SDL_GetTicks +#include // for rand +#include // for char_traits, basic_ostream, operator<< +#include "defines.h" // for GAME_SPEED +#include "global_events.h" // for check +#include "global_inputs.h" // for check +#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() diff --git a/source/loading_screen.h b/source/loading_screen.h index b6858ec..42a1aae 100644 --- a/source/loading_screen.h +++ b/source/loading_screen.h @@ -1,16 +1,11 @@ #pragma once -#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 +#include // for SDL_Rect +#include // for SDL_Texture +#include // for Uint32 +#include // for shared_ptr +class Sprite; // lines 11-11 +class Texture; // lines 12-12 class LoadingScreen { diff --git a/source/logo.cpp b/source/logo.cpp index c821da3..8f386dd 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -1,19 +1,17 @@ #include "logo.h" -#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 -#include "defines.h" +#include // for SDL_PollEvent, SDL_Event +#include // for SDL_GetTicks +#include // for basic_string, string +#include "defines.h" // for GAME_SPEED +#include "global_events.h" // for check +#include "global_inputs.h" // for check +#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() @@ -225,7 +223,7 @@ void Logo::render() Screen::get()->clean(); // Dibuja los objetos - for (auto s : jailgames_sprite_) + for (const auto &s : jailgames_sprite_) { s->render(); } diff --git a/source/logo.h b/source/logo.h index f9d2e91..fed27e7 100644 --- a/source/logo.h +++ b/source/logo.h @@ -1,16 +1,11 @@ #pragma once -#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 +#include // for Uint32 +#include // for shared_ptr +#include // for vector +#include "utils.h" // for Color +class Sprite; // lines 12-12 +class Texture; // lines 13-13 class Logo { diff --git a/source/notifier.cpp b/source/notifier.cpp index 09986ef..0507ac6 100644 --- a/source/notifier.cpp +++ b/source/notifier.cpp @@ -1,16 +1,17 @@ #include "notifier.h" -#include // Para SDL_BLENDMODE_BLEND -#include // Para SDL_PIXELFORMAT_RGBA8888 -#include // Para string -#include -#include -#include "jail_audio.h" // Para JA_DeleteSound, JA_LoadSound, JA_Pla... -#include "screen.h" // Para Screen -#include "sprite.h" // Para Sprite -#include "text.h" // Para Text -#include "texture.h" // Para Texture -#include "resource.h" -#include "options.h" +#include // for SDL_BLENDMODE_BLEND +#include // for SDL_PIXELFORMAT_RGBA8888 +#include // for SDL_RenderFillRect, SDL_RenderClear +#include // for remove_if +#include // for string, basic_string +#include // for vector +#include "jail_audio.h" // for JA_PlaySound +#include "options.h" // for Options, options, OptionsNotification +#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 // [SINGLETON] Notifier *Notifier::notifier_ = nullptr; diff --git a/source/notifier.h b/source/notifier.h index 0a03003..ff2e480 100644 --- a/source/notifier.h +++ b/source/notifier.h @@ -1,14 +1,13 @@ #pragma once -#include // Para SDL_Rect -#include // Para SDL_Renderer -#include // Para shared_ptr -#include // Para string, basic_string -#include // Para vector -#include "utils.h" // Para Color -class Sprite; // lines 9-9 -class Text; // lines 10-10 -class Texture; // lines 11-11 +#include // for SDL_Rect +#include // for shared_ptr +#include // for string, basic_string +#include // for vector +#include "utils.h" // for Color +class Sprite; // lines 9-9 +class Text; // lines 10-10 +class Texture; // lines 11-11 enum class NotificationText { diff --git a/source/options.cpp b/source/options.cpp index 0922f8e..f8a5f78 100644 --- a/source/options.cpp +++ b/source/options.cpp @@ -1,13 +1,14 @@ #include "options.h" -#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 -#include -#include -#include +#include // for SDL_WINDOW_FULLSCREEN_DESKTOP +#include // for find_if +#include // for isspace +#include // for basic_ostream, operator<<, basic_ofstream +#include // for function +#include // for cout, cerr +#include // for basic_istringstream +#include // for char_traits, string, operator<<, hash +#include // for unordered_map, operator==, _Node_const_i... +#include // for pair // Variables Options options; diff --git a/source/player.cpp b/source/player.cpp index c1aa844..bfd1a63 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -1,19 +1,18 @@ // IWYU pragma: no_include #include "player.h" -#include // Para rand -#include // Para max, min -#include // Para ceil, abs -#include "animated_sprite.h" // Para AnimatedSprite -#include "asset.h" // Para Asset -#include "defines.h" // Para BORDER_TOP, BLOCK, BORDER_BOTTOM, BORDER... -#include "debug.h" // Para Debug -#include "input.h" // Para Input, inputs_e -#include "jail_audio.h" // Para JA_LoadSound, JA_Sound_t, JA_PlaySound -#include "resource.h" // Para Resource -#include "room.h" // Para Room, tile_e -#include "texture.h" // Para Texture -#include "options.h" -#include "screen.h" +#include // for rand +#include // for max, min +#include // for ceil, abs +#include "animated_sprite.h" // for AnimatedSprite +#include "debug.h" // for Debug +#include "defines.h" // for BORDER_BOTTOM, BORDER_LEFT, BORDER_RIGHT +#include "input.h" // for Input, InputAction +#include "jail_audio.h" // for JA_PlaySound +#include "options.h" // for Options, options, Cheat, OptionsVideo +#include "resource.h" // for Resource +#include "room.h" // for Room, JA_Sound_t, TileType +#include "screen.h" // for Screen +#include "texture.h" // for Texture // Constructor Player::Player(const PlayerData &player) @@ -289,7 +288,7 @@ void Player::move() // Si ha tocado alguna rampa mientras camina (sin saltar), asciende if (state_ != PlayerState::JUMPING) { - v_line_t leftSide = {static_cast(x_), static_cast(y_) + HEIGHT_ - 2, static_cast(y_) + HEIGHT_ - 1}; // Comprueba solo los dos pixels de abajo + LineVertical leftSide = {static_cast(x_), static_cast(y_) + HEIGHT_ - 2, static_cast(y_) + HEIGHT_ - 1}; // Comprueba solo los dos pixels de abajo const int ly = room_->checkLeftSlopes(&leftSide); if (ly > -1) { @@ -336,7 +335,7 @@ void Player::move() // Si ha tocado alguna rampa mientras camina (sin saltar), asciende if (state_ != PlayerState::JUMPING) { - v_line_t rightSide = {static_cast(x_) + WIDTH_ - 1, static_cast(y_) + HEIGHT_ - 2, static_cast(y_) + HEIGHT_ - 1}; // Comprueba solo los dos pixels de abajo + LineVertical rightSide = {static_cast(x_) + WIDTH_ - 1, static_cast(y_) + HEIGHT_ - 2, static_cast(y_) + HEIGHT_ - 1}; // Comprueba solo los dos pixels de abajo const int ry = room_->checkRightSlopes(&rightSide); if (ry > -1) { @@ -428,8 +427,8 @@ void Player::move() // Si no hay colisión con los muros, comprueba la colisión con las rampas if (state_ != PlayerState::JUMPING) { // Las rampas no se miran si se está saltando - v_line_t leftSide = {proj.x, proj.y, proj.y + proj.h - 1}; - v_line_t rightSide = {proj.x + proj.w - 1, proj.y, proj.y + proj.h - 1}; + LineVertical leftSide = {proj.x, proj.y, proj.y + proj.h - 1}; + LineVertical rightSide = {proj.x + proj.w - 1, proj.y, proj.y + proj.h - 1}; const int p = std::max(room_->checkRightSlopes(&rightSide), room_->checkLeftSlopes(&leftSide)); if (p > -1) { @@ -618,21 +617,17 @@ bool Player::checkKillingTiles() // Actualiza los puntos de colisión updateColliderPoints(); - // Comprueba si hay contacto - bool check = false; - - for (auto c : collider_points_) + // Comprueba si hay contacto y retorna en cuanto se encuentra colisión + for (const auto &c : collider_points_) { - check |= (room_->getTile(c) == t_kill); + if (room_->getTile(c) == TileType::KILL) + { + is_alive_ = false; // Mata al jugador inmediatamente + return true; // Retorna en cuanto se detecta una colisión + } } - // Mata al jugador si hay colisión - if (check) - { - is_alive_ = false; - } - - return check; + return false; // No se encontró ninguna colisión } // Establece el color del jugador @@ -705,13 +700,6 @@ void Player::initSounds() } } -// Coloca el sprite en la posición del jugador -void Player::placeSprite() -{ - sprite_->setPosX(x_); - sprite_->setPosY(y_); -} - // Aplica los valores de spawn al jugador void Player::applySpawnValues(const PlayerSpawn &spawn) { diff --git a/source/player.h b/source/player.h index c142a91..aed1117 100644 --- a/source/player.h +++ b/source/player.h @@ -1,20 +1,16 @@ #pragma once -#include // Para SDL_Rect, SDL_Point -#include // Para SDL_Renderer -#include // Para basic_string, string -#include // Para vector -#include // Para shared_ptr -#include "utils.h" // Para color_t -#include "defines.h" // Para BLOCK -#include "room.h" -#include "animated_sprite.h" -class Asset; -class Debug; -class Input; -class Resource; -class Room; -struct JA_Sound_t; +#include // for SDL_Rect, SDL_Point +#include // for SDL_RendererFlip, SDL_FLIP_NONE +#include // for shared_ptr, __shared_ptr_access +#include // for string +#include // for vector +#include "animated_sprite.h" // for AnimatedSprite +#include "defines.h" // for BORDER_TOP, BLOCK +#include "texture.h" // for Texture +#include "utils.h" // for Color +class Room; // lines 16-16 +struct JA_Sound_t; // lines 17-17 enum class PlayerState { @@ -149,7 +145,7 @@ public: void initSounds(); // Coloca el sprite en la posición del jugador - void placeSprite(); + void placeSprite() { sprite_->setPos(x_, y_); } // Aplica los valores de spawn al jugador void applySpawnValues(const PlayerSpawn &spawn); diff --git a/source/resource.cpp b/source/resource.cpp index e4599fa..cbbc960 100644 --- a/source/resource.cpp +++ b/source/resource.cpp @@ -1,16 +1,20 @@ #include "resource.h" -#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 -#include "options.h" // for getFileName, printWithDots -#include // for SDL_PollEvent -struct JA_Music_t; // lines 10-10 -struct JA_Sound_t; // lines 11-11 +#include // for SDL_PollEvent, SDL_Event, SDL_KEYDOWN +#include // for SDLK_ESCAPE +#include // for SDL_Rect +#include // for SDL_RenderDrawRect, SDL_RenderFillRect +#include // for exit, size_t +#include // for find_if +#include // for basic_ostream, operator<<, endl, cout +#include // for runtime_error +#include "asset.h" // for AssetType, Asset +#include "jail_audio.h" // for JA_DeleteMusic, JA_DeleteSound, JA_Loa... +#include "options.h" // for Options, OptionsGame, options +#include "screen.h" // for Screen +#include "text.h" // for Text, loadTextFile +#include "utils.h" // for getFileName, printWithDots, Color +struct JA_Music_t; // lines 12-12 +struct JA_Sound_t; // lines 13-13 // [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado Resource *Resource::resource_ = nullptr; diff --git a/source/room.cpp b/source/room.cpp index b1b5414..532820b 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -1,22 +1,23 @@ #include "room.h" -#include // Para SDL_BLENDMODE_BLEND -#include // Para SDL_GetError -#include // Para SDL_PIXELFORMAT_RGBA8888 -#include // Para rand -#include // Para basic_ostream, operator<<, basic_ist... -#include // Para cout -#include // Para basic_stringstream -#include "asset.h" // Para Asset -#include "defines.h" // Para BLOCK, PLAY_AREA_HEIGHT, PLAY_AREA_W... -#include "debug.h" // Para Debug -#include "item_tracker.h" // Para ItemTracker -#include "jail_audio.h" // Para JA_DeleteSound, JA_LoadSound, JA_Pla... -#include "screen.h" // Para Screen -#include "sprite.h" // Para Sprite -#include "texture.h" // Para Texture -#include "options.h" -#include "utils.h" // Para stringToBool, stringToColor -#include "resource.h" +#include // for SDL_BLENDMODE_BLEND +#include // for SDL_GetError +#include // for SDL_PIXELFORMAT_RGBA8888 +#include // for rand +#include // for exception +#include // for basic_ostream, operator<<, basic_ist... +#include // for cout, cerr +#include // for basic_stringstream +#include "debug.h" // for Debug +#include "defines.h" // for BLOCK, PLAY_AREA_HEIGHT, PLAY_AREA_W... +#include "item_tracker.h" // for ItemTracker +#include "jail_audio.h" // for JA_PlaySound +#include "options.h" // for Options, options, OptionsVideo, Opti... +#include "resource.h" // for Resource +#include "scoreboard.h" // for ScoreboardData +#include "screen.h" // for Screen +#include "sprite.h" // for Sprite +#include "texture.h" // for Texture +#include "utils.h" // for LineHorizontal, LineDiagonal, LineVe... // Carga las variables y texturas desde un fichero de mapa de tiles std::vector loadRoomTileFile(const std::string &file_path, bool verbose) @@ -402,60 +403,13 @@ Room::Room(const std::string &room_path, std::shared_ptr data) : data_(data) { auto room = Resource::get()->getRoom(room_path); - number_ = room->number; - name_ = room->name; - bg_color_ = room->bg_color; - border_color_ = room->border_color; - item_color1_ = room->item_color1 == "" ? "yellow" : room->item_color1; - item_color2_ = room->item_color2 == "" ? "magenta" : room->item_color2; - room_top_ = room->room_top; - room_bottom_ = room->room_bottom; - room_left_ = room->room_left; - room_right_ = room->room_right; - tile_set_file_ = room->tile_set_file; - tile_map_file_ = room->tile_map_file; - auto_surface_direction_ = room->auto_surface_direction; - tile_map_ = Resource::get()->getTileMap(room->tile_map_file); - texture_ = Resource::get()->getTexture(room->tile_set_file); + initializeRoom(*room); - // Inicializa variables - tile_set_width_ = texture_->getWidth() / TILE_SIZE_; - is_paused_ = false; - counter_ = 0; + // Abre la Jail si se da el caso + openTheJail(); - // Crea los enemigos - for (auto &enemy_data : room->enemies) - { - enemies_.emplace_back(std::make_shared(enemy_data)); - } - - // Crea los items - for (auto &item : room->items) - { - const SDL_Point itemPos = {item.x, item.y}; - - if (!ItemTracker::get()->hasBeenPicked(room->name, itemPos)) - { - item.color1 = stringToColor(options.video.palette, item_color1_); - item.color2 = stringToColor(options.video.palette, item_color2_); - items_.emplace_back(std::make_shared(item)); - } - } - - // Abre la jail para poder entrar - if (data_->jail_is_open) - { - openTheJail(); - } - - // Calcula las superficies - setBottomSurfaces(); - setTopSurfaces(); - setLeftSurfaces(); - setRightSurfaces(); - setLeftSlopes(); - setRightSlopes(); - setAutoSurfaces(); + // Inicializa las superficies de colision + initRoomSurfaces(); // Busca los tiles animados setAnimatedTiles(); @@ -475,16 +429,14 @@ Room::Room(const std::string &room_path, std::shared_ptr data) fillMapTexture(); // Establece el color del borde - Screen::get()->setBorderColor(stringToColor(options.video.palette, room->border_color)); + Screen::get()->setBorderColor(stringToColor(options.video.palette, border_color_)); } // Destructor -Room::~Room() -{ - SDL_DestroyTexture(map_texture_); -} +Room::~Room() { SDL_DestroyTexture(map_texture_); } -void Room::initializeRoom(const RoomData& room) { +void Room::initializeRoom(const RoomData &room) +{ // Asignar valores a las variables miembro number_ = room.number; name_ = room.name; @@ -506,40 +458,29 @@ void Room::initializeRoom(const RoomData& room) { counter_ = 0; // Crear los enemigos - for (auto &enemy_data : room.enemies) { + for (auto &enemy_data : room.enemies) + { enemies_.emplace_back(std::make_shared(enemy_data)); } // Crear los items - for (auto &item : room.items) { + for (const auto &item : room.items) + { const SDL_Point itemPos = {item.x, item.y}; - if (!ItemTracker::get()->hasBeenPicked(room.name, itemPos)) { - item.color1 = stringToColor(options.video.palette, item_color1_); - item.color2 = stringToColor(options.video.palette, item_color2_); - items_.emplace_back(std::make_shared(item)); + if (!ItemTracker::get()->hasBeenPicked(room.name, itemPos)) + { + // Crear una copia local de los datos del item + ItemData itemCopy = item; + itemCopy.color1 = stringToColor(options.video.palette, item_color1_); + itemCopy.color2 = stringToColor(options.video.palette, item_color2_); + + // Crear el objeto Item usando la copia modificada + items_.emplace_back(std::make_shared(itemCopy)); } } } -// Devuelve el nombre de la habitación -std::string Room::getName() -{ - return name_; -} - -// Devuelve el color de la habitación -Color Room::getBGColor() -{ - return stringToColor(options.video.palette, bg_color_); -} - -// Devuelve el color del borde -Color Room::getBorderColor() -{ - return stringToColor(options.video.palette, border_color_); -} - // Crea la textura con el mapeado de la habitación void Room::fillMapTexture() { @@ -687,7 +628,7 @@ void Room::renderMap() // Dibuja los enemigos en pantalla void Room::renderEnemies() { - for (auto enemy : enemies_) + for (const auto &enemy : enemies_) { enemy->render(); } @@ -696,7 +637,7 @@ void Room::renderEnemies() // Dibuja los objetos en pantalla void Room::renderItems() { - for (auto item : items_) + for (const auto &item : items_) { item->render(); } @@ -706,7 +647,8 @@ void Room::renderItems() void Room::update() { if (is_paused_) - { // Si está en modo pausa no se actualiza nada + { + // Si está en modo pausa no se actualiza nada return; } @@ -717,12 +659,14 @@ void Room::update() updateAnimatedTiles(); for (auto enemy : enemies_) - { // Actualiza los enemigos + { + // Actualiza los enemigos enemy->update(); } for (auto item : items_) - { // Actualiza los items + { + // Actualiza los items item->update(); } } @@ -755,14 +699,14 @@ std::string Room::getRoom(int border) } // Devuelve el tipo de tile que hay en ese pixel -tile_e Room::getTile(SDL_Point point) +TileType Room::getTile(SDL_Point point) { const int pos = ((point.y / TILE_SIZE_) * MAP_WIDTH_) + (point.x / TILE_SIZE_); return getTile(pos); } // Devuelve el tipo de tile que hay en ese indice -tile_e Room::getTile(int index) +TileType Room::getTile(int index) { // const bool onRange = (index > -1) && (index < mapWidth * mapHeight); const bool onRange = (index > -1) && (index < (int)tile_map_.size()); @@ -772,64 +716,64 @@ tile_e Room::getTile(int index) // Las filas 0-8 son de tiles t_wall if ((tile_map_[index] >= 0) && (tile_map_[index] < 9 * tile_set_width_)) { - return t_wall; + return TileType::WALL; } // Las filas 9-17 son de tiles t_passable else if ((tile_map_[index] >= 9 * tile_set_width_) && (tile_map_[index] < 18 * tile_set_width_)) { - return t_passable; + return TileType::PASSABLE; } // Las filas 18-20 es de tiles t_animated else if ((tile_map_[index] >= 18 * tile_set_width_) && (tile_map_[index] < 21 * tile_set_width_)) { - return t_animated; + return TileType::ANIMATED; } // La fila 21 es de tiles t_slope_r else if ((tile_map_[index] >= 21 * tile_set_width_) && (tile_map_[index] < 22 * tile_set_width_)) { - return t_slope_r; + return TileType::SLOPE_R; } // La fila 22 es de tiles t_slope_l else if ((tile_map_[index] >= 22 * tile_set_width_) && (tile_map_[index] < 23 * tile_set_width_)) { - return t_slope_l; + return TileType::SLOPE_L; } // La fila 23 es de tiles t_kill else if ((tile_map_[index] >= 23 * tile_set_width_) && (tile_map_[index] < 24 * tile_set_width_)) { - return t_kill; + return TileType::KILL; } } - return t_empty; + return TileType::EMPTY; } // Indica si hay colision con un enemigo a partir de un rectangulo bool Room::enemyCollision(SDL_Rect &rect) { - bool collision = false; - - for (auto enemy : enemies_) + for (const auto &enemy : enemies_) { - collision |= checkCollision(rect, enemy->getCollider()); + if (checkCollision(rect, enemy->getCollider())) + { + return true; + } } - - return collision; + return false; } // Indica si hay colision con un objeto a partir de un rectangulo bool Room::itemCollision(SDL_Rect &rect) { - for (int i = 0; i < (int)items_.size(); ++i) + for (int i = 0; i < static_cast(items_.size()); ++i) { - if (checkCollision(rect, items_[i]->getCollider())) + if (checkCollision(rect, items_.at(i)->getCollider())) { - ItemTracker::get()->addItem(name_, items_[i]->getPos()); + ItemTracker::get()->addItem(name_, items_.at(i)->getPos()); items_.erase(items_.begin() + i); JA_PlaySound(Resource::get()->getSound("item.wav")); data_->items++; @@ -842,7 +786,7 @@ bool Room::itemCollision(SDL_Rect &rect) } // Obten la coordenada de la cuesta a partir de un punto perteneciente a ese tile -int Room::getSlopeHeight(SDL_Point p, tile_e slope) +int Room::getSlopeHeight(SDL_Point p, TileType slope) { // Calcula la base del tile int base = ((p.y / TILE_SIZE_) * TILE_SIZE_) + TILE_SIZE_; @@ -857,7 +801,7 @@ int Room::getSlopeHeight(SDL_Point p, tile_e slope) #endif // Se resta a la base la cantidad de pixeles pos en funcion de la rampa - if (slope == t_slope_r) + if (slope == TileType::SLOPE_R) { base -= pos + 1; #ifdef DEBUG @@ -884,7 +828,7 @@ void Room::setBottomSurfaces() // Hay que recorrer la habitación por filas (excepto los de la última fila) for (int i = 0; i < (int)tile_map_.size() - MAP_WIDTH_; ++i) { - if (getTile(i) == t_wall && getTile(i + MAP_WIDTH_) != t_wall) + if (getTile(i) == TileType::WALL && getTile(i + MAP_WIDTH_) != TileType::WALL) { tile.push_back(i); @@ -905,7 +849,7 @@ void Room::setBottomSurfaces() int i = 0; do { - h_line_t line; + LineHorizontal line; line.x1 = (tile[i] % MAP_WIDTH_) * TILE_SIZE_; line.y = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1; int last_one = i; @@ -946,7 +890,7 @@ void Room::setTopSurfaces() // Hay que recorrer la habitación por filas (excepto los de la primera fila) for (int i = MAP_WIDTH_; i < (int)tile_map_.size(); ++i) { - if ((getTile(i) == t_wall || getTile(i) == t_passable) && getTile(i - MAP_WIDTH_) != t_wall) + if ((getTile(i) == TileType::WALL || getTile(i) == TileType::PASSABLE) && getTile(i - MAP_WIDTH_) != TileType::WALL) { tile.push_back(i); @@ -967,7 +911,7 @@ void Room::setTopSurfaces() int i = 0; do { - h_line_t line; + LineHorizontal line; line.x1 = (tile[i] % MAP_WIDTH_) * TILE_SIZE_; line.y = (tile[i] / MAP_WIDTH_) * TILE_SIZE_; int last_one = i; @@ -1011,7 +955,7 @@ void Room::setLeftSurfaces() for (int j = 0; j < MAP_HEIGHT_; ++j) { const int pos = (j * MAP_WIDTH_ + i); - if (getTile(pos) == t_wall && getTile(pos - 1) != t_wall) + if (getTile(pos) == TileType::WALL && getTile(pos - 1) != TileType::WALL) { tile.push_back(pos); } @@ -1029,7 +973,7 @@ void Room::setLeftSurfaces() int i = 0; do { - v_line_t line; + LineVertical line; line.x = (tile[i] % MAP_WIDTH_) * TILE_SIZE_; line.y1 = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_); while (tile[i] + MAP_WIDTH_ == tile[i + 1]) @@ -1059,7 +1003,7 @@ void Room::setRightSurfaces() for (int j = 0; j < MAP_HEIGHT_; ++j) { const int pos = (j * MAP_WIDTH_ + i); - if (getTile(pos) == t_wall && getTile(pos + 1) != t_wall) + if (getTile(pos) == TileType::WALL && getTile(pos + 1) != TileType::WALL) { tile.push_back(pos); } @@ -1077,7 +1021,7 @@ void Room::setRightSurfaces() int i = 0; do { - v_line_t line; + LineVertical line; line.x = ((tile[i] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1; line.y1 = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_); while (tile[i] + MAP_WIDTH_ == tile[i + 1]) @@ -1102,7 +1046,7 @@ void Room::setLeftSlopes() std::vector found; for (int i = 0; i < (int)tile_map_.size(); ++i) { - if (getTile(i) == t_slope_l) + if (getTile(i) == TileType::SLOPE_L) { found.push_back(i); } @@ -1114,7 +1058,7 @@ void Room::setLeftSlopes() while (found.size() > 0) { - d_line_t line; + LineDiagonal line; line.x1 = (found[0] % MAP_WIDTH_) * TILE_SIZE_; line.y1 = (found[0] / MAP_WIDTH_) * TILE_SIZE_; int lookingFor = found[0] + MAP_WIDTH_ + 1; @@ -1143,7 +1087,7 @@ void Room::setRightSlopes() std::vector found; for (int i = 0; i < (int)tile_map_.size(); ++i) { - if (getTile(i) == t_slope_r) + if (getTile(i) == TileType::SLOPE_R) { found.push_back(i); } @@ -1155,7 +1099,7 @@ void Room::setRightSlopes() while (found.size() > 0) { - d_line_t line; + LineDiagonal line; line.x1 = ((found[0] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1; line.y1 = (found[0] / MAP_WIDTH_) * TILE_SIZE_; int lookingFor = found[0] + MAP_WIDTH_ - 1; @@ -1186,7 +1130,7 @@ void Room::setAutoSurfaces() // Hay que recorrer la habitación por filas (excepto los de la primera fila) for (int i = MAP_WIDTH_; i < (int)tile_map_.size(); ++i) { - if (getTile(i) == t_animated) + if (getTile(i) == TileType::ANIMATED) { tile.push_back(i); @@ -1204,7 +1148,7 @@ void Room::setAutoSurfaces() int i = 0; do { - h_line_t line; + LineHorizontal line; line.x1 = (tile[i] % MAP_WIDTH_) * TILE_SIZE_; line.y = (tile[i] / MAP_WIDTH_) * TILE_SIZE_; int last_one = i; @@ -1242,7 +1186,7 @@ void Room::setAnimatedTiles() // Recorre la habitación entera por filas buscando tiles de tipo t_animated for (int i = 0; i < (int)tile_map_.size(); ++i) { - if (getTile(i) == t_animated) + if (getTile(i) == TileType::ANIMATED) { // La i es la ubicación const int x = (i % MAP_WIDTH_) * TILE_SIZE_; @@ -1286,7 +1230,7 @@ void Room::updateAnimatedTiles() // Pinta los tiles animados en pantalla void Room::renderAnimatedTiles() { - for (auto a : animated_tiles_) + for (const auto &a : animated_tiles_) { a.sprite->render(); } @@ -1295,7 +1239,7 @@ void Room::renderAnimatedTiles() // Comprueba las colisiones int Room::checkRightSurfaces(SDL_Rect *rect) { - for (auto s : right_surfaces_) + for (const auto &s : right_surfaces_) { if (checkCollision(s, *rect)) { @@ -1309,7 +1253,7 @@ int Room::checkRightSurfaces(SDL_Rect *rect) // Comprueba las colisiones int Room::checkLeftSurfaces(SDL_Rect *rect) { - for (auto s : left_surfaces_) + for (const auto &s : left_surfaces_) { if (checkCollision(s, *rect)) { @@ -1323,7 +1267,7 @@ int Room::checkLeftSurfaces(SDL_Rect *rect) // Comprueba las colisiones int Room::checkTopSurfaces(SDL_Rect *rect) { - for (auto s : top_surfaces_) + for (const auto &s : top_surfaces_) { if (checkCollision(s, *rect)) { @@ -1337,7 +1281,7 @@ int Room::checkTopSurfaces(SDL_Rect *rect) // Comprueba las colisiones int Room::checkBottomSurfaces(SDL_Rect *rect) { - for (auto s : bottom_surfaces_) + for (const auto &s : bottom_surfaces_) { if (checkCollision(s, *rect)) { @@ -1351,7 +1295,7 @@ int Room::checkBottomSurfaces(SDL_Rect *rect) // Comprueba las colisiones int Room::checkAutoSurfaces(SDL_Rect *rect) { - for (auto s : auto_surfaces_) + for (const auto &s : auto_surfaces_) { if (checkCollision(s, *rect)) { @@ -1365,7 +1309,7 @@ int Room::checkAutoSurfaces(SDL_Rect *rect) // Comprueba las colisiones bool Room::checkTopSurfaces(SDL_Point *p) { - for (auto s : top_surfaces_) + for (const auto &s : top_surfaces_) { if (checkCollision(s, *p)) { @@ -1379,7 +1323,7 @@ bool Room::checkTopSurfaces(SDL_Point *p) // Comprueba las colisiones bool Room::checkAutoSurfaces(SDL_Point *p) { - for (auto s : auto_surfaces_) + for (const auto &s : auto_surfaces_) { if (checkCollision(s, *p)) { @@ -1391,9 +1335,9 @@ bool Room::checkAutoSurfaces(SDL_Point *p) } // Comprueba las colisiones -int Room::checkLeftSlopes(const v_line_t *line) +int Room::checkLeftSlopes(const LineVertical *line) { - for (auto slope : left_slopes_) + for (const auto &slope : left_slopes_) { const SDL_Point p = checkCollision(slope, *line); if (p.x != -1) @@ -1408,7 +1352,7 @@ int Room::checkLeftSlopes(const v_line_t *line) // Comprueba las colisiones bool Room::checkLeftSlopes(SDL_Point *p) { - for (auto slope : left_slopes_) + for (const auto &slope : left_slopes_) { if (checkCollision(*p, slope)) { @@ -1420,9 +1364,9 @@ bool Room::checkLeftSlopes(SDL_Point *p) } // Comprueba las colisiones -int Room::checkRightSlopes(const v_line_t *line) +int Room::checkRightSlopes(const LineVertical *line) { - for (auto slope : right_slopes_) + for (const auto &slope : right_slopes_) { const SDL_Point p = checkCollision(slope, *line); if (p.x != -1) @@ -1437,7 +1381,7 @@ int Room::checkRightSlopes(const v_line_t *line) // Comprueba las colisiones bool Room::checkRightSlopes(SDL_Point *p) { - for (auto slope : right_slopes_) + for (const auto &slope : right_slopes_) { if (checkCollision(*p, slope)) { @@ -1448,24 +1392,39 @@ bool Room::checkRightSlopes(SDL_Point *p) return false; } -// Obten la direccion de las superficies automaticas -int Room::getAutoSurfaceDirection() -{ - return auto_surface_direction_; -} - -// Abre la jail para poder entrar +// Abre la Jail si se da el caso void Room::openTheJail() { - if (name_ == "THE JAIL") + if (data_->jail_is_open && name_ == "THE JAIL") { - // Elimina el último enemigo (Bry debe ser el ultimo enemigo definido en el fichero) - enemies_.pop_back(); + // Elimina el último enemigo (Bry debe ser el último enemigo definido en el fichero) + if (!enemies_.empty()) + { + enemies_.pop_back(); + } // Abre las puertas - const int tileA = 16 + (13 * 32); - const int tileB = 16 + (14 * 32); - tile_map_[tileA] = -1; - tile_map_[tileB] = -1; + constexpr int TILE_A = 16 + (13 * 32); + constexpr int TILE_B = 16 + (14 * 32); + if (TILE_A < tile_map_.size()) + { + tile_map_[TILE_A] = -1; + } + if (TILE_B < tile_map_.size()) + { + tile_map_[TILE_B] = -1; + } } +} + +// Inicializa las superficies de colision +void Room::initRoomSurfaces() +{ + setBottomSurfaces(); + setTopSurfaces(); + setLeftSurfaces(); + setRightSurfaces(); + setLeftSlopes(); + setRightSlopes(); + setAutoSurfaces(); } \ No newline at end of file diff --git a/source/room.h b/source/room.h index 21e9951..5cc09de 100644 --- a/source/room.h +++ b/source/room.h @@ -1,31 +1,30 @@ #pragma once -#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 -#include "scoreboard.h" -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 +#include // for SDL_Rect, SDL_Point +#include // for SDL_Texture +#include // for shared_ptr +#include // for string +#include // for vector +#include "enemy.h" // for EnemyData +#include "item.h" // for ItemData +#include "options.h" // for Options, OptionsVideo, options +#include "utils.h" // for stringToColor, Color +class Sprite; // lines 17-17 +class Texture; // lines 18-18 +struct JA_Sound_t; // lines 19-19 +struct ScoreboardData; // lines 20-20 -enum tile_e + + +enum class TileType { - t_empty, - t_wall, - t_passable, - t_slope_l, - t_slope_r, - t_kill, - t_animated + EMPTY, + WALL, + PASSABLE, + SLOPE_L, + SLOPE_R, + KILL, + ANIMATED }; struct AnimatedTile @@ -85,34 +84,34 @@ private: std::shared_ptr data_; // Puntero a los datos del marcador // Variables - std::string number_; // Numero de la habitación - std::string name_; // Nombre de la habitación - std::string bg_color_; // Color de fondo de la habitación - std::string border_color_; // Color del borde de la pantalla - std::string item_color1_; // Color 1 para los items de la habitación - std::string item_color2_; // Color 2 para los items de la habitación - std::string room_top_; // Identificador de la habitación que se encuentra arriba - std::string room_bottom_; // Identificador de la habitación que se encuentra abajp - std::string room_left_; // Identificador de la habitación que se encuentra a la izquierda - std::string room_right_; // Identificador de la habitación que se encuentra a la derecha - std::string tile_set_file_; // Imagen con los graficos para la habitación - std::string tile_map_file_; // Fichero con el mapa de indices de tile - std::vector tile_map_; // Indice de los tiles a dibujar en la habitación - int auto_surface_direction_; // Sentido en el que arrastran las superficies automáticas de la habitación - JA_Sound_t *item_sound_; // Sonido producido al coger un objeto - std::vector bottom_surfaces_; // Lista con las superficies inferiores de la habitación - std::vector top_surfaces_; // Lista con las superficies superiores de la habitación - std::vector left_surfaces_; // Lista con las superficies laterales de la parte izquierda de la habitación - std::vector right_surfaces_; // Lista con las superficies laterales de la parte derecha de la habitación - std::vector left_slopes_; // Lista con todas las rampas que suben hacia la izquierda - std::vector right_slopes_; // Lista con todas las rampas que suben hacia la derecha - int counter_; // Contador para lo que haga falta - bool is_paused_; // Indica si el mapa esta en modo pausa - std::vector animated_tiles_; // Vector con los indices de tiles animados - std::vector auto_surfaces_; // Lista con las superficies automaticas de la habitación - int tile_set_width_; // Ancho del tileset en tiles + std::string number_; // Numero de la habitación + std::string name_; // Nombre de la habitación + std::string bg_color_; // Color de fondo de la habitación + std::string border_color_; // Color del borde de la pantalla + std::string item_color1_; // Color 1 para los items de la habitación + std::string item_color2_; // Color 2 para los items de la habitación + std::string room_top_; // Identificador de la habitación que se encuentra arriba + std::string room_bottom_; // Identificador de la habitación que se encuentra abajp + std::string room_left_; // Identificador de la habitación que se encuentra a la izquierda + std::string room_right_; // Identificador de la habitación que se encuentra a la derecha + std::string tile_set_file_; // Imagen con los graficos para la habitación + std::string tile_map_file_; // Fichero con el mapa de indices de tile + std::vector tile_map_; // Indice de los tiles a dibujar en la habitación + int auto_surface_direction_; // Sentido en el que arrastran las superficies automáticas de la habitación + JA_Sound_t *item_sound_; // Sonido producido al coger un objeto + std::vector bottom_surfaces_; // Lista con las superficies inferiores de la habitación + std::vector top_surfaces_; // Lista con las superficies superiores de la habitación + std::vector left_surfaces_; // Lista con las superficies laterales de la parte izquierda de la habitación + std::vector right_surfaces_; // Lista con las superficies laterales de la parte derecha de la habitación + std::vector left_slopes_; // Lista con todas las rampas que suben hacia la izquierda + std::vector right_slopes_; // Lista con todas las rampas que suben hacia la derecha + int counter_; // Contador para lo que haga falta + bool is_paused_; // Indica si el mapa esta en modo pausa + std::vector animated_tiles_; // Vector con los indices de tiles animados + std::vector auto_surfaces_; // Lista con las superficies automaticas de la habitación + int tile_set_width_; // Ancho del tileset en tiles - void initializeRoom(const RoomData& room); + void initializeRoom(const RoomData &room); // Pinta el mapa de la habitación en la textura void fillMapTexture(); @@ -148,11 +147,14 @@ private: void renderAnimatedTiles(); // Devuelve el tipo de tile que hay en ese indice - tile_e getTile(int index); + TileType getTile(int index); // Abre la jail para poder entrar void openTheJail(); + // Inicializa las superficies de colision + void initRoomSurfaces(); + public: // Constructor Room(const std::string &room_path, std::shared_ptr data); @@ -161,13 +163,13 @@ public: ~Room(); // Devuelve el nombre de la habitación - std::string getName(); + std::string getName() const { return name_; } // Devuelve el color de la habitación - Color getBGColor(); + Color getBGColor() const { return stringToColor(options.video.palette, bg_color_); } // Devuelve el color del borde - Color getBorderColor(); + Color getBorderColor() const { return stringToColor(options.video.palette, border_color_); } // Dibuja el mapa en pantalla void renderMap(); @@ -185,7 +187,7 @@ public: std::string getRoom(int border); // Devuelve el tipo de tile que hay en ese pixel - tile_e getTile(SDL_Point point); + TileType getTile(SDL_Point point); // Indica si hay colision con un enemigo a partir de un rectangulo bool enemyCollision(SDL_Rect &rect); @@ -197,7 +199,7 @@ public: int getTileSize() const { return TILE_SIZE_; } // Obten la coordenada de la cuesta a partir de un punto perteneciente a ese tile - int getSlopeHeight(SDL_Point p, tile_e slope); + int getSlopeHeight(SDL_Point p, TileType slope); // Comprueba las colisiones int checkRightSurfaces(SDL_Rect *rect); @@ -221,13 +223,13 @@ public: bool checkAutoSurfaces(SDL_Point *p); // Comprueba las colisiones - int checkLeftSlopes(const v_line_t *line); + int checkLeftSlopes(const LineVertical *line); // Comprueba las colisiones bool checkLeftSlopes(SDL_Point *p); // Comprueba las colisiones - int checkRightSlopes(const v_line_t *line); + int checkRightSlopes(const LineVertical *line); // Comprueba las colisiones bool checkRightSlopes(SDL_Point *p); @@ -236,5 +238,5 @@ public: void setPaused(bool value) { is_paused_ = value; }; // Obten la direccion de las superficies automaticas - int getAutoSurfaceDirection(); + int getAutoSurfaceDirection() const { return auto_surface_direction_; } }; \ No newline at end of file diff --git a/source/scoreboard.cpp b/source/scoreboard.cpp index 9eea1f2..d2e2571 100644 --- a/source/scoreboard.cpp +++ b/source/scoreboard.cpp @@ -1,15 +1,16 @@ #include "scoreboard.h" -#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 -#include +#include // for SDL_GetError +#include // for SDL_PIXELFORMAT_RGBA8888 +#include // for SDL_Rect +#include // for SDL_GetTicks +#include // for basic_ostream, operator<<, cout, endl +#include "animated_sprite.h" // for AnimatedSprite +#include "defines.h" // for BLOCK +#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(std::shared_ptr data) diff --git a/source/scoreboard.h b/source/scoreboard.h index 772a733..5b94ed0 100644 --- a/source/scoreboard.h +++ b/source/scoreboard.h @@ -1,16 +1,14 @@ #pragma once -#include // Para SDL_Renderer -#include // Para Uint32 -#include // Para basic_string, string -#include // Para vector -#include "utils.h" // Para color_t -#include // Para shared_ptr -class AnimatedSprite; -class Asset; -class Resource; -class Text; -class Texture; +#include // for SDL_Rect +#include // for SDL_Texture +#include // for Uint32 +#include // for shared_ptr +#include // for string, basic_string +#include // for vector +#include "utils.h" // for Color +class AnimatedSprite; // lines 9-9 +class Texture; // lines 13-13 struct ScoreboardData { diff --git a/source/screen.h b/source/screen.h index ab6daa8..d73f202 100644 --- a/source/screen.h +++ b/source/screen.h @@ -1,14 +1,11 @@ #pragma once -#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 // for shared_ptr -#include "utils.h" // for Color -//#include "surface.h" +#include // for SDL_BlendMode +#include // for SDL_Rect +#include // for SDL_Texture, SDL_Renderer +#include // for Uint32 +#include // for SDL_Window +#include "utils.h" // for Color // Tipos de filtro enum class ScreenFilter : Uint32 diff --git a/source/surface.cpp b/source/surface.cpp index 8da6ff7..7d2144d 100644 --- a/source/surface.cpp +++ b/source/surface.cpp @@ -1,14 +1,14 @@ #include "surface.h" -#include // Para SDL_PIXELFORMAT_ARGB8888 -#include // Para SDL_Rect -#include // Para std::ifstream -#include // Para std::cerr -#include // Para std::vector -#include // For exceptions -#include "gif.h" // Para LoadGif, LoadPalette -#include // Para std::shared_ptr -#include // Para std::copy -#include "asset.h" +#include // for SDL_GetError +#include // for size_t +#include // for min, copy, fill +#include // for basic_ostream, basic_ifstream, basic_ios +#include // for cerr, cout +#include // for shared_ptr, __shared_ptr_access, unique_ptr +#include // for runtime_error +#include // for vector +#include "asset.h" // for Asset +#include "gif.h" // for LoadGif, LoadPalette Surface::Surface(std::shared_ptr surface_dest, int w, int h) : surface_dest_(surface_dest), diff --git a/source/texture.cpp b/source/texture.cpp index 7168e93..a7e9f7a 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -1,14 +1,12 @@ #include "texture.h" -#include // Para SDL_GetError -#include // Para SDL_CreateRGBSurfaceWithFormatFrom -#include // Para basic_ostream, operator<<, basic_ifstream -#include // Para cerr, cout -#include // Para runtime_error -#include // Para char_traits, operator<<, operator+ -#include // Para vector -#include "stb_image.h" // Para stbi_image_free, stbi_load, STBI_rgb_a... -#include "utils.h" // Para getFileName, printWithDots +#include // for SDL_GetError +#include // for SDL_CreateRGBSurfaceWithFormatFrom +#include // for basic_ostream, operator<<, endl, cout +#include // for runtime_error +#include // for char_traits, operator<<, string, opera... +#include // for vector +#include "utils.h" // for getFileName, Color, printWithDots #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" // para stbi_failure_reason, stbi_image_free diff --git a/source/texture.h b/source/texture.h index 98f3709..a9435de 100644 --- a/source/texture.h +++ b/source/texture.h @@ -1,14 +1,13 @@ #pragma once -#include // Para SDL_BlendMode -#include // Para SDL_PIXELFORMAT_RGBA8888, SDL_PixelF... -#include // Para SDL_Point, SDL_Rect -#include // Para SDL_Renderer, SDL_FLIP_NONE, SDL_TEX... -#include // Para Uint8, Uint16, Uint32 -#include // Para shared_ptr -#include // Para string -#include // Para vector -struct Color; +#include // for SDL_BlendMode +#include // for SDL_PIXELFORMAT_RGBA8888, SDL_PixelF... +#include // for SDL_Point, SDL_Rect +#include // for SDL_Renderer, SDL_FLIP_NONE, SDL_TEX... +#include // for Uint8, Uint32 +#include // for string +#include // for vector +struct Color; // lines 11-11 // Definiciones de tipos /*struct Surface diff --git a/source/title.h b/source/title.h index 3781f97..dfa09c3 100644 --- a/source/title.h +++ b/source/title.h @@ -1,18 +1,14 @@ #pragma once -#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 +#include // for SDL_Rect +#include // for SDL_Texture +#include // for Uint32 +#include // for shared_ptr +#include // for string +#include // for vector +#include "paleta.h" // for jSurface +class Sprite; // lines 13-13 +class Texture; // lines 15-15 class Title { diff --git a/source/utils.cpp b/source/utils.cpp index 8c24bf3..ef5f40b 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -1,15 +1,16 @@ #include "utils.h" -#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 -#include "jail_audio.h" -#include "resource.h" +#include // for abs +#include // for find, 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 basic_string, string, char_traits, allocator +#include // for unordered_map, operator==, _Node_const_iter... +#include // for pair +#include "jail_audio.h" // for JA_GetMusicState, JA_Music_state, JA_PlayMusic +#include "resource.h" // for Resource // Calcula el cuadrado de la distancia entre dos puntos double distanceSquared(int x1, int y1, int x2, int y2) @@ -154,7 +155,7 @@ bool checkCollision(const SDL_Point &p, const SDL_Rect &r) } // Detector de colisiones entre una linea horizontal y un rectangulo -bool checkCollision(const h_line_t &l, const SDL_Rect &r) +bool checkCollision(const LineHorizontal &l, const SDL_Rect &r) { // Comprueba si la linea esta por encima del rectangulo if (l.y < r.y) @@ -185,7 +186,7 @@ bool checkCollision(const h_line_t &l, const SDL_Rect &r) } // Detector de colisiones entre una linea vertical y un rectangulo -bool checkCollision(const v_line_t &l, const SDL_Rect &r) +bool checkCollision(const LineVertical &l, const SDL_Rect &r) { // Comprueba si la linea esta por la izquierda del rectangulo if (l.x < r.x) @@ -216,7 +217,7 @@ bool checkCollision(const v_line_t &l, const SDL_Rect &r) } // Detector de colisiones entre una linea horizontal y un punto -bool checkCollision(const h_line_t &l, const SDL_Point &p) +bool checkCollision(const LineHorizontal &l, const SDL_Point &p) { // Comprueba si el punto esta sobre la linea if (p.y > l.y) @@ -247,7 +248,7 @@ bool checkCollision(const h_line_t &l, const SDL_Point &p) } // Detector de colisiones entre dos lineas -SDL_Point checkCollision(const line_t &l1, const line_t &l2) +SDL_Point checkCollision(const Line &l1, const Line &l2) { const float x1 = l1.x1; const float y1 = l1.y1; @@ -276,7 +277,7 @@ SDL_Point checkCollision(const line_t &l1, const line_t &l2) } // Detector de colisiones entre dos lineas -SDL_Point checkCollision(const d_line_t &l1, const v_line_t &l2) +SDL_Point checkCollision(const LineDiagonal &l1, const LineVertical &l2) { const float x1 = l1.x1; const float y1 = l1.y1; @@ -305,7 +306,7 @@ SDL_Point checkCollision(const d_line_t &l1, const v_line_t &l2) } // Normaliza una linea diagonal -void normalizeLine(d_line_t &l) +void normalizeLine(LineDiagonal &l) { // Las lineas diagonales van de izquierda a derecha // x2 mayor que x1 @@ -321,7 +322,7 @@ void normalizeLine(d_line_t &l) } // Detector de colisiones entre un punto y una linea diagonal -bool checkCollision(const SDL_Point &p, const d_line_t &l) +bool checkCollision(const SDL_Point &p, const LineDiagonal &l) { // Comprueba si el punto está en alineado con la linea if (abs(p.x - l.x1) != abs(p.y - l.y1)) @@ -467,8 +468,10 @@ bool colorAreEqual(Color color1, Color color2) // Convierte una cadena a minúsculas std::string toLower(std::string str) { - for (char& c : str) { - if (c >= 'A' && c <= 'Z') { + for (char &c : str) + { + if (c >= 'A' && c <= 'Z') + { c += 32; // Convierte a minúscula } } @@ -478,8 +481,10 @@ std::string toLower(std::string str) // Convierte una cadena a mayúsculas std::string toUpper(std::string str) { - for (char& c : str) { - if (c >= 'a' && c <= 'z') { + for (char &c : str) + { + if (c >= 'a' && c <= 'z') + { c -= 32; // Convierte a mayúscula } } @@ -521,18 +526,18 @@ bool stringInVector(const std::vector &vec, const std::string &str) // Hace sonar la música void playMusic(const std::string &music_path) { - // Si la música no está sonando - if (JA_GetMusicState() == JA_MUSIC_INVALID || JA_GetMusicState() == JA_MUSIC_STOPPED) - { - JA_PlayMusic(Resource::get()->getMusic(music_path)); - } + // Si la música no está sonando + if (JA_GetMusicState() == JA_MUSIC_INVALID || JA_GetMusicState() == JA_MUSIC_STOPPED) + { + JA_PlayMusic(Resource::get()->getMusic(music_path)); + } } // Rellena una textura de un color -void fillTextureWithColor(SDL_Renderer* renderer, SDL_Texture* texture, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +void fillTextureWithColor(SDL_Renderer *renderer, SDL_Texture *texture, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { // Guardar el render target actual - SDL_Texture* previous_target = SDL_GetRenderTarget(renderer); + SDL_Texture *previous_target = SDL_GetRenderTarget(renderer); // Establecer la textura como el render target SDL_SetRenderTarget(renderer, texture); diff --git a/source/utils.h b/source/utils.h index 2ab306d..5af037c 100644 --- a/source/utils.h +++ b/source/utils.h @@ -1,11 +1,10 @@ #pragma once -#include // for SDL_Rect, SDL_Point -#include // for Uint8 -#include // for string -#include -#include // for SDL_Renderer -#include // for SDL_Texture +#include // for SDL_Rect, SDL_Point +#include // for SDL_Renderer, SDL_Texture +#include // for Uint8 +#include // for string +#include // for vector // Tipos de paleta enum class Palette : int @@ -23,25 +22,25 @@ struct Circle }; // Estructura para definir una linea horizontal -struct h_line_t +struct LineHorizontal { int x1, x2, y; }; // Estructura para definir una linea vertical -struct v_line_t +struct LineVertical { int x, y1, y2; }; // Estructura para definir una linea diagonal -struct d_line_t +struct LineDiagonal { int x1, y1, x2, y2; }; // Estructura para definir una linea -struct line_t +struct Line { int x1, y1, x2, y2; }; @@ -77,25 +76,25 @@ bool checkCollision(const SDL_Rect &a, const SDL_Rect &b); bool checkCollision(const SDL_Point &p, const SDL_Rect &r); // Detector de colisiones entre una linea horizontal y un rectangulo -bool checkCollision(const h_line_t &l, const SDL_Rect &r); +bool checkCollision(const LineHorizontal &l, const SDL_Rect &r); // Detector de colisiones entre una linea vertical y un rectangulo -bool checkCollision(const v_line_t &l, const SDL_Rect &r); +bool checkCollision(const LineVertical &l, const SDL_Rect &r); // Detector de colisiones entre una linea horizontal y un punto -bool checkCollision(const h_line_t &l, const SDL_Point &p); +bool checkCollision(const LineHorizontal &l, const SDL_Point &p); // Detector de colisiones entre dos lineas -SDL_Point checkCollision(const line_t &l1, const line_t &l2); +SDL_Point checkCollision(const Line &l1, const Line &l2); // Detector de colisiones entre dos lineas -SDL_Point checkCollision(const d_line_t &l1, const v_line_t &l2); +SDL_Point checkCollision(const LineDiagonal &l1, const LineVertical &l2); // Detector de colisiones entre un punto y una linea diagonal -bool checkCollision(const SDL_Point &p, const d_line_t &l); +bool checkCollision(const SDL_Point &p, const LineDiagonal &l); // Normaliza una linea diagonal -void normalizeLine(d_line_t &l); +void normalizeLine(LineDiagonal &l); // Devuelve un Color a partir de un string Color stringToColor(Palette pal, const std::string &str);