forked from jaildesigner-jailgames/jaildoctors_dilemma
corregits mes includes
llevats els errors en texture
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -1,44 +1,34 @@
|
|||||||
#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 <errno.h> // Para errno, EEXIST, EACCES, ENAMETOO...
|
||||||
#include <SDL3/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
|
#include <stdio.h> // Para printf, perror
|
||||||
#include <SDL3/SDL_error.h> // Para SDL_GetError
|
#include <sys/stat.h> // Para mkdir, stat, S_IRWXU
|
||||||
#include <SDL3/SDL_events.h> // Para SDL_DISABLE
|
#include <unistd.h> // Para getuid
|
||||||
#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 <stdio.h> // Para printf, perror
|
|
||||||
#include <sys/stat.h> // Para mkdir, stat, S_IRWXU
|
|
||||||
#include <unistd.h> // Para getuid
|
|
||||||
|
|
||||||
#include <cstdlib> // Para exit, EXIT_FAILURE, srand
|
#include <cstdlib> // Para exit, EXIT_FAILURE, srand
|
||||||
#include <iostream> // Para basic_ostream, operator<<, cout
|
#include <iostream> // Para basic_ostream, operator<<, cout
|
||||||
#include <memory> // Para make_unique, unique_ptr
|
#include <memory> // Para make_unique, unique_ptr
|
||||||
#include <string> // Para operator+, allocator, char_traits
|
#include <string> // Para operator+, allocator, char_traits
|
||||||
|
|
||||||
#include "asset.h" // Para Asset, AssetType
|
#include "asset.h" // Para Asset, AssetType
|
||||||
#include "cheevos.h" // Para Cheevos
|
#include "cheevos.h" // Para Cheevos
|
||||||
#include "credits.h" // Para Credits
|
#include "credits.h" // Para Credits
|
||||||
#include "debug.h" // Para Debug
|
#include "debug.h" // Para Debug
|
||||||
#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 "game.h" // Para Game, GameMode
|
#include "external/jail_audio.h" // Para JA_SetMusicVolume, JA_SetSoundV...
|
||||||
#include "game_over.h" // Para GameOver
|
#include "game.h" // Para Game, GameMode
|
||||||
#include "input.h" // Para Input, InputAction
|
#include "game_over.h" // Para GameOver
|
||||||
#include "jail_audio.h" // Para JA_SetMusicVolume, JA_SetSoundV...
|
#include "input.h" // Para Input, InputAction
|
||||||
#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>
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#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
|
||||||
Enemy::Enemy(const EnemyData& enemy)
|
Enemy::Enemy(const EnemyData& enemy)
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
5
source/external/jail_audio.cpp
vendored
5
source/external/jail_audio.cpp
vendored
@@ -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
|
||||||
|
|||||||
3
source/external/jail_audio.h
vendored
3
source/external/jail_audio.h
vendored
@@ -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
|
||||||
|
|
||||||
|
|||||||
5
source/external/jail_shader.cpp
vendored
5
source/external/jail_shader.cpp
vendored
@@ -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
|
||||||
|
|||||||
3
source/external/jail_shader.h
vendored
3
source/external/jail_shader.h
vendored
@@ -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>
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
#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 {
|
||||||
void quit() {
|
void quit() {
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "resource.h" // Para Resource
|
|
||||||
#include "s_sprite.h" // Para SSprite
|
#include "resource.h" // Para Resource
|
||||||
|
#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();
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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 <cmath> // Para ceil, abs
|
#include <algorithm> // Para max, min
|
||||||
#include "debug.h" // Para Debug
|
#include <cmath> // Para ceil, abs
|
||||||
#include "defines.h" // Para RoomBorder::BOTTOM, RoomBorder::LEFT, RoomBorder::RIGHT
|
|
||||||
#include "input.h" // Para Input, InputAction
|
#include "debug.h" // Para Debug
|
||||||
#include "jail_audio.h" // Para JA_PlaySound
|
#include "defines.h" // Para RoomBorder::BOTTOM, RoomBorder::LEFT, RoomBorder::RIGHT
|
||||||
#include "options.h" // Para Cheat, Options, options
|
#include "external/jail_audio.h" // Para JA_PlaySound
|
||||||
#include "resource.h" // Para Resource
|
#include "input.h" // Para Input, InputAction
|
||||||
#include "room.h" // Para Room, TileType
|
#include "options.h" // Para Cheat, Options, options
|
||||||
#include "s_animated_sprite.h" // Para SAnimatedSprite
|
#include "resource.h" // Para Resource
|
||||||
|
#include "room.h" // Para Room, TileType
|
||||||
|
#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,77 +48,61 @@ 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
|
||||||
{
|
move(); // Recalcula la posición del jugador
|
||||||
checkInput(); // Comprueba las entradas y modifica variables
|
animate(); // Establece la animación del jugador
|
||||||
move(); // Recalcula la posición del jugador
|
checkBorders(); // Comprueba si está situado en alguno de los cuatro bordes de la habitación
|
||||||
animate(); // Establece la animación del jugador
|
checkJumpEnd(); // Comprueba si ha finalizado el salto al alcanzar la altura de inicio
|
||||||
checkBorders(); // Comprueba si está situado en alguno de los cuatro bordes de la habitación
|
checkKillingTiles(); // Comprueba que el jugador no toque ningun tile de los que matan}
|
||||||
checkJumpEnd(); // Comprueba si ha finalizado el salto al alcanzar la altura de inicio
|
|
||||||
checkKillingTiles(); // Comprueba que el jugador no toque ningun tile de los que matan}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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,30 +172,28 @@ 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:
|
||||||
{
|
y_ = PLAY_AREA_BOTTOM - HEIGHT_ - BLOCK;
|
||||||
case RoomBorder::TOP:
|
setState(PlayerState::STANDING);
|
||||||
y_ = PLAY_AREA_BOTTOM - HEIGHT_ - BLOCK;
|
break;
|
||||||
setState(PlayerState::STANDING);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RoomBorder::BOTTOM:
|
case RoomBorder::BOTTOM:
|
||||||
y_ = PLAY_AREA_TOP;
|
y_ = PLAY_AREA_TOP;
|
||||||
setState(PlayerState::STANDING);
|
setState(PlayerState::STANDING);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RoomBorder::RIGHT:
|
case RoomBorder::RIGHT:
|
||||||
x_ = PLAY_AREA_LEFT;
|
x_ = PLAY_AREA_LEFT;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RoomBorder::LEFT:
|
case RoomBorder::LEFT:
|
||||||
x_ = PLAY_AREA_RIGHT - WIDTH_;
|
x_ = PLAY_AREA_RIGHT - WIDTH_;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
is_on_border_ = false;
|
is_on_border_ = false;
|
||||||
@@ -232,42 +202,37 @@ 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
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
debug_color_ = static_cast<Uint8>(PaletteColor::GREEN);
|
debug_color_ = static_cast<Uint8>(PaletteColor::GREEN);
|
||||||
#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_);
|
||||||
proj.y = static_cast<int>(y_);
|
proj.y = static_cast<int>(y_);
|
||||||
proj.h = HEIGHT_;
|
proj.h = HEIGHT_;
|
||||||
proj.w = static_cast<int>(std::ceil(std::fabs(vx_))); // Para evitar que tenga un ancho de 0 pixels
|
proj.w = static_cast<int>(std::ceil(std::fabs(vx_))); // Para evitar que tenga un ancho de 0 pixels
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
debug_rect_x_ = proj;
|
debug_rect_x_ = proj;
|
||||||
@@ -277,44 +242,37 @@ 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_;
|
||||||
proj.y = static_cast<int>(y_);
|
proj.y = static_cast<int>(y_);
|
||||||
proj.h = HEIGHT_;
|
proj.h = HEIGHT_;
|
||||||
proj.w = ceil(vx_); // Para evitar que tenga un ancho de 0 pixels
|
proj.w = ceil(vx_); // Para evitar que tenga un ancho de 0 pixels
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
debug_rect_x_ = proj;
|
debug_rect_x_ = proj;
|
||||||
@@ -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,20 +314,18 @@ 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_);
|
||||||
proj.y = static_cast<int>(y_ + vy_);
|
proj.y = static_cast<int>(y_ + vy_);
|
||||||
proj.h = static_cast<int>(std::ceil(std::fabs(vy_))); // Para evitar que tenga una altura de 0 pixels
|
proj.h = static_cast<int>(std::ceil(std::fabs(vy_))); // Para evitar que tenga una altura de 0 pixels
|
||||||
proj.w = WIDTH_;
|
proj.w = WIDTH_;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@@ -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,13 +347,12 @@ 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_);
|
||||||
proj.y = static_cast<int>(y_) + HEIGHT_;
|
proj.y = static_cast<int>(y_) + HEIGHT_;
|
||||||
proj.h = ceil(vy_); // Para evitar que tenga una altura de 0 pixels
|
proj.h = ceil(vy_); // Para evitar que tenga una altura de 0 pixels
|
||||||
proj.w = WIDTH_;
|
proj.w = WIDTH_;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@@ -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_;
|
||||||
@@ -463,8 +399,8 @@ void Player::move()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
placeSprite(); // Coloca el sprite en la nueva posición
|
placeSprite(); // Coloca el sprite en la nueva posición
|
||||||
collider_box_ = getRect(); // Actualiza el rectangulo de colisión
|
collider_box_ = getRect(); // Actualiza el rectangulo de colisión
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
Debug::get()->add("RECT_X: " + std::to_string(debug_rect_x_.x) + "," + std::to_string(debug_rect_x_.y) + "," + std::to_string(debug_rect_x_.w) + "," + std::to_string(debug_rect_x_.h));
|
Debug::get()->add("RECT_X: " + std::to_string(debug_rect_x_.x) + "," + std::to_string(debug_rect_x_.y) + "," + std::to_string(debug_rect_x_.w) + "," + std::to_string(debug_rect_x_.h));
|
||||||
@@ -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,44 +531,34 @@ 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
|
||||||
{
|
return true; // Retorna en cuanto se detecta una colisión
|
||||||
is_alive_ = false; // Mata al jugador inmediatamente
|
|
||||||
return true; // Retorna en cuanto se detecta una colisión
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false; // No se encontró ninguna colisión
|
return false; // No se encontró ninguna colisión
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -757,4 +652,4 @@ void Player::renderDebugInfo()
|
|||||||
surface->putPixel(debug_point_.x, debug_point_.y, rand() % 16);
|
surface->putPixel(debug_point_.x, debug_point_.y, rand() % 16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
@@ -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,9 +8,9 @@
|
|||||||
|
|
||||||
#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
|
||||||
|
|
||||||
enum class PlayerState {
|
enum class PlayerState {
|
||||||
STANDING,
|
STANDING,
|
||||||
|
|||||||
@@ -1,24 +1,21 @@
|
|||||||
#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 <stdlib.h> // Para exit, size_t
|
||||||
#include <SDL3/SDL_rect.h> // Para SDL_Rect
|
|
||||||
#include <SDL3/SDL_stdinc.h> // Para Uint8
|
|
||||||
#include <stdlib.h> // Para exit, size_t
|
|
||||||
|
|
||||||
#include <algorithm> // Para find_if
|
#include <algorithm> // Para find_if
|
||||||
#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
|
||||||
|
|
||||||
#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
|
||||||
#include "text.h" // Para Text, loadTextFile
|
#include "text.h" // Para Text, loadTextFile
|
||||||
#include "utils.h" // Para getFileName, printWithDots, PaletteColor
|
#include "utils.h" // Para getFileName, printWithDots, PaletteColor
|
||||||
struct JA_Music_t; // lines 17-17
|
struct JA_Music_t; // lines 17-17
|
||||||
struct JA_Sound_t; // lines 18-18
|
struct JA_Sound_t; // lines 18-18
|
||||||
|
|
||||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||||
Resource* Resource::resource_ = nullptr;
|
Resource* Resource::resource_ = nullptr;
|
||||||
|
|||||||
@@ -1,258 +1,257 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#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
|
||||||
struct JA_Music_t; // lines 11-11
|
#include "text.h" // Para Text, TextFile
|
||||||
struct JA_Sound_t; // lines 12-12
|
struct JA_Music_t; // lines 11-11
|
||||||
|
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
|
||||||
std::vector<ResourceSurface> surfaces_; // Vector con las surfaces
|
std::vector<ResourceSurface> surfaces_; // Vector con las surfaces
|
||||||
std::vector<ResourcePalette> palettes_; // Vector con las paletas
|
std::vector<ResourcePalette> palettes_; // Vector con las paletas
|
||||||
std::vector<ResourceTextFile> text_files_; // Vector con los ficheros de texto
|
std::vector<ResourceTextFile> text_files_; // Vector con los ficheros de texto
|
||||||
std::vector<ResourceText> texts_; // Vector con los objetos de texto
|
std::vector<ResourceText> texts_; // Vector con los objetos de texto
|
||||||
std::vector<ResourceAnimation> animations_; // Vector con las animaciones
|
std::vector<ResourceAnimation> animations_; // Vector con las animaciones
|
||||||
std::vector<ResourceTileMap> tile_maps_; // Vector con los mapas de tiles
|
std::vector<ResourceTileMap> tile_maps_; // Vector con los mapas de tiles
|
||||||
std::vector<ResourceRoom> rooms_; // Vector con las habitaciones
|
std::vector<ResourceRoom> rooms_; // Vector con las habitaciones
|
||||||
|
|
||||||
ResourceCount count_; // Contador de recursos
|
ResourceCount count_; // Contador de recursos
|
||||||
|
|
||||||
// Carga los sonidos
|
// Carga los sonidos
|
||||||
void loadSounds();
|
void loadSounds();
|
||||||
|
|
||||||
// Carga las musicas
|
// Carga las musicas
|
||||||
void loadMusics();
|
void loadMusics();
|
||||||
|
|
||||||
// Carga las surfaces
|
// Carga las surfaces
|
||||||
void loadSurfaces();
|
void loadSurfaces();
|
||||||
|
|
||||||
// Carga las paletas
|
// Carga las paletas
|
||||||
void loadPalettes();
|
void loadPalettes();
|
||||||
|
|
||||||
// Carga los ficheros de texto
|
// Carga los ficheros de texto
|
||||||
void loadTextFiles();
|
void loadTextFiles();
|
||||||
|
|
||||||
// Carga las animaciones
|
// Carga las animaciones
|
||||||
void loadAnimations();
|
void loadAnimations();
|
||||||
|
|
||||||
// Carga los mapas de tiles
|
// Carga los mapas de tiles
|
||||||
void loadTileMaps();
|
void loadTileMaps();
|
||||||
|
|
||||||
// Carga las habitaciones
|
// Carga las habitaciones
|
||||||
void loadRooms();
|
void loadRooms();
|
||||||
|
|
||||||
// Crea los objetos de texto
|
// Crea los objetos de texto
|
||||||
void createText();
|
void createText();
|
||||||
|
|
||||||
// Vacia todos los vectores de recursos
|
// Vacia todos los vectores de recursos
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
// Carga todos los recursos
|
// Carga todos los recursos
|
||||||
void load();
|
void load();
|
||||||
|
|
||||||
// Vacía el vector de sonidos
|
// Vacía el vector de sonidos
|
||||||
void clearSounds();
|
void clearSounds();
|
||||||
|
|
||||||
// Vacía el vector de musicas
|
// Vacía el vector de musicas
|
||||||
void clearMusics();
|
void clearMusics();
|
||||||
|
|
||||||
// Calcula el numero de recursos para cargar
|
// Calcula el numero de recursos para cargar
|
||||||
void calculateTotal();
|
void calculateTotal();
|
||||||
|
|
||||||
// Muestra el progreso de carga
|
// Muestra el progreso de carga
|
||||||
void renderProgress();
|
void renderProgress();
|
||||||
|
|
||||||
// Comprueba los eventos
|
// Comprueba los eventos
|
||||||
void checkEvents();
|
void checkEvents();
|
||||||
|
|
||||||
// Actualiza el progreso de carga
|
// Actualiza el progreso de carga
|
||||||
void updateLoadingProgress(int steps = 5);
|
void updateLoadingProgress(int steps = 5);
|
||||||
|
|
||||||
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos resource desde fuera
|
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos resource desde fuera
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Resource();
|
Resource();
|
||||||
|
|
||||||
// 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();
|
||||||
|
|
||||||
// [SINGLETON] Destruiremos el objeto resource con esta función estática
|
// [SINGLETON] Destruiremos el objeto resource con esta función estática
|
||||||
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();
|
||||||
};
|
};
|
||||||
809
source/room.cpp
809
source/room.cpp
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
#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
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)
|
Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
#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 <ctype.h> // Para toupper
|
||||||
#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 <algorithm> // Para max, min, transform
|
#include <algorithm> // Para max, min, transform
|
||||||
#include <fstream> // Para basic_ostream, operator<<, endl, basic_...
|
#include <fstream> // Para basic_ostream, operator<<, endl, basic_...
|
||||||
@@ -13,14 +9,14 @@
|
|||||||
#include <iterator> // Para istreambuf_iterator, operator==
|
#include <iterator> // Para istreambuf_iterator, operator==
|
||||||
#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() {
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
#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 <stddef.h> // Para size_t
|
||||||
#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 <memory> // Para shared_ptr, __shared_ptr_access
|
#include <memory> // Para shared_ptr, __shared_ptr_access
|
||||||
#include <string> // Para string
|
#include <string> // Para string
|
||||||
|
|||||||
@@ -1,21 +1,19 @@
|
|||||||
#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
|
||||||
|
|
||||||
#include "defines.h" // Para GAME_SPEED, PLAY_AREA_CENTER_X, PLAY_...
|
#include "defines.h" // Para GAME_SPEED, PLAY_AREA_CENTER_X, PLAY_...
|
||||||
#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, 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
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Credits::Credits()
|
Credits::Credits()
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -1,22 +1,20 @@
|
|||||||
#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 "global_events.h" // Para check
|
#include "external/jail_audio.h" // Para JA_SetVolume, JA_PlayMusic, JA_StopMusic
|
||||||
#include "global_inputs.h" // Para check
|
#include "global_events.h" // Para check
|
||||||
#include "jail_audio.h" // Para JA_SetVolume, JA_PlayMusic, JA_StopMusic
|
#include "global_inputs.h" // Para check
|
||||||
#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
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Ending::Ending()
|
Ending::Ending()
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -1,23 +1,21 @@
|
|||||||
#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 "global_events.h" // Para check
|
#include "external/jail_audio.h" // Para JA_SetVolume, JA_PlayMusic, JA_StopMusic
|
||||||
#include "global_inputs.h" // Para check
|
#include "global_events.h" // Para check
|
||||||
#include "jail_audio.h" // Para JA_SetVolume, JA_PlayMusic, JA_StopMusic
|
#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 "s_moving_sprite.h" // Para SMovingSprite
|
#include "sprite/surface_animated_sprite.h" // Para SAnimatedSprite
|
||||||
#include "screen.h" // Para Screen
|
#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
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Ending2::Ending2()
|
Ending2::Ending2()
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -1,31 +1,29 @@
|
|||||||
#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
|
||||||
|
|
||||||
#include "asset.h" // Para Asset
|
#include "asset.h" // Para Asset
|
||||||
#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 "global_events.h" // Para check
|
#include "external/jail_audio.h" // Para JA_PauseMusic, JA_GetMusicState, JA_P...
|
||||||
#include "global_inputs.h" // Para check
|
#include "global_events.h" // Para check
|
||||||
#include "input.h" // Para Input, InputAction, INPUT_DO_NOT_ALLOW_REPEAT
|
#include "global_inputs.h" // Para check
|
||||||
#include "item_tracker.h" // Para ItemTracker
|
#include "input.h" // Para Input, InputAction, INPUT_DO_NOT_ALLOW_REPEAT
|
||||||
#include "jail_audio.h" // Para JA_PauseMusic, JA_GetMusicState, JA_P...
|
#include "item_tracker.h" // Para ItemTracker
|
||||||
#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
|
#include "room_tracker.h" // Para RoomTracker
|
||||||
#include "room_tracker.h" // Para RoomTracker
|
#include "scoreboard.h" // Para ScoreboardData, Scoreboard
|
||||||
#include "scoreboard.h" // Para ScoreboardData, Scoreboard
|
#include "screen.h" // Para Screen
|
||||||
#include "screen.h" // Para Screen
|
#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
|
||||||
Game::Game(GameMode mode)
|
Game::Game(GameMode mode)
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -1,21 +1,20 @@
|
|||||||
#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 "global_events.h" // Para check
|
#include "external/jail_audio.h" // Para JA_PlayMusic
|
||||||
#include "global_inputs.h" // Para check
|
#include "global_events.h" // Para check
|
||||||
#include "jail_audio.h" // Para JA_PlayMusic
|
#include "global_inputs.h" // Para check
|
||||||
#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
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
GameOver::GameOver()
|
GameOver::GameOver()
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -1,19 +1,18 @@
|
|||||||
#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 "global_events.h" // Para check
|
#include "external/jail_audio.h" // Para JA_PlayMusic, JA_SetVolume, JA_StopMusic
|
||||||
#include "global_inputs.h" // Para check
|
#include "global_events.h" // Para check
|
||||||
#include "jail_audio.h" // Para JA_PlayMusic, JA_SetVolume, JA_StopMusic
|
#include "global_inputs.h" // Para check
|
||||||
#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
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
LoadingScreen::LoadingScreen()
|
LoadingScreen::LoadingScreen()
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
#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
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Logo::Logo()
|
Logo::Logo()
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -1,23 +1,21 @@
|
|||||||
#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
|
||||||
|
|
||||||
#include "cheevos.h" // Para Cheevos, Achievement
|
#include "cheevos.h" // Para Cheevos, Achievement
|
||||||
#include "defines.h" // Para PLAY_AREA_CENTER_X, GAMECANVAS_WIDTH
|
#include "defines.h" // Para PLAY_AREA_CENTER_X, GAMECANVAS_WIDTH
|
||||||
#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, 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
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Title::Title()
|
Title::Title()
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -1,269 +1,236 @@
|
|||||||
#include "s_animated_sprite.h"
|
#include "sprite/surface_animated_sprite.h"
|
||||||
#include <stddef.h> // Para size_t
|
|
||||||
#include <fstream> // Para basic_ostream, basic_istream, operator<<, basic...
|
#include <stddef.h> // Para size_t
|
||||||
#include <iostream> // Para cout, cerr
|
|
||||||
#include <sstream> // Para basic_stringstream
|
#include <fstream> // Para basic_ostream, basic_istream, operator<<, basic...
|
||||||
#include <stdexcept> // Para runtime_error
|
#include <iostream> // Para cout, cerr
|
||||||
#include "surface.h" // Para Surface
|
#include <sstream> // Para basic_stringstream
|
||||||
#include "utils.h" // Para printWithDots
|
#include <stdexcept> // Para runtime_error
|
||||||
|
|
||||||
|
#include "surface.h" // Para Surface
|
||||||
|
#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;
|
||||||
{
|
throw std::runtime_error("Fichero no encontrado: " + file_path);
|
||||||
std::cerr << "Error: Fichero no encontrado " << file_path << std::endl;
|
}
|
||||||
throw std::runtime_error("Fichero no encontrado: " + file_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
printWithDots("Animation : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]");
|
printWithDots("Animation : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]");
|
||||||
|
|
||||||
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);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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);
|
||||||
{
|
setAnimations(v);
|
||||||
Animations v = loadAnimationsFromFile(file_path);
|
}
|
||||||
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;
|
}
|
||||||
}
|
std::cout << "** Warning: could not find \"" << name.c_str() << "\" animation" << std::endl;
|
||||||
}
|
return -1;
|
||||||
std::cout << "** Warning: could not find \"" << name.c_str() << "\" animation" << std::endl;
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calcula el frame actual a partir del contador
|
// Calcula el frame actual a partir del contador
|
||||||
animations_[current_animation_].current_frame = animations_[current_animation_].counter / animations_[current_animation_].speed;
|
animations_[current_animation_].current_frame = animations_[current_animation_].counter / animations_[current_animation_].speed;
|
||||||
|
|
||||||
// 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)
|
animations_[current_animation_].current_frame = animations_[current_animation_].frames.size();
|
||||||
{ // Si no hay loop, deja el último frame
|
animations_[current_animation_].completed = true;
|
||||||
animations_[current_animation_].current_frame = animations_[current_animation_].frames.size();
|
} else { // Si hay loop, vuelve al frame indicado
|
||||||
animations_[current_animation_].completed = true;
|
animations_[current_animation_].counter = 0;
|
||||||
}
|
animations_[current_animation_].current_frame = animations_[current_animation_].loop;
|
||||||
else
|
}
|
||||||
{ // Si hay loop, vuelve al frame indicado
|
}
|
||||||
animations_[current_animation_].counter = 0;
|
// En caso contrario
|
||||||
animations_[current_animation_].current_frame = animations_[current_animation_].loop;
|
else {
|
||||||
}
|
// Escoge el frame correspondiente de la animación
|
||||||
}
|
setClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]);
|
||||||
// En caso contrario
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Escoge el frame correspondiente de la animación
|
|
||||||
setClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]);
|
|
||||||
|
|
||||||
// Incrementa el contador de la animacion
|
// Incrementa el contador de la animacion
|
||||||
animations_[current_animation_].counter++;
|
animations_[current_animation_].counter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
||||||
{
|
animations_[current_animation_].current_frame = 0;
|
||||||
current_animation_ = new_animation;
|
animations_[current_animation_].counter = 0;
|
||||||
animations_[current_animation_].current_frame = 0;
|
animations_[current_animation_].completed = false;
|
||||||
animations_[current_animation_].counter = 0;
|
setClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]);
|
||||||
animations_[current_animation_].completed = false;
|
}
|
||||||
setClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
||||||
{
|
animations_[current_animation_].current_frame = 0;
|
||||||
current_animation_ = new_animation;
|
animations_[current_animation_].counter = 0;
|
||||||
animations_[current_animation_].current_frame = 0;
|
animations_[current_animation_].completed = false;
|
||||||
animations_[current_animation_].counter = 0;
|
setClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]);
|
||||||
animations_[current_animation_].completed = false;
|
}
|
||||||
setClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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")
|
frame_width = value;
|
||||||
frame_width = value;
|
else if (key == "frame_height")
|
||||||
else if (key == "frame_height")
|
frame_height = value;
|
||||||
frame_height = value;
|
else
|
||||||
else
|
std::cout << "Warning: unknown parameter " << key << std::endl;
|
||||||
std::cout << "Warning: unknown parameter " << key << std::endl;
|
|
||||||
|
|
||||||
frames_per_row = surface_->getWidth() / frame_width;
|
frames_per_row = surface_->getWidth() / frame_width;
|
||||||
const int w = surface_->getWidth() / frame_width;
|
const int w = surface_->getWidth() / frame_width;
|
||||||
const int h = surface_->getHeight() / frame_height;
|
const int h = surface_->getHeight() / frame_height;
|
||||||
max_tiles = w * h;
|
max_tiles = w * h;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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++;
|
||||||
{
|
line = animations.at(index);
|
||||||
index++;
|
size_t pos = line.find("=");
|
||||||
line = animations.at(index);
|
|
||||||
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);
|
|
||||||
|
|
||||||
if (key == "name")
|
if (key == "name")
|
||||||
animation.name = value;
|
animation.name = value;
|
||||||
else if (key == "speed")
|
else if (key == "speed")
|
||||||
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
|
||||||
{
|
const int num_tile = std::stoi(tmp);
|
||||||
// Comprueba que el tile no sea mayor que el maximo indice permitido
|
if (num_tile <= max_tiles) {
|
||||||
const int num_tile = std::stoi(tmp);
|
rect.x = (num_tile % frames_per_row) * frame_width;
|
||||||
if (num_tile <= max_tiles)
|
rect.y = (num_tile / frames_per_row) * frame_height;
|
||||||
{
|
animation.frames.emplace_back(rect);
|
||||||
rect.x = (num_tile % frames_per_row) * frame_width;
|
}
|
||||||
rect.y = (num_tile / frames_per_row) * frame_height;
|
}
|
||||||
animation.frames.emplace_back(rect);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
else
|
||||||
std::cout << "Warning: unknown parameter " << key << std::endl;
|
std::cout << "Warning: unknown parameter " << key << std::endl;
|
||||||
}
|
}
|
||||||
} while (line != "[/animation]");
|
} while (line != "[/animation]");
|
||||||
|
|
||||||
// Añade la animación al vector de animaciones
|
// Añade la animación al vector de animaciones
|
||||||
animations_.emplace_back(animation);
|
animations_.emplace_back(animation);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Una vez procesada la linea, aumenta el indice para pasar a la siguiente
|
// Una vez procesada la linea, aumenta el indice para pasar a la siguiente
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pone un valor por defecto
|
// Pone un valor por defecto
|
||||||
setWidth(frame_width);
|
setWidth(frame_width);
|
||||||
setHeight(frame_height);
|
setHeight(frame_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cambia el valor de la variable
|
// Cambia el valor de la variable
|
||||||
animations_[current_animation_].current_frame = num;
|
animations_[current_animation_].current_frame = num;
|
||||||
animations_[current_animation_].counter = 0;
|
animations_[current_animation_].counter = 0;
|
||||||
|
|
||||||
// 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]);
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
#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 {
|
||||||
std::string name; // Nombre de la animacion
|
std::string name; // Nombre de la animacion
|
||||||
|
|||||||
@@ -1,102 +1,94 @@
|
|||||||
#include "s_moving_sprite.h"
|
#include "sprite/surface_moving_sprite.h"
|
||||||
#include "surface.h" // Para Surface
|
|
||||||
|
#include "surface.h" // Para Surface
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
SMovingSprite::SMovingSprite(std::shared_ptr<Surface> surface, SDL_Rect pos, SDL_RendererFlip flip)
|
SMovingSprite::SMovingSprite(std::shared_ptr<Surface> surface, SDL_Rect pos, SDL_RendererFlip flip)
|
||||||
: SSprite(surface, pos),
|
: SSprite(surface, pos),
|
||||||
x_(pos.x),
|
x_(pos.x),
|
||||||
y_(pos.y),
|
y_(pos.y),
|
||||||
flip_(flip) { SSprite::pos_ = pos; }
|
flip_(flip) { SSprite::pos_ = pos; }
|
||||||
|
|
||||||
SMovingSprite::SMovingSprite(std::shared_ptr<Surface> surface, SDL_Rect pos)
|
SMovingSprite::SMovingSprite(std::shared_ptr<Surface> surface, SDL_Rect pos)
|
||||||
: SSprite(surface, pos),
|
: SSprite(surface, pos),
|
||||||
x_(pos.x),
|
x_(pos.x),
|
||||||
y_(pos.y),
|
y_(pos.y),
|
||||||
flip_(SDL_FLIP_NONE) { SSprite::pos_ = pos; }
|
flip_(SDL_FLIP_NONE) { SSprite::pos_ = pos; }
|
||||||
|
|
||||||
SMovingSprite::SMovingSprite(std::shared_ptr<Surface> surface)
|
SMovingSprite::SMovingSprite(std::shared_ptr<Surface> surface)
|
||||||
: SSprite(surface),
|
: SSprite(surface),
|
||||||
x_(0.0f),
|
x_(0.0f),
|
||||||
y_(0.0f),
|
y_(0.0f),
|
||||||
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
|
|
||||||
|
|
||||||
vx_ = 0.0f; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
|
vx_ = 0.0f; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
|
||||||
vy_ = 0.0f; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
|
vy_ = 0.0f; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
|
||||||
|
|
||||||
ax_ = 0.0f; // Aceleración en el eje X. Variación de la velocidad
|
ax_ = 0.0f; // Aceleración en el eje X. Variación de la velocidad
|
||||||
ay_ = 0.0f; // Aceleración en el eje Y. Variación de la velocidad
|
ay_ = 0.0f; // Aceleración en el eje Y. Variación de la velocidad
|
||||||
|
|
||||||
flip_ = SDL_FLIP_NONE; // Establece como se ha de voltear el sprite
|
flip_ = SDL_FLIP_NONE; // Establece como se ha de voltear el sprite
|
||||||
|
|
||||||
SSprite::clear();
|
SSprite::clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mueve el sprite
|
// Mueve el sprite
|
||||||
void SMovingSprite::move()
|
void SMovingSprite::move() {
|
||||||
{
|
x_ += vx_;
|
||||||
x_ += vx_;
|
y_ += vy_;
|
||||||
y_ += vy_;
|
|
||||||
|
|
||||||
vx_ += ax_;
|
vx_ += ax_;
|
||||||
vy_ += ay_;
|
vy_ += ay_;
|
||||||
|
|
||||||
pos_.x = static_cast<int>(x_);
|
pos_.x = static_cast<int>(x_);
|
||||||
pos_.y = static_cast<int>(y_);
|
pos_.y = static_cast<int>(y_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
pos_ = rect;
|
pos_ = 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;
|
|
||||||
|
|
||||||
pos_.x = static_cast<int>(x_);
|
pos_.x = static_cast<int>(x_);
|
||||||
pos_.y = static_cast<int>(y_);
|
pos_.y = static_cast<int>(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_);
|
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,11 @@
|
|||||||
#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
|
||||||
class SMovingSprite : public SSprite {
|
class SMovingSprite : public SSprite {
|
||||||
|
|||||||
@@ -1,50 +1,46 @@
|
|||||||
#include "s_sprite.h"
|
#include "sprite/surface_sprite.h"
|
||||||
#include "surface.h" // Para Surface
|
|
||||||
|
#include "surface.h" // Para Surface
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
SSprite::SSprite(std::shared_ptr<Surface> surface, int x, int y, int w, int h)
|
SSprite::SSprite(std::shared_ptr<Surface> surface, int x, int y, int w, int h)
|
||||||
: surface_(surface),
|
: surface_(surface),
|
||||||
pos_((SDL_Rect){x, y, w, h}),
|
pos_((SDL_Rect){x, y, w, h}),
|
||||||
clip_((SDL_Rect){0, 0, pos_.w, pos_.h}) {}
|
clip_((SDL_Rect){0, 0, pos_.w, pos_.h}) {}
|
||||||
|
|
||||||
SSprite::SSprite(std::shared_ptr<Surface> surface, SDL_Rect rect)
|
SSprite::SSprite(std::shared_ptr<Surface> surface, SDL_Rect rect)
|
||||||
: surface_(surface),
|
: surface_(surface),
|
||||||
pos_(rect),
|
pos_(rect),
|
||||||
clip_((SDL_Rect){0, 0, pos_.w, pos_.h}) {}
|
clip_((SDL_Rect){0, 0, pos_.w, pos_.h}) {}
|
||||||
|
|
||||||
SSprite::SSprite(std::shared_ptr<Surface> surface)
|
SSprite::SSprite(std::shared_ptr<Surface> surface)
|
||||||
: surface_(surface),
|
: surface_(surface),
|
||||||
pos_({0, 0, surface_->getWidth(), surface_->getHeight()}),
|
pos_({0, 0, surface_->getWidth(), surface_->getHeight()}),
|
||||||
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};
|
|
||||||
}
|
}
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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...
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
#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
|
||||||
|
|
||||||
// Llena una estructuta TextFile desde un fichero
|
// Llena una estructuta TextFile desde un fichero
|
||||||
std::shared_ptr<TextFile> loadTextFile(const std::string& file_path) {
|
std::shared_ptr<TextFile> loadTextFile(const std::string& file_path) {
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#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;
|
||||||
constexpr int TEXT_SHADOW = 2;
|
constexpr int TEXT_SHADOW = 2;
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
#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
|
||||||
|
|
||||||
// [SINGLETON]
|
// [SINGLETON]
|
||||||
Notifier* Notifier::notifier_ = nullptr;
|
Notifier* Notifier::notifier_ = nullptr;
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -12,8 +12,8 @@
|
|||||||
#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
|
||||||
double distanceSquared(int x1, int y1, int x2, int y2) {
|
double distanceSquared(int x1, int y1, int x2, int y2) {
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user