Arreglos en la estructura i format del codi

This commit is contained in:
2025-03-02 09:32:25 +01:00
parent 193dac708f
commit b1ba5e67dc
41 changed files with 611 additions and 739 deletions

View File

@@ -8,11 +8,9 @@
#include <algorithm> // for min #include <algorithm> // for min
#include <iostream> // for basic_ostream, operator<<, cout, endl #include <iostream> // for basic_ostream, operator<<, cout, endl
#include "animated_sprite.h" // for AnimatedSprite #include "animated_sprite.h" // for AnimatedSprite
#include "asset.h" // for Asset
#include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH #include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH
#include "global_events.h" // for check #include "global_events.h" // for check
#include "global_inputs.h" // for check #include "global_inputs.h" // for check
#include "input.h" // for Input
#include "options.h" // for Options, options, OptionsVideo, Sect... #include "options.h" // for Options, options, OptionsVideo, Sect...
#include "resource.h" // for Resource #include "resource.h" // for Resource
#include "screen.h" // for Screen #include "screen.h" // for Screen

View File

@@ -1,17 +1,12 @@
#pragma once #pragma once
#include <SDL2/SDL_render.h> // for SDL_Texture, SDL_Renderer #include <SDL2/SDL_render.h> // for SDL_Texture
#include <SDL2/SDL_stdinc.h> // for Uint32 #include <SDL2/SDL_stdinc.h> // for Uint32
#include <memory> // for shared_ptr #include <memory> // for shared_ptr
#include <string> // for string #include <string> // for string
#include <vector> // for vector #include <vector> // for vector
#include "utils.h" // for Color #include "utils.h" // for Color
class AnimatedSprite; // lines 10-10 class AnimatedSprite; // lines 9-9
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 class Credits
{ {

View File

@@ -1,7 +1,7 @@
#include "debug.h" #include "debug.h"
#include <algorithm> // for max #include <algorithm> // for max
#include <memory> // for __shared_ptr_access, shared_ptr
#include "resource.h" // for Resource #include "resource.h" // for Resource
#include "screen.h" // for Screen
#include "text.h" // for Text #include "text.h" // for Text
#include "utils.h" // for Color #include "utils.h" // for Color

View File

@@ -1,13 +1,8 @@
#pragma once #pragma once
#include <SDL2/SDL_rect.h> // for SDL_Point #include <SDL2/SDL_rect.h> // for SDL_Point
#include <SDL2/SDL_render.h> // for SDL_Renderer
#include <memory> // for shared_ptr
#include <string> // for string #include <string> // for string
#include <vector> // for vector #include <vector> // for vector
class Screen; // lines 9-9
class Text; // lines 10-10
class Texture; // lines 11-11
// Clase Debug // Clase Debug
class Debug class Debug

View File

@@ -1,20 +1,19 @@
#include "demo.h" #include "demo.h"
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event #include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
#include <SDL2/SDL_rect.h> // for SDL_Rect #include <SDL2/SDL_rect.h> // for SDL_Rect
#include <SDL2/SDL_render.h> // for SDL_RenderFillRect, SDL_SetRenderDrawColor
#include <SDL2/SDL_timer.h> // for SDL_GetTicks #include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <iostream> // for basic_ostream, operator<<, cout, endl
#include "asset.h" // for Asset #include "asset.h" // for Asset
#include "debug.h" // for Debug
#include "defines.h" // for BLOCK, PLAY_AREA_WIDTH, GAMECANVAS_CENT... #include "defines.h" // for BLOCK, PLAY_AREA_WIDTH, GAMECANVAS_CENT...
#include "global_events.h" // for check #include "global_events.h" // for check
#include "global_inputs.h" // for check #include "global_inputs.h" // for check
#include "input.h" // for Input
#include "item_tracker.h" // for ItemTracker #include "item_tracker.h" // for ItemTracker
#include "options.h" // for Options, options, OptionsVideo, Section... #include "options.h" // for Options, options, OptionsVideo, Section...
#include "resource.h" // for Resource #include "resource.h" // for Resource
#include "room.h" // for Room #include "room.h" // for Room
#include "scoreboard.h" // for ScoreboardData, Scoreboard
#include "screen.h" // for Screen #include "screen.h" // for Screen
#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR #include "text.h" // for TEXT_CENTER, TEXT_COLOR, Text
#include "utils.h" // for Color, stringToColor, colorAreEqual #include "utils.h" // for Color, stringToColor, colorAreEqual
// Constructor // Constructor

View File

@@ -1,19 +1,12 @@
#pragma once #pragma once
#include <SDL2/SDL_render.h> // for SDL_Renderer
#include <SDL2/SDL_stdinc.h> // for Uint32 #include <SDL2/SDL_stdinc.h> // for Uint32
#include <memory> // for shared_ptr #include <memory> // for shared_ptr
#include <string> // for string #include <string> // for string
#include <vector> // for vector #include <vector> // for vector
#include "scoreboard.h" // for board_t class Room; // lines 14-14
class Asset; // lines 11-11 class Scoreboard;
class Debug; // lines 12-12 struct ScoreboardData;
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 class Demo
{ {

View File

@@ -3,7 +3,6 @@
#include <SDL2/SDL_render.h> // for SDL_Renderer #include <SDL2/SDL_render.h> // for SDL_Renderer
#include <SDL2/SDL_video.h> // for SDL_Window #include <SDL2/SDL_video.h> // for SDL_Window
#include <string> // for string #include <string> // for string
struct JA_Music_t; // lines 11-11
class Director class Director
{ {

View File

@@ -7,11 +7,9 @@
#include <SDL2/SDL_timer.h> // for SDL_GetTicks #include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <algorithm> // for min #include <algorithm> // for min
#include <iostream> // for basic_ostream, operator<<, cout, endl #include <iostream> // for basic_ostream, operator<<, cout, endl
#include "asset.h" // for Asset
#include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH #include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH
#include "global_events.h" // for check #include "global_events.h" // for check
#include "global_inputs.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 "jail_audio.h" // for JA_SetVolume, JA_PlayMusic, JA_StopM...
#include "options.h" // for Options, options, OptionsVideo, Sect... #include "options.h" // for Options, options, OptionsVideo, Sect...
#include "resource.h" // for Resource #include "resource.h" // for Resource

View File

@@ -1,18 +1,12 @@
#pragma once #pragma once
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture #include <SDL2/SDL_render.h> // for SDL_Texture
#include <SDL2/SDL_stdinc.h> // for Uint32 #include <SDL2/SDL_stdinc.h> // for Uint32
#include <memory> // for shared_ptr #include <memory> // for shared_ptr
#include <string> // for string #include <string> // for string
#include <vector> // for vector #include <vector> // for vector
class Asset; // lines 9-9 class Sprite; // lines 12-12
class Input; // lines 10-10 class Texture; // lines 14-14
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 class Ending
{ {

View File

@@ -2,14 +2,13 @@
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND #include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event #include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
#include <SDL2/SDL_rect.h> // for SDL_Rect #include <SDL2/SDL_rect.h> // for SDL_Rect
#include <SDL2/SDL_render.h> // for SDL_RenderDrawPoint, SDL_SetRenderDr...
#include <SDL2/SDL_timer.h> // for SDL_GetTicks #include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <algorithm> // for max, min, replace #include <algorithm> // for max, min, replace
#include "animated_sprite.h" // for AnimatedSprite #include "animated_sprite.h" // for AnimatedSprite
#include "asset.h" // for Asset
#include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_CENTER_X #include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_CENTER_X
#include "global_events.h" // for check #include "global_events.h" // for check
#include "global_inputs.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 "jail_audio.h" // for JA_SetVolume, JA_PlayMusic, JA_StopM...
#include "moving_sprite.h" // for MovingSprite #include "moving_sprite.h" // for MovingSprite
#include "options.h" // for Options, options, OptionsVideo, Sect... #include "options.h" // for Options, options, OptionsVideo, Sect...

View File

@@ -1,20 +1,13 @@
#pragma once #pragma once
#include <SDL2/SDL_render.h> // for SDL_Renderer
#include <SDL2/SDL_stdinc.h> // for Uint32 #include <SDL2/SDL_stdinc.h> // for Uint32
#include <memory> // for shared_ptr #include <memory> // for shared_ptr
#include <string> // for string #include <string> // for string
#include <vector> // for vector #include <vector> // for vector
#include "defines.h" // for GAMECANVAS_WIDTH, GAMECANVAS_FIRST_QUAR...
#include "utils.h" // for Color #include "utils.h" // for Color
#include "defines.h" // for GAMECANVAS_FIRST_QUARTER_X, GAMECANVAS_THIRD_QUARTER_X, GAMECANVAS_WIDTH class AnimatedSprite; // lines 10-10
class AnimatedSprite; // lines 9-9 class MovingSprite; // lines 13-13
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 class Ending2
{ {

View File

@@ -8,23 +8,23 @@
#include <vector> // for vector #include <vector> // for vector
#include "asset.h" // for Asset #include "asset.h" // for Asset
#include "cheevos.h" // for Cheevos #include "cheevos.h" // for Cheevos
#include "defines.h" // for PLAY_AREA_HEIGHT, GAMECANVAS_WIDTH
#include "debug.h" // for Debug #include "debug.h" // for Debug
#include "input.h" // for Input, REPEAT_FALSE, inputs_e #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 "item_tracker.h" // for ItemTracker
#include "jail_audio.h" // for JA_PauseMusic, JA_PlaySound, JA_Resu... #include "jail_audio.h" // for JA_PauseMusic, JA_PlaySound, JA_Resu...
#include "resource.h" // for Resource, res_room_t #include "notifier.h" // for Notifier, NotificationText
#include "room.h" // for Room, room_t #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 "room_tracker.h" // for RoomTracker
#include "scoreboard.h" // for ScoreboardData, Scoreboard
#include "screen.h" // for Screen #include "screen.h" // for Screen
#include "stats.h" // for Stats #include "stats.h" // for Stats
#include "text.h" // for Text, TXT_CENTER, TXT_COLOR #include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR
#include "utils.h" // for options_t, cheat_t, stringToColor #include "utils.h" // for Color, stringToColor, colorAreEqual
#include "options.h"
#include "notifier.h"
#include "global_inputs.h"
#include "global_events.h"
// #include "surface.h"
// Constructor // Constructor
Game::Game() Game::Game()

View File

@@ -1,28 +1,17 @@
#pragma once #pragma once
#include <SDL2/SDL_events.h> // Para SDL_Event #include <SDL2/SDL_events.h> // for SDL_Event
#include <SDL2/SDL_rect.h> // Para SDL_Rect #include <SDL2/SDL_rect.h> // for SDL_Rect
#include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_Texture #include <SDL2/SDL_render.h> // for SDL_Texture
#include <SDL2/SDL_stdinc.h> // Para Uint32 #include <SDL2/SDL_stdinc.h> // for Uint32
#include <string> // Para string, basic_string #include <memory> // for shared_ptr
#include "player.h" // Para playerSpawn_t #include <string> // for string
#include "scoreboard.h" // Para board_t #include "player.h" // for PlayerSpawn
#include "room.h" class Room; // lines 17-17
class Asset; class RoomTracker; // lines 18-18
class Cheevos; class Scoreboard;
class Debug; class Stats; // lines 20-20
class Input; struct ScoreboardData;
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;
class Game class Game
{ {

View File

@@ -4,11 +4,9 @@
#include <algorithm> // for min, max #include <algorithm> // for min, max
#include <string> // for basic_string, operator+, to_string, cha... #include <string> // for basic_string, operator+, to_string, cha...
#include "animated_sprite.h" // for AnimatedSprite #include "animated_sprite.h" // for AnimatedSprite
#include "asset.h" // for Asset #include "defines.h" // for GAMECANVAS_CENTER_X, GAME_SPEED
#include "defines.h" // for GAMECANVAS_CENTER_X
#include "global_events.h" // for check #include "global_events.h" // for check
#include "global_inputs.h" // for check #include "global_inputs.h" // for check
#include "input.h" // for Input
#include "jail_audio.h" // for JA_PlayMusic #include "jail_audio.h" // for JA_PlayMusic
#include "options.h" // for Options, options, OptionsStats, Section... #include "options.h" // for Options, options, OptionsStats, Section...
#include "resource.h" // for Resource #include "resource.h" // for Resource

View File

@@ -1,17 +1,10 @@
#pragma once #pragma once
#include <SDL2/SDL_render.h> // for SDL_Renderer
#include <SDL2/SDL_stdinc.h> // for Uint32 #include <SDL2/SDL_stdinc.h> // for Uint32
#include <memory> // for shared_ptr #include <memory> // for shared_ptr
#include <vector> // for vector #include <vector> // for vector
#include "utils.h" // for Color #include "utils.h" // for Color
class AnimatedSprite; // lines 9-9 class AnimatedSprite; // lines 8-8
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 class GameOver
{ {

View File

@@ -1,8 +1,6 @@
#include "gif.h" #include "gif.h"
#include <stdio.h> #include <stdio.h> // for NULL, fprintf, stderr
#include <stdlib.h> #include <stdlib.h> // for malloc, realloc, exit, calloc, free
#include <string.h>
#include <fcntl.h>
void uncompress( int code_length, void uncompress( int code_length,
const unsigned char *input, const unsigned char *input,

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <stdint.h> #include <stdint.h> // for uint32_t
#include <string.h> // for memcpy
#define EXTENSION_INTRODUCER 0x21 #define EXTENSION_INTRODUCER 0x21
#define IMAGE_DESCRIPTOR 0x2C #define IMAGE_DESCRIPTOR 0x2C

View File

@@ -32,12 +32,12 @@ Input::Input(const std::string &game_controller_db_path)
: db_path_(game_controller_db_path) : db_path_(game_controller_db_path)
{ {
// Inicializa las variables // Inicializa las variables
keyBindings_t kb; KeyBindings kb;
kb.scancode = 0; kb.scancode = 0;
kb.active = false; kb.active = false;
key_bindings_.resize(static_cast<int>(InputAction::SIZE), kb); key_bindings_.resize(static_cast<int>(InputAction::SIZE), kb);
GameControllerBindings_t gcb; GameControllerBindings gcb;
gcb.button = SDL_CONTROLLER_BUTTON_INVALID; gcb.button = SDL_CONTROLLER_BUTTON_INVALID;
gcb.active = false; gcb.active = false;
game_controller_bindings_.resize(static_cast<int>(InputAction::SIZE), gcb); game_controller_bindings_.resize(static_cast<int>(InputAction::SIZE), gcb);

View File

@@ -48,13 +48,13 @@ private:
// [SINGLETON] Objeto privado // [SINGLETON] Objeto privado
static Input *input_; static Input *input_;
struct keyBindings_t struct KeyBindings
{ {
Uint8 scancode; // Scancode asociado Uint8 scancode; // Scancode asociado
bool active; // Indica si está activo bool active; // Indica si está activo
}; };
struct GameControllerBindings_t struct GameControllerBindings
{ {
SDL_GameControllerButton button; // GameControllerButton asociado SDL_GameControllerButton button; // GameControllerButton asociado
bool active; // Indica si está activo bool active; // Indica si está activo
@@ -64,8 +64,8 @@ private:
std::vector<SDL_GameController *> connected_controllers_; // Vector con todos los mandos conectados std::vector<SDL_GameController *> connected_controllers_; // Vector con todos los mandos conectados
// Variables // Variables
std::vector<keyBindings_t> key_bindings_; // Vector con las teclas asociadas a los inputs predefinidos std::vector<KeyBindings> key_bindings_; // Vector con las teclas asociadas a los inputs predefinidos
std::vector<GameControllerBindings_t> game_controller_bindings_; // Vector con las teclas asociadas a los inputs predefinidos std::vector<GameControllerBindings> game_controller_bindings_; // Vector con las teclas asociadas a los inputs predefinidos
std::vector<std::string> controller_names_; // Vector con los nombres de los mandos std::vector<std::string> controller_names_; // Vector con los nombres de los mandos
int num_gamepads_ = 0; // Numero de mandos conectados int num_gamepads_ = 0; // Numero de mandos conectados
std::string db_path_; // Ruta al archivo gamecontrollerdb.txt std::string db_path_; // Ruta al archivo gamecontrollerdb.txt

View File

@@ -1,7 +1,6 @@
#pragma once #pragma once
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point #include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
#include <SDL2/SDL_render.h> // for SDL_Renderer
#include <memory> // for shared_ptr, __shared_ptr_access #include <memory> // for shared_ptr, __shared_ptr_access
#include <string> // for string #include <string> // for string
#include <vector> // for vector #include <vector> // for vector

View File

@@ -1,12 +1,13 @@
#include "loading_screen.h" #include "loading_screen.h"
#include <SDL2/SDL_error.h> // for SDL_GetError
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event #include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
#include <SDL2/SDL_timer.h> // for SDL_GetTicks #include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <stdlib.h> // for rand #include <stdlib.h> // for rand
#include "asset.h" // for Asset #include <iostream> // for char_traits, basic_ostream, operator<<
#include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH #include "defines.h" // for GAME_SPEED
#include "global_events.h" // for check #include "global_events.h" // for check
#include "global_inputs.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 "jail_audio.h" // for JA_PlayMusic, JA_SetVolume, JA_StopMusic
#include "options.h" // for Options, options, OptionsVideo, Section... #include "options.h" // for Options, options, OptionsVideo, Section...
#include "resource.h" // for Resource #include "resource.h" // for Resource
@@ -14,7 +15,6 @@
#include "sprite.h" // for Sprite #include "sprite.h" // for Sprite
#include "texture.h" // for Texture #include "texture.h" // for Texture
#include "utils.h" // for Color, stringToColor, Palette #include "utils.h" // for Color, stringToColor, Palette
#include <iostream>
// Constructor // Constructor
LoadingScreen::LoadingScreen() LoadingScreen::LoadingScreen()

View File

@@ -1,16 +1,11 @@
#pragma once #pragma once
#include <SDL2/SDL_rect.h> // for SDL_Rect #include <SDL2/SDL_rect.h> // for SDL_Rect
#include <SDL2/SDL_render.h> // for SDL_Renderer #include <SDL2/SDL_render.h> // for SDL_Texture
#include <SDL2/SDL_stdinc.h> // for Uint32 #include <SDL2/SDL_stdinc.h> // for Uint32
#include <memory> // for shared_ptr #include <memory> // for shared_ptr
class Asset; // lines 8-8 class Sprite; // lines 11-11
class Input; // lines 9-9 class Texture; // lines 12-12
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 class LoadingScreen
{ {

View File

@@ -2,10 +2,9 @@
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event #include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
#include <SDL2/SDL_timer.h> // for SDL_GetTicks #include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <string> // for basic_string, string #include <string> // for basic_string, string
#include "asset.h" // for Asset #include "defines.h" // for GAME_SPEED
#include "global_events.h" // for check #include "global_events.h" // for check
#include "global_inputs.h" // for check #include "global_inputs.h" // for check
#include "input.h" // for Input
#include "jail_audio.h" // for JA_StopMusic #include "jail_audio.h" // for JA_StopMusic
#include "options.h" // for Options, options, SectionState, Section #include "options.h" // for Options, options, SectionState, Section
#include "resource.h" // for Resource #include "resource.h" // for Resource
@@ -13,7 +12,6 @@
#include "sprite.h" // for Sprite #include "sprite.h" // for Sprite
#include "texture.h" // for Texture #include "texture.h" // for Texture
#include "utils.h" // for Color, stringToColor #include "utils.h" // for Color, stringToColor
#include "defines.h"
// Constructor // Constructor
Logo::Logo() Logo::Logo()
@@ -225,7 +223,7 @@ void Logo::render()
Screen::get()->clean(); Screen::get()->clean();
// Dibuja los objetos // Dibuja los objetos
for (auto s : jailgames_sprite_) for (const auto &s : jailgames_sprite_)
{ {
s->render(); s->render();
} }

View File

@@ -1,14 +1,9 @@
#pragma once #pragma once
#include <SDL2/SDL_render.h> // for SDL_Renderer
#include <SDL2/SDL_stdinc.h> // for Uint32 #include <SDL2/SDL_stdinc.h> // for Uint32
#include <memory> // for shared_ptr #include <memory> // for shared_ptr
#include <vector> // for vector #include <vector> // for vector
#include "utils.h" // for Color #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 Sprite; // lines 12-12
class Texture; // lines 13-13 class Texture; // lines 13-13

View File

@@ -1,16 +1,17 @@
#include "notifier.h" #include "notifier.h"
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND #include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888 #include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
#include <string> // Para string #include <SDL2/SDL_render.h> // for SDL_RenderFillRect, SDL_RenderClear
#include <algorithm> #include <algorithm> // for remove_if
#include <vector> #include <string> // for string, basic_string
#include "jail_audio.h" // Para JA_DeleteSound, JA_LoadSound, JA_Pla... #include <vector> // for vector
#include "screen.h" // Para Screen #include "jail_audio.h" // for JA_PlaySound
#include "sprite.h" // Para Sprite #include "options.h" // for Options, options, OptionsNotification
#include "text.h" // Para Text #include "resource.h" // for Resource
#include "texture.h" // Para Texture #include "screen.h" // for Screen
#include "resource.h" #include "sprite.h" // for Sprite
#include "options.h" #include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR
#include "texture.h" // for Texture
// [SINGLETON] // [SINGLETON]
Notifier *Notifier::notifier_ = nullptr; Notifier *Notifier::notifier_ = nullptr;

View File

@@ -1,11 +1,10 @@
#pragma once #pragma once
#include <SDL2/SDL_rect.h> // Para SDL_Rect #include <SDL2/SDL_rect.h> // for SDL_Rect
#include <SDL2/SDL_render.h> // Para SDL_Renderer #include <memory> // for shared_ptr
#include <memory> // Para shared_ptr #include <string> // for string, basic_string
#include <string> // Para string, basic_string #include <vector> // for vector
#include <vector> // Para vector #include "utils.h" // for Color
#include "utils.h" // Para Color
class Sprite; // lines 9-9 class Sprite; // lines 9-9
class Text; // lines 10-10 class Text; // lines 10-10
class Texture; // lines 11-11 class Texture; // lines 11-11

View File

@@ -1,13 +1,14 @@
#include "options.h" #include "options.h"
#include <SDL2/SDL_video.h> // for SDL_WINDOW_FULLSCREEN, SDL_WINDOW_FULLSC... #include <SDL2/SDL_video.h> // for SDL_WINDOW_FULLSCREEN_DESKTOP
#include <algorithm> // for find_if
#include <cctype> // for isspace
#include <fstream> // for basic_ostream, operator<<, basic_ofstream #include <fstream> // for basic_ostream, operator<<, basic_ofstream
#include <functional> // for function #include <functional> // for function
#include <iostream> // for cout, cerr #include <iostream> // for cout, cerr
#include <sstream> // for basic_istringstream
#include <string> // for char_traits, string, operator<<, hash
#include <unordered_map> // for unordered_map, operator==, _Node_const_i... #include <unordered_map> // for unordered_map, operator==, _Node_const_i...
#include <utility> // for pair #include <utility> // for pair
#include <sstream>
#include <string>
#include <algorithm>
// Variables // Variables
Options options; Options options;

View File

@@ -1,19 +1,18 @@
// IWYU pragma: no_include <bits/std_abs.h> // IWYU pragma: no_include <bits/std_abs.h>
#include "player.h" #include "player.h"
#include <stdlib.h> // Para rand #include <stdlib.h> // for rand
#include <algorithm> // Para max, min #include <algorithm> // for max, min
#include <cmath> // Para ceil, abs #include <cmath> // for ceil, abs
#include "animated_sprite.h" // Para AnimatedSprite #include "animated_sprite.h" // for AnimatedSprite
#include "asset.h" // Para Asset #include "debug.h" // for Debug
#include "defines.h" // Para BORDER_TOP, BLOCK, BORDER_BOTTOM, BORDER... #include "defines.h" // for BORDER_BOTTOM, BORDER_LEFT, BORDER_RIGHT
#include "debug.h" // Para Debug #include "input.h" // for Input, InputAction
#include "input.h" // Para Input, inputs_e #include "jail_audio.h" // for JA_PlaySound
#include "jail_audio.h" // Para JA_LoadSound, JA_Sound_t, JA_PlaySound #include "options.h" // for Options, options, Cheat, OptionsVideo
#include "resource.h" // Para Resource #include "resource.h" // for Resource
#include "room.h" // Para Room, tile_e #include "room.h" // for Room, JA_Sound_t, TileType
#include "texture.h" // Para Texture #include "screen.h" // for Screen
#include "options.h" #include "texture.h" // for Texture
#include "screen.h"
// Constructor // Constructor
Player::Player(const PlayerData &player) Player::Player(const PlayerData &player)
@@ -289,7 +288,7 @@ void Player::move()
// Si ha tocado alguna rampa mientras camina (sin saltar), asciende // Si ha tocado alguna rampa mientras camina (sin saltar), asciende
if (state_ != PlayerState::JUMPING) if (state_ != PlayerState::JUMPING)
{ {
v_line_t leftSide = {static_cast<int>(x_), static_cast<int>(y_) + HEIGHT_ - 2, static_cast<int>(y_) + HEIGHT_ - 1}; // Comprueba solo los dos pixels de abajo LineVertical leftSide = {static_cast<int>(x_), static_cast<int>(y_) + HEIGHT_ - 2, static_cast<int>(y_) + HEIGHT_ - 1}; // Comprueba solo los dos pixels de abajo
const int ly = room_->checkLeftSlopes(&leftSide); const int ly = room_->checkLeftSlopes(&leftSide);
if (ly > -1) if (ly > -1)
{ {
@@ -336,7 +335,7 @@ void Player::move()
// Si ha tocado alguna rampa mientras camina (sin saltar), asciende // Si ha tocado alguna rampa mientras camina (sin saltar), asciende
if (state_ != PlayerState::JUMPING) if (state_ != PlayerState::JUMPING)
{ {
v_line_t rightSide = {static_cast<int>(x_) + WIDTH_ - 1, static_cast<int>(y_) + HEIGHT_ - 2, static_cast<int>(y_) + HEIGHT_ - 1}; // Comprueba solo los dos pixels de abajo LineVertical rightSide = {static_cast<int>(x_) + WIDTH_ - 1, static_cast<int>(y_) + HEIGHT_ - 2, static_cast<int>(y_) + HEIGHT_ - 1}; // Comprueba solo los dos pixels de abajo
const int ry = room_->checkRightSlopes(&rightSide); const int ry = room_->checkRightSlopes(&rightSide);
if (ry > -1) 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 // Si no hay colisión con los muros, comprueba la colisión con las rampas
if (state_ != PlayerState::JUMPING) if (state_ != PlayerState::JUMPING)
{ // Las rampas no se miran si se está saltando { // Las rampas no se miran si se está saltando
v_line_t leftSide = {proj.x, proj.y, proj.y + proj.h - 1}; LineVertical 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 rightSide = {proj.x + proj.w - 1, proj.y, proj.y + proj.h - 1};
const int p = std::max(room_->checkRightSlopes(&rightSide), room_->checkLeftSlopes(&leftSide)); const int p = std::max(room_->checkRightSlopes(&rightSide), room_->checkLeftSlopes(&leftSide));
if (p > -1) if (p > -1)
{ {
@@ -618,21 +617,17 @@ bool Player::checkKillingTiles()
// Actualiza los puntos de colisión // Actualiza los puntos de colisión
updateColliderPoints(); updateColliderPoints();
// Comprueba si hay contacto // Comprueba si hay contacto y retorna en cuanto se encuentra colisión
bool check = false; for (const auto &c : collider_points_)
for (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 return false; // No se encontró ninguna colisión
if (check)
{
is_alive_ = false;
}
return check;
} }
// Establece el color del jugador // 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 // Aplica los valores de spawn al jugador
void Player::applySpawnValues(const PlayerSpawn &spawn) void Player::applySpawnValues(const PlayerSpawn &spawn)
{ {

View File

@@ -1,20 +1,16 @@
#pragma once #pragma once
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point #include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
#include <SDL2/SDL_render.h> // Para SDL_Renderer #include <SDL2/SDL_render.h> // for SDL_RendererFlip, SDL_FLIP_NONE
#include <string> // Para basic_string, string #include <memory> // for shared_ptr, __shared_ptr_access
#include <vector> // Para vector #include <string> // for string
#include <memory> // Para shared_ptr #include <vector> // for vector
#include "utils.h" // Para color_t #include "animated_sprite.h" // for AnimatedSprite
#include "defines.h" // Para BLOCK #include "defines.h" // for BORDER_TOP, BLOCK
#include "room.h" #include "texture.h" // for Texture
#include "animated_sprite.h" #include "utils.h" // for Color
class Asset; class Room; // lines 16-16
class Debug; struct JA_Sound_t; // lines 17-17
class Input;
class Resource;
class Room;
struct JA_Sound_t;
enum class PlayerState enum class PlayerState
{ {
@@ -149,7 +145,7 @@ public:
void initSounds(); void initSounds();
// Coloca el sprite en la posición del jugador // Coloca el sprite en la posición del jugador
void placeSprite(); void placeSprite() { sprite_->setPos(x_, y_); }
// Aplica los valores de spawn al jugador // Aplica los valores de spawn al jugador
void applySpawnValues(const PlayerSpawn &spawn); void applySpawnValues(const PlayerSpawn &spawn);

View File

@@ -1,16 +1,20 @@
#include "resource.h" #include "resource.h"
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event, SDL_KEYDOWN
#include <SDL2/SDL_keycode.h> // for SDLK_ESCAPE
#include <SDL2/SDL_rect.h> // for SDL_Rect
#include <SDL2/SDL_render.h> // for SDL_RenderDrawRect, SDL_RenderFillRect
#include <stdlib.h> // for exit, size_t
#include <algorithm> // for find_if #include <algorithm> // for find_if
#include <iostream> // for basic_ostream, operator<<, endl, cout, cerr #include <iostream> // for basic_ostream, operator<<, endl, cout
#include <stdexcept> // for runtime_error #include <stdexcept> // for runtime_error
#include "asset.h" // for Asset, AssetType #include "asset.h" // for AssetType, Asset
#include "jail_audio.h" // for JA_DeleteMusic, JA_DeleteSound, JA_LoadMusic #include "jail_audio.h" // for JA_DeleteMusic, JA_DeleteSound, JA_Loa...
#include "options.h" // for Options, OptionsGame, options
#include "screen.h" // for Screen #include "screen.h" // for Screen
#include "text.h" // for Text, loadTextFile #include "text.h" // for Text, loadTextFile
#include "utils.h" // for getFileName, printWithDots #include "utils.h" // for getFileName, printWithDots, Color
#include "options.h" // for getFileName, printWithDots struct JA_Music_t; // lines 12-12
#include <SDL2/SDL_events.h> // for SDL_PollEvent struct JA_Sound_t; // lines 13-13
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 // [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
Resource *Resource::resource_ = nullptr; Resource *Resource::resource_ = nullptr;

View File

@@ -1,22 +1,23 @@
#include "room.h" #include "room.h"
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND #include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
#include <SDL2/SDL_error.h> // Para SDL_GetError #include <SDL2/SDL_error.h> // for SDL_GetError
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888 #include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
#include <stdlib.h> // Para rand #include <stdlib.h> // for rand
#include <fstream> // Para basic_ostream, operator<<, basic_ist... #include <exception> // for exception
#include <iostream> // Para cout #include <fstream> // for basic_ostream, operator<<, basic_ist...
#include <sstream> // Para basic_stringstream #include <iostream> // for cout, cerr
#include "asset.h" // Para Asset #include <sstream> // for basic_stringstream
#include "defines.h" // Para BLOCK, PLAY_AREA_HEIGHT, PLAY_AREA_W... #include "debug.h" // for Debug
#include "debug.h" // Para Debug #include "defines.h" // for BLOCK, PLAY_AREA_HEIGHT, PLAY_AREA_W...
#include "item_tracker.h" // Para ItemTracker #include "item_tracker.h" // for ItemTracker
#include "jail_audio.h" // Para JA_DeleteSound, JA_LoadSound, JA_Pla... #include "jail_audio.h" // for JA_PlaySound
#include "screen.h" // Para Screen #include "options.h" // for Options, options, OptionsVideo, Opti...
#include "sprite.h" // Para Sprite #include "resource.h" // for Resource
#include "texture.h" // Para Texture #include "scoreboard.h" // for ScoreboardData
#include "options.h" #include "screen.h" // for Screen
#include "utils.h" // Para stringToBool, stringToColor #include "sprite.h" // for Sprite
#include "resource.h" #include "texture.h" // for Texture
#include "utils.h" // for LineHorizontal, LineDiagonal, LineVe...
// Carga las variables y texturas desde un fichero de mapa de tiles // Carga las variables y texturas desde un fichero de mapa de tiles
std::vector<int> loadRoomTileFile(const std::string &file_path, bool verbose) std::vector<int> loadRoomTileFile(const std::string &file_path, bool verbose)
@@ -402,60 +403,13 @@ Room::Room(const std::string &room_path, std::shared_ptr<ScoreboardData> data)
: data_(data) : data_(data)
{ {
auto room = Resource::get()->getRoom(room_path); auto room = Resource::get()->getRoom(room_path);
number_ = room->number; initializeRoom(*room);
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);
// Inicializa variables // Abre la Jail si se da el caso
tile_set_width_ = texture_->getWidth() / TILE_SIZE_;
is_paused_ = false;
counter_ = 0;
// Crea los enemigos
for (auto &enemy_data : room->enemies)
{
enemies_.emplace_back(std::make_shared<Enemy>(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>(item));
}
}
// Abre la jail para poder entrar
if (data_->jail_is_open)
{
openTheJail(); openTheJail();
}
// Calcula las superficies // Inicializa las superficies de colision
setBottomSurfaces(); initRoomSurfaces();
setTopSurfaces();
setLeftSurfaces();
setRightSurfaces();
setLeftSlopes();
setRightSlopes();
setAutoSurfaces();
// Busca los tiles animados // Busca los tiles animados
setAnimatedTiles(); setAnimatedTiles();
@@ -475,16 +429,14 @@ Room::Room(const std::string &room_path, std::shared_ptr<ScoreboardData> data)
fillMapTexture(); fillMapTexture();
// Establece el color del borde // 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 // Destructor
Room::~Room() Room::~Room() { SDL_DestroyTexture(map_texture_); }
{
SDL_DestroyTexture(map_texture_);
}
void Room::initializeRoom(const RoomData& room) { void Room::initializeRoom(const RoomData &room)
{
// Asignar valores a las variables miembro // Asignar valores a las variables miembro
number_ = room.number; number_ = room.number;
name_ = room.name; name_ = room.name;
@@ -506,38 +458,27 @@ void Room::initializeRoom(const RoomData& room) {
counter_ = 0; counter_ = 0;
// Crear los enemigos // Crear los enemigos
for (auto &enemy_data : room.enemies) { for (auto &enemy_data : room.enemies)
{
enemies_.emplace_back(std::make_shared<Enemy>(enemy_data)); enemies_.emplace_back(std::make_shared<Enemy>(enemy_data));
} }
// Crear los items // Crear los items
for (auto &item : room.items) { for (const auto &item : room.items)
{
const SDL_Point itemPos = {item.x, item.y}; const SDL_Point itemPos = {item.x, item.y};
if (!ItemTracker::get()->hasBeenPicked(room.name, itemPos)) { 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>(item));
}
}
}
// Devuelve el nombre de la habitación
std::string Room::getName()
{ {
return name_; // 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_);
// Devuelve el color de la habitación // Crear el objeto Item usando la copia modificada
Color Room::getBGColor() items_.emplace_back(std::make_shared<Item>(itemCopy));
{ }
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 // Crea la textura con el mapeado de la habitación
@@ -687,7 +628,7 @@ void Room::renderMap()
// Dibuja los enemigos en pantalla // Dibuja los enemigos en pantalla
void Room::renderEnemies() void Room::renderEnemies()
{ {
for (auto enemy : enemies_) for (const auto &enemy : enemies_)
{ {
enemy->render(); enemy->render();
} }
@@ -696,7 +637,7 @@ void Room::renderEnemies()
// Dibuja los objetos en pantalla // Dibuja los objetos en pantalla
void Room::renderItems() void Room::renderItems()
{ {
for (auto item : items_) for (const auto &item : items_)
{ {
item->render(); item->render();
} }
@@ -706,7 +647,8 @@ void Room::renderItems()
void Room::update() void Room::update()
{ {
if (is_paused_) if (is_paused_)
{ // Si está en modo pausa no se actualiza nada {
// Si está en modo pausa no se actualiza nada
return; return;
} }
@@ -717,12 +659,14 @@ void Room::update()
updateAnimatedTiles(); updateAnimatedTiles();
for (auto enemy : enemies_) for (auto enemy : enemies_)
{ // Actualiza los enemigos {
// Actualiza los enemigos
enemy->update(); enemy->update();
} }
for (auto item : items_) for (auto item : items_)
{ // Actualiza los items {
// Actualiza los items
item->update(); item->update();
} }
} }
@@ -755,14 +699,14 @@ std::string Room::getRoom(int border)
} }
// Devuelve el tipo de tile que hay en ese pixel // 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_); const int pos = ((point.y / TILE_SIZE_) * MAP_WIDTH_) + (point.x / TILE_SIZE_);
return getTile(pos); return getTile(pos);
} }
// Devuelve el tipo de tile que hay en ese indice // 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 < mapWidth * mapHeight);
const bool onRange = (index > -1) && (index < (int)tile_map_.size()); 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 // Las filas 0-8 son de tiles t_wall
if ((tile_map_[index] >= 0) && (tile_map_[index] < 9 * tile_set_width_)) 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 // 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_)) 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 // 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_)) 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 // 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_)) 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 // 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_)) 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 // La fila 23 es de tiles t_kill
else if ((tile_map_[index] >= 23 * tile_set_width_) && (tile_map_[index] < 24 * tile_set_width_)) 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 // Indica si hay colision con un enemigo a partir de un rectangulo
bool Room::enemyCollision(SDL_Rect &rect) bool Room::enemyCollision(SDL_Rect &rect)
{ {
bool collision = false; for (const auto &enemy : enemies_)
for (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 // Indica si hay colision con un objeto a partir de un rectangulo
bool Room::itemCollision(SDL_Rect &rect) bool Room::itemCollision(SDL_Rect &rect)
{ {
for (int i = 0; i < (int)items_.size(); ++i) for (int i = 0; i < static_cast<int>(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); items_.erase(items_.begin() + i);
JA_PlaySound(Resource::get()->getSound("item.wav")); JA_PlaySound(Resource::get()->getSound("item.wav"));
data_->items++; 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 // 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 // Calcula la base del tile
int base = ((p.y / TILE_SIZE_) * TILE_SIZE_) + TILE_SIZE_; int base = ((p.y / TILE_SIZE_) * TILE_SIZE_) + TILE_SIZE_;
@@ -857,7 +801,7 @@ int Room::getSlopeHeight(SDL_Point p, tile_e slope)
#endif #endif
// Se resta a la base la cantidad de pixeles pos en funcion de la rampa // 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; base -= pos + 1;
#ifdef DEBUG #ifdef DEBUG
@@ -884,7 +828,7 @@ void Room::setBottomSurfaces()
// Hay que recorrer la habitación por filas (excepto los de la última fila) // 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) 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); tile.push_back(i);
@@ -905,7 +849,7 @@ void Room::setBottomSurfaces()
int i = 0; int i = 0;
do do
{ {
h_line_t line; LineHorizontal line;
line.x1 = (tile[i] % MAP_WIDTH_) * TILE_SIZE_; line.x1 = (tile[i] % MAP_WIDTH_) * TILE_SIZE_;
line.y = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1; line.y = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
int last_one = i; 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) // 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) 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); tile.push_back(i);
@@ -967,7 +911,7 @@ void Room::setTopSurfaces()
int i = 0; int i = 0;
do do
{ {
h_line_t line; LineHorizontal line;
line.x1 = (tile[i] % MAP_WIDTH_) * TILE_SIZE_; line.x1 = (tile[i] % MAP_WIDTH_) * TILE_SIZE_;
line.y = (tile[i] / MAP_WIDTH_) * TILE_SIZE_; line.y = (tile[i] / MAP_WIDTH_) * TILE_SIZE_;
int last_one = i; int last_one = i;
@@ -1011,7 +955,7 @@ void Room::setLeftSurfaces()
for (int j = 0; j < MAP_HEIGHT_; ++j) for (int j = 0; j < MAP_HEIGHT_; ++j)
{ {
const int pos = (j * MAP_WIDTH_ + i); 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); tile.push_back(pos);
} }
@@ -1029,7 +973,7 @@ void Room::setLeftSurfaces()
int i = 0; int i = 0;
do do
{ {
v_line_t line; LineVertical line;
line.x = (tile[i] % MAP_WIDTH_) * TILE_SIZE_; line.x = (tile[i] % MAP_WIDTH_) * TILE_SIZE_;
line.y1 = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_); line.y1 = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_);
while (tile[i] + MAP_WIDTH_ == tile[i + 1]) while (tile[i] + MAP_WIDTH_ == tile[i + 1])
@@ -1059,7 +1003,7 @@ void Room::setRightSurfaces()
for (int j = 0; j < MAP_HEIGHT_; ++j) for (int j = 0; j < MAP_HEIGHT_; ++j)
{ {
const int pos = (j * MAP_WIDTH_ + i); 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); tile.push_back(pos);
} }
@@ -1077,7 +1021,7 @@ void Room::setRightSurfaces()
int i = 0; int i = 0;
do do
{ {
v_line_t line; LineVertical line;
line.x = ((tile[i] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1; line.x = ((tile[i] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
line.y1 = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_); line.y1 = ((tile[i] / MAP_WIDTH_) * TILE_SIZE_);
while (tile[i] + MAP_WIDTH_ == tile[i + 1]) while (tile[i] + MAP_WIDTH_ == tile[i + 1])
@@ -1102,7 +1046,7 @@ void Room::setLeftSlopes()
std::vector<int> found; std::vector<int> found;
for (int i = 0; i < (int)tile_map_.size(); ++i) 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); found.push_back(i);
} }
@@ -1114,7 +1058,7 @@ void Room::setLeftSlopes()
while (found.size() > 0) while (found.size() > 0)
{ {
d_line_t line; LineDiagonal line;
line.x1 = (found[0] % MAP_WIDTH_) * TILE_SIZE_; line.x1 = (found[0] % MAP_WIDTH_) * TILE_SIZE_;
line.y1 = (found[0] / MAP_WIDTH_) * TILE_SIZE_; line.y1 = (found[0] / MAP_WIDTH_) * TILE_SIZE_;
int lookingFor = found[0] + MAP_WIDTH_ + 1; int lookingFor = found[0] + MAP_WIDTH_ + 1;
@@ -1143,7 +1087,7 @@ void Room::setRightSlopes()
std::vector<int> found; std::vector<int> found;
for (int i = 0; i < (int)tile_map_.size(); ++i) 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); found.push_back(i);
} }
@@ -1155,7 +1099,7 @@ void Room::setRightSlopes()
while (found.size() > 0) while (found.size() > 0)
{ {
d_line_t line; LineDiagonal line;
line.x1 = ((found[0] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1; line.x1 = ((found[0] % MAP_WIDTH_) * TILE_SIZE_) + TILE_SIZE_ - 1;
line.y1 = (found[0] / MAP_WIDTH_) * TILE_SIZE_; line.y1 = (found[0] / MAP_WIDTH_) * TILE_SIZE_;
int lookingFor = found[0] + MAP_WIDTH_ - 1; 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) // 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) 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); tile.push_back(i);
@@ -1204,7 +1148,7 @@ void Room::setAutoSurfaces()
int i = 0; int i = 0;
do do
{ {
h_line_t line; LineHorizontal line;
line.x1 = (tile[i] % MAP_WIDTH_) * TILE_SIZE_; line.x1 = (tile[i] % MAP_WIDTH_) * TILE_SIZE_;
line.y = (tile[i] / MAP_WIDTH_) * TILE_SIZE_; line.y = (tile[i] / MAP_WIDTH_) * TILE_SIZE_;
int last_one = i; int last_one = i;
@@ -1242,7 +1186,7 @@ void Room::setAnimatedTiles()
// Recorre la habitación entera por filas buscando tiles de tipo t_animated // Recorre la habitación entera por filas buscando tiles de tipo t_animated
for (int i = 0; i < (int)tile_map_.size(); ++i) 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 // La i es la ubicación
const int x = (i % MAP_WIDTH_) * TILE_SIZE_; const int x = (i % MAP_WIDTH_) * TILE_SIZE_;
@@ -1286,7 +1230,7 @@ void Room::updateAnimatedTiles()
// Pinta los tiles animados en pantalla // Pinta los tiles animados en pantalla
void Room::renderAnimatedTiles() void Room::renderAnimatedTiles()
{ {
for (auto a : animated_tiles_) for (const auto &a : animated_tiles_)
{ {
a.sprite->render(); a.sprite->render();
} }
@@ -1295,7 +1239,7 @@ void Room::renderAnimatedTiles()
// Comprueba las colisiones // Comprueba las colisiones
int Room::checkRightSurfaces(SDL_Rect *rect) int Room::checkRightSurfaces(SDL_Rect *rect)
{ {
for (auto s : right_surfaces_) for (const auto &s : right_surfaces_)
{ {
if (checkCollision(s, *rect)) if (checkCollision(s, *rect))
{ {
@@ -1309,7 +1253,7 @@ int Room::checkRightSurfaces(SDL_Rect *rect)
// Comprueba las colisiones // Comprueba las colisiones
int Room::checkLeftSurfaces(SDL_Rect *rect) int Room::checkLeftSurfaces(SDL_Rect *rect)
{ {
for (auto s : left_surfaces_) for (const auto &s : left_surfaces_)
{ {
if (checkCollision(s, *rect)) if (checkCollision(s, *rect))
{ {
@@ -1323,7 +1267,7 @@ int Room::checkLeftSurfaces(SDL_Rect *rect)
// Comprueba las colisiones // Comprueba las colisiones
int Room::checkTopSurfaces(SDL_Rect *rect) int Room::checkTopSurfaces(SDL_Rect *rect)
{ {
for (auto s : top_surfaces_) for (const auto &s : top_surfaces_)
{ {
if (checkCollision(s, *rect)) if (checkCollision(s, *rect))
{ {
@@ -1337,7 +1281,7 @@ int Room::checkTopSurfaces(SDL_Rect *rect)
// Comprueba las colisiones // Comprueba las colisiones
int Room::checkBottomSurfaces(SDL_Rect *rect) int Room::checkBottomSurfaces(SDL_Rect *rect)
{ {
for (auto s : bottom_surfaces_) for (const auto &s : bottom_surfaces_)
{ {
if (checkCollision(s, *rect)) if (checkCollision(s, *rect))
{ {
@@ -1351,7 +1295,7 @@ int Room::checkBottomSurfaces(SDL_Rect *rect)
// Comprueba las colisiones // Comprueba las colisiones
int Room::checkAutoSurfaces(SDL_Rect *rect) int Room::checkAutoSurfaces(SDL_Rect *rect)
{ {
for (auto s : auto_surfaces_) for (const auto &s : auto_surfaces_)
{ {
if (checkCollision(s, *rect)) if (checkCollision(s, *rect))
{ {
@@ -1365,7 +1309,7 @@ int Room::checkAutoSurfaces(SDL_Rect *rect)
// Comprueba las colisiones // Comprueba las colisiones
bool Room::checkTopSurfaces(SDL_Point *p) bool Room::checkTopSurfaces(SDL_Point *p)
{ {
for (auto s : top_surfaces_) for (const auto &s : top_surfaces_)
{ {
if (checkCollision(s, *p)) if (checkCollision(s, *p))
{ {
@@ -1379,7 +1323,7 @@ bool Room::checkTopSurfaces(SDL_Point *p)
// Comprueba las colisiones // Comprueba las colisiones
bool Room::checkAutoSurfaces(SDL_Point *p) bool Room::checkAutoSurfaces(SDL_Point *p)
{ {
for (auto s : auto_surfaces_) for (const auto &s : auto_surfaces_)
{ {
if (checkCollision(s, *p)) if (checkCollision(s, *p))
{ {
@@ -1391,9 +1335,9 @@ bool Room::checkAutoSurfaces(SDL_Point *p)
} }
// Comprueba las colisiones // 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); const SDL_Point p = checkCollision(slope, *line);
if (p.x != -1) if (p.x != -1)
@@ -1408,7 +1352,7 @@ int Room::checkLeftSlopes(const v_line_t *line)
// Comprueba las colisiones // Comprueba las colisiones
bool Room::checkLeftSlopes(SDL_Point *p) bool Room::checkLeftSlopes(SDL_Point *p)
{ {
for (auto slope : left_slopes_) for (const auto &slope : left_slopes_)
{ {
if (checkCollision(*p, slope)) if (checkCollision(*p, slope))
{ {
@@ -1420,9 +1364,9 @@ bool Room::checkLeftSlopes(SDL_Point *p)
} }
// Comprueba las colisiones // 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); const SDL_Point p = checkCollision(slope, *line);
if (p.x != -1) if (p.x != -1)
@@ -1437,7 +1381,7 @@ int Room::checkRightSlopes(const v_line_t *line)
// Comprueba las colisiones // Comprueba las colisiones
bool Room::checkRightSlopes(SDL_Point *p) bool Room::checkRightSlopes(SDL_Point *p)
{ {
for (auto slope : right_slopes_) for (const auto &slope : right_slopes_)
{ {
if (checkCollision(*p, slope)) if (checkCollision(*p, slope))
{ {
@@ -1448,24 +1392,39 @@ bool Room::checkRightSlopes(SDL_Point *p)
return false; return false;
} }
// Obten la direccion de las superficies automaticas // Abre la Jail si se da el caso
int Room::getAutoSurfaceDirection()
{
return auto_surface_direction_;
}
// Abre la jail para poder entrar
void Room::openTheJail() void Room::openTheJail()
{ {
if (name_ == "THE JAIL") if (data_->jail_is_open && name_ == "THE JAIL")
{
// Elimina el último enemigo (Bry debe ser el último enemigo definido en el fichero)
if (!enemies_.empty())
{ {
// Elimina el último enemigo (Bry debe ser el ultimo enemigo definido en el fichero)
enemies_.pop_back(); enemies_.pop_back();
}
// Abre las puertas // Abre las puertas
const int tileA = 16 + (13 * 32); constexpr int TILE_A = 16 + (13 * 32);
const int tileB = 16 + (14 * 32); constexpr int TILE_B = 16 + (14 * 32);
tile_map_[tileA] = -1; if (TILE_A < tile_map_.size())
tile_map_[tileB] = -1; {
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();
}

View File

@@ -1,31 +1,30 @@
#pragma once #pragma once
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point #include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture #include <SDL2/SDL_render.h> // for SDL_Texture
#include <memory> // for shared_ptr #include <memory> // for shared_ptr
#include <string> // for string #include <string> // for string
#include <vector> // for vector #include <vector> // for vector
#include "enemy.h" // for EnemyData #include "enemy.h" // for EnemyData
#include "item.h" // for item_t #include "item.h" // for ItemData
#include "utils.h" // for Color #include "options.h" // for Options, OptionsVideo, options
#include "scoreboard.h" #include "utils.h" // for stringToColor, Color
class Asset; // lines 12-12 class Sprite; // lines 17-17
class Debug; // lines 13-13 class Texture; // lines 18-18
class ItemTracker; struct JA_Sound_t; // lines 19-19
class Screen; // lines 14-14 struct ScoreboardData; // lines 20-20
class Sprite; // lines 15-15
class Texture; // lines 16-16
struct JA_Sound_t; // lines 17-17
enum tile_e
enum class TileType
{ {
t_empty, EMPTY,
t_wall, WALL,
t_passable, PASSABLE,
t_slope_l, SLOPE_L,
t_slope_r, SLOPE_R,
t_kill, KILL,
t_animated ANIMATED
}; };
struct AnimatedTile struct AnimatedTile
@@ -100,16 +99,16 @@ private:
std::vector<int> tile_map_; // Indice de los tiles a dibujar en la habitación std::vector<int> 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 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 JA_Sound_t *item_sound_; // Sonido producido al coger un objeto
std::vector<h_line_t> bottom_surfaces_; // Lista con las superficies inferiores de la habitación std::vector<LineHorizontal> bottom_surfaces_; // Lista con las superficies inferiores de la habitación
std::vector<h_line_t> top_surfaces_; // Lista con las superficies superiores de la habitación std::vector<LineHorizontal> top_surfaces_; // Lista con las superficies superiores de la habitación
std::vector<v_line_t> left_surfaces_; // Lista con las superficies laterales de la parte izquierda de la habitación std::vector<LineVertical> left_surfaces_; // Lista con las superficies laterales de la parte izquierda de la habitación
std::vector<v_line_t> right_surfaces_; // Lista con las superficies laterales de la parte derecha de la habitación std::vector<LineVertical> right_surfaces_; // Lista con las superficies laterales de la parte derecha de la habitación
std::vector<d_line_t> left_slopes_; // Lista con todas las rampas que suben hacia la izquierda std::vector<LineDiagonal> left_slopes_; // Lista con todas las rampas que suben hacia la izquierda
std::vector<d_line_t> right_slopes_; // Lista con todas las rampas que suben hacia la derecha std::vector<LineDiagonal> right_slopes_; // Lista con todas las rampas que suben hacia la derecha
int counter_; // Contador para lo que haga falta int counter_; // Contador para lo que haga falta
bool is_paused_; // Indica si el mapa esta en modo pausa bool is_paused_; // Indica si el mapa esta en modo pausa
std::vector<AnimatedTile> animated_tiles_; // Vector con los indices de tiles animados std::vector<AnimatedTile> animated_tiles_; // Vector con los indices de tiles animados
std::vector<h_line_t> auto_surfaces_; // Lista con las superficies automaticas de la habitación std::vector<LineHorizontal> auto_surfaces_; // Lista con las superficies automaticas de la habitación
int tile_set_width_; // Ancho del tileset en tiles int tile_set_width_; // Ancho del tileset en tiles
void initializeRoom(const RoomData &room); void initializeRoom(const RoomData &room);
@@ -148,11 +147,14 @@ private:
void renderAnimatedTiles(); void renderAnimatedTiles();
// Devuelve el tipo de tile que hay en ese indice // 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 // Abre la jail para poder entrar
void openTheJail(); void openTheJail();
// Inicializa las superficies de colision
void initRoomSurfaces();
public: public:
// Constructor // Constructor
Room(const std::string &room_path, std::shared_ptr<ScoreboardData> data); Room(const std::string &room_path, std::shared_ptr<ScoreboardData> data);
@@ -161,13 +163,13 @@ public:
~Room(); ~Room();
// Devuelve el nombre de la habitación // Devuelve el nombre de la habitación
std::string getName(); std::string getName() const { return name_; }
// Devuelve el color de la habitación // Devuelve el color de la habitación
Color getBGColor(); Color getBGColor() const { return stringToColor(options.video.palette, bg_color_); }
// Devuelve el color del borde // Devuelve el color del borde
Color getBorderColor(); Color getBorderColor() const { return stringToColor(options.video.palette, border_color_); }
// Dibuja el mapa en pantalla // Dibuja el mapa en pantalla
void renderMap(); void renderMap();
@@ -185,7 +187,7 @@ public:
std::string getRoom(int border); std::string getRoom(int border);
// Devuelve el tipo de tile que hay en ese pixel // 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 // Indica si hay colision con un enemigo a partir de un rectangulo
bool enemyCollision(SDL_Rect &rect); bool enemyCollision(SDL_Rect &rect);
@@ -197,7 +199,7 @@ public:
int getTileSize() const { return TILE_SIZE_; } int getTileSize() const { return TILE_SIZE_; }
// Obten la coordenada de la cuesta a partir de un punto perteneciente a ese tile // 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 // Comprueba las colisiones
int checkRightSurfaces(SDL_Rect *rect); int checkRightSurfaces(SDL_Rect *rect);
@@ -221,13 +223,13 @@ public:
bool checkAutoSurfaces(SDL_Point *p); bool checkAutoSurfaces(SDL_Point *p);
// Comprueba las colisiones // Comprueba las colisiones
int checkLeftSlopes(const v_line_t *line); int checkLeftSlopes(const LineVertical *line);
// Comprueba las colisiones // Comprueba las colisiones
bool checkLeftSlopes(SDL_Point *p); bool checkLeftSlopes(SDL_Point *p);
// Comprueba las colisiones // Comprueba las colisiones
int checkRightSlopes(const v_line_t *line); int checkRightSlopes(const LineVertical *line);
// Comprueba las colisiones // Comprueba las colisiones
bool checkRightSlopes(SDL_Point *p); bool checkRightSlopes(SDL_Point *p);
@@ -236,5 +238,5 @@ public:
void setPaused(bool value) { is_paused_ = value; }; void setPaused(bool value) { is_paused_ = value; };
// Obten la direccion de las superficies automaticas // Obten la direccion de las superficies automaticas
int getAutoSurfaceDirection(); int getAutoSurfaceDirection() const { return auto_surface_direction_; }
}; };

View File

@@ -1,15 +1,16 @@
#include "scoreboard.h" #include "scoreboard.h"
#include <SDL2/SDL_error.h> // for SDL_GetError
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
#include <SDL2/SDL_rect.h> // for SDL_Rect #include <SDL2/SDL_rect.h> // for SDL_Rect
#include <SDL2/SDL_timer.h> // for SDL_GetTicks #include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <iostream> // for basic_ostream, operator<<, cout, endl
#include "animated_sprite.h" // for AnimatedSprite #include "animated_sprite.h" // for AnimatedSprite
#include "asset.h" // for Asset #include "defines.h" // for BLOCK
#include "defines.h" // for BLOCK, GAMECANVAS_HEIGHT, PLAY_AREA_HEIGHT
#include "options.h" // for Options, options, OptionsVideo, Cheat #include "options.h" // for Options, options, OptionsVideo, Cheat
#include "resource.h" // for Resource #include "resource.h" // for Resource
#include "screen.h" // for Screen #include "screen.h" // for Screen
#include "text.h" // for Text #include "text.h" // for Text
#include "texture.h" // for Texture #include "texture.h" // for Texture
#include <iostream>
// Constructor // Constructor
Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data) Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)

View File

@@ -1,16 +1,14 @@
#pragma once #pragma once
#include <SDL2/SDL_render.h> // Para SDL_Renderer #include <SDL2/SDL_rect.h> // for SDL_Rect
#include <SDL2/SDL_stdinc.h> // Para Uint32 #include <SDL2/SDL_render.h> // for SDL_Texture
#include <string> // Para basic_string, string #include <SDL2/SDL_stdinc.h> // for Uint32
#include <vector> // Para vector #include <memory> // for shared_ptr
#include "utils.h" // Para color_t #include <string> // for string, basic_string
#include <memory> // Para shared_ptr #include <vector> // for vector
class AnimatedSprite; #include "utils.h" // for Color
class Asset; class AnimatedSprite; // lines 9-9
class Resource; class Texture; // lines 13-13
class Text;
class Texture;
struct ScoreboardData struct ScoreboardData
{ {

View File

@@ -2,13 +2,10 @@
#include <SDL2/SDL_blendmode.h> // for SDL_BlendMode #include <SDL2/SDL_blendmode.h> // for SDL_BlendMode
#include <SDL2/SDL_rect.h> // for SDL_Rect #include <SDL2/SDL_rect.h> // for SDL_Rect
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture #include <SDL2/SDL_render.h> // for SDL_Texture, SDL_Renderer
#include <SDL2/SDL_stdinc.h> // for Uint32 #include <SDL2/SDL_stdinc.h> // for Uint32
#include <SDL2/SDL_video.h> // for SDL_Window #include <SDL2/SDL_video.h> // for SDL_Window
#include <vector> // for vector
#include <memory> // for shared_ptr
#include "utils.h" // for Color #include "utils.h" // for Color
//#include "surface.h"
// Tipos de filtro // Tipos de filtro
enum class ScreenFilter : Uint32 enum class ScreenFilter : Uint32

View File

@@ -1,14 +1,14 @@
#include "surface.h" #include "surface.h"
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_ARGB8888 #include <SDL2/SDL_error.h> // for SDL_GetError
#include <SDL2/SDL_rect.h> // Para SDL_Rect #include <stddef.h> // for size_t
#include <fstream> // Para std::ifstream #include <algorithm> // for min, copy, fill
#include <iostream> // Para std::cerr #include <fstream> // for basic_ostream, basic_ifstream, basic_ios
#include <vector> // Para std::vector #include <iostream> // for cerr, cout
#include <stdexcept> // For exceptions #include <memory> // for shared_ptr, __shared_ptr_access, unique_ptr
#include "gif.h" // Para LoadGif, LoadPalette #include <stdexcept> // for runtime_error
#include <memory> // Para std::shared_ptr #include <vector> // for vector
#include <algorithm> // Para std::copy #include "asset.h" // for Asset
#include "asset.h" #include "gif.h" // for LoadGif, LoadPalette
Surface::Surface(std::shared_ptr<SurfaceData> surface_dest, int w, int h) Surface::Surface(std::shared_ptr<SurfaceData> surface_dest, int w, int h)
: surface_dest_(surface_dest), : surface_dest_(surface_dest),

View File

@@ -1,14 +1,12 @@
#include "texture.h" #include "texture.h"
#include <SDL2/SDL_error.h> // Para SDL_GetError #include <SDL2/SDL_error.h> // for SDL_GetError
#include <SDL2/SDL_surface.h> // Para SDL_CreateRGBSurfaceWithFormatFrom #include <SDL2/SDL_surface.h> // for SDL_CreateRGBSurfaceWithFormatFrom
#include <fstream> // Para basic_ostream, operator<<, basic_ifstream #include <iostream> // for basic_ostream, operator<<, endl, cout
#include <iostream> // Para cerr, cout #include <stdexcept> // for runtime_error
#include <stdexcept> // Para runtime_error #include <string> // for char_traits, operator<<, string, opera...
#include <string> // Para char_traits, operator<<, operator+ #include <vector> // for vector
#include <vector> // Para vector #include "utils.h" // for getFileName, Color, printWithDots
#include "stb_image.h" // Para stbi_image_free, stbi_load, STBI_rgb_a...
#include "utils.h" // Para getFileName, printWithDots
#define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h" // para stbi_failure_reason, stbi_image_free #include "stb_image.h" // para stbi_failure_reason, stbi_image_free

View File

@@ -1,14 +1,13 @@
#pragma once #pragma once
#include <SDL2/SDL_blendmode.h> // Para SDL_BlendMode #include <SDL2/SDL_blendmode.h> // for SDL_BlendMode
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888, SDL_PixelF... #include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888, SDL_PixelF...
#include <SDL2/SDL_rect.h> // Para SDL_Point, SDL_Rect #include <SDL2/SDL_rect.h> // for SDL_Point, SDL_Rect
#include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_FLIP_NONE, SDL_TEX... #include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_FLIP_NONE, SDL_TEX...
#include <SDL2/SDL_stdinc.h> // Para Uint8, Uint16, Uint32 #include <SDL2/SDL_stdinc.h> // for Uint8, Uint32
#include <memory> // Para shared_ptr #include <string> // for string
#include <string> // Para string #include <vector> // for vector
#include <vector> // Para vector struct Color; // lines 11-11
struct Color;
// Definiciones de tipos // Definiciones de tipos
/*struct Surface /*struct Surface

View File

@@ -1,18 +1,14 @@
#pragma once #pragma once
#include <SDL2/SDL_rect.h> // for SDL_Rect #include <SDL2/SDL_rect.h> // for SDL_Rect
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture #include <SDL2/SDL_render.h> // for SDL_Texture
#include <SDL2/SDL_stdinc.h> // for Uint32 #include <SDL2/SDL_stdinc.h> // for Uint32
#include <memory> // for shared_ptr #include <memory> // for shared_ptr
#include <string> // for string #include <string> // for string
#include <vector> // for vector #include <vector> // for vector
#include "paleta.h" // for jSurface #include "paleta.h" // for jSurface
class Input; // lines 13-13 class Sprite; // lines 13-13
class Resource; // lines 14-14 class Texture; // lines 15-15
class Screen; // lines 15-15
class Sprite; // lines 16-16
class Text; // lines 17-17
class Texture; // lines 18-18
class Title class Title
{ {

View File

@@ -1,15 +1,16 @@
#include "utils.h" #include "utils.h"
#include <stdlib.h> // for free, malloc, abs #include <stdlib.h> // for abs
#include <algorithm> // for transform #include <algorithm> // for find, transform
#include <cctype> // for tolower #include <cctype> // for tolower
#include <cmath> // for round, abs #include <cmath> // for round, abs
#include <exception> // for exception #include <exception> // for exception
#include <filesystem> // for path #include <filesystem> // for path
#include <iostream> // for basic_ostream, cout, basic_ios, ios, endl #include <iostream> // for basic_ostream, cout, basic_ios, ios, endl
#include <unordered_map> // for unordered_map #include <string> // for basic_string, string, char_traits, allocator
#include <string> // for string #include <unordered_map> // for unordered_map, operator==, _Node_const_iter...
#include "jail_audio.h" #include <utility> // for pair
#include "resource.h" #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 // Calcula el cuadrado de la distancia entre dos puntos
double distanceSquared(int x1, int y1, int x2, int y2) 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 // 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 // Comprueba si la linea esta por encima del rectangulo
if (l.y < r.y) 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 // 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 // Comprueba si la linea esta por la izquierda del rectangulo
if (l.x < r.x) 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 // 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 // Comprueba si el punto esta sobre la linea
if (p.y > l.y) 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 // 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 x1 = l1.x1;
const float y1 = l1.y1; 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 // 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 x1 = l1.x1;
const float y1 = l1.y1; 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 // Normaliza una linea diagonal
void normalizeLine(d_line_t &l) void normalizeLine(LineDiagonal &l)
{ {
// Las lineas diagonales van de izquierda a derecha // Las lineas diagonales van de izquierda a derecha
// x2 mayor que x1 // x2 mayor que x1
@@ -321,7 +322,7 @@ void normalizeLine(d_line_t &l)
} }
// Detector de colisiones entre un punto y una linea diagonal // 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 // Comprueba si el punto está en alineado con la linea
if (abs(p.x - l.x1) != abs(p.y - l.y1)) 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 // Convierte una cadena a minúsculas
std::string toLower(std::string str) std::string toLower(std::string str)
{ {
for (char& c : str) { for (char &c : str)
if (c >= 'A' && c <= 'Z') { {
if (c >= 'A' && c <= 'Z')
{
c += 32; // Convierte a minúscula c += 32; // Convierte a minúscula
} }
} }
@@ -478,8 +481,10 @@ std::string toLower(std::string str)
// Convierte una cadena a mayúsculas // Convierte una cadena a mayúsculas
std::string toUpper(std::string str) std::string toUpper(std::string str)
{ {
for (char& c : str) { for (char &c : str)
if (c >= 'a' && c <= 'z') { {
if (c >= 'a' && c <= 'z')
{
c -= 32; // Convierte a mayúscula c -= 32; // Convierte a mayúscula
} }
} }

View File

@@ -1,11 +1,10 @@
#pragma once #pragma once
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point #include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
#include <SDL2/SDL_stdinc.h> // for Uint8 #include <SDL2/SDL_stdinc.h> // for Uint8
#include <string> // for string #include <string> // for string
#include <vector> #include <vector> // for vector
#include <SDL2/SDL_render.h> // for SDL_Renderer
#include <SDL2/SDL.h> // for SDL_Texture
// Tipos de paleta // Tipos de paleta
enum class Palette : int enum class Palette : int
@@ -23,25 +22,25 @@ struct Circle
}; };
// Estructura para definir una linea horizontal // Estructura para definir una linea horizontal
struct h_line_t struct LineHorizontal
{ {
int x1, x2, y; int x1, x2, y;
}; };
// Estructura para definir una linea vertical // Estructura para definir una linea vertical
struct v_line_t struct LineVertical
{ {
int x, y1, y2; int x, y1, y2;
}; };
// Estructura para definir una linea diagonal // Estructura para definir una linea diagonal
struct d_line_t struct LineDiagonal
{ {
int x1, y1, x2, y2; int x1, y1, x2, y2;
}; };
// Estructura para definir una linea // Estructura para definir una linea
struct line_t struct Line
{ {
int x1, y1, x2, y2; 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); bool checkCollision(const SDL_Point &p, const SDL_Rect &r);
// Detector de colisiones entre una linea horizontal y un rectangulo // 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 // 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 // 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 // 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 // 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 // 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 // Normaliza una linea diagonal
void normalizeLine(d_line_t &l); void normalizeLine(LineDiagonal &l);
// Devuelve un Color a partir de un string // Devuelve un Color a partir de un string
Color stringToColor(Palette pal, const std::string &str); Color stringToColor(Palette pal, const std::string &str);