corregits mes includes

llevats els errors en texture
This commit is contained in:
2025-10-15 09:14:30 +02:00
parent 78c5333144
commit 7c102e42cc
63 changed files with 1122 additions and 1621 deletions

View File

@@ -1,14 +1,13 @@
#include "cheevos.h" #include "cheevos.h"
#include <SDL3/SDL_error.h> // Para SDL_GetError #include <SDL3/SDL.h>
#include <SDL3/SDL_rwops.h> // Para SDL_RWFromFile, SDL_RWclose, SDL_RWwrite
#include <stddef.h> // Para NULL #include <stddef.h> // Para NULL
#include <fstream> // Para basic_ostream, operator<<, basic_ofstream #include <fstream> // Para basic_ostream, operator<<, basic_ofstream
#include <iostream> // Para cout, cerr #include <iostream> // Para cout, cerr
#include "notifier.h" // Para Notifier
#include "options.h" // Para Options, options #include "options.h" // Para Options, options
#include "ui/notifier.h" // Para Notifier
// [SINGLETON] // [SINGLETON]
Cheevos* Cheevos::cheevos_ = nullptr; Cheevos* Cheevos::cheevos_ = nullptr;

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_rect.h> // Para SDL_Point #include <SDL3/SDL.h>
#include <string> // Para string #include <string> // Para string
#include <vector> // Para vector #include <vector> // Para vector

View File

@@ -1,16 +1,6 @@
#include "director.h" #include "director.h"
#include <SDL3/SDL.h> // Para SDL_Init, SDL_Quit, SDL_INIT_EV... #include <SDL3/SDL.h>
#include <SDL3/SDL_audio.h> // Para AUDIO_S16
#include <SDL3/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
#include <SDL3/SDL_error.h> // Para SDL_GetError
#include <SDL3/SDL_events.h> // Para SDL_DISABLE
#include <SDL3/SDL_gamecontroller.h> // Para SDL_CONTROLLER_BUTTON_B, SDL_CO...
#include <SDL3/SDL_hints.h> // Para SDL_SetHint, SDL_HINT_RENDER_DR...
#include <SDL3/SDL_mouse.h> // Para SDL_ShowCursor
#include <SDL3/SDL_scancode.h> // Para SDL_SCANCODE_A, SDL_SCANCODE_ES...
#include <SDL3/SDL_stdinc.h> // Para Uint32
#include <SDL3/SDL_timer.h> // Para SDL_GetTicks
#include <errno.h> // Para errno, EEXIST, EACCES, ENAMETOO... #include <errno.h> // Para errno, EEXIST, EACCES, ENAMETOO...
#include <stdio.h> // Para printf, perror #include <stdio.h> // Para printf, perror
#include <sys/stat.h> // Para mkdir, stat, S_IRWXU #include <sys/stat.h> // Para mkdir, stat, S_IRWXU
@@ -28,17 +18,17 @@
#include "defines.h" // Para WINDOW_CAPTION #include "defines.h" // Para WINDOW_CAPTION
#include "ending.h" // Para Ending #include "ending.h" // Para Ending
#include "ending2.h" // Para Ending2 #include "ending2.h" // Para Ending2
#include "external/jail_audio.h" // Para JA_SetMusicVolume, JA_SetSoundV...
#include "game.h" // Para Game, GameMode #include "game.h" // Para Game, GameMode
#include "game_over.h" // Para GameOver #include "game_over.h" // Para GameOver
#include "input.h" // Para Input, InputAction #include "input.h" // Para Input, InputAction
#include "jail_audio.h" // Para JA_SetMusicVolume, JA_SetSoundV...
#include "loading_screen.h" // Para LoadingScreen #include "loading_screen.h" // Para LoadingScreen
#include "logo.h" // Para Logo #include "logo.h" // Para Logo
#include "notifier.h" // Para Notifier
#include "options.h" // Para Options, options, OptionsVideo #include "options.h" // Para Options, options, OptionsVideo
#include "resource.h" // Para Resource #include "resource.h" // Para Resource
#include "screen.h" // Para Screen #include "screen.h" // Para Screen
#include "title.h" // Para Title #include "title.h" // Para Title
#include "ui/notifier.h" // Para Notifier
#ifndef _WIN32 #ifndef _WIN32
#include <pwd.h> #include <pwd.h>

View File

@@ -1,7 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_render.h> // Para SDL_Renderer #include <SDL3/SDL.h>
#include <SDL3/SDL_video.h> // Para SDL_Window
#include <string> // Para string #include <string> // Para string

View File

@@ -1,10 +1,10 @@
#include "enemy.h" #include "enemy.h"
#include <SDL3/SDL_render.h> // Para SDL_RendererFlip, SDL_FLIP_NONE, SDL_... #include <SDL3/SDL.h>
#include <stdlib.h> // Para rand #include <stdlib.h> // Para rand
#include "resource.h" // Para Resource #include "resource.h" // Para Resource
#include "s_animated_sprite.h" // Para SAnimatedSprite #include "sprite/surface_animated_sprite.h" // Para SAnimatedSprite
#include "utils.h" // Para stringToColor #include "utils.h" // Para stringToColor
// Constructor // Constructor

View File

@@ -1,7 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_rect.h> // Para SDL_Rect #include <SDL3/SDL.h>
#include <SDL3/SDL_stdinc.h> // Para Uint8
#include <memory> // Para shared_ptr #include <memory> // Para shared_ptr
#include <string> // Para string #include <string> // Para string

View File

@@ -1,7 +1,6 @@
#include "jail_audio.h" #include "external/jail_audio.h"
#include <SDL3/SDL_rwops.h> // Para SDL_RWFromMem #include <SDL3/SDL.h>
#include <SDL3/SDL_timer.h> // Para SDL_GetTicks
#include <stdint.h> // Para uint8_t, uint32_t #include <stdint.h> // Para uint8_t, uint32_t
#include <stdio.h> // Para NULL, fseek, fclose, fopen, fread, ftell #include <stdio.h> // Para NULL, fseek, fclose, fopen, fread, ftell
#include <stdlib.h> // Para free, malloc #include <stdlib.h> // Para free, malloc

View File

@@ -1,7 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_audio.h> // Para SDL_AudioFormat #include <SDL3/SDL.h>
#include <SDL3/SDL_stdinc.h> // Para Uint32, Uint8
struct JA_Music_t; // lines 5-5 struct JA_Music_t; // lines 5-5
struct JA_Sound_t; // lines 6-6 struct JA_Sound_t; // lines 6-6

View File

@@ -1,7 +1,6 @@
#include "jail_shader.h" #include "external/jail_shader.h"
#include <SDL3/SDL_rect.h> // Para SDL_Point #include <SDL3/SDL.h>
#include <SDL3/SDL_stdinc.h> // Para SDL_bool
#include <cstring> // Para strncmp #include <cstring> // Para strncmp
#include <iostream> // Para basic_ostream, operator<<, endl, cout #include <iostream> // Para basic_ostream, operator<<, endl, cout

View File

@@ -1,7 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_render.h> // Para SDL_Texture #include <SDL3/SDL.h>
#include <SDL3/SDL_video.h> // Para SDL_Window
#include <string> #include <string>

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_events.h> #include <SDL3/SDL.h>
namespace globalEvents { namespace globalEvents {
// Comprueba los eventos que se pueden producir en cualquier sección del juego // Comprueba los eventos que se pueden producir en cualquier sección del juego

View File

@@ -1,15 +1,14 @@
#include "global_inputs.h" #include "global_inputs.h"
#include <SDL3/SDL_render.h> // Para SDL_RenderSetIntegerScale #include <SDL3/SDL.h>
#include <SDL3/SDL_stdinc.h> // Para SDL_FALSE, SDL_TRUE
#include <string> // Para allocator, operator+, char_traits, string #include <string> // Para allocator, operator+, char_traits, string
#include <vector> // Para vector #include <vector> // Para vector
#include "input.h" // Para Input, InputAction, INPUT_DO_NOT_ALLOW_REPEAT #include "input.h" // Para Input, InputAction, INPUT_DO_NOT_ALLOW_REPEAT
#include "notifier.h" // Para Notifier, NotificationText
#include "options.h" // Para Options, options, OptionsVideo, Section #include "options.h" // Para Options, options, OptionsVideo, Section
#include "screen.h" // Para Screen #include "screen.h" // Para Screen
#include "ui/notifier.h" // Para Notifier, NotificationText
#include "utils.h" // Para stringInVector #include "utils.h" // Para stringInVector
namespace globalInputs { namespace globalInputs {

View File

@@ -1,9 +1,6 @@
#include "input.h" #include "input.h"
#include <SDL3/SDL.h> // Para SDL_INIT_GAMECONTROLLER, SDL_InitSubS... #include <SDL3/SDL.h>
#include <SDL3/SDL_error.h> // Para SDL_GetError
#include <SDL3/SDL_events.h> // Para SDL_ENABLE
#include <SDL3/SDL_keyboard.h> // Para SDL_GetKeyboardState
#include <algorithm> // Para find #include <algorithm> // Para find
#include <iostream> // Para basic_ostream, operator<<, cout, endl #include <iostream> // Para basic_ostream, operator<<, cout, endl

View File

@@ -1,8 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_gamecontroller.h> // Para SDL_GameControllerButton, SDL_G... #include <SDL3/SDL.h>
#include <SDL3/SDL_scancode.h> // Para SDL_Scancode
#include <SDL3/SDL_stdinc.h> // Para Uint8
#include <string> // Para string, basic_string #include <string> // Para string, basic_string
#include <vector> // Para vector #include <vector> // Para vector

View File

@@ -1,12 +1,12 @@
#include "item.h" #include "item.h"
#include "resource.h" // Para Resource #include "resource.h" // Para Resource
#include "s_sprite.h" // Para SSprite #include "sprite/surface_sprite.h" // Para SSprite
// Constructor // Constructor
Item::Item(ItemData item) Item::Item(ItemData item)
: sprite_(std::make_shared<SSprite>(Resource::get()->getSurface(item.tile_set_file), item.x, item.y, ITEM_SIZE_, ITEM_SIZE_)), : sprite_(std::make_shared<SSprite>(Resource::get()->getSurface(item.tile_set_file), item.x, item.y, ITEM_SIZE_, ITEM_SIZE_)),
change_color_speed(4) change_color_speed(4) {
{
// Inicia variables // Inicia variables
sprite_->setClip((item.tile % 10) * ITEM_SIZE_, (item.tile / 10) * ITEM_SIZE_, ITEM_SIZE_, ITEM_SIZE_); sprite_->setClip((item.tile % 10) * ITEM_SIZE_, (item.tile / 10) * ITEM_SIZE_, ITEM_SIZE_, ITEM_SIZE_);
collider_ = sprite_->getRect(); collider_ = sprite_->getRect();
@@ -21,22 +21,19 @@ Item::Item(ItemData item)
} }
// Pinta el objeto en pantalla // Pinta el objeto en pantalla
void Item::render() void Item::render() {
{
const int INDEX = (counter_ / change_color_speed) % color_.size(); const int INDEX = (counter_ / change_color_speed) % color_.size();
sprite_->render(1, color_.at(INDEX)); sprite_->render(1, color_.at(INDEX));
} }
// Obtiene su ubicación // Obtiene su ubicación
SDL_Point Item::getPos() SDL_Point Item::getPos() {
{
const SDL_Point p = {sprite_->getX(), sprite_->getY()}; const SDL_Point p = {sprite_->getX(), sprite_->getY()};
return p; return p;
} }
// Asigna los colores del objeto // Asigna los colores del objeto
void Item::setColors(Uint8 col1, Uint8 col2) void Item::setColors(Uint8 col1, Uint8 col2) {
{
// Reinicializa el vector de colores // Reinicializa el vector de colores
color_.clear(); color_.clear();

View File

@@ -1,7 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_rect.h> // Para SDL_Rect, SDL_Point #include <SDL3/SDL.h>
#include <SDL3/SDL_stdinc.h> // Para Uint8
#include <memory> // Para shared_ptr #include <memory> // Para shared_ptr
#include <string> // Para string #include <string> // Para string

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_rect.h> // Para SDL_Point #include <SDL3/SDL.h>
#include <string> // Para string, basic_string #include <string> // Para string, basic_string
#include <vector> // Para vector #include <vector> // Para vector

View File

@@ -1,7 +1,5 @@
#include "mouse.h" #include "mouse.h"
#include <SDL3/SDL_mouse.h> // Para SDL_ShowCursor
#include <SDL3/SDL_timer.h> // Para SDL_GetTicks
namespace Mouse { namespace Mouse {
Uint32 cursor_hide_time = 3000; // Tiempo en milisegundos para ocultar el cursor Uint32 cursor_hide_time = 3000; // Tiempo en milisegundos para ocultar el cursor

View File

@@ -1,7 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_events.h> // Para SDL_Event #include <SDL3/SDL.h>
#include <SDL3/SDL_stdinc.h> // Para Uint32
namespace Mouse { namespace Mouse {
extern Uint32 cursor_hide_time; // Tiempo en milisegundos para ocultar el cursor extern Uint32 cursor_hide_time; // Tiempo en milisegundos para ocultar el cursor

View File

@@ -1,6 +1,6 @@
#include "options.h" #include "options.h"
#include <SDL3/SDL_video.h> // Para SDL_WINDOW_FULLSCREEN_DESKTOP #include <SDL3/SDL.h>
#include <algorithm> // Para find_if #include <algorithm> // Para find_if
#include <cctype> // Para isspace #include <cctype> // Para isspace

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_stdinc.h> // Para Uint32 #include <SDL3/SDL.h>
#include <algorithm> #include <algorithm>
#include <string> // Para string, basic_string #include <string> // Para string, basic_string

View File

@@ -1,20 +1,21 @@
// IWYU pragma: no_include <bits/std_abs.h> // IWYU pragma: no_include <bits/std_abs.h>
#include "player.h" #include "player.h"
#include <algorithm> // Para max, min #include <algorithm> // Para max, min
#include <cmath> // Para ceil, abs #include <cmath> // Para ceil, abs
#include "debug.h" // Para Debug #include "debug.h" // Para Debug
#include "defines.h" // Para RoomBorder::BOTTOM, RoomBorder::LEFT, RoomBorder::RIGHT #include "defines.h" // Para RoomBorder::BOTTOM, RoomBorder::LEFT, RoomBorder::RIGHT
#include "external/jail_audio.h" // Para JA_PlaySound
#include "input.h" // Para Input, InputAction #include "input.h" // Para Input, InputAction
#include "jail_audio.h" // Para JA_PlaySound
#include "options.h" // Para Cheat, Options, options #include "options.h" // Para Cheat, Options, options
#include "resource.h" // Para Resource #include "resource.h" // Para Resource
#include "room.h" // Para Room, TileType #include "room.h" // Para Room, TileType
#include "s_animated_sprite.h" // Para SAnimatedSprite #include "sprite/surface_animated_sprite.h" // Para SAnimatedSprite
// Constructor // Constructor
Player::Player(const PlayerData &player) Player::Player(const PlayerData& player)
: room_(player.room) : room_(player.room) {
{
// Inicializa algunas variables // Inicializa algunas variables
initSprite(player.texture_path, player.animations_path); initSprite(player.texture_path, player.animations_path);
setColor(); setColor();
@@ -38,8 +39,7 @@ Player::Player(const PlayerData &player)
} }
// Pinta el jugador en pantalla // Pinta el jugador en pantalla
void Player::render() void Player::render() {
{
sprite_->render(1, color_); sprite_->render(1, color_);
#ifdef DEBUG #ifdef DEBUG
@@ -48,10 +48,8 @@ void Player::render()
} }
// Actualiza las variables del objeto // Actualiza las variables del objeto
void Player::update() void Player::update() {
{ if (!is_paused_) {
if (!is_paused_)
{
checkInput(); // Comprueba las entradas y modifica variables checkInput(); // Comprueba las entradas y modifica variables
move(); // Recalcula la posición del jugador move(); // Recalcula la posición del jugador
animate(); // Establece la animación del jugador animate(); // Establece la animación del jugador
@@ -62,63 +60,49 @@ void Player::update()
} }
// Comprueba las entradas y modifica variables // Comprueba las entradas y modifica variables
void Player::checkInput() void Player::checkInput() {
{
// Solo comprueba las entradas de dirección cuando está sobre una superficie // Solo comprueba las entradas de dirección cuando está sobre una superficie
if (state_ != PlayerState::STANDING) if (state_ != PlayerState::STANDING) {
{
return; return;
} }
if (!auto_movement_) if (!auto_movement_) {
{
// Comprueba las entradas de desplazamiento lateral solo en el caso de no estar enganchado a una superficie automatica // Comprueba las entradas de desplazamiento lateral solo en el caso de no estar enganchado a una superficie automatica
if (Input::get()->checkInput(InputAction::LEFT)) if (Input::get()->checkInput(InputAction::LEFT)) {
{
vx_ = -0.6f; vx_ = -0.6f;
sprite_->setFlip(SDL_FLIP_HORIZONTAL); sprite_->setFlip(SDL_FLIP_HORIZONTAL);
} }
else if (Input::get()->checkInput(InputAction::RIGHT)) else if (Input::get()->checkInput(InputAction::RIGHT)) {
{
vx_ = 0.6f; vx_ = 0.6f;
sprite_->setFlip(SDL_FLIP_NONE); sprite_->setFlip(SDL_FLIP_NONE);
} }
else else {
{
// No se pulsa ninguna dirección // No se pulsa ninguna dirección
vx_ = 0.0f; vx_ = 0.0f;
if (isOnAutoSurface()) if (isOnAutoSurface()) {
{
// Si deja de moverse sobre una superficie se engancha // Si deja de moverse sobre una superficie se engancha
auto_movement_ = true; auto_movement_ = true;
} }
} }
} } else { // El movimiento lo proporciona la superficie
else
{ // El movimiento lo proporciona la superficie
vx_ = 0.6f * room_->getAutoSurfaceDirection(); vx_ = 0.6f * room_->getAutoSurfaceDirection();
if (vx_ > 0.0f) if (vx_ > 0.0f) {
{
sprite_->setFlip(SDL_FLIP_NONE); sprite_->setFlip(SDL_FLIP_NONE);
} } else {
else
{
sprite_->setFlip(SDL_FLIP_HORIZONTAL); sprite_->setFlip(SDL_FLIP_HORIZONTAL);
} }
} }
if (Input::get()->checkInput(InputAction::JUMP)) if (Input::get()->checkInput(InputAction::JUMP)) {
{
// Solo puede saltar si ademas de estar (state == s_standing) // Solo puede saltar si ademas de estar (state == s_standing)
// Esta sobre el suelo, rampa o suelo que se mueve // Esta sobre el suelo, rampa o suelo que se mueve
// Esto es para evitar el salto desde el vacio al cambiar de pantalla verticalmente // Esto es para evitar el salto desde el vacio al cambiar de pantalla verticalmente
// Ya que se coloca el estado s_standing al cambiar de pantalla // Ya que se coloca el estado s_standing al cambiar de pantalla
if (isOnFloor() || isOnAutoSurface()) if (isOnFloor() || isOnAutoSurface()) {
{
setState(PlayerState::JUMPING); setState(PlayerState::JUMPING);
vy_ = -MAX_VY_; vy_ = -MAX_VY_;
jump_init_pos_ = y_; jump_init_pos_ = y_;
@@ -128,61 +112,50 @@ void Player::checkInput()
} }
// Comprueba si está situado en alguno de los cuatro bordes de la habitación // Comprueba si está situado en alguno de los cuatro bordes de la habitación
void Player::checkBorders() void Player::checkBorders() {
{ if (x_ < PLAY_AREA_LEFT) {
if (x_ < PLAY_AREA_LEFT)
{
border_ = RoomBorder::LEFT; border_ = RoomBorder::LEFT;
is_on_border_ = true; is_on_border_ = true;
} }
else if (x_ + WIDTH_ > PLAY_AREA_RIGHT) else if (x_ + WIDTH_ > PLAY_AREA_RIGHT) {
{
border_ = RoomBorder::RIGHT; border_ = RoomBorder::RIGHT;
is_on_border_ = true; is_on_border_ = true;
} }
else if (y_ < PLAY_AREA_TOP) else if (y_ < PLAY_AREA_TOP) {
{
border_ = RoomBorder::TOP; border_ = RoomBorder::TOP;
is_on_border_ = true; is_on_border_ = true;
} }
else if (y_ + HEIGHT_ > PLAY_AREA_BOTTOM) else if (y_ + HEIGHT_ > PLAY_AREA_BOTTOM) {
{
border_ = RoomBorder::BOTTOM; border_ = RoomBorder::BOTTOM;
is_on_border_ = true; is_on_border_ = true;
} }
else else {
{
is_on_border_ = false; is_on_border_ = false;
} }
} }
// Comprueba el estado del jugador // Comprueba el estado del jugador
void Player::checkState() void Player::checkState() {
{
// Actualiza las variables en función del estado // Actualiza las variables en función del estado
if (state_ == PlayerState::FALLING) if (state_ == PlayerState::FALLING) {
{
vx_ = 0.0f; vx_ = 0.0f;
vy_ = MAX_VY_; vy_ = MAX_VY_;
falling_counter_++; falling_counter_++;
playFallSound(); playFallSound();
} }
else if (state_ == PlayerState::STANDING) else if (state_ == PlayerState::STANDING) {
{ if (previous_state_ == PlayerState::FALLING && falling_counter_ > MAX_FALLING_HEIGHT_) { // Si cae de muy alto, el jugador muere
if (previous_state_ == PlayerState::FALLING && falling_counter_ > MAX_FALLING_HEIGHT_)
{ // Si cae de muy alto, el jugador muere
is_alive_ = false; is_alive_ = false;
} }
vy_ = 0.0f; vy_ = 0.0f;
jumping_counter_ = 0; jumping_counter_ = 0;
falling_counter_ = 0; falling_counter_ = 0;
if (!isOnFloor() && !isOnAutoSurface() && !isOnDownSlope()) if (!isOnFloor() && !isOnAutoSurface() && !isOnDownSlope()) {
{
setState(PlayerState::FALLING); setState(PlayerState::FALLING);
vx_ = 0.0f; vx_ = 0.0f;
vy_ = MAX_VY_; vy_ = MAX_VY_;
@@ -191,8 +164,7 @@ void Player::checkState()
} }
} }
else if (state_ == PlayerState::JUMPING) else if (state_ == PlayerState::JUMPING) {
{
falling_counter_ = 0; falling_counter_ = 0;
jumping_counter_++; jumping_counter_++;
playJumpSound(); playJumpSound();
@@ -200,10 +172,8 @@ void Player::checkState()
} }
// Cambia al jugador de un borde al opuesto. Util para el cambio de pantalla // Cambia al jugador de un borde al opuesto. Util para el cambio de pantalla
void Player::switchBorders() void Player::switchBorders() {
{ switch (border_) {
switch (border_)
{
case RoomBorder::TOP: case RoomBorder::TOP:
y_ = PLAY_AREA_BOTTOM - HEIGHT_ - BLOCK; y_ = PLAY_AREA_BOTTOM - HEIGHT_ - BLOCK;
setState(PlayerState::STANDING); setState(PlayerState::STANDING);
@@ -232,25 +202,21 @@ void Player::switchBorders()
} }
// Aplica gravedad al jugador // Aplica gravedad al jugador
void Player::applyGravity() void Player::applyGravity() {
{
constexpr float GRAVITY_FORCE = 0.035f; constexpr float GRAVITY_FORCE = 0.035f;
// La gravedad solo se aplica cuando el jugador esta saltando // La gravedad solo se aplica cuando el jugador esta saltando
// Nunca mientras cae o esta de pie // Nunca mientras cae o esta de pie
if (state_ == PlayerState::JUMPING) if (state_ == PlayerState::JUMPING) {
{
vy_ += GRAVITY_FORCE; vy_ += GRAVITY_FORCE;
if (vy_ > MAX_VY_) if (vy_ > MAX_VY_) {
{
vy_ = MAX_VY_; vy_ = MAX_VY_;
} }
} }
} }
// Recalcula la posición del jugador y su animación // Recalcula la posición del jugador y su animación
void Player::move() void Player::move() {
{
last_position_ = {static_cast<int>(x_), static_cast<int>(y_)}; // Guarda la posicion actual antes de modificarla last_position_ = {static_cast<int>(x_), static_cast<int>(y_)}; // Guarda la posicion actual antes de modificarla
applyGravity(); // Aplica gravedad al jugador applyGravity(); // Aplica gravedad al jugador
checkState(); // Comprueba el estado del jugador checkState(); // Comprueba el estado del jugador
@@ -260,8 +226,7 @@ void Player::move()
#endif #endif
// Se mueve hacia la izquierda // Se mueve hacia la izquierda
if (vx_ < 0.0f) if (vx_ < 0.0f) {
{
// Crea el rectangulo de proyección en el eje X para ver si colisiona // Crea el rectangulo de proyección en el eje X para ver si colisiona
SDL_Rect proj; SDL_Rect proj;
proj.x = static_cast<int>(x_ + vx_); proj.x = static_cast<int>(x_ + vx_);
@@ -277,38 +242,31 @@ void Player::move()
const int POS = room_->checkRightSurfaces(&proj); const int POS = room_->checkRightSurfaces(&proj);
// Calcula la nueva posición // Calcula la nueva posición
if (POS == -1) if (POS == -1) {
{
// Si no hay colisión // Si no hay colisión
x_ += vx_; x_ += vx_;
} } else {
else
{
// Si hay colisión lo mueve hasta donde no colisiona // Si hay colisión lo mueve hasta donde no colisiona
x_ = POS + 1; x_ = POS + 1;
} }
// 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) {
{
const LineVertical LEFT_SIDE = {static_cast<int>(x_), static_cast<int>(y_) + HEIGHT_ - 2, static_cast<int>(y_) + HEIGHT_ - 1}; // Comprueba solo los dos pixels de abajo const LineVertical LEFT_SIDE = {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(&LEFT_SIDE); const int LY = room_->checkLeftSlopes(&LEFT_SIDE);
if (LY > -1) if (LY > -1) {
{
y_ = LY - HEIGHT_; y_ = LY - HEIGHT_;
} }
} }
// Si está bajando la rampa, recoloca al jugador // Si está bajando la rampa, recoloca al jugador
if (isOnDownSlope() && state_ != PlayerState::JUMPING) if (isOnDownSlope() && state_ != PlayerState::JUMPING) {
{
y_ += 1; y_ += 1;
} }
} }
// Se mueve hacia la derecha // Se mueve hacia la derecha
else if (vx_ > 0.0f) else if (vx_ > 0.0f) {
{
// Crea el rectangulo de proyección en el eje X para ver si colisiona // Crea el rectangulo de proyección en el eje X para ver si colisiona
SDL_Rect proj; SDL_Rect proj;
proj.x = static_cast<int>(x_) + WIDTH_; proj.x = static_cast<int>(x_) + WIDTH_;
@@ -324,38 +282,31 @@ void Player::move()
const int POS = room_->checkLeftSurfaces(&proj); const int POS = room_->checkLeftSurfaces(&proj);
// Calcula la nueva posición // Calcula la nueva posición
if (POS == -1) if (POS == -1) {
{
// Si no hay colisión // Si no hay colisión
x_ += vx_; x_ += vx_;
} } else {
else
{
// Si hay colisión lo mueve hasta donde no colisiona // Si hay colisión lo mueve hasta donde no colisiona
x_ = POS - WIDTH_; x_ = POS - WIDTH_;
} }
// 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) {
{
const LineVertical RIGHT_SIDE = {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 LineVertical RIGHT_SIDE = {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(&RIGHT_SIDE); const int RY = room_->checkRightSlopes(&RIGHT_SIDE);
if (RY > -1) if (RY > -1) {
{
y_ = RY - HEIGHT_; y_ = RY - HEIGHT_;
} }
} }
// Si está bajando la rampa, recoloca al jugador // Si está bajando la rampa, recoloca al jugador
if (isOnDownSlope() && state_ != PlayerState::JUMPING) if (isOnDownSlope() && state_ != PlayerState::JUMPING) {
{
y_ += 1; y_ += 1;
} }
} }
// Si ha salido del suelo, el jugador cae // Si ha salido del suelo, el jugador cae
if (state_ == PlayerState::STANDING && !isOnFloor()) if (state_ == PlayerState::STANDING && !isOnFloor()) {
{
setState(PlayerState::FALLING); setState(PlayerState::FALLING);
// Deja de estar enganchado a la superficie automatica // Deja de estar enganchado a la superficie automatica
@@ -363,15 +314,13 @@ void Player::move()
} }
// Si ha salido de una superficie automatica, detiene el movimiento automatico // Si ha salido de una superficie automatica, detiene el movimiento automatico
if (state_ == PlayerState::STANDING && isOnFloor() && !isOnAutoSurface()) if (state_ == PlayerState::STANDING && isOnFloor() && !isOnAutoSurface()) {
{
// Deja de estar enganchado a la superficie automatica // Deja de estar enganchado a la superficie automatica
auto_movement_ = false; auto_movement_ = false;
} }
// Se mueve hacia arriba // Se mueve hacia arriba
if (vy_ < 0.0f) if (vy_ < 0.0f) {
{
// Crea el rectangulo de proyección en el eje Y para ver si colisiona // Crea el rectangulo de proyección en el eje Y para ver si colisiona
SDL_Rect proj; SDL_Rect proj;
proj.x = static_cast<int>(x_); proj.x = static_cast<int>(x_);
@@ -387,13 +336,10 @@ void Player::move()
const int POS = room_->checkBottomSurfaces(&proj); const int POS = room_->checkBottomSurfaces(&proj);
// Calcula la nueva posición // Calcula la nueva posición
if (POS == -1) if (POS == -1) {
{
// Si no hay colisión // Si no hay colisión
y_ += vy_; y_ += vy_;
} } else {
else
{
// Si hay colisión lo mueve hasta donde no colisiona y entra en caída // Si hay colisión lo mueve hasta donde no colisiona y entra en caída
y_ = POS + 1; y_ = POS + 1;
setState(PlayerState::FALLING); setState(PlayerState::FALLING);
@@ -401,8 +347,7 @@ void Player::move()
} }
// Se mueve hacia abajo // Se mueve hacia abajo
else if (vy_ > 0.0f) else if (vy_ > 0.0f) {
{
// Crea el rectangulo de proyección en el eje Y para ver si colisiona // Crea el rectangulo de proyección en el eje Y para ver si colisiona
SDL_Rect proj; SDL_Rect proj;
proj.x = static_cast<int>(x_); proj.x = static_cast<int>(x_);
@@ -416,25 +361,20 @@ void Player::move()
// Comprueba la colisión con las superficies normales y las automáticas // Comprueba la colisión con las superficies normales y las automáticas
const int POS = std::max(room_->checkTopSurfaces(&proj), room_->checkAutoSurfaces(&proj)); const int POS = std::max(room_->checkTopSurfaces(&proj), room_->checkAutoSurfaces(&proj));
if (POS > -1) if (POS > -1) {
{
// Si hay colisión lo mueve hasta donde no colisiona y pasa a estar sobre la superficie // Si hay colisión lo mueve hasta donde no colisiona y pasa a estar sobre la superficie
y_ = POS - HEIGHT_; y_ = POS - HEIGHT_;
setState(PlayerState::STANDING); setState(PlayerState::STANDING);
// Deja de estar enganchado a la superficie automatica // Deja de estar enganchado a la superficie automatica
auto_movement_ = false; auto_movement_ = false;
} } else {
else
{
// 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
const LineVertical LEFT_SIDE = {proj.x, proj.y, proj.y + proj.h - 1}; const LineVertical LEFT_SIDE = {proj.x, proj.y, proj.y + proj.h - 1};
const LineVertical RIGHT_SIDE = {proj.x + proj.w - 1, proj.y, proj.y + proj.h - 1}; const LineVertical RIGHT_SIDE = {proj.x + proj.w - 1, proj.y, proj.y + proj.h - 1};
const int POINT = std::max(room_->checkRightSlopes(&RIGHT_SIDE), room_->checkLeftSlopes(&LEFT_SIDE)); const int POINT = std::max(room_->checkRightSlopes(&RIGHT_SIDE), room_->checkLeftSlopes(&LEFT_SIDE));
if (POINT > -1) if (POINT > -1) {
{
// No está saltando y hay colisión con una rampa // No está saltando y hay colisión con una rampa
// Calcula la nueva posición // Calcula la nueva posición
y_ = POINT - HEIGHT_; y_ = POINT - HEIGHT_;
@@ -443,9 +383,7 @@ void Player::move()
debug_color_ = static_cast<Uint8>(PaletteColor::YELLOW); debug_color_ = static_cast<Uint8>(PaletteColor::YELLOW);
debug_point_ = {(int)x_ + (WIDTH_ / 2), POINT}; debug_point_ = {(int)x_ + (WIDTH_ / 2), POINT};
#endif #endif
} } else {
else
{
// No está saltando y no hay colisón con una rampa // No está saltando y no hay colisón con una rampa
// Calcula la nueva posición // Calcula la nueva posición
y_ += vy_; y_ += vy_;
@@ -453,9 +391,7 @@ void Player::move()
debug_color_ = static_cast<Uint8>(PaletteColor::RED); debug_color_ = static_cast<Uint8>(PaletteColor::RED);
#endif #endif
} }
} } else {
else
{
// Esta saltando y no hay colisión con los muros // Esta saltando y no hay colisión con los muros
// Calcula la nueva posición // Calcula la nueva posición
y_ += vy_; y_ += vy_;
@@ -473,23 +409,17 @@ void Player::move()
} }
// Establece la animación del jugador // Establece la animación del jugador
void Player::animate() void Player::animate() {
{ if (vx_ != 0) {
if (vx_ != 0)
{
sprite_->update(); sprite_->update();
} }
} }
// Comprueba si ha finalizado el salto al alcanzar la altura de inicio // Comprueba si ha finalizado el salto al alcanzar la altura de inicio
void Player::checkJumpEnd() void Player::checkJumpEnd() {
{ if (state_ == PlayerState::JUMPING) {
if (state_ == PlayerState::JUMPING) if (vy_ > 0) {
{ if (y_ >= jump_init_pos_) {
if (vy_ > 0)
{
if (y_ >= jump_init_pos_)
{
// Si alcanza la altura de salto inicial, pasa al estado de caída // Si alcanza la altura de salto inicial, pasa al estado de caída
setState(PlayerState::FALLING); setState(PlayerState::FALLING);
vy_ = MAX_VY_; vy_ = MAX_VY_;
@@ -500,10 +430,8 @@ void Player::checkJumpEnd()
} }
// Calcula y reproduce el sonido de salto // Calcula y reproduce el sonido de salto
void Player::playJumpSound() void Player::playJumpSound() {
{ if (jumping_counter_ % 4 == 0) {
if (jumping_counter_ % 4 == 0)
{
JA_PlaySound(jumping_sound_[jumping_counter_ / 4]); JA_PlaySound(jumping_sound_[jumping_counter_ / 4]);
} }
@@ -513,10 +441,8 @@ void Player::playJumpSound()
} }
// Calcula y reproduce el sonido de caer // Calcula y reproduce el sonido de caer
void Player::playFallSound() void Player::playFallSound() {
{ if (falling_counter_ % 4 == 0) {
if (falling_counter_ % 4 == 0)
{
JA_PlaySound(falling_sound_[std::min((falling_counter_ / 4), (int)falling_sound_.size() - 1)]); JA_PlaySound(falling_sound_[std::min((falling_counter_ / 4), (int)falling_sound_.size() - 1)]);
} }
@@ -526,8 +452,7 @@ void Player::playFallSound()
} }
// Comprueba si el jugador tiene suelo debajo de los pies // Comprueba si el jugador tiene suelo debajo de los pies
bool Player::isOnFloor() bool Player::isOnFloor() {
{
bool on_floor = false; bool on_floor = false;
bool on_slope_l = false; bool on_slope_l = false;
bool on_slope_r = false; bool on_slope_r = false;
@@ -535,8 +460,7 @@ bool Player::isOnFloor()
updateFeet(); updateFeet();
// Comprueba las superficies // Comprueba las superficies
for (auto f : under_feet_) for (auto f : under_feet_) {
{
on_floor |= room_->checkTopSurfaces(&f); on_floor |= room_->checkTopSurfaces(&f);
on_floor |= room_->checkAutoSurfaces(&f); on_floor |= room_->checkAutoSurfaces(&f);
} }
@@ -546,18 +470,15 @@ bool Player::isOnFloor()
on_slope_r = room_->checkRightSlopes(&under_feet_[1]); on_slope_r = room_->checkRightSlopes(&under_feet_[1]);
#ifdef DEBUG #ifdef DEBUG
if (on_floor) if (on_floor) {
{
Debug::get()->add("ON_FLOOR"); Debug::get()->add("ON_FLOOR");
} }
if (on_slope_l) if (on_slope_l) {
{
Debug::get()->add("ON_SLOPE_L: " + std::to_string(under_feet_[0].x) + "," + std::to_string(under_feet_[0].y)); Debug::get()->add("ON_SLOPE_L: " + std::to_string(under_feet_[0].x) + "," + std::to_string(under_feet_[0].y));
} }
if (on_slope_r) if (on_slope_r) {
{
Debug::get()->add("ON_SLOPE_R: " + std::to_string(under_feet_[1].x) + "," + std::to_string(under_feet_[1].y)); Debug::get()->add("ON_SLOPE_R: " + std::to_string(under_feet_[1].x) + "," + std::to_string(under_feet_[1].y));
} }
#endif #endif
@@ -566,21 +487,18 @@ bool Player::isOnFloor()
} }
// Comprueba si el jugador esta sobre una superficie automática // Comprueba si el jugador esta sobre una superficie automática
bool Player::isOnAutoSurface() bool Player::isOnAutoSurface() {
{
bool on_auto_surface = false; bool on_auto_surface = false;
updateFeet(); updateFeet();
// Comprueba las superficies // Comprueba las superficies
for (auto f : under_feet_) for (auto f : under_feet_) {
{
on_auto_surface |= room_->checkAutoSurfaces(&f); on_auto_surface |= room_->checkAutoSurfaces(&f);
} }
#ifdef DEBUG #ifdef DEBUG
if (on_auto_surface) if (on_auto_surface) {
{
Debug::get()->add("ON_AUTO_SURFACE"); Debug::get()->add("ON_AUTO_SURFACE");
} }
#endif #endif
@@ -589,8 +507,7 @@ bool Player::isOnAutoSurface()
} }
// Comprueba si el jugador está sobre una rampa hacia abajo // Comprueba si el jugador está sobre una rampa hacia abajo
bool Player::isOnDownSlope() bool Player::isOnDownSlope() {
{
bool on_slope = false; bool on_slope = false;
updateFeet(); updateFeet();
@@ -605,8 +522,7 @@ bool Player::isOnDownSlope()
on_slope |= room_->checkRightSlopes(&under_feet_[1]); on_slope |= room_->checkRightSlopes(&under_feet_[1]);
#ifdef DEBUG #ifdef DEBUG
if (on_slope) if (on_slope) {
{
Debug::get()->add("ON_DOWN_SLOPE"); Debug::get()->add("ON_DOWN_SLOPE");
} }
#endif #endif
@@ -615,16 +531,13 @@ bool Player::isOnDownSlope()
} }
// Comprueba que el jugador no toque ningun tile de los que matan // Comprueba que el jugador no toque ningun tile de los que matan
bool Player::checkKillingTiles() bool Player::checkKillingTiles() {
{
// Actualiza los puntos de colisión // Actualiza los puntos de colisión
updateColliderPoints(); updateColliderPoints();
// Comprueba si hay contacto y retorna en cuanto se encuentra colisión // Comprueba si hay contacto y retorna en cuanto se encuentra colisión
for (const auto &c : collider_points_) for (const auto& c : collider_points_) {
{ if (room_->getTile(c) == TileType::KILL) {
if (room_->getTile(c) == TileType::KILL)
{
is_alive_ = false; // Mata al jugador inmediatamente is_alive_ = false; // Mata al jugador inmediatamente
return true; // Retorna en cuanto se detecta una colisión return true; // Retorna en cuanto se detecta una colisión
} }
@@ -634,25 +547,18 @@ bool Player::checkKillingTiles()
} }
// Establece el color del jugador // Establece el color del jugador
void Player::setColor() void Player::setColor() {
{ if (options.cheats.invincible == Cheat::CheatState::ENABLED) {
if (options.cheats.invincible == Cheat::CheatState::ENABLED)
{
color_ = static_cast<Uint8>(PaletteColor::CYAN); color_ = static_cast<Uint8>(PaletteColor::CYAN);
} } else if (options.cheats.infinite_lives == Cheat::CheatState::ENABLED) {
else if (options.cheats.infinite_lives == Cheat::CheatState::ENABLED)
{
color_ = static_cast<Uint8>(PaletteColor::YELLOW); color_ = static_cast<Uint8>(PaletteColor::YELLOW);
} } else {
else
{
color_ = static_cast<Uint8>(PaletteColor::WHITE); color_ = static_cast<Uint8>(PaletteColor::WHITE);
} }
} }
// Actualiza los puntos de colisión // Actualiza los puntos de colisión
void Player::updateColliderPoints() void Player::updateColliderPoints() {
{
const SDL_Rect rect = getRect(); const SDL_Rect rect = getRect();
collider_points_[0] = {rect.x, rect.y}; collider_points_[0] = {rect.x, rect.y};
collider_points_[1] = {rect.x + 7, rect.y}; collider_points_[1] = {rect.x + 7, rect.y};
@@ -665,8 +571,7 @@ void Player::updateColliderPoints()
} }
// Actualiza los puntos de los pies // Actualiza los puntos de los pies
void Player::updateFeet() void Player::updateFeet() {
{
const SDL_Point p = {static_cast<int>(x_), static_cast<int>(y_)}; const SDL_Point p = {static_cast<int>(x_), static_cast<int>(y_)};
under_feet_[0] = {p.x, p.y + HEIGHT_}; under_feet_[0] = {p.x, p.y + HEIGHT_};
@@ -677,8 +582,7 @@ void Player::updateFeet()
} }
// Cambia el estado del jugador // Cambia el estado del jugador
void Player::setState(PlayerState value) void Player::setState(PlayerState value) {
{
previous_state_ = state_; previous_state_ = state_;
state_ = value; state_ = value;
@@ -686,26 +590,22 @@ void Player::setState(PlayerState value)
} }
// Inicializa los sonidos de salto y caida // Inicializa los sonidos de salto y caida
void Player::initSounds() void Player::initSounds() {
{
jumping_sound_.clear(); jumping_sound_.clear();
falling_sound_.clear(); falling_sound_.clear();
for (int i = 1; i <= 24; ++i) for (int i = 1; i <= 24; ++i) {
{
std::string soundFile = "jump" + std::to_string(i) + ".wav"; std::string soundFile = "jump" + std::to_string(i) + ".wav";
jumping_sound_.push_back(Resource::get()->getSound(soundFile)); jumping_sound_.push_back(Resource::get()->getSound(soundFile));
if (i >= 11) if (i >= 11) {
{
falling_sound_.push_back(Resource::get()->getSound(soundFile)); falling_sound_.push_back(Resource::get()->getSound(soundFile));
} }
} }
} }
// 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) {
{
x_ = spawn.x; x_ = spawn.x;
y_ = spawn.y; y_ = spawn.y;
vx_ = spawn.vx; vx_ = spawn.vx;
@@ -716,8 +616,7 @@ void Player::applySpawnValues(const PlayerSpawn &spawn)
} }
// Inicializa el sprite del jugador // Inicializa el sprite del jugador
void Player::initSprite(const std::string &surface_path, const std::string &animations_path) void Player::initSprite(const std::string& surface_path, const std::string& animations_path) {
{
auto surface = Resource::get()->getSurface(surface_path); auto surface = Resource::get()->getSurface(surface_path);
auto animations = Resource::get()->getAnimations(animations_path); auto animations = Resource::get()->getAnimations(animations_path);
@@ -729,27 +628,23 @@ void Player::initSprite(const std::string &surface_path, const std::string &anim
#ifdef DEBUG #ifdef DEBUG
// Pinta la información de debug del jugador // Pinta la información de debug del jugador
void Player::renderDebugInfo() void Player::renderDebugInfo() {
{ if (Debug::get()->getEnabled()) {
if (Debug::get()->getEnabled())
{
auto surface = Screen::get()->getRendererSurface(); auto surface = Screen::get()->getRendererSurface();
// Pinta los underfeet // Pinta los underfeet
surface->putPixel(under_feet_[0].x, under_feet_[0].y,static_cast<Uint8>(PaletteColor::BRIGHT_MAGENTA)); surface->putPixel(under_feet_[0].x, under_feet_[0].y, static_cast<Uint8>(PaletteColor::BRIGHT_MAGENTA));
surface->putPixel(under_feet_[1].x, under_feet_[1].y,static_cast<Uint8>(PaletteColor::BRIGHT_MAGENTA)); surface->putPixel(under_feet_[1].x, under_feet_[1].y, static_cast<Uint8>(PaletteColor::BRIGHT_MAGENTA));
// Pinta rectangulo del jugador // Pinta rectangulo del jugador
SDL_Rect rect = getRect(); SDL_Rect rect = getRect();
surface->drawRectBorder(&rect, static_cast<Uint8>(PaletteColor::BRIGHT_CYAN)); surface->drawRectBorder(&rect, static_cast<Uint8>(PaletteColor::BRIGHT_CYAN));
// Pinta el rectangulo de movimiento // Pinta el rectangulo de movimiento
if (vx_ != 0.0f) if (vx_ != 0.0f) {
{
surface->fillRect(&debug_rect_x_, static_cast<Uint8>(PaletteColor::BRIGHT_RED)); surface->fillRect(&debug_rect_x_, static_cast<Uint8>(PaletteColor::BRIGHT_RED));
} }
if (vy_ != 0.0f) if (vy_ != 0.0f) {
{
surface->fillRect(&debug_rect_y_, static_cast<Uint8>(PaletteColor::BRIGHT_RED)); surface->fillRect(&debug_rect_y_, static_cast<Uint8>(PaletteColor::BRIGHT_RED));
} }

View File

@@ -1,8 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_rect.h> // Para SDL_Rect, SDL_Point #include <SDL3/SDL.h>
#include <SDL3/SDL_render.h> // Para SDL_RendererFlip, SDL_FLIP_NONE
#include <SDL3/SDL_stdinc.h> // Para Uint8
#include <memory> // Para shared_ptr, __shared_ptr_access #include <memory> // Para shared_ptr, __shared_ptr_access
#include <string> // Para string #include <string> // Para string
@@ -10,7 +8,7 @@
#include "defines.h" // Para BORDER_TOP, BLOCK #include "defines.h" // Para BORDER_TOP, BLOCK
#include "room.h" #include "room.h"
#include "s_animated_sprite.h" // Para SAnimatedSprite #include "sprite/surface_animated_sprite.h" // Para SAnimatedSprite
#include "utils.h" // Para Color #include "utils.h" // Para Color
struct JA_Sound_t; // lines 13-13 struct JA_Sound_t; // lines 13-13

View File

@@ -1,9 +1,6 @@
#include "resource.h" #include "resource.h"
#include <SDL3/SDL_events.h> // Para SDL_PollEvent, SDL_Event, SDL_KEYDOWN #include <SDL3/SDL.h>
#include <SDL3/SDL_keycode.h> // Para SDLK_ESCAPE
#include <SDL3/SDL_rect.h> // Para SDL_Rect
#include <SDL3/SDL_stdinc.h> // Para Uint8
#include <stdlib.h> // Para exit, size_t #include <stdlib.h> // Para exit, size_t
#include <algorithm> // Para find_if #include <algorithm> // Para find_if
@@ -11,7 +8,7 @@
#include <stdexcept> // Para runtime_error #include <stdexcept> // Para runtime_error
#include "asset.h" // Para AssetType, Asset #include "asset.h" // Para AssetType, Asset
#include "jail_audio.h" // Para JA_DeleteMusic, JA_DeleteSound, JA_Loa... #include "external/jail_audio.h" // Para JA_DeleteMusic, JA_DeleteSound, JA_Loa...
#include "options.h" // Para Options, OptionsGame, options #include "options.h" // Para Options, OptionsGame, options
#include "room.h" // Para RoomData, loadRoomFile, loadRoomTileFile #include "room.h" // Para RoomData, loadRoomFile, loadRoomTileFile
#include "screen.h" // Para Screen #include "screen.h" // Para Screen

View File

@@ -3,144 +3,143 @@
#include <memory> // Para shared_ptr #include <memory> // Para shared_ptr
#include <string> // Para string #include <string> // Para string
#include <vector> // Para vector #include <vector> // Para vector
#include "s_animated_sprite.h" // Para AnimationsFileBuffer
#include "room.h" // Para room_t #include "room.h" // Para room_t
#include "text.h" // Para Text, TextFile #include "sprite/surface_animated_sprite.h" // Para AnimationsFileBuffer
#include "surface.h" // Para Surface #include "surface.h" // Para Surface
#include "text.h" // Para Text, TextFile
struct JA_Music_t; // lines 11-11 struct JA_Music_t; // lines 11-11
struct JA_Sound_t; // lines 12-12 struct JA_Sound_t; // lines 12-12
// Estructura para almacenar ficheros de sonido y su nombre // Estructura para almacenar ficheros de sonido y su nombre
struct ResourceSound struct ResourceSound {
{
std::string name; // Nombre del sonido std::string name; // Nombre del sonido
JA_Sound_t *sound; // Objeto con el sonido JA_Sound_t* sound; // Objeto con el sonido
// Constructor // Constructor
ResourceSound(const std::string &name, JA_Sound_t *sound) ResourceSound(const std::string& name, JA_Sound_t* sound)
: name(name), sound(sound) {} : name(name),
sound(sound) {}
}; };
// Estructura para almacenar ficheros musicales y su nombre // Estructura para almacenar ficheros musicales y su nombre
struct ResourceMusic struct ResourceMusic {
{
std::string name; // Nombre de la musica std::string name; // Nombre de la musica
JA_Music_t *music; // Objeto con la música JA_Music_t* music; // Objeto con la música
// Constructor // Constructor
ResourceMusic(const std::string &name, JA_Music_t *music) ResourceMusic(const std::string& name, JA_Music_t* music)
: name(name), music(music) {} : name(name),
music(music) {}
}; };
// Estructura para almacenar objetos Surface y su nombre // Estructura para almacenar objetos Surface y su nombre
struct ResourceSurface struct ResourceSurface {
{
std::string name; // Nombre de la surface std::string name; // Nombre de la surface
std::shared_ptr<Surface> surface; // Objeto con la surface std::shared_ptr<Surface> surface; // Objeto con la surface
// Constructor // Constructor
ResourceSurface(const std::string &name, std::shared_ptr<Surface> surface) ResourceSurface(const std::string& name, std::shared_ptr<Surface> surface)
: name(name), surface(surface) {} : name(name),
surface(surface) {}
}; };
// Estructura para almacenar objetos Palette y su nombre // Estructura para almacenar objetos Palette y su nombre
struct ResourcePalette struct ResourcePalette {
{
std::string name; // Nombre de la surface std::string name; // Nombre de la surface
Palette palette; // Paleta Palette palette; // Paleta
// Constructor // Constructor
ResourcePalette(const std::string &name, Palette palette) ResourcePalette(const std::string& name, Palette palette)
: name(name), palette(palette) {} : name(name),
palette(palette) {}
}; };
// Estructura para almacenar ficheros TextFile y su nombre // Estructura para almacenar ficheros TextFile y su nombre
struct ResourceTextFile struct ResourceTextFile {
{
std::string name; // Nombre del fichero std::string name; // Nombre del fichero
std::shared_ptr<TextFile> text_file; // Objeto con los descriptores de la fuente de texto std::shared_ptr<TextFile> text_file; // Objeto con los descriptores de la fuente de texto
// Constructor // Constructor
ResourceTextFile(const std::string &name, std::shared_ptr<TextFile> text_file) ResourceTextFile(const std::string& name, std::shared_ptr<TextFile> text_file)
: name(name), text_file(text_file) {} : name(name),
text_file(text_file) {}
}; };
// Estructura para almacenar objetos Text y su nombre // Estructura para almacenar objetos Text y su nombre
struct ResourceText struct ResourceText {
{
std::string name; // Nombre del objeto std::string name; // Nombre del objeto
std::shared_ptr<Text> text; // Objeto std::shared_ptr<Text> text; // Objeto
// Constructor // Constructor
ResourceText(const std::string &name, std::shared_ptr<Text> text) ResourceText(const std::string& name, std::shared_ptr<Text> text)
: name(name), text(text) {} : name(name),
text(text) {}
}; };
// Estructura para almacenar ficheros animaciones y su nombre // Estructura para almacenar ficheros animaciones y su nombre
struct ResourceAnimation struct ResourceAnimation {
{
std::string name; // Nombre del fichero std::string name; // Nombre del fichero
Animations animation; // Objeto con las animaciones Animations animation; // Objeto con las animaciones
// Constructor // Constructor
ResourceAnimation(const std::string &name, const Animations &animation) ResourceAnimation(const std::string& name, const Animations& animation)
: name(name), animation(animation) {} : name(name),
animation(animation) {}
}; };
// Estructura para almacenar ficheros con el mapa de tiles de una habitación y su nombre // Estructura para almacenar ficheros con el mapa de tiles de una habitación y su nombre
struct ResourceTileMap struct ResourceTileMap {
{
std::string name; // Nombre del mapa de tiles std::string name; // Nombre del mapa de tiles
std::vector<int> tileMap; // Vector con los indices del mapa de tiles std::vector<int> tileMap; // Vector con los indices del mapa de tiles
// Constructor // Constructor
ResourceTileMap(const std::string &name, const std::vector<int> &tileMap) ResourceTileMap(const std::string& name, const std::vector<int>& tileMap)
: name(name), tileMap(tileMap) {} : name(name),
tileMap(tileMap) {}
}; };
// Estructura para almacenar habitaciones y su nombre // Estructura para almacenar habitaciones y su nombre
struct ResourceRoom struct ResourceRoom {
{
std::string name; // Nombre de la habitación std::string name; // Nombre de la habitación
std::shared_ptr<RoomData> room; // Habitación std::shared_ptr<RoomData> room; // Habitación
// Constructor // Constructor
ResourceRoom(const std::string &name, std::shared_ptr<RoomData> room) ResourceRoom(const std::string& name, std::shared_ptr<RoomData> room)
: name(name), room(room) {} : name(name),
room(room) {}
}; };
// Estructura para llevar la cuenta de los recursos cargados // Estructura para llevar la cuenta de los recursos cargados
struct ResourceCount struct ResourceCount {
{
int total; // Número total de recursos int total; // Número total de recursos
int loaded; // Número de recursos cargados int loaded; // Número de recursos cargados
// Constructor // Constructor
ResourceCount() ResourceCount()
: total(0), loaded(0) {} : total(0),
loaded(0) {}
// Constructor // Constructor
ResourceCount(int total, int loaded) ResourceCount(int total, int loaded)
: total(total), loaded(loaded) {} : total(total),
loaded(loaded) {}
// Añade una cantidad a los recursos cargados // Añade una cantidad a los recursos cargados
void add(int amount) void add(int amount) {
{
loaded += amount; loaded += amount;
} }
// Obtiene el porcentaje de recursos cargados // Obtiene el porcentaje de recursos cargados
float getPercentage() float getPercentage() {
{
return static_cast<float>(loaded) / static_cast<float>(total); return static_cast<float>(loaded) / static_cast<float>(total);
} }
}; };
class Resource class Resource {
{ private:
private:
// [SINGLETON] Objeto resource privado para Don Melitón // [SINGLETON] Objeto resource privado para Don Melitón
static Resource *resource_; static Resource* resource_;
std::vector<ResourceSound> sounds_; // Vector con los sonidos std::vector<ResourceSound> sounds_; // Vector con los sonidos
std::vector<ResourceMusic> musics_; // Vector con las musicas std::vector<ResourceMusic> musics_; // Vector con las musicas
@@ -213,7 +212,7 @@ private:
// Destructor // Destructor
~Resource() = default; ~Resource() = default;
public: public:
// [SINGLETON] Crearemos el objeto resource con esta función estática // [SINGLETON] Crearemos el objeto resource con esta función estática
static void init(); static void init();
@@ -221,37 +220,37 @@ public:
static void destroy(); static void destroy();
// [SINGLETON] Con este método obtenemos el objeto resource y podemos trabajar con él // [SINGLETON] Con este método obtenemos el objeto resource y podemos trabajar con él
static Resource *get(); static Resource* get();
// Obtiene el sonido a partir de un nombre // Obtiene el sonido a partir de un nombre
JA_Sound_t *getSound(const std::string &name); JA_Sound_t* getSound(const std::string& name);
// Obtiene la música a partir de un nombre // Obtiene la música a partir de un nombre
JA_Music_t *getMusic(const std::string &name); JA_Music_t* getMusic(const std::string& name);
// Obtiene la surface a partir de un nombre // Obtiene la surface a partir de un nombre
std::shared_ptr<Surface> getSurface(const std::string &name); std::shared_ptr<Surface> getSurface(const std::string& name);
// Obtiene la paleta a partir de un nombre // Obtiene la paleta a partir de un nombre
Palette getPalette(const std::string &name); Palette getPalette(const std::string& name);
// Obtiene el fichero de texto a partir de un nombre // Obtiene el fichero de texto a partir de un nombre
std::shared_ptr<TextFile> getTextFile(const std::string &name); std::shared_ptr<TextFile> getTextFile(const std::string& name);
// Obtiene el objeto de texto a partir de un nombre // Obtiene el objeto de texto a partir de un nombre
std::shared_ptr<Text> getText(const std::string &name); std::shared_ptr<Text> getText(const std::string& name);
// Obtiene la animación a partir de un nombre // Obtiene la animación a partir de un nombre
Animations &getAnimations(const std::string &name); Animations& getAnimations(const std::string& name);
// Obtiene el mapa de tiles a partir de un nombre // Obtiene el mapa de tiles a partir de un nombre
std::vector<int> &getTileMap(const std::string &name); std::vector<int>& getTileMap(const std::string& name);
// Obtiene la habitación a partir de un nombre // Obtiene la habitación a partir de un nombre
std::shared_ptr<RoomData> getRoom(const std::string &name); std::shared_ptr<RoomData> getRoom(const std::string& name);
// Obtiene todas las habitaciones // Obtiene todas las habitaciones
std::vector<ResourceRoom> &getRooms(); std::vector<ResourceRoom>& getRooms();
// Recarga todos los recursos // Recarga todos los recursos
void reload(); void reload();

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
#pragma once #pragma once
#include <SDL3/SDL_rect.h> // Para SDL_Rect, SDL_Point #include <SDL3/SDL.h>
#include <SDL3/SDL_stdinc.h> // Para Uint8
#include <memory> // Para shared_ptr #include <memory> // Para shared_ptr
#include <string> // Para string #include <string> // Para string

View File

@@ -1,13 +1,12 @@
#include "scoreboard.h" #include "scoreboard.h"
#include <SDL3/SDL_rect.h> // Para SDL_Rect #include <SDL3/SDL.h>
#include <SDL3/SDL_timer.h> // Para SDL_GetTicks
#include "defines.h" // Para BLOCK #include "defines.h" // Para BLOCK
#include "options.h" // Para Options, options, Cheat, OptionsGame #include "options.h" // Para Options, options, Cheat, OptionsGame
#include "resource.h" // Para Resource #include "resource.h" // Para Resource
#include "s_animated_sprite.h" // Para SAnimatedSprite
#include "screen.h" // Para Screen #include "screen.h" // Para Screen
#include "sprite/surface_animated_sprite.h" // Para SAnimatedSprite
#include "surface.h" // Para Surface #include "surface.h" // Para Surface
#include "text.h" // Para Text #include "text.h" // Para Text
#include "utils.h" // Para stringToColor #include "utils.h" // Para stringToColor

View File

@@ -1,7 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_rect.h> // Para SDL_Rect #include <SDL3/SDL.h>
#include <SDL3/SDL_stdinc.h> // Para Uint32, Uint8
#include <memory> // Para shared_ptr #include <memory> // Para shared_ptr
#include <string> // Para string, basic_string #include <string> // Para string, basic_string

View File

@@ -1,10 +1,6 @@
#include "screen.h" #include "screen.h"
#include <SDL3/SDL_error.h> // Para SDL_GetError #include <SDL3/SDL.h>
#include <SDL3/SDL_events.h> // Para SDL_DISABLE, SDL_ENABLE
#include <SDL3/SDL_mouse.h> // Para SDL_ShowCursor
#include <SDL3/SDL_pixels.h> // Para SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORM...
#include <SDL3/SDL_timer.h> // Para SDL_GetTicks
#include <ctype.h> // Para toupper #include <ctype.h> // Para toupper
#include <algorithm> // Para max, min, transform #include <algorithm> // Para max, min, transform
@@ -14,13 +10,13 @@
#include <string> // Para char_traits, string, operator+, operator== #include <string> // Para char_traits, string, operator+, operator==
#include "asset.h" // Para Asset, AssetType #include "asset.h" // Para Asset, AssetType
#include "jail_shader.h" // Para init, render #include "external/jail_shader.h" // Para init, render
#include "mouse.h" // Para updateCursorVisibility #include "mouse.h" // Para updateCursorVisibility
#include "notifier.h" // Para Notifier
#include "options.h" // Para Options, options, OptionsVideo, Border #include "options.h" // Para Options, options, OptionsVideo, Border
#include "resource.h" // Para Resource #include "resource.h" // Para Resource
#include "surface.h" // Para Surface, readPalFile #include "surface.h" // Para Surface, readPalFile
#include "text.h" // Para Text #include "text.h" // Para Text
#include "ui/notifier.h" // Para Notifier
// [SINGLETON] // [SINGLETON]
Screen* Screen::screen_ = nullptr; Screen* Screen::screen_ = nullptr;
@@ -253,7 +249,9 @@ void Screen::adjustWindowSize() {
} }
// Ajusta el tamaño lógico del renderizador // Ajusta el tamaño lógico del renderizador
void Screen::adjustRenderLogicalSize() { SDL_RenderSetLogicalSize(renderer_, window_width_, window_height_); } void Screen::adjustRenderLogicalSize() {
SDL_SetRenderLogicalPresentation(renderer_, window_width_, window_height_);
}
// Obtiene el tamaño máximo de zoom posible para la ventana // Obtiene el tamaño máximo de zoom posible para la ventana
int Screen::getMaxZoom() { int Screen::getMaxZoom() {

View File

@@ -1,10 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_blendmode.h> // Para SDL_BlendMode #include <SDL3/SDL.h>
#include <SDL3/SDL_rect.h> // Para SDL_Rect
#include <SDL3/SDL_render.h> // Para SDL_Renderer, SDL_Texture
#include <SDL3/SDL_stdinc.h> // Para Uint8, Uint32
#include <SDL3/SDL_video.h> // Para SDL_Window
#include <stddef.h> // Para size_t #include <stddef.h> // Para size_t
#include <memory> // Para shared_ptr, __shared_ptr_access #include <memory> // Para shared_ptr, __shared_ptr_access

View File

@@ -1,8 +1,6 @@
#include "credits.h" #include "credits.h"
#include <SDL3/SDL_events.h> // Para SDL_PollEvent, SDL_Event #include <SDL3/SDL.h>
#include <SDL3/SDL_rect.h> // Para SDL_Rect
#include <SDL3/SDL_timer.h> // Para SDL_GetTicks
#include <algorithm> // Para min #include <algorithm> // Para min
@@ -11,8 +9,8 @@
#include "global_inputs.h" // Para check #include "global_inputs.h" // Para check
#include "options.h" // Para Options, options, OptionsGame, Sectio... #include "options.h" // Para Options, options, OptionsGame, Sectio...
#include "resource.h" // Para Resource #include "resource.h" // Para Resource
#include "s_animated_sprite.h" // Para SAnimatedSprite
#include "screen.h" // Para Screen #include "screen.h" // Para Screen
#include "sprite/surface_animated_sprite.h" // Para SAnimatedSprite
#include "surface.h" // Para Surface #include "surface.h" // Para Surface
#include "text.h" // Para Text, TEXT_CENTER, TEXT_COLOR #include "text.h" // Para Text, TEXT_CENTER, TEXT_COLOR
#include "utils.h" // Para PaletteColor #include "utils.h" // Para PaletteColor

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_stdinc.h> // Para Uint32, Uint8 #include <SDL3/SDL.h>
#include <memory> // Para shared_ptr #include <memory> // Para shared_ptr
#include <string> // Para string #include <string> // Para string

View File

@@ -1,19 +1,17 @@
#include "ending.h" #include "ending.h"
#include <SDL3/SDL_events.h> // Para SDL_PollEvent, SDL_Event #include <SDL3/SDL.h>
#include <SDL3/SDL_rect.h> // Para SDL_Rect
#include <SDL3/SDL_timer.h> // Para SDL_GetTicks
#include <algorithm> // Para min #include <algorithm> // Para min
#include "defines.h" // Para GAME_SPEED #include "defines.h" // Para GAME_SPEED
#include "external/jail_audio.h" // Para JA_SetVolume, JA_PlayMusic, JA_StopMusic
#include "global_events.h" // Para check #include "global_events.h" // Para check
#include "global_inputs.h" // Para check #include "global_inputs.h" // Para check
#include "jail_audio.h" // Para JA_SetVolume, JA_PlayMusic, JA_StopMusic
#include "options.h" // Para Options, options, OptionsGame, SectionS... #include "options.h" // Para Options, options, OptionsGame, SectionS...
#include "resource.h" // Para Resource #include "resource.h" // Para Resource
#include "s_sprite.h" // Para SSprite
#include "screen.h" // Para Screen #include "screen.h" // Para Screen
#include "sprite/surface_sprite.h" // Para SSprite
#include "surface.h" // Para Surface #include "surface.h" // Para Surface
#include "text.h" // Para Text, TEXT_STROKE #include "text.h" // Para Text, TEXT_STROKE
#include "utils.h" // Para PaletteColor #include "utils.h" // Para PaletteColor

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_stdinc.h> // Para Uint32 #include <SDL3/SDL.h>
#include <memory> // Para shared_ptr #include <memory> // Para shared_ptr
#include <string> // Para string #include <string> // Para string

View File

@@ -1,20 +1,18 @@
#include "ending2.h" #include "ending2.h"
#include <SDL3/SDL_events.h> // Para SDL_PollEvent, SDL_Event #include <SDL3/SDL.h>
#include <SDL3/SDL_rect.h> // Para SDL_Rect
#include <SDL3/SDL_timer.h> // Para SDL_GetTicks
#include <algorithm> // Para max, replace #include <algorithm> // Para max, replace
#include "defines.h" // Para GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y #include "defines.h" // Para GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y
#include "external/jail_audio.h" // Para JA_SetVolume, JA_PlayMusic, JA_StopMusic
#include "global_events.h" // Para check #include "global_events.h" // Para check
#include "global_inputs.h" // Para check #include "global_inputs.h" // Para check
#include "jail_audio.h" // Para JA_SetVolume, JA_PlayMusic, JA_StopMusic
#include "options.h" // Para Options, options, OptionsGame, Sectio... #include "options.h" // Para Options, options, OptionsGame, Sectio...
#include "resource.h" // Para Resource #include "resource.h" // Para Resource
#include "s_animated_sprite.h" // Para SAnimatedSprite
#include "s_moving_sprite.h" // Para SMovingSprite
#include "screen.h" // Para Screen #include "screen.h" // Para Screen
#include "sprite/surface_animated_sprite.h" // Para SAnimatedSprite
#include "sprite/surface_moving_sprite.h" // Para SMovingSprite
#include "surface.h" // Para Surface #include "surface.h" // Para Surface
#include "text.h" // Para Text #include "text.h" // Para Text
#include "utils.h" // Para PaletteColor, stringToColor #include "utils.h" // Para PaletteColor, stringToColor

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_stdinc.h> // Para Uint32, Uint8 #include <SDL3/SDL.h>
#include <memory> // Para shared_ptr #include <memory> // Para shared_ptr
#include <string> // Para string #include <string> // Para string

View File

@@ -1,8 +1,6 @@
#include "game.h" #include "game.h"
#include <SDL3/SDL_render.h> // Para SDL_FLIP_HORIZONTAL #include <SDL3/SDL.h>
#include <SDL3/SDL_scancode.h> // Para SDL_SCANCODE_7, SDL_SCANCODE_A, SDL_S...
#include <SDL3/SDL_timer.h> // Para SDL_GetTicks
#include <vector> // Para vector #include <vector> // Para vector
@@ -10,12 +8,11 @@
#include "cheevos.h" // Para Cheevos #include "cheevos.h" // Para Cheevos
#include "debug.h" // Para Debug #include "debug.h" // Para Debug
#include "defines.h" // Para BLOCK, PLAY_AREA_HEIGHT, RoomBorder::BOTTOM #include "defines.h" // Para BLOCK, PLAY_AREA_HEIGHT, RoomBorder::BOTTOM
#include "external/jail_audio.h" // Para JA_PauseMusic, JA_GetMusicState, JA_P...
#include "global_events.h" // Para check #include "global_events.h" // Para check
#include "global_inputs.h" // Para check #include "global_inputs.h" // Para check
#include "input.h" // Para Input, InputAction, INPUT_DO_NOT_ALLOW_REPEAT #include "input.h" // Para Input, InputAction, INPUT_DO_NOT_ALLOW_REPEAT
#include "item_tracker.h" // Para ItemTracker #include "item_tracker.h" // Para ItemTracker
#include "jail_audio.h" // Para JA_PauseMusic, JA_GetMusicState, JA_P...
#include "notifier.h" // Para Notifier, NotificationText, CHEEVO_NO...
#include "options.h" // Para Options, options, Cheat, SectionState #include "options.h" // Para Options, options, Cheat, SectionState
#include "resource.h" // Para ResourceRoom, Resource #include "resource.h" // Para ResourceRoom, Resource
#include "room.h" // Para Room, RoomData #include "room.h" // Para Room, RoomData
@@ -25,6 +22,7 @@
#include "stats.h" // Para Stats #include "stats.h" // Para Stats
#include "surface.h" // Para Surface #include "surface.h" // Para Surface
#include "text.h" // Para Text, TEXT_CENTER, TEXT_COLOR #include "text.h" // Para Text, TEXT_CENTER, TEXT_COLOR
#include "ui/notifier.h" // Para Notifier, NotificationText, CHEEVO_NO...
#include "utils.h" // Para PaletteColor, stringToColor #include "utils.h" // Para PaletteColor, stringToColor
// Constructor // Constructor

View File

@@ -1,8 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_events.h> // Para SDL_Event #include <SDL3/SDL.h>
#include <SDL3/SDL_rect.h> // Para SDL_Rect
#include <SDL3/SDL_stdinc.h> // Para Uint32
#include <initializer_list> // Para initializer_list #include <initializer_list> // Para initializer_list
#include <memory> // Para shared_ptr #include <memory> // Para shared_ptr

View File

@@ -1,19 +1,18 @@
#include "game_over.h" #include "game_over.h"
#include <SDL3/SDL_events.h> // Para SDL_PollEvent, SDL_Event #include <SDL3/SDL.h>
#include <SDL3/SDL_timer.h> // Para SDL_GetTicks
#include <algorithm> // Para min, max #include <algorithm> // Para min, max
#include <string> // Para basic_string, operator+, to_string #include <string> // Para basic_string, operator+, to_string
#include "defines.h" // Para GAMECANVAS_CENTER_X, GAME_SPEED #include "defines.h" // Para GAMECANVAS_CENTER_X, GAME_SPEED
#include "external/jail_audio.h" // Para JA_PlayMusic
#include "global_events.h" // Para check #include "global_events.h" // Para check
#include "global_inputs.h" // Para check #include "global_inputs.h" // Para check
#include "jail_audio.h" // Para JA_PlayMusic
#include "options.h" // Para Options, options, OptionsStats, Secti... #include "options.h" // Para Options, options, OptionsStats, Secti...
#include "resource.h" // Para Resource #include "resource.h" // Para Resource
#include "s_animated_sprite.h" // Para SAnimatedSprite
#include "screen.h" // Para Screen #include "screen.h" // Para Screen
#include "sprite/surface_animated_sprite.h" // Para SAnimatedSprite
#include "text.h" // Para TEXT_CENTER, TEXT_COLOR, Text #include "text.h" // Para TEXT_CENTER, TEXT_COLOR, Text
#include "utils.h" // Para PaletteColor, stringToColor #include "utils.h" // Para PaletteColor, stringToColor

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_stdinc.h> // Para Uint8, Uint32 #include <SDL3/SDL.h>
#include <memory> // Para shared_ptr #include <memory> // Para shared_ptr
#include <vector> // Para vector #include <vector> // Para vector

View File

@@ -1,17 +1,16 @@
#include "loading_screen.h" #include "loading_screen.h"
#include <SDL3/SDL_events.h> // Para SDL_PollEvent, SDL_Event #include <SDL3/SDL.h>
#include <SDL3/SDL_timer.h> // Para SDL_GetTicks
#include <stdlib.h> // Para rand #include <stdlib.h> // Para rand
#include "defines.h" // Para GAME_SPEED #include "defines.h" // Para GAME_SPEED
#include "external/jail_audio.h" // Para JA_PlayMusic, JA_SetVolume, JA_StopMusic
#include "global_events.h" // Para check #include "global_events.h" // Para check
#include "global_inputs.h" // Para check #include "global_inputs.h" // Para check
#include "jail_audio.h" // Para JA_PlayMusic, JA_SetVolume, JA_StopMusic
#include "options.h" // Para Options, options, SectionState, Options... #include "options.h" // Para Options, options, SectionState, Options...
#include "resource.h" // Para Resource #include "resource.h" // Para Resource
#include "s_sprite.h" // Para SSprite
#include "screen.h" // Para Screen #include "screen.h" // Para Screen
#include "sprite/surface_sprite.h" // Para SSprite
#include "surface.h" // Para Surface #include "surface.h" // Para Surface
#include "utils.h" // Para stringToColor, PaletteColor #include "utils.h" // Para stringToColor, PaletteColor

View File

@@ -1,7 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_rect.h> // Para SDL_Rect #include <SDL3/SDL.h>
#include <SDL3/SDL_stdinc.h> // Para Uint32
#include <memory> // Para shared_ptr #include <memory> // Para shared_ptr
class SSprite; // lines 7-7 class SSprite; // lines 7-7

View File

@@ -1,15 +1,14 @@
#include "logo.h" #include "logo.h"
#include <SDL3/SDL_events.h> // Para SDL_PollEvent, SDL_Event #include <SDL3/SDL.h>
#include <SDL3/SDL_timer.h> // Para SDL_GetTicks
#include "defines.h" // Para GAME_SPEED #include "defines.h" // Para GAME_SPEED
#include "global_events.h" // Para check #include "global_events.h" // Para check
#include "global_inputs.h" // Para check #include "global_inputs.h" // Para check
#include "options.h" // Para Options, SectionState, options, Section #include "options.h" // Para Options, SectionState, options, Section
#include "resource.h" // Para Resource #include "resource.h" // Para Resource
#include "s_sprite.h" // Para SSprite
#include "screen.h" // Para Screen #include "screen.h" // Para Screen
#include "sprite/surface_sprite.h" // Para SSprite
#include "surface.h" // Para Surface #include "surface.h" // Para Surface
#include "utils.h" // Para PaletteColor #include "utils.h" // Para PaletteColor

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_stdinc.h> // Para Uint8, Uint32 #include <SDL3/SDL.h>
#include <memory> // Para shared_ptr #include <memory> // Para shared_ptr
#include <vector> // Para vector #include <vector> // Para vector

View File

@@ -1,8 +1,6 @@
#include "title.h" #include "title.h"
#include <SDL3/SDL_events.h> // Para SDL_PollEvent, SDL_Event, SDL_KEYDOWN #include <SDL3/SDL.h>
#include <SDL3/SDL_scancode.h> // Para SDL_SCANCODE_1, SDL_SCANCODE_2
#include <SDL3/SDL_timer.h> // Para SDL_GetTicks
#include <algorithm> // Para clamp #include <algorithm> // Para clamp
@@ -13,8 +11,8 @@
#include "input.h" // Para Input, InputAction, INPUT_DO_NOT_ALLOW_REPEAT, REP... #include "input.h" // Para Input, InputAction, INPUT_DO_NOT_ALLOW_REPEAT, REP...
#include "options.h" // Para Options, options, SectionState, Section #include "options.h" // Para Options, options, SectionState, Section
#include "resource.h" // Para Resource #include "resource.h" // Para Resource
#include "s_sprite.h" // Para SSprite
#include "screen.h" // Para Screen #include "screen.h" // Para Screen
#include "sprite/surface_sprite.h" // Para SSprite
#include "surface.h" // Para Surface #include "surface.h" // Para Surface
#include "text.h" // Para Text, TEXT_CENTER, TEXT_COLOR #include "text.h" // Para Text, TEXT_CENTER, TEXT_COLOR
#include "utils.h" // Para stringToColor, PaletteColor, playMusic #include "utils.h" // Para stringToColor, PaletteColor, playMusic

View File

@@ -1,7 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_rect.h> // Para SDL_Rect #include <SDL3/SDL.h>
#include <SDL3/SDL_stdinc.h> // Para Uint32
#include <memory> // Para shared_ptr #include <memory> // Para shared_ptr
#include <string> // Para string #include <string> // Para string

View File

@@ -1,18 +1,19 @@
#include "s_animated_sprite.h" #include "sprite/surface_animated_sprite.h"
#include <stddef.h> // Para size_t #include <stddef.h> // Para size_t
#include <fstream> // Para basic_ostream, basic_istream, operator<<, basic... #include <fstream> // Para basic_ostream, basic_istream, operator<<, basic...
#include <iostream> // Para cout, cerr #include <iostream> // Para cout, cerr
#include <sstream> // Para basic_stringstream #include <sstream> // Para basic_stringstream
#include <stdexcept> // Para runtime_error #include <stdexcept> // Para runtime_error
#include "surface.h" // Para Surface #include "surface.h" // Para Surface
#include "utils.h" // Para printWithDots #include "utils.h" // Para printWithDots
// Carga las animaciones en un vector(Animations) desde un fichero // Carga las animaciones en un vector(Animations) desde un fichero
Animations loadAnimationsFromFile(const std::string &file_path) Animations loadAnimationsFromFile(const std::string& file_path) {
{
std::ifstream file(file_path); std::ifstream file(file_path);
if (!file) if (!file) {
{
std::cerr << "Error: Fichero no encontrado " << file_path << std::endl; std::cerr << "Error: Fichero no encontrado " << file_path << std::endl;
throw std::runtime_error("Fichero no encontrado: " + file_path); throw std::runtime_error("Fichero no encontrado: " + file_path);
} }
@@ -21,8 +22,7 @@ Animations loadAnimationsFromFile(const std::string &file_path)
std::vector<std::string> buffer; std::vector<std::string> buffer;
std::string line; std::string line;
while (std::getline(file, line)) while (std::getline(file, line)) {
{
if (!line.empty()) if (!line.empty())
buffer.push_back(line); buffer.push_back(line);
} }
@@ -31,37 +31,30 @@ Animations loadAnimationsFromFile(const std::string &file_path)
} }
// Constructor // Constructor
SAnimatedSprite::SAnimatedSprite(std::shared_ptr<Surface> surface, const std::string &file_path) SAnimatedSprite::SAnimatedSprite(std::shared_ptr<Surface> surface, const std::string& file_path)
: SMovingSprite(surface) : SMovingSprite(surface) {
{
// Carga las animaciones // Carga las animaciones
if (!file_path.empty()) if (!file_path.empty()) {
{
Animations v = loadAnimationsFromFile(file_path); Animations v = loadAnimationsFromFile(file_path);
setAnimations(v); setAnimations(v);
} }
} }
// Constructor // Constructor
SAnimatedSprite::SAnimatedSprite(std::shared_ptr<Surface> surface, const Animations &animations) SAnimatedSprite::SAnimatedSprite(std::shared_ptr<Surface> surface, const Animations& animations)
: SMovingSprite(surface) : SMovingSprite(surface) {
{ if (!animations.empty()) {
if (!animations.empty())
{
setAnimations(animations); setAnimations(animations);
} }
} }
// Obtiene el indice de la animación a partir del nombre // Obtiene el indice de la animación a partir del nombre
int SAnimatedSprite::getIndex(const std::string &name) int SAnimatedSprite::getIndex(const std::string& name) {
{
auto index = -1; auto index = -1;
for (const auto &a : animations_) for (const auto& a : animations_) {
{
index++; index++;
if (a.name == name) if (a.name == name) {
{
return index; return index;
} }
} }
@@ -70,10 +63,8 @@ int SAnimatedSprite::getIndex(const std::string &name)
} }
// Calcula el frame correspondiente a la animación // Calcula el frame correspondiente a la animación
void SAnimatedSprite::animate() void SAnimatedSprite::animate() {
{ if (animations_[current_animation_].speed == 0) {
if (animations_[current_animation_].speed == 0)
{
return; return;
} }
@@ -82,22 +73,17 @@ void SAnimatedSprite::animate()
// Si alcanza el final de la animación, reinicia el contador de la animación // Si alcanza el final de la animación, reinicia el contador de la animación
// en función de la variable loop y coloca el nuevo frame // en función de la variable loop y coloca el nuevo frame
if (animations_[current_animation_].current_frame >= static_cast<int>(animations_[current_animation_].frames.size())) if (animations_[current_animation_].current_frame >= static_cast<int>(animations_[current_animation_].frames.size())) {
{ if (animations_[current_animation_].loop == -1) { // Si no hay loop, deja el último frame
if (animations_[current_animation_].loop == -1)
{ // Si no hay loop, deja el último frame
animations_[current_animation_].current_frame = animations_[current_animation_].frames.size(); animations_[current_animation_].current_frame = animations_[current_animation_].frames.size();
animations_[current_animation_].completed = true; animations_[current_animation_].completed = true;
} } else { // Si hay loop, vuelve al frame indicado
else
{ // Si hay loop, vuelve al frame indicado
animations_[current_animation_].counter = 0; animations_[current_animation_].counter = 0;
animations_[current_animation_].current_frame = animations_[current_animation_].loop; animations_[current_animation_].current_frame = animations_[current_animation_].loop;
} }
} }
// En caso contrario // En caso contrario
else else {
{
// Escoge el frame correspondiente de la animación // Escoge el frame correspondiente de la animación
setClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]); setClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]);
@@ -107,17 +93,14 @@ void SAnimatedSprite::animate()
} }
// Comprueba si ha terminado la animación // Comprueba si ha terminado la animación
bool SAnimatedSprite::animationIsCompleted() bool SAnimatedSprite::animationIsCompleted() {
{
return animations_[current_animation_].completed; return animations_[current_animation_].completed;
} }
// Establece la animacion actual // Establece la animacion actual
void SAnimatedSprite::setCurrentAnimation(const std::string &name) void SAnimatedSprite::setCurrentAnimation(const std::string& name) {
{
const auto new_animation = getIndex(name); const auto new_animation = getIndex(name);
if (current_animation_ != new_animation) if (current_animation_ != new_animation) {
{
current_animation_ = new_animation; current_animation_ = new_animation;
animations_[current_animation_].current_frame = 0; animations_[current_animation_].current_frame = 0;
animations_[current_animation_].counter = 0; animations_[current_animation_].counter = 0;
@@ -127,11 +110,9 @@ void SAnimatedSprite::setCurrentAnimation(const std::string &name)
} }
// Establece la animacion actual // Establece la animacion actual
void SAnimatedSprite::setCurrentAnimation(int index) void SAnimatedSprite::setCurrentAnimation(int index) {
{
const auto new_animation = index; const auto new_animation = index;
if (current_animation_ != new_animation) if (current_animation_ != new_animation) {
{
current_animation_ = new_animation; current_animation_ = new_animation;
animations_[current_animation_].current_frame = 0; animations_[current_animation_].current_frame = 0;
animations_[current_animation_].counter = 0; animations_[current_animation_].counter = 0;
@@ -141,42 +122,36 @@ void SAnimatedSprite::setCurrentAnimation(int index)
} }
// Actualiza las variables del objeto // Actualiza las variables del objeto
void SAnimatedSprite::update() void SAnimatedSprite::update() {
{
animate(); animate();
SMovingSprite::update(); SMovingSprite::update();
} }
// Reinicia la animación // Reinicia la animación
void SAnimatedSprite::resetAnimation() void SAnimatedSprite::resetAnimation() {
{
animations_[current_animation_].current_frame = 0; animations_[current_animation_].current_frame = 0;
animations_[current_animation_].counter = 0; animations_[current_animation_].counter = 0;
animations_[current_animation_].completed = false; animations_[current_animation_].completed = false;
} }
// Carga la animación desde un vector de cadenas // Carga la animación desde un vector de cadenas
void SAnimatedSprite::setAnimations(const Animations &animations) void SAnimatedSprite::setAnimations(const Animations& animations) {
{
int frame_width = 1; int frame_width = 1;
int frame_height = 1; int frame_height = 1;
int frames_per_row = 1; int frames_per_row = 1;
int max_tiles = 1; int max_tiles = 1;
size_t index = 0; size_t index = 0;
while (index < animations.size()) while (index < animations.size()) {
{
std::string line = animations.at(index); std::string line = animations.at(index);
// Parsea el fichero para buscar variables y valores // Parsea el fichero para buscar variables y valores
if (line != "[animation]") if (line != "[animation]") {
{
// Encuentra la posición del caracter '=' // Encuentra la posición del caracter '='
size_t pos = line.find("="); size_t pos = line.find("=");
// Procesa las dos subcadenas // Procesa las dos subcadenas
if (pos != std::string::npos) if (pos != std::string::npos) {
{
std::string key = line.substr(0, pos); std::string key = line.substr(0, pos);
int value = std::stoi(line.substr(pos + 1)); int value = std::stoi(line.substr(pos + 1));
if (key == "frame_width") if (key == "frame_width")
@@ -194,17 +169,14 @@ void SAnimatedSprite::setAnimations(const Animations &animations)
} }
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación // Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
if (line == "[animation]") if (line == "[animation]") {
{
AnimationData animation; AnimationData animation;
do do {
{
index++; index++;
line = animations.at(index); line = animations.at(index);
size_t pos = line.find("="); size_t pos = line.find("=");
if (pos != std::string::npos) if (pos != std::string::npos) {
{
std::string key = line.substr(0, pos); std::string key = line.substr(0, pos);
std::string value = line.substr(pos + 1); std::string value = line.substr(pos + 1);
@@ -214,18 +186,15 @@ void SAnimatedSprite::setAnimations(const Animations &animations)
animation.speed = std::stoi(value); animation.speed = std::stoi(value);
else if (key == "loop") else if (key == "loop")
animation.loop = std::stoi(value); animation.loop = std::stoi(value);
else if (key == "frames") else if (key == "frames") {
{
// Se introducen los valores separados por comas en un vector // Se introducen los valores separados por comas en un vector
std::stringstream ss(value); std::stringstream ss(value);
std::string tmp; std::string tmp;
SDL_Rect rect = {0, 0, frame_width, frame_height}; SDL_Rect rect = {0, 0, frame_width, frame_height};
while (getline(ss, tmp, ',')) while (getline(ss, tmp, ',')) {
{
// Comprueba que el tile no sea mayor que el maximo indice permitido // Comprueba que el tile no sea mayor que el maximo indice permitido
const int num_tile = std::stoi(tmp); const int num_tile = std::stoi(tmp);
if (num_tile <= max_tiles) if (num_tile <= max_tiles) {
{
rect.x = (num_tile % frames_per_row) * frame_width; rect.x = (num_tile % frames_per_row) * frame_width;
rect.y = (num_tile / frames_per_row) * frame_height; rect.y = (num_tile / frames_per_row) * frame_height;
animation.frames.emplace_back(rect); animation.frames.emplace_back(rect);
@@ -252,11 +221,9 @@ void SAnimatedSprite::setAnimations(const Animations &animations)
} }
// Establece el frame actual de la animación // Establece el frame actual de la animación
void SAnimatedSprite::setCurrentAnimationFrame(int num) void SAnimatedSprite::setCurrentAnimationFrame(int num) {
{
// Descarta valores fuera de rango // Descarta valores fuera de rango
if (num < 0 || num >= static_cast<int>(animations_[current_animation_].frames.size())) if (num < 0 || num >= static_cast<int>(animations_[current_animation_].frames.size())) {
{
num = 0; num = 0;
} }

View File

@@ -1,12 +1,12 @@
#pragma once #pragma once
#include <SDL3/SDL_rect.h> // Para SDL_Rect #include <SDL3/SDL.h>
#include <memory> // Para shared_ptr #include <memory> // Para shared_ptr
#include <string> // Para string #include <string> // Para string
#include <vector> // Para vector #include <vector> // Para vector
#include "s_moving_sprite.h" // Para SMovingSprite #include "sprite/surface_moving_sprite.h" // Para SMovingSprite
class Surface; // lines 9-9 class Surface; // lines 9-9
struct AnimationData { struct AnimationData {

View File

@@ -1,4 +1,5 @@
#include "s_moving_sprite.h" #include "sprite/surface_moving_sprite.h"
#include "surface.h" // Para Surface #include "surface.h" // Para Surface
// Constructor // Constructor
@@ -21,8 +22,7 @@ SMovingSprite::SMovingSprite(std::shared_ptr<Surface> surface)
flip_(SDL_FLIP_NONE) { SSprite::clear(); } flip_(SDL_FLIP_NONE) { SSprite::clear(); }
// Reinicia todas las variables // Reinicia todas las variables
void SMovingSprite::clear() void SMovingSprite::clear() {
{
x_ = 0.0f; // Posición en el eje X x_ = 0.0f; // Posición en el eje X
y_ = 0.0f; // Posición en el eje Y y_ = 0.0f; // Posición en el eje Y
@@ -38,8 +38,7 @@ void SMovingSprite::clear()
} }
// Mueve el sprite // Mueve el sprite
void SMovingSprite::move() void SMovingSprite::move() {
{
x_ += vx_; x_ += vx_;
y_ += vy_; y_ += vy_;
@@ -51,26 +50,22 @@ void SMovingSprite::move()
} }
// Actualiza las variables internas del objeto // Actualiza las variables internas del objeto
void SMovingSprite::update() void SMovingSprite::update() {
{
move(); move();
} }
// Muestra el sprite por pantalla // Muestra el sprite por pantalla
void SMovingSprite::render() void SMovingSprite::render() {
{
surface_->render(pos_.x, pos_.y, &clip_, flip_); surface_->render(pos_.x, pos_.y, &clip_, flip_);
} }
// Muestra el sprite por pantalla // Muestra el sprite por pantalla
void SMovingSprite::render(Uint8 source_color, Uint8 target_color) void SMovingSprite::render(Uint8 source_color, Uint8 target_color) {
{
surface_->renderWithColorReplace(pos_.x, pos_.y, source_color, target_color, &clip_, flip_); surface_->renderWithColorReplace(pos_.x, pos_.y, source_color, target_color, &clip_, flip_);
} }
// Establece la posición y_ el tamaño del objeto // Establece la posición y_ el tamaño del objeto
void SMovingSprite::setPos(SDL_Rect rect) void SMovingSprite::setPos(SDL_Rect rect) {
{
x_ = static_cast<float>(rect.x); x_ = static_cast<float>(rect.x);
y_ = static_cast<float>(rect.y); y_ = static_cast<float>(rect.y);
@@ -78,8 +73,7 @@ void SMovingSprite::setPos(SDL_Rect rect)
} }
// Establece el valor de las variables // Establece el valor de las variables
void SMovingSprite::setPos(float x, float y) void SMovingSprite::setPos(float x, float y) {
{
x_ = x; x_ = x;
y_ = y; y_ = y;
@@ -88,15 +82,13 @@ void SMovingSprite::setPos(float x, float y)
} }
// Establece el valor de la variable // Establece el valor de la variable
void SMovingSprite::setPosX(float value) void SMovingSprite::setPosX(float value) {
{
x_ = value; x_ = value;
pos_.x = static_cast<int>(x_); pos_.x = static_cast<int>(x_);
} }
// Establece el valor de la variable // Establece el valor de la variable
void SMovingSprite::setPosY(float value) void SMovingSprite::setPosY(float value) {
{
y_ = value; y_ = value;
pos_.y = static_cast<int>(y_); pos_.y = static_cast<int>(y_);
} }

View File

@@ -1,12 +1,10 @@
#pragma once #pragma once
#include <SDL3/SDL_rect.h> // Para SDL_Rect #include <SDL3/SDL.h>
#include <SDL3/SDL_render.h> // Para SDL_RendererFlip, SDL_FLIP_HORIZONTAL
#include <SDL3/SDL_stdinc.h> // Para Uint8
#include <memory> // Para shared_ptr #include <memory> // Para shared_ptr
#include "s_sprite.h" // Para SSprite #include "sprite/surface_sprite.h" // Para SSprite
class Surface; // lines 8-8 class Surface; // lines 8-8
// Clase SMovingSprite. Añade movimiento y flip al sprite // Clase SMovingSprite. Añade movimiento y flip al sprite

View File

@@ -1,4 +1,5 @@
#include "s_sprite.h" #include "sprite/surface_sprite.h"
#include "surface.h" // Para Surface #include "surface.h" // Para Surface
// Constructor // Constructor
@@ -18,33 +19,28 @@ SSprite::SSprite(std::shared_ptr<Surface> surface)
clip_(pos_) {} clip_(pos_) {}
// Muestra el sprite por pantalla // Muestra el sprite por pantalla
void SSprite::render() void SSprite::render() {
{
surface_->render(pos_.x, pos_.y, &clip_); surface_->render(pos_.x, pos_.y, &clip_);
} }
void SSprite::render(Uint8 source_color, Uint8 target_color) void SSprite::render(Uint8 source_color, Uint8 target_color) {
{
surface_->renderWithColorReplace(pos_.x, pos_.y, source_color, target_color, &clip_); surface_->renderWithColorReplace(pos_.x, pos_.y, source_color, target_color, &clip_);
} }
// Establece la posición del objeto // Establece la posición del objeto
void SSprite::setPosition(int x, int y) void SSprite::setPosition(int x, int y) {
{
pos_.x = x; pos_.x = x;
pos_.y = y; pos_.y = y;
} }
// Establece la posición del objeto // Establece la posición del objeto
void SSprite::setPosition(SDL_Point p) void SSprite::setPosition(SDL_Point p) {
{
pos_.x = p.x; pos_.x = p.x;
pos_.y = p.y; pos_.y = p.y;
} }
// Reinicia las variables a cero // Reinicia las variables a cero
void SSprite::clear() void SSprite::clear() {
{
pos_ = {0, 0, 0, 0}; pos_ = {0, 0, 0, 0};
clip_ = {0, 0, 0, 0}; clip_ = {0, 0, 0, 0};
} }

View File

@@ -1,7 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_rect.h> // Para SDL_Rect, SDL_Point #include <SDL3/SDL.h>
#include <SDL3/SDL_stdinc.h> // Para Uint8
#include <memory> // Para shared_ptr #include <memory> // Para shared_ptr
class Surface; // lines 5-5 class Surface; // lines 5-5

View File

@@ -1,8 +1,6 @@
// IWYU pragma: no_include <bits/std_abs.h> // IWYU pragma: no_include <bits/std_abs.h>
#include "surface.h" #include "surface.h"
#include <SDL3/SDL.h>
#include <SDL3/SDL_error.h> // Para SDL_GetError
#include <SDL3/SDL_timer.h> // Para SDL_GetTicks
#include <algorithm> // Para min, max, copy_n, fill #include <algorithm> // Para min, max, copy_n, fill
#include <cmath> // Para abs #include <cmath> // Para abs

View File

@@ -1,8 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_rect.h> // Para SDL_Rect #include <SDL3/SDL.h>
#include <SDL3/SDL_render.h> // Para SDL_FLIP_NONE, SDL_RendererFlip, SDL_Re...
#include <SDL3/SDL_stdinc.h> // Para Uint8, Uint16, Uint32
#include <array> // Para array #include <array> // Para array
#include <memory> // Para default_delete, shared_ptr, __shared_pt... #include <memory> // Para default_delete, shared_ptr, __shared_pt...

View File

@@ -1,14 +1,14 @@
#include "text.h" #include "text.h"
#include <SDL3/SDL_rect.h> // Para SDL_Rect #include <SDL3/SDL.h>
#include <stddef.h> // Para size_t #include <stddef.h> // Para size_t
#include <fstream> // Para basic_ifstream, basic_istream, basic_ostream #include <fstream> // Para basic_ifstream, basic_istream, basic_ostream
#include <iostream> // Para cerr #include <iostream> // Para cerr
#include <stdexcept> // Para runtime_error #include <stdexcept> // Para runtime_error
#include "s_sprite.h" // Para SSprite
#include "screen.h" // Para Screen #include "screen.h" // Para Screen
#include "sprite/surface_sprite.h" // Para SSprite
#include "surface.h" // Para Surface #include "surface.h" // Para Surface
#include "utils.h" // Para getFileName, stringToColor, printWithDots #include "utils.h" // Para getFileName, stringToColor, printWithDots

View File

@@ -1,11 +1,11 @@
#pragma once #pragma once
#include <SDL3/SDL_stdinc.h> // Para Uint8 #include <SDL3/SDL.h>
#include <memory> // Para shared_ptr, unique_ptr #include <memory> // Para shared_ptr, unique_ptr
#include <string> // Para string #include <string> // Para string
#include "s_sprite.h" // Para SSprite #include "sprite/surface_sprite.h" // Para SSprite
class Surface; // lines 8-8 class Surface; // lines 8-8
constexpr int TEXT_COLOR = 1; constexpr int TEXT_COLOR = 1;

View File

@@ -1,8 +1,7 @@
#include "texture.h" #include "texture.h"
#include <SDL3/SDL.h>
#include <SDL3/SDL_error.h> // Para SDL_GetError
#include <SDL3/SDL_surface.h> // Para SDL_CreateRGBSurfaceWithFormatFrom
#include <iostream> // Para basic_ostream, operator<<, endl, cout #include <iostream> // Para basic_ostream, operator<<, endl, cout
#include <stdexcept> // Para runtime_error #include <stdexcept> // Para runtime_error
@@ -12,7 +11,7 @@
#include "utils.h" // Para getFileName, Color, printWithDots #include "utils.h" // Para getFileName, Color, printWithDots
#define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h" // para stbi_failure_reason, stbi_image_free #include "external/stb_image.h" // para stbi_failure_reason, stbi_image_free
// Constructor // Constructor
Texture::Texture(SDL_Renderer* renderer, const std::string& path) Texture::Texture(SDL_Renderer* renderer, const std::string& path)
@@ -53,7 +52,7 @@ bool Texture::loadFromFile(const std::string& file_path) {
} }
int depth, pitch; int depth, pitch;
Uint32 pixel_format; SDL_PixelFormat pixel_format;
// STBI_rgb_alpha (RGBA) // STBI_rgb_alpha (RGBA)
depth = 32; depth = 32;
pitch = 4 * width; pitch = 4 * width;
@@ -66,22 +65,22 @@ bool Texture::loadFromFile(const std::string& file_path) {
SDL_Texture* newTexture = nullptr; SDL_Texture* newTexture = nullptr;
// Carga la imagen desde una ruta específica // Carga la imagen desde una ruta específica
auto loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom(static_cast<void*>(data), width, height, depth, pitch, pixel_format); auto *loaded_surface = SDL_CreateSurfaceFrom(width, height, pixel_format, static_cast<void *>(data), pitch);
if (loadedSurface == nullptr) { if (loaded_surface == nullptr) {
std::cout << "Unable to load image " << file_path << std::endl; std::cout << "Unable to load image " << file_path << std::endl;
} else { } else {
// Crea la textura desde los pixels de la surface // Crea la textura desde los pixels de la surface
newTexture = SDL_CreateTextureFromSurface(renderer_, loadedSurface); newTexture = SDL_CreateTextureFromSurface(renderer_, loaded_surface);
if (newTexture == nullptr) { if (newTexture == nullptr) {
std::cout << "Unable to create texture from " << file_path << "! SDL Error: " << SDL_GetError() << std::endl; std::cout << "Unable to create texture from " << file_path << "! SDL Error: " << SDL_GetError() << std::endl;
} else { } else {
// Obtiene las dimensiones de la imagen // Obtiene las dimensiones de la imagen
width_ = loadedSurface->w; width_ = loaded_surface->w;
height_ = loadedSurface->h; height_ = loaded_surface->h;
} }
// Elimina la textura cargada // Elimina la textura cargada
SDL_FreeSurface(loadedSurface); SDL_DestroySurface(loaded_surface);
} }
// Return success // Return success
@@ -91,11 +90,11 @@ bool Texture::loadFromFile(const std::string& file_path) {
} }
// Crea una textura en blanco // Crea una textura en blanco
bool Texture::createBlank(int width, int height, SDL_PixelFormatEnum format, SDL_TextureAccess access) { auto Texture::createBlank(int width, int height, SDL_PixelFormat format, SDL_TextureAccess access) -> bool {
// Crea una textura sin inicializar // Crea una textura sin inicializar
texture_ = SDL_CreateTexture(renderer_, format, access, width, height); texture_ = SDL_CreateTexture(renderer_, format, access, width, height);
if (!texture_) { if (texture_ == nullptr) {
std::cout << "Unable to create blank texture! SDL Error: " << SDL_GetError() << std::endl; SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create blank texture! SDL Error: %s", SDL_GetError());
} else { } else {
width_ = width; width_ = width;
height_ = height; height_ = height;
@@ -126,28 +125,28 @@ void Texture::setBlendMode(SDL_BlendMode blending) { SDL_SetTextureBlendMode(tex
void Texture::setAlpha(Uint8 alpha) { SDL_SetTextureAlphaMod(texture_, alpha); } void Texture::setAlpha(Uint8 alpha) { SDL_SetTextureAlphaMod(texture_, alpha); }
// Renderiza la textura en un punto específico // Renderiza la textura en un punto específico
void Texture::render(int x, int y, SDL_Rect* clip, float zoomW, float zoomH, double angle, SDL_Point* center, SDL_RendererFlip flip) { void Texture::render(int x, int y, SDL_FRect* clip, float zoomW, float zoomH, double angle, SDL_FPoint* center, SDL_FlipMode flip) {
// Establece el destino de renderizado en la pantalla // Establece el destino de renderizado en la pantalla
SDL_Rect renderQuad = {x, y, width_, height_}; SDL_FRect render_quad = {x, y, width_, height_};
// Obtiene las dimesiones del clip de renderizado // Obtiene las dimesiones del clip de renderizado
if (clip != nullptr) { if (clip != nullptr) {
renderQuad.w = clip->w; render_quad.w = clip->w;
renderQuad.h = clip->h; render_quad.h = clip->h;
} }
// Calcula el zoom y las coordenadas // Calcula el zoom y las coordenadas
if (zoomH != 1.0f || zoomW != 1.0f) { if (zoomH != 1.0f || zoomW != 1.0f) {
renderQuad.x = renderQuad.x + (renderQuad.w / 2); render_quad.x = render_quad.x + (render_quad.w / 2);
renderQuad.y = renderQuad.y + (renderQuad.h / 2); render_quad.y = render_quad.y + (render_quad.h / 2);
renderQuad.w = renderQuad.w * zoomW; render_quad.w = render_quad.w * zoomW;
renderQuad.h = renderQuad.h * zoomH; render_quad.h = render_quad.h * zoomH;
renderQuad.x = renderQuad.x - (renderQuad.w / 2); render_quad.x = render_quad.x - (render_quad.w / 2);
renderQuad.y = renderQuad.y - (renderQuad.h / 2); render_quad.y = render_quad.y - (render_quad.h / 2);
} }
// Renderiza a pantalla // Renderiza a pantalla
SDL_RenderCopyEx(renderer_, texture_, clip, &renderQuad, angle, center, flip); SDL_RenderTextureRotated(renderer_, texture_, clip, &render_quad, angle, center, flip);
} }
// Establece la textura como objetivo de renderizado // Establece la textura como objetivo de renderizado

View File

@@ -1,10 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_blendmode.h> // Para SDL_BlendMode #include <SDL3/SDL.h>
#include <SDL3/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888, SDL_PixelF...
#include <SDL3/SDL_rect.h> // Para SDL_Point, SDL_Rect
#include <SDL3/SDL_render.h> // Para SDL_Renderer, SDL_FLIP_NONE, SDL_TEX...
#include <SDL3/SDL_stdinc.h> // Para Uint8, Uint32
#include <string> // Para string #include <string> // Para string
#include <vector> // Para vector #include <vector> // Para vector
@@ -36,7 +32,7 @@ class Texture {
bool loadFromFile(const std::string& path); bool loadFromFile(const std::string& path);
// Crea una textura en blanco // Crea una textura en blanco
bool createBlank(int width, int height, SDL_PixelFormatEnum format = SDL_PIXELFORMAT_RGBA8888, SDL_TextureAccess = SDL_TEXTUREACCESS_TARGET); auto createBlank(int width, int height, SDL_PixelFormat format = SDL_PIXELFORMAT_RGBA8888, SDL_TextureAccess access = SDL_TEXTUREACCESS_STREAMING) -> bool;
// Establece el color para la modulacion // Establece el color para la modulacion
void setColor(Uint8 red, Uint8 green, Uint8 blue); void setColor(Uint8 red, Uint8 green, Uint8 blue);
@@ -49,7 +45,7 @@ class Texture {
void setAlpha(Uint8 alpha); void setAlpha(Uint8 alpha);
// Renderiza la textura en un punto específico // Renderiza la textura en un punto específico
void render(int x, int y, SDL_Rect* clip = nullptr, float zoomW = 1, float zoomH = 1, double angle = 0.0, SDL_Point* center = nullptr, SDL_RendererFlip flip = SDL_FLIP_NONE); void render(int x, int y, SDL_FRect* clip = nullptr, float zoomW = 1, float zoomH = 1, double angle = 0.0, SDL_FPoint* center = nullptr, SDL_FlipMode flip = SDL_FLIP_NONE);
// Establece la textura como objetivo de renderizado // Establece la textura como objetivo de renderizado
void setAsRenderTarget(SDL_Renderer* renderer); void setAsRenderTarget(SDL_Renderer* renderer);

View File

@@ -1,17 +1,17 @@
#include "notifier.h" #include "ui/notifier.h"
#include <SDL3/SDL_timer.h> // Para SDL_GetTicks #include <SDL3/SDL.h>
#include <algorithm> // Para remove_if #include <algorithm> // Para remove_if
#include <iterator> // Para prev #include <iterator> // Para prev
#include <string> // Para string, basic_string #include <string> // Para string, basic_string
#include <vector> // Para vector #include <vector> // Para vector
#include "jail_audio.h" // Para JA_PlaySound #include "external/jail_audio.h" // Para JA_PlaySound
#include "options.h" // Para Options, options, NotificationPosition #include "options.h" // Para Options, options, NotificationPosition
#include "resource.h" // Para Resource #include "resource.h" // Para Resource
#include "s_sprite.h" // Para SSprite
#include "screen.h" // Para Screen #include "screen.h" // Para Screen
#include "sprite/surface_sprite.h" // Para SSprite
#include "surface.h" // Para Surface #include "surface.h" // Para Surface
#include "text.h" // Para Text, TEXT_CENTER, TEXT_COLOR #include "text.h" // Para Text, TEXT_CENTER, TEXT_COLOR
#include "utils.h" // Para PaletteColor #include "utils.h" // Para PaletteColor

View File

@@ -1,7 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_rect.h> // Para SDL_Rect #include <SDL3/SDL.h>
#include <SDL3/SDL_stdinc.h> // Para Uint32, Uint8
#include <memory> // Para shared_ptr #include <memory> // Para shared_ptr
#include <string> // Para string, basic_string #include <string> // Para string, basic_string

View File

@@ -12,7 +12,7 @@
#include <unordered_map> // Para unordered_map, operator==, _Node_const_iter... #include <unordered_map> // Para unordered_map, operator==, _Node_const_iter...
#include <utility> // Para pair #include <utility> // Para pair
#include "jail_audio.h" // Para JA_GetMusicState, JA_Music_state, JA_PlayMusic #include "external/jail_audio.h" // Para JA_GetMusicState, JA_Music_state, JA_PlayMusic
#include "resource.h" // Para Resource #include "resource.h" // Para Resource
// Calcula el cuadrado de la distancia entre dos puntos // Calcula el cuadrado de la distancia entre dos puntos

View File

@@ -1,8 +1,6 @@
#pragma once #pragma once
#include <SDL3/SDL_rect.h> // Para SDL_Rect, SDL_Point #include <SDL3/SDL.h>
#include <SDL3/SDL_render.h> // Para SDL_Renderer, SDL_Texture
#include <SDL3/SDL_stdinc.h> // Para Uint8
#include <string> // Para string #include <string> // Para string
#include <vector> // Para vector #include <vector> // Para vector