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 <iostream> // 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

View File

@@ -1,17 +1,12 @@
#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 <memory> // for shared_ptr
#include <string> // for string
#include <vector> // for vector
#include "utils.h" // for Color
class AnimatedSprite; // lines 10-10
class Asset; // lines 11-11
class Input; // lines 12-12
class Resource; // lines 13-13
class Screen; // lines 14-14
class Text; // lines 15-15
class AnimatedSprite; // lines 9-9
class Credits
{

View File

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

View File

@@ -1,13 +1,8 @@
#pragma once
#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 <vector> // for vector
class Screen; // lines 9-9
class Text; // lines 10-10
class Texture; // lines 11-11
// Clase Debug
class Debug

View File

@@ -1,20 +1,19 @@
#include "demo.h"
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
#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 <iostream> // 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 "scoreboard.h" // for ScoreboardData, Scoreboard
#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
// Constructor

View File

@@ -1,19 +1,12 @@
#pragma once
#include <SDL2/SDL_render.h> // for SDL_Renderer
#include <SDL2/SDL_stdinc.h> // for Uint32
#include <memory> // for shared_ptr
#include <string> // for string
#include <vector> // for vector
#include "scoreboard.h" // for board_t
class Asset; // lines 11-11
class Debug; // lines 12-12
class Input; // lines 13-13
class ItemTracker; // lines 14-14
class Resource; // lines 15-15
class Room; // lines 16-16
class Screen; // lines 17-17
class Text; // lines 18-18
class Room; // lines 14-14
class Scoreboard;
struct ScoreboardData;
class Demo
{

View File

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

View File

@@ -7,11 +7,9 @@
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <algorithm> // for min
#include <iostream> // 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

View File

@@ -1,18 +1,12 @@
#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 <memory> // for shared_ptr
#include <string> // for string
#include <vector> // for vector
class Asset; // lines 9-9
class Input; // lines 10-10
class Resource; // lines 11-11
class Screen; // lines 12-12
class Sprite; // lines 13-13
class Text; // lines 14-14
class Texture; // lines 15-15
struct JA_Music_t; // lines 16-16
class Sprite; // lines 12-12
class Texture; // lines 14-14
class Ending
{

View File

@@ -2,14 +2,13 @@
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
#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 <algorithm> // 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...

View File

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

View File

@@ -8,23 +8,23 @@
#include <vector> // 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 "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 "resource.h" // for Resource, res_room_t
#include "room.h" // for Room, room_t
#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, 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 "text.h" // for Text, TEXT_CENTER, TEXT_COLOR
#include "utils.h" // for Color, stringToColor, colorAreEqual
// Constructor
Game::Game()

View File

@@ -1,28 +1,17 @@
#pragma once
#include <SDL2/SDL_events.h> // Para SDL_Event
#include <SDL2/SDL_rect.h> // Para SDL_Rect
#include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_Texture
#include <SDL2/SDL_stdinc.h> // Para Uint32
#include <string> // 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 <SDL2/SDL_events.h> // for SDL_Event
#include <SDL2/SDL_rect.h> // for SDL_Rect
#include <SDL2/SDL_render.h> // for SDL_Texture
#include <SDL2/SDL_stdinc.h> // for Uint32
#include <memory> // for shared_ptr
#include <string> // 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
{

View File

@@ -4,11 +4,9 @@
#include <algorithm> // for min, max
#include <string> // 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 "defines.h" // for GAMECANVAS_CENTER_X, GAME_SPEED
#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

View File

@@ -1,17 +1,10 @@
#pragma once
#include <SDL2/SDL_render.h> // for SDL_Renderer
#include <SDL2/SDL_stdinc.h> // for Uint32
#include <memory> // for shared_ptr
#include <vector> // for vector
#include "utils.h" // for Color
class AnimatedSprite; // lines 9-9
class Asset; // lines 10-10
class Input; // lines 11-11
class Resource; // lines 12-12
class Screen; // lines 13-13
class Text; // lines 14-14
struct JA_Music_t; // lines 15-15
class AnimatedSprite; // lines 8-8
class GameOver
{

View File

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

View File

@@ -1,6 +1,7 @@
#pragma once
#include <stdint.h>
#include <stdint.h> // for uint32_t
#include <string.h> // for memcpy
#define EXTENSION_INTRODUCER 0x21
#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)
{
// Inicializa las variables
keyBindings_t kb;
KeyBindings kb;
kb.scancode = 0;
kb.active = false;
key_bindings_.resize(static_cast<int>(InputAction::SIZE), kb);
GameControllerBindings_t gcb;
GameControllerBindings gcb;
gcb.button = SDL_CONTROLLER_BUTTON_INVALID;
gcb.active = false;
game_controller_bindings_.resize(static_cast<int>(InputAction::SIZE), gcb);

View File

@@ -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,8 +64,8 @@ private:
std::vector<SDL_GameController *> connected_controllers_; // Vector con todos los mandos conectados
// Variables
std::vector<keyBindings_t> 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<KeyBindings> key_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
int num_gamepads_ = 0; // Numero de mandos conectados
std::string db_path_; // Ruta al archivo gamecontrollerdb.txt

View File

@@ -1,7 +1,6 @@
#pragma once
#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 <string> // for string
#include <vector> // for vector

View File

@@ -1,12 +1,13 @@
#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_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <stdlib.h> // for rand
#include "asset.h" // for Asset
#include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH
#include <iostream> // 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 "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
@@ -14,7 +15,6 @@
#include "sprite.h" // for Sprite
#include "texture.h" // for Texture
#include "utils.h" // for Color, stringToColor, Palette
#include <iostream>
// Constructor
LoadingScreen::LoadingScreen()

View File

@@ -1,16 +1,11 @@
#pragma once
#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 <memory> // for shared_ptr
class Asset; // lines 8-8
class Input; // lines 9-9
class Resource; // lines 10-10
class Screen; // lines 11-11
class Sprite; // lines 12-12
class Texture; // lines 13-13
struct JA_Music_t; // lines 14-14
class Sprite; // lines 11-11
class Texture; // lines 12-12
class LoadingScreen
{

View File

@@ -2,10 +2,9 @@
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
#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_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
@@ -13,7 +12,6 @@
#include "sprite.h" // for Sprite
#include "texture.h" // for Texture
#include "utils.h" // for Color, stringToColor
#include "defines.h"
// 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();
}

View File

@@ -1,14 +1,9 @@
#pragma once
#include <SDL2/SDL_render.h> // for SDL_Renderer
#include <SDL2/SDL_stdinc.h> // for Uint32
#include <memory> // for shared_ptr
#include <vector> // 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

View File

@@ -1,16 +1,17 @@
#include "notifier.h"
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
#include <string> // Para string
#include <algorithm>
#include <vector>
#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 <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
#include <SDL2/SDL_render.h> // for SDL_RenderFillRect, SDL_RenderClear
#include <algorithm> // for remove_if
#include <string> // for string, basic_string
#include <vector> // 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;

View File

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

View File

@@ -1,13 +1,14 @@
#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 <functional> // for function
#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 <utility> // for pair
#include <sstream>
#include <string>
#include <algorithm>
// Variables
Options options;

View File

@@ -1,19 +1,18 @@
// IWYU pragma: no_include <bits/std_abs.h>
#include "player.h"
#include <stdlib.h> // Para rand
#include <algorithm> // Para max, min
#include <cmath> // 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 <stdlib.h> // for rand
#include <algorithm> // for max, min
#include <cmath> // 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<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);
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<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);
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)
{

View File

@@ -1,20 +1,16 @@
#pragma once
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
#include <SDL2/SDL_render.h> // Para SDL_Renderer
#include <string> // Para basic_string, string
#include <vector> // Para vector
#include <memory> // 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 <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
#include <SDL2/SDL_render.h> // for SDL_RendererFlip, SDL_FLIP_NONE
#include <memory> // for shared_ptr, __shared_ptr_access
#include <string> // for string
#include <vector> // 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);

View File

@@ -1,16 +1,20 @@
#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 <iostream> // for basic_ostream, operator<<, endl, cout, cerr
#include <iostream> // for basic_ostream, operator<<, endl, cout
#include <stdexcept> // for runtime_error
#include "asset.h" // for Asset, AssetType
#include "jail_audio.h" // for JA_DeleteMusic, JA_DeleteSound, JA_LoadMusic
#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
#include "options.h" // for getFileName, printWithDots
#include <SDL2/SDL_events.h> // for SDL_PollEvent
struct JA_Music_t; // lines 10-10
struct JA_Sound_t; // lines 11-11
#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;

View File

@@ -1,22 +1,23 @@
#include "room.h"
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
#include <SDL2/SDL_error.h> // Para SDL_GetError
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
#include <stdlib.h> // Para rand
#include <fstream> // Para basic_ostream, operator<<, basic_ist...
#include <iostream> // Para cout
#include <sstream> // 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 <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
#include <SDL2/SDL_error.h> // for SDL_GetError
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
#include <stdlib.h> // for rand
#include <exception> // for exception
#include <fstream> // for basic_ostream, operator<<, basic_ist...
#include <iostream> // for cout, cerr
#include <sstream> // 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<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)
{
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;
// 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)
{
// Abre la Jail si se da el caso
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<ScoreboardData> 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,38 +458,27 @@ 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>(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>(item));
}
}
}
// Devuelve el nombre de la habitación
std::string Room::getName()
if (!ItemTracker::get()->hasBeenPicked(room.name, itemPos))
{
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
Color Room::getBGColor()
{
return stringToColor(options.video.palette, bg_color_);
// Crear el objeto Item usando la copia modificada
items_.emplace_back(std::make_shared<Item>(itemCopy));
}
}
// 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
@@ -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<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);
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<int> 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<int> 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 ú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();
}
// 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();
}

View File

@@ -1,31 +1,30 @@
#pragma once
#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 <string> // for string
#include <vector> // 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 "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
@@ -100,16 +99,16 @@ private:
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
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<h_line_t> 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<v_line_t> 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<d_line_t> right_slopes_; // Lista con todas las rampas que suben hacia la derecha
std::vector<LineHorizontal> bottom_surfaces_; // Lista con las superficies inferiores de la habitación
std::vector<LineHorizontal> top_surfaces_; // Lista con las superficies superiores de la habitación
std::vector<LineVertical> left_surfaces_; // Lista con las superficies laterales de la parte izquierda de la habitación
std::vector<LineVertical> right_surfaces_; // Lista con las superficies laterales de la parte derecha de la habitación
std::vector<LineDiagonal> left_slopes_; // Lista con todas las rampas que suben hacia la izquierda
std::vector<LineDiagonal> 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<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
void initializeRoom(const RoomData &room);
@@ -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<ScoreboardData> 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_; }
};

View File

@@ -1,15 +1,16 @@
#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_timer.h> // for SDL_GetTicks
#include <iostream> // for basic_ostream, operator<<, cout, endl
#include "animated_sprite.h" // for AnimatedSprite
#include "asset.h" // for Asset
#include "defines.h" // for BLOCK, GAMECANVAS_HEIGHT, PLAY_AREA_HEIGHT
#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
#include <iostream>
// Constructor
Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)

View File

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

View File

@@ -2,13 +2,10 @@
#include <SDL2/SDL_blendmode.h> // for SDL_BlendMode
#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_video.h> // for SDL_Window
#include <vector> // for vector
#include <memory> // for shared_ptr
#include "utils.h" // for Color
//#include "surface.h"
// Tipos de filtro
enum class ScreenFilter : Uint32

View File

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

View File

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

View File

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

View File

@@ -1,18 +1,14 @@
#pragma once
#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 <memory> // for shared_ptr
#include <string> // for string
#include <vector> // for vector
#include "paleta.h" // for jSurface
class Input; // lines 13-13
class Resource; // lines 14-14
class Screen; // lines 15-15
class Sprite; // lines 16-16
class Text; // lines 17-17
class Texture; // lines 18-18
class Sprite; // lines 13-13
class Texture; // lines 15-15
class Title
{

View File

@@ -1,15 +1,16 @@
#include "utils.h"
#include <stdlib.h> // for free, malloc, abs
#include <algorithm> // for transform
#include <stdlib.h> // for abs
#include <algorithm> // for find, transform
#include <cctype> // for tolower
#include <cmath> // for round, abs
#include <exception> // for exception
#include <filesystem> // for path
#include <iostream> // for basic_ostream, cout, basic_ios, ios, endl
#include <unordered_map> // for unordered_map
#include <string> // for string
#include "jail_audio.h"
#include "resource.h"
#include <string> // for basic_string, string, char_traits, allocator
#include <unordered_map> // for unordered_map, operator==, _Node_const_iter...
#include <utility> // 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
}
}

View File

@@ -1,11 +1,10 @@
#pragma once
#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 <string> // for string
#include <vector>
#include <SDL2/SDL_render.h> // for SDL_Renderer
#include <SDL2/SDL.h> // for SDL_Texture
#include <vector> // 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);