commit de moure a un Linux a gastar eines de home

This commit is contained in:
2025-02-25 19:37:08 +01:00
parent c9da5135b2
commit 32c31a8cb6
28 changed files with 145 additions and 647 deletions

View File

@@ -89,7 +89,7 @@ void Cheevos::unlock(int id)
// Marcar el logro como completado // Marcar el logro como completado
cheevos_list_.at(index).completed = true; cheevos_list_.at(index).completed = true;
// Mostrar notificación en la pantalla // Mostrar notificación en la pantalla
Notifier::get()->show("ACHIEVEMENT UNLOCKED!", cheevos_list_.at(index).caption, cheevos_list_.at(index).icon); Notifier::get()->show({"ACHIEVEMENT UNLOCKED!", cheevos_list_.at(index).caption}, cheevos_list_.at(index).icon);
// Guardar el estado de los logros // Guardar el estado de los logros
saveToFile(); saveToFile();
} }

View File

@@ -7,7 +7,7 @@
#include <algorithm> // Para min #include <algorithm> // Para min
#include <iostream> // Para char_traits, basic_ostream, operator<< #include <iostream> // Para char_traits, basic_ostream, operator<<
#include "animated_sprite.h" // Para AnimatedSprite #include "animated_sprite.h" // Para AnimatedSprite
#include "const.h" // Para GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH #include "defines.h" // Para GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH
#include "input.h" // Para Input, REPEAT_FALSE, inputs_e #include "input.h" // Para Input, REPEAT_FALSE, inputs_e
#include "resource.h" // Para Resource #include "resource.h" // Para Resource
#include "screen.h" // Para Screen #include "screen.h" // Para Screen
@@ -27,7 +27,7 @@ Credits::Credits()
input_(Input::get()) input_(Input::get())
{ {
// Reserva memoria para los punteros // Reserva memoria para los punteros
text_ = resource_->getText("smb2.txt"); text_ = resource_->getText("smb2");
sprite_ = std::make_shared<AnimatedSprite>(resource_->getTexture("shine.png"), resource_->getAnimation("shine.ani")); sprite_ = std::make_shared<AnimatedSprite>(resource_->getTexture("shine.png"), resource_->getAnimation("shine.ani"));
// Inicializa variables // Inicializa variables

View File

@@ -3,7 +3,7 @@
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks #include <SDL2/SDL_timer.h> // Para SDL_GetTicks
#include <iostream> // Para basic_ostream, basic_ios, operator<<, cout #include <iostream> // Para basic_ostream, basic_ios, operator<<, cout
#include "asset.h" // Para Asset #include "asset.h" // Para Asset
#include "const.h" // Para BLOCK, PLAY_AREA_WIDTH, SECTION_DEMO #include "defines.h" // Para BLOCK, PLAY_AREA_WIDTH, SECTION_DEMO
#include "input.h" // Para Input, REPEAT_FALSE, inputs_e #include "input.h" // Para Input, REPEAT_FALSE, inputs_e
#include "item_tracker.h" // Para ItemTracker #include "item_tracker.h" // Para ItemTracker
#include "resource.h" // Para Resource #include "resource.h" // Para Resource
@@ -40,8 +40,8 @@ Demo::Demo()
currentRoom = rooms[roomIndex]; currentRoom = rooms[roomIndex];
// Crea los objetos // Crea los objetos
itemTracker = std::make_unique<ItemTracker>(); itemTracker = std::make_shared<ItemTracker>();
scoreboard = std::make_unique<Scoreboard>(&board); scoreboard = std::make_shared<Scoreboard>(&board);
room = std::make_shared<Room>(resource->getRoom(currentRoom), itemTracker, &board.items, false); room = std::make_shared<Room>(resource->getRoom(currentRoom), itemTracker, &board.items, false);
text = resource->getText("smb2.txt"); text = resource->getText("smb2.txt");

View File

@@ -7,6 +7,7 @@
#include <vector> // Para vector #include <vector> // Para vector
#include <memory> // Para shared_ptr #include <memory> // Para shared_ptr
#include "scoreboard.h" // Para board_t #include "scoreboard.h" // Para board_t
#include "room.h"
class Asset; class Asset;
class Debug; class Debug;
class Input; class Input;
@@ -30,8 +31,8 @@ private:
Debug *debug; // Objeto para gestionar la información de debug Debug *debug; // Objeto para gestionar la información de debug
std::shared_ptr<Room> room; // Objeto encargado de gestionar cada habitación del juego std::shared_ptr<Room> room; // Objeto encargado de gestionar cada habitación del juego
std::shared_ptr<Text> text; // Objeto para los textos del juego std::shared_ptr<Text> text; // Objeto para los textos del juego
std::unique_ptr<Scoreboard> scoreboard; // Objeto encargado de gestionar el marcador std::shared_ptr<Scoreboard> scoreboard; // Objeto encargado de gestionar el marcador
std::unique_ptr<ItemTracker> itemTracker; // Lleva el control de los objetos recogidos std::shared_ptr<ItemTracker> itemTracker; // Lleva el control de los objetos recogidos
// Variables // Variables
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa

View File

@@ -20,7 +20,7 @@
#include <vector> // Para vector #include <vector> // Para vector
#include <memory> // Para std::make_unique #include <memory> // Para std::make_unique
#include "asset.h" // Para Asset, assetType #include "asset.h" // Para Asset, assetType
#include "const.h" // Para Section::LOGO, Section::TITLE #include "defines.h" // Para Section::LOGO, Section::TITLE
#include "debug.h" // Para Debug #include "debug.h" // Para Debug
#include "credits.h" // Para Credits #include "credits.h" // Para Credits
#include "demo.h" // Para Demo #include "demo.h" // Para Demo
@@ -81,7 +81,7 @@ Director::Director(int argc, const char *argv[])
Screen::init(window_, renderer_); Screen::init(window_, renderer_);
Screen::get()->setBorderColor(borderColor); Screen::get()->setBorderColor(borderColor);
Resource::init(); Resource::init();
Notifier::init(Asset::get()->get("notify.png"), Asset::get()->get("smb2.png"), Asset::get()->get("smb2.txt"), Asset::get()->get("notify.wav")); Notifier::init(Asset::get()->get("notify.png"), Resource::get()->getText("smb2"));
Input::init(Asset::get()->get("gamecontrollerdb.txt")); Input::init(Asset::get()->get("gamecontrollerdb.txt"));
initInput(); initInput();
Debug::init(); Debug::init();

View File

@@ -7,7 +7,7 @@
#include <algorithm> // Para min #include <algorithm> // Para min
#include <iostream> // Para basic_ostream, operator<<, basic_ios #include <iostream> // Para basic_ostream, operator<<, basic_ios
#include "asset.h" // Para Asset #include "asset.h" // Para Asset
#include "const.h" // Para GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH #include "defines.h" // Para GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH
#include "input.h" // Para Input, REPEAT_FALSE, inputs_e #include "input.h" // Para Input, REPEAT_FALSE, inputs_e
#include "jail_audio.h" // Para JA_SetVolume, JA_DeleteMusic, JA_Loa... #include "jail_audio.h" // Para JA_SetVolume, JA_DeleteMusic, JA_Loa...
#include "resource.h" // Para Resource #include "resource.h" // Para Resource

View File

@@ -4,7 +4,7 @@
#include <algorithm> // for max, min, replace #include <algorithm> // for max, min, replace
#include "animated_sprite.h" // for AnimatedSprite #include "animated_sprite.h" // for AnimatedSprite
#include "asset.h" // for Asset #include "asset.h" // for Asset
#include "const.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_CENTER_X #include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_CENTER_X
#include "input.h" // for Input, REPEAT_FALSE, inputs_e #include "input.h" // for Input, REPEAT_FALSE, inputs_e
#include "jail_audio.h" // for JA_SetVolume, JA_DeleteMusic, JA_Loa... #include "jail_audio.h" // for JA_SetVolume, JA_DeleteMusic, JA_Loa...
#include "moving_sprite.h" // for MovingSprite #include "moving_sprite.h" // for MovingSprite
@@ -319,7 +319,7 @@ void Ending2::loadSprites()
// Carga los sprites // Carga los sprites
for (auto sl : spriteList) for (auto sl : spriteList)
{ {
sprites.emplace_back(std::make_shared<AnimatedSprite>(renderer, resource->getAnimation(sl + ".ani"))); sprites.emplace_back(std::make_shared<AnimatedSprite>(resource->getTexture(sl + ".png"), resource->getAnimation(sl + ".ani")));
maxSpriteWidth = std::max(sprites.back()->getWidth(), maxSpriteWidth); maxSpriteWidth = std::max(sprites.back()->getWidth(), maxSpriteWidth);
maxSpriteHeight = std::max(sprites.back()->getHeight(), maxSpriteHeight); maxSpriteHeight = std::max(sprites.back()->getHeight(), maxSpriteHeight);
} }

View File

@@ -4,21 +4,22 @@
#include <algorithm> // Para min #include <algorithm> // Para min
#include "animated_sprite.h" // Para AnimatedSprite #include "animated_sprite.h" // Para AnimatedSprite
#include "texture.h" // Para Texture #include "texture.h" // Para Texture
#include "resource.h" // Para Resource
#include "options.h" // Para options
// Constructor // Constructor
Enemy::Enemy(enemy_t enemy) Enemy::Enemy(EnemyData enemy)
{ {
// Crea objetos // Crea objetos
sprite_ = std::make_shared<AnimatedSprite>(falta_la_textura, enemy.animation); sprite_ = std::make_shared<AnimatedSprite>(Resource::get()->getTexture(enemy.texture_path), Resource::get()->getAnimation(enemy.animation_path));
// Obten el resto de valores // Obten el resto de valores
x1_ = enemy.x1; x1_ = enemy.x1;
x2_ = enemy.x2; x2_ = enemy.x2;
y1_ = enemy.y1; y1_ = enemy.y1;
y2_ = enemy.y2; y2_ = enemy.y2;
palette_ = enemy.palette;
color_string_ = enemy.color; color_string_ = enemy.color;
color_ = stringToColor(palette_, color_string_); setPalette(options.video.palette);
sprite_->setPosX(enemy.x); sprite_->setPosX(enemy.x);
sprite_->setPosY(enemy.y); sprite_->setPosY(enemy.y);
sprite_->setVelX(enemy.vx); sprite_->setVelX(enemy.vx);
@@ -130,6 +131,5 @@ void Enemy::reLoadTexture()
// Asigna la paleta // Asigna la paleta
void Enemy::setPalette(Palette pal) void Enemy::setPalette(Palette pal)
{ {
palette_ = pal; color_ = stringToColor(pal, color_string_);
color_ = stringToColor(palette_, color_string_);
} }

View File

@@ -5,30 +5,27 @@
#include <string> // Para basic_string, string #include <string> // Para basic_string, string
#include "utils.h" // Para palette_e, color_t #include "utils.h" // Para palette_e, color_t
#include <memory> // Para shared_ptr #include <memory> // Para shared_ptr
class AnimatedSprite; #include "animated_sprite.h" // Para AnimatedSprite
struct animatedSprite_t;
// Estructura para pasar los datos de un enemigo // Estructura para pasar los datos de un enemigo
struct enemy_t struct EnemyData
{ {
SDL_Renderer *renderer; // El renderizador de la ventana std::string texture_path; // Ruta al fichero con la textura
animatedSprite_t *animation; // Puntero a las animaciones del enemigo std::string animation_path; // Ruta al fichero con la animación
std::string animation_path; // Ruta al fichero con la animación int w; // Anchura del enemigo
int w; // Anchura del enemigo int h; // Altura del enemigo
int h; // Altura del enemigo float x; // Posición inicial en el eje X
float x; // Posición inicial en el eje X float y; // Posición inicial en el eje Y
float y; // Posición inicial en el eje Y float vx; // Velocidad en el eje X
float vx; // Velocidad en el eje X float vy; // Velocidad en el eje Y
float vy; // Velocidad en el eje Y int x1; // Limite izquierdo de la ruta en el eje X
int x1; // Limite izquierdo de la ruta en el eje X int x2; // Limite derecho de la ruta en el eje X
int x2; // Limite derecho de la ruta en el eje X int y1; // Limite superior de la ruta en el eje Y
int y1; // Limite superior de la ruta en el eje Y int y2; // Limite inferior de la ruta en el eje Y
int y2; // Limite inferior de la ruta en el eje Y bool flip; // Indica si el enemigo hace flip al terminar su ruta
bool flip; // Indica si el enemigo hace flip al terminar su ruta bool mirror; // Indica si el enemigo está volteado verticalmente
bool mirror; // Indica si el enemigo está volteado verticalmente int frame; // Frame inicial para la animación del enemigo
int frame; // Frame inicial para la animación del enemigo std::string color; // Color del enemigo
std::string color; // Color del enemigo
Palette palette; // Paleta de colores
}; };
class Enemy class Enemy
@@ -40,7 +37,6 @@ private:
// Variables // Variables
Color color_; // Color del enemigo Color color_; // Color del enemigo
std::string color_string_; // Color del enemigo en formato texto std::string color_string_; // Color del enemigo en formato texto
Palette palette_; // Paleta de colores
int x1_; // Limite izquierdo de la ruta en el eje X int x1_; // Limite izquierdo de la ruta en el eje X
int x2_; // Limite derecho de la ruta en el eje X int x2_; // Limite derecho de la ruta en el eje X
int y1_; // Limite superior de la ruta en el eje Y int y1_; // Limite superior de la ruta en el eje Y
@@ -54,7 +50,7 @@ private:
public: public:
// Constructor // Constructor
Enemy(enemy_t enemy); Enemy(EnemyData enemy);
// Destructor // Destructor
~Enemy() = default; ~Enemy() = default;

View File

@@ -8,7 +8,7 @@
#include <vector> // for vector #include <vector> // for vector
#include "asset.h" // for Asset #include "asset.h" // for Asset
#include "cheevos.h" // for Cheevos #include "cheevos.h" // for Cheevos
#include "const.h" // for PLAY_AREA_HEIGHT, GAMECANVAS_WIDTH #include "defines.h" // for PLAY_AREA_HEIGHT, GAMECANVAS_WIDTH
#include "debug.h" // for Debug #include "debug.h" // for Debug
#include "input.h" // for Input, REPEAT_FALSE, inputs_e #include "input.h" // for Input, REPEAT_FALSE, inputs_e
#include "item_tracker.h" // for ItemTracker #include "item_tracker.h" // for ItemTracker

View File

@@ -7,6 +7,7 @@
#include <string> // Para string, basic_string #include <string> // Para string, basic_string
#include "player.h" // Para playerSpawn_t #include "player.h" // Para playerSpawn_t
#include "scoreboard.h" // Para board_t #include "scoreboard.h" // Para board_t
#include "room.h"
class Asset; class Asset;
class Cheevos; class Cheevos;
class Debug; class Debug;

View File

@@ -4,7 +4,7 @@
#include <string> // Para basic_string, operator+, to_string, char... #include <string> // Para basic_string, operator+, to_string, char...
#include "animated_sprite.h" // Para AnimatedSprite #include "animated_sprite.h" // Para AnimatedSprite
#include "asset.h" // Para Asset #include "asset.h" // Para Asset
#include "const.h" // Para GAMECANVAS_CENTER_X, SECTION_GAME_OVER #include "defines.h" // Para GAMECANVAS_CENTER_X, SECTION_GAME_OVER
#include "input.h" // Para Input, REPEAT_FALSE, inputs_e #include "input.h" // Para Input, REPEAT_FALSE, inputs_e
#include "jail_audio.h" // Para JA_DeleteMusic, JA_LoadMusic, JA_PlayMusic #include "jail_audio.h" // Para JA_DeleteMusic, JA_LoadMusic, JA_PlayMusic
#include "resource.h" // Para Resource #include "resource.h" // Para Resource

View File

@@ -69,7 +69,7 @@ namespace globalInputs
else if (Input::get()->checkInput(input_toggle_shaders, REPEAT_FALSE)) else if (Input::get()->checkInput(input_toggle_shaders, REPEAT_FALSE))
{ {
Screen::get()->toggleShaders(); Screen::get()->toggleShaders();
Notifier::get()->show("HOLA"); Notifier::get()->show({"HOLA"});
} }
else if (Input::get()->checkInput(input_toggle_palette, REPEAT_FALSE)) else if (Input::get()->checkInput(input_toggle_palette, REPEAT_FALSE))

View File

@@ -2,7 +2,7 @@
#include <SDL2/SDL_timer.h> // for SDL_GetTicks #include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <stdlib.h> // for rand #include <stdlib.h> // for rand
#include "asset.h" // for Asset #include "asset.h" // for Asset
#include "const.h" // for SECTION_LOADING_SCREEN, SECTION_QUIT #include "defines.h" // for SECTION_LOADING_SCREEN, SECTION_QUIT
#include "input.h" // for Input, REPEAT_FALSE, inputs_e #include "input.h" // for Input, REPEAT_FALSE, inputs_e
#include "jail_audio.h" // for JA_DeleteMusic, JA_LoadMusic, JA_PlayMusic #include "jail_audio.h" // for JA_DeleteMusic, JA_LoadMusic, JA_PlayMusic
#include "resource.h" // for Resource #include "resource.h" // for Resource
@@ -33,8 +33,8 @@ LoadingScreen::LoadingScreen()
mono_loading_screen_texture_ = resource_->getTexture("loading_screen_bn_zxarne.png"); mono_loading_screen_texture_ = resource_->getTexture("loading_screen_bn_zxarne.png");
color_loading_screen_texture_ = resource_->getTexture("loading_screen_color_zxarne.png"); color_loading_screen_texture_ = resource_->getTexture("loading_screen_color_zxarne.png");
} }
mono_loading_screen_sprite_ = std::make_shared<Sprite>(0, 0, mono_loading_screen_texture_->getWidth(), mono_loading_screen_texture_->getHeight(), mono_loading_screen_texture_, renderer_); mono_loading_screen_sprite_ = std::make_shared<Sprite>(mono_loading_screen_texture_, 0, 0, mono_loading_screen_texture_->getWidth(), mono_loading_screen_texture_->getHeight());
color_loading_screen_sprite_ = std::make_shared<Sprite>(0, 0, color_loading_screen_texture_->getWidth(), color_loading_screen_texture_->getHeight(), color_loading_screen_texture_, renderer_); color_loading_screen_sprite_ = std::make_shared<Sprite>(color_loading_screen_texture_, 0, 0, color_loading_screen_texture_->getWidth(), color_loading_screen_texture_->getHeight());
loading_sound1_ = resource_->getMusic("loading_sound1.ogg"); loading_sound1_ = resource_->getMusic("loading_sound1.ogg");
loading_sound2_ = resource_->getMusic("loading_sound2.ogg"); loading_sound2_ = resource_->getMusic("loading_sound2.ogg");
loading_sound3_ = resource_->getMusic("loading_sound3.ogg"); loading_sound3_ = resource_->getMusic("loading_sound3.ogg");

View File

@@ -1,7 +1,7 @@
#include "logo.h" #include "logo.h"
#include <SDL2/SDL_timer.h> // for SDL_GetTicks #include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <string> // for basic_string, string #include <string> // for basic_string, string
#include "const.h" // for SECTION_LOGO, SECTION_TITLE, SUBSECTION_... #include "defines.h" // for SECTION_LOGO, SECTION_TITLE, SUBSECTION_...
#include "input.h" // for Input, REPEAT_FALSE, inputs_e #include "input.h" // for Input, REPEAT_FALSE, inputs_e
#include "jail_audio.h" // for JA_StopMusic #include "jail_audio.h" // for JA_StopMusic
#include "resource.h" // for Resource #include "resource.h" // for Resource
@@ -26,14 +26,14 @@ Logo::Logo()
// Reserva memoria para los punteros // Reserva memoria para los punteros
jailgames_texture_ = resource_->getTexture("jailgames.png"); jailgames_texture_ = resource_->getTexture("jailgames.png");
since_1998_texture_ = resource_->getTexture("since_1998.png"); since_1998_texture_ = resource_->getTexture("since_1998.png");
since_1998_sprite_ = std::make_shared<Sprite>((256 - since_1998_texture_->getWidth()) / 2, 83 + jailgames_texture_->getHeight() + 5, since_1998_texture_->getWidth(), since_1998_texture_->getHeight(), since_1998_texture_, renderer_); since_1998_sprite_ = std::make_shared<Sprite>(since_1998_texture_, (256 - since_1998_texture_->getWidth()) / 2, 83 + jailgames_texture_->getHeight() + 5, since_1998_texture_->getWidth(), since_1998_texture_->getHeight());
since_1998_sprite_->setClip(0, 0, since_1998_texture_->getWidth(), since_1998_texture_->getHeight()); since_1998_sprite_->setClip(0, 0, since_1998_texture_->getWidth(), since_1998_texture_->getHeight());
since_1998_texture_->setColor(0, 0, 0); since_1998_texture_->setColor(0, 0, 0);
// Crea los sprites de cada linea // Crea los sprites de cada linea
for (int i = 0; i < jailgames_texture_->getHeight(); ++i) for (int i = 0; i < jailgames_texture_->getHeight(); ++i)
{ {
jailgames_sprite_.push_back(std::make_shared<Sprite>(0, i, jailgames_texture_->getWidth(), 1, jailgames_texture_, renderer_)); jailgames_sprite_.push_back(std::make_shared<Sprite>(jailgames_texture_, 0, i, jailgames_texture_->getWidth(), 1));
jailgames_sprite_.back()->setClip(0, i, jailgames_texture_->getWidth(), 1); jailgames_sprite_.back()->setClip(0, i, jailgames_texture_->getWidth(), 1);
if (i % 2 == 0) if (i % 2 == 0)
{ {

View File

@@ -4,6 +4,8 @@
#include <SDL2/SDL_render.h> // Para SDL_RendererFlip #include <SDL2/SDL_render.h> // Para SDL_RendererFlip
#include <memory> // Para shared_ptr #include <memory> // Para shared_ptr
#include "sprite.h" // Para Sprite #include "sprite.h" // Para Sprite
#include <cmath>
#include <algorithm>
class Texture; // lines 8-8 class Texture; // lines 8-8
// Clase MovingSprite. Añade movimiento y efectos de rotación, zoom y flip al sprite // Clase MovingSprite. Añade movimiento y efectos de rotación, zoom y flip al sprite

View File

@@ -198,20 +198,20 @@ void Notifier::show(std::vector<std::string> texts, int icon, const std::string
} }
else if (options.notifications.getHorizontalPosition() == "CENTER") else if (options.notifications.getHorizontalPosition() == "CENTER")
{ {
desp_h = ((param.game.width / 2) - (width / 2)); desp_h = ((options.game.width / 2) - (width / 2));
} }
else else
{ {
desp_h = param.game.width - width - padding_out; desp_h = options.game.width - width - padding_out;
} }
// Posición vertical // Posición vertical
const int desp_v = (param.notification.pos_v == NotifyPosition::TOP) ? padding_out : (param.game.height - height - padding_out); const int desp_v = (options.notifications.getVerticalPosition() == "TOP") ? padding_out : (options.game.height - height - padding_out);
// Offset // Offset
const auto travel_dist = height + padding_out; const auto travel_dist = height + padding_out;
auto offset = 0; auto offset = 0;
if (param.notification.pos_v == NotifyPosition::TOP) if (options.notifications.getVerticalPosition() == "TOP")
{ {
offset = !notifications_.empty() ? notifications_.back().y + travel_dist : desp_v; offset = !notifications_.empty() ? notifications_.back().y + travel_dist : desp_v;
} }
@@ -229,7 +229,7 @@ void Notifier::show(std::vector<std::string> texts, int icon, const std::string
n.travel_dist = travel_dist; n.travel_dist = travel_dist;
n.texts = texts; n.texts = texts;
n.shape = shape; n.shape = shape;
auto y_pos = offset + (param.notification.pos_v == NotifyPosition::TOP ? -travel_dist : travel_dist); int y_pos = offset + ((options.notifications.getVerticalPosition() == "TOP") ? -travel_dist : travel_dist);
n.rect = {desp_h, y_pos, width, height}; n.rect = {desp_h, y_pos, width, height};
// Crea la textura // Crea la textura
@@ -268,7 +268,7 @@ void Notifier::show(std::vector<std::string> texts, int icon, const std::string
{ {
auto sp = std::make_unique<Sprite>(icon_texture_, (SDL_Rect){0, 0, icon_size, icon_size}); auto sp = std::make_unique<Sprite>(icon_texture_, (SDL_Rect){0, 0, icon_size, icon_size});
sp->setPosition({padding_in_h, padding_in_v, icon_size, icon_size}); sp->setPosition({padding_in_h, padding_in_v, icon_size, icon_size});
sp->setSpriteClip({icon_size * (icon % 10), icon_size * (icon / 10), icon_size, icon_size}); sp->setClip({icon_size * (icon % 10), icon_size * (icon / 10), icon_size, icon_size});
sp->render(); sp->render();
} }

View File

@@ -1,10 +1,10 @@
#include "options.h" #include "options.h"
#include "const.h" #include "defines.h"
#include "screen.h" #include "screen.h"
#include <fstream> // Para basic_ofstream, basic_ifstream #include <fstream> // Para basic_ofstream, basic_ifstream
#include <iostream> // Para basic_ostream, operator<<, cout #include <iostream> // Para basic_ostream, operator<<, cout
#include <unordered_map> // Para unordered_map #include <unordered_map> // Para unordered_map
#include <functional> // Para std::function #include <functional> // Para std::function
// Variables // Variables
Options options; Options options;
@@ -149,24 +149,37 @@ bool saveOptionsToFile(const std::string &file_path)
} }
// Establece las opciones // Establece las opciones
bool setOptions(const std::string &var, const std::string &value) { bool setOptions(const std::string &var, const std::string &value)
{
static const std::unordered_map<std::string, std::function<void(std::string)>> optionHandlers = { static const std::unordered_map<std::string, std::function<void(std::string)>> optionHandlers = {
{"version", [](std::string v) { options.version = v; }}, {"version", [](std::string v)
{"keys", [](std::string v) { options.keys = static_cast<ControlScheme>(safeStoi(v, static_cast<int>(ControlScheme::CURSOR))); }}, { options.version = v; }},
{"video.mode", [](std::string v) { options.video.mode = safeStoi(v, 0); }}, {"keys", [](std::string v)
{"window.zoom", [](std::string v) { options.window.zoom = safeStoi(v, 1); }}, { options.keys = static_cast<ControlScheme>(safeStoi(v, static_cast<int>(ControlScheme::CURSOR))); }},
{"video.shaders", [](std::string v) { options.video.shaders = stringToBool(v); }}, {"video.mode", [](std::string v)
{"video.vertical_sync", [](std::string v) { options.video.vertical_sync = stringToBool(v); }}, { options.video.mode = safeStoi(v, 0); }},
{"video.integer_scale", [](std::string v) { options.video.integer_scale = stringToBool(v); }}, {"window.zoom", [](std::string v)
{"video.keep_aspect", [](std::string v) { options.video.keep_aspect = stringToBool(v); }}, { options.window.zoom = safeStoi(v, 1); }},
{"video.border.enabled", [](std::string v) { options.video.border.enabled = stringToBool(v); }}, {"video.shaders", [](std::string v)
{"video.border.width", [](std::string v) { options.video.border.width = safeStoi(v, 32); }}, { options.video.shaders = stringToBool(v); }},
{"video.border.height", [](std::string v) { options.video.border.height = safeStoi(v, 24); }}, {"video.vertical_sync", [](std::string v)
{"video.palette", [](std::string v) { options.video.palette = static_cast<Palette>(safeStoi(v, static_cast<int>(DEFAULT_PALETTE))); }} { options.video.vertical_sync = stringToBool(v); }},
}; {"video.integer_scale", [](std::string v)
{ options.video.integer_scale = stringToBool(v); }},
{"video.keep_aspect", [](std::string v)
{ options.video.keep_aspect = stringToBool(v); }},
{"video.border.enabled", [](std::string v)
{ options.video.border.enabled = stringToBool(v); }},
{"video.border.width", [](std::string v)
{ options.video.border.width = safeStoi(v, 32); }},
{"video.border.height", [](std::string v)
{ options.video.border.height = safeStoi(v, 24); }},
{"video.palette", [](std::string v)
{ options.video.palette = static_cast<Palette>(safeStoi(v, static_cast<int>(DEFAULT_PALETTE))); }}};
auto it = optionHandlers.find(var); auto it = optionHandlers.find(var);
if (it != optionHandlers.end()) { if (it != optionHandlers.end())
{
it->second(value); it->second(value);
return true; return true;
} }

View File

@@ -5,7 +5,7 @@
#include <cmath> // Para ceil, abs #include <cmath> // Para ceil, abs
#include "animated_sprite.h" // Para AnimatedSprite #include "animated_sprite.h" // Para AnimatedSprite
#include "asset.h" // Para Asset #include "asset.h" // Para Asset
#include "const.h" // Para BORDER_TOP, BLOCK, BORDER_BOTTOM, BORDER... #include "defines.h" // Para BORDER_TOP, BLOCK, BORDER_BOTTOM, BORDER...
#include "debug.h" // Para Debug #include "debug.h" // Para Debug
#include "input.h" // Para Input, inputs_e #include "input.h" // Para Input, inputs_e
#include "jail_audio.h" // Para JA_LoadSound, JA_Sound_t, JA_PlaySound #include "jail_audio.h" // Para JA_LoadSound, JA_Sound_t, JA_PlaySound
@@ -21,11 +21,11 @@ Player::Player(player_t player)
input_(Input::get()), input_(Input::get()),
resource_(Resource::get()), resource_(Resource::get()),
asset_(Asset::get()), asset_(Asset::get()),
room_(player.room), debug_(Debug::get()),
debug_(Debug::get()) room_(player.room)
{ {
// Crea objetos // Crea objetos
sprite_ = std::make_shared<AnimatedSprite>(resource_->getAnimation(player.animation)); sprite_ = std::make_shared<AnimatedSprite>(resource_->getTexture(player.png), resource_->getAnimation(player.animation));
// Inicializa variables // Inicializa variables
reLoadPalette(); reLoadPalette();

View File

@@ -6,6 +6,8 @@
#include <vector> // Para vector #include <vector> // Para vector
#include <memory> // Para shared_ptr #include <memory> // Para shared_ptr
#include "utils.h" // Para color_t #include "utils.h" // Para color_t
#include "defines.h" // Para BLOCK
#include "room.h"
class AnimatedSprite; class AnimatedSprite;
class Asset; class Asset;
class Debug; class Debug;
@@ -44,8 +46,8 @@ class Player
{ {
public: public:
// Constantes // Constantes
static const int MAX_FALLING_HEIGHT_ = BLOCK * 4; // Altura maxima permitida de caída. static constexpr int MAX_FALLING_HEIGHT_ = BLOCK * 4; // Altura maxima permitida de caída.
static const float MAX_VY_ = 1.2f; // Velocidad máxima que puede alcanzar al desplazarse en vertical static constexpr float MAX_VY_ = 1.2f; // Velocidad máxima que puede alcanzar al desplazarse en vertical
// Objetos y punteros // Objetos y punteros
SDL_Renderer *renderer_; // El renderizador de la ventana SDL_Renderer *renderer_; // El renderizador de la ventana

View File

@@ -1,360 +0,0 @@
#include "resource.h"
#include <iostream> // Para basic_ostream, operator<<, cout, endl
#include "animated_sprite.h" // Para animatedSprite_t, loadAnimationFromFile
#include "asset.h" // Para Asset
#include "enemy.h" // Para enemy_t
#include "item.h" // Para item_t
#include "room.h" // Para room_t, loadRoomFile, loadRoomTileFile
#include "text.h" // Para textFile_t, LoadTextFile
#include "texture.h" // Para Texture
#include "utils.h" // Para options_t
#include "screen.h"
#include "options.h"
// [SINGLETON]
Resource *Resource::resource_ = nullptr;
// [SINGLETON] Crearemos el objeto con esta función estática
void Resource::init()
{
Resource::resource_ = new Resource();
}
// [SINGLETON] Destruiremos el objeto con esta función estática
void Resource::destroy()
{
delete Resource::resource_;
}
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
Resource *Resource::get()
{
return Resource::resource_;
}
// Carga las texturas de una lista
void Resource::loadTextures(std::vector<std::string> list)
{
for (auto l : list)
{
if (options.console)
{
std::cout << "\nLOAD TEXTURE: " << l << std::endl;
std::cout << "png: " << Asset::get()->get(l) << std::endl;
}
res_texture_t t;
t.name = l;
t.texture = std::make_shared<Texture>(Screen::get()->getRenderer(), Asset::get()->get(t.name), options.console);
textures_.push_back(t);
}
}
// Vuelve a cargar las texturas
void Resource::reLoadTextures()
{
for (auto texture : textures_)
{
texture.texture->reLoad();
}
}
// Carga las animaciones desde una lista
void Resource::loadAnimations(std::vector<std::string> list)
{
for (auto l : list)
{
// Extrae el nombre del fichero sin la extension para crear el nombre del fichero de la textura
const std::string pngFile = l.substr(0, l.find_last_of(".")) + ".png";
if (options.console)
{
std::cout << "\nLOAD ANIMATION: " << l << std::endl;
std::cout << "png: " << Asset::get()->get(pngFile) << std::endl;
std::cout << "ani: " << Asset::get()->get(l) << std::endl;
}
res_animation_t as;
as.name = l;
as.animation = std::make_shared<animatedSprite_t>(loadAnimationFromFile(getTexture(pngFile), Asset::get()->get(as.name), options.console));
animations_.push_back(as);
}
}
// Vuelve a cargar las animaciones
void Resource::reLoadAnimations()
{
// reLoadTextures();
for (auto &a : animations_)
{
// Extrae el nombre del fichero sin la extension para crear el nombre del fichero de la textura
const std::string pngFile = a.name.substr(0, a.name.find_last_of(".")) + ".png";
delete a.animation;
a.animation = std::make_shared<animatedSprite_t>(loadAnimationFromFile(getTexture(pngFile), Asset::get()->get(a.name), options.console));
}
}
// Carga los offsets desde una lista
void Resource::loadOffsets(std::vector<std::string> list)
{
for (auto l : list)
{
res_textOffset_t to;
to.name = l;
to.textFile = std::make_shared<textFile_t>(LoadTextFile(Asset::get()->get(l), options.console));
offsets_.push_back(to);
}
}
// Vuelve a cargar los offsets
void Resource::reLoadOffsets()
{
for (auto &o : offsets_)
{
delete o.textFile;
o.textFile = std::make_shared<textFile_t>(LoadTextFile(Asset::get()->get(o.name), options.console));
}
}
// Carga los mapas de tiles desde una lista
void Resource::loadTileMaps(std::vector<std::string> list)
{
for (auto l : list)
{
res_tileMap_t tm;
tm.name = l;
tm.tileMap = new std::vector<int>(loadRoomTileFile(Asset::get()->get(l), options.console));
tile_maps_.push_back(tm);
}
}
// Vuelve a cargar los mapas de tiles
void Resource::reLoadTileMaps()
{
for (auto &tm : tile_maps_)
{
delete tm.tileMap;
tm.tileMap = new std::vector<int>(loadRoomTileFile(Asset::get()->get(tm.name), options.console));
}
}
// Carga las habitaciones desde una lista
void Resource::loadRooms(std::vector<std::string> list)
{
for (auto l : list)
{
res_room_t r;
r.name = l;
r.room = new room_t(loadRoomFile(Asset::get()->get(l), options.console));
r.room->tileMap = getTileMap(r.room->tileMapFile);
for (auto &e : r.room->enemies)
{
e.animation = getAnimation(e.animationString);
}
for (auto &i : r.room->items)
{
i.texture = getTexture(i.tileSetFile);
}
r.room->textureA = getTexture("standard.png");
r.room->textureB = getTexture("standard_zxarne.png");
rooms_.push_back(r);
}
}
// Vuelve a cargar las habitaciones
void Resource::reLoadRooms()
{
reLoadTileMaps();
for (auto &r : rooms_)
{
delete r.room;
r.room = new room_t(loadRoomFile(Asset::get()->get(r.name)));
r.room->tileMap = getTileMap(r.room->tileMapFile);
for (auto &e : r.room->enemies)
{
e.animation = getAnimation(e.animationString);
}
for (auto &i : r.room->items)
{
i.texture = getTexture(i.tileSetFile);
}
r.room->textureA = getTexture("standard.png");
r.room->textureB = getTexture("standard_zxarne.png");
}
}
// Vuelve a cargar todos los recursos
void Resource::reLoad()
{
reLoadAnimations();
reLoadOffsets();
reLoadRooms();
}
// Libera las texturas
void Resource::freeTextures()
{
for (auto texture : textures_)
{
delete texture.texture;
}
textures_.clear();
}
// Libera las animaciones
void Resource::freeAnimations()
{
for (auto a : animations_)
{
delete a.animation;
}
animations_.clear();
}
// Libera los offsets
void Resource::freeOffsets()
{
for (auto o : offsets_)
{
delete o.textFile;
}
offsets_.clear();
}
// Libera los mapas de tiles
void Resource::freeTileMaps()
{
for (auto t : tile_maps_)
{
delete t.tileMap;
}
tile_maps_.clear();
}
// Libera las habitaciones
void Resource::freeRooms()
{
for (auto r : rooms_)
{
delete r.room;
}
rooms_.clear();
}
// Libera todos los recursos
void Resource::free()
{
freeTextures();
freeAnimations();
freeOffsets();
freeTileMaps();
freeRooms();
}
// Obtiene una textura
Texture *Resource::getTexture(std::string name)
{
for (auto texture : textures_)
{
// if (texture.name.find(name) != std::string::npos)
if (texture.name == name)
{
// std::cout << "\nTEXTURE REQUESTED: " << name << std::endl;
// std::cout << "served: " << texture.name << std::endl;
return texture.texture;
}
}
if (options.console)
{
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
}
return nullptr;
}
// Obtiene una animación
animatedSprite_t *Resource::getAnimation(std::string name)
{
for (auto animation : animations_)
{
// if (animation.name.find(name) != std::string::npos)
if (animation.name == name)
{
// std::cout << "\nANIMATION REQUESTED: " << name << std::endl;
// std::cout << "served: " << animation.name << std::endl;
return animation.animation;
}
}
if (options.console)
{
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
}
return nullptr;
}
// Obtiene un offset
textFile_t *Resource::getOffset(std::string name)
{
for (auto offset : offsets_)
{
// if (offset.name.find(name) != std::string::npos)
if (offset.name == name)
{
return offset.textFile;
}
}
if (options.console)
{
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
}
return nullptr;
}
// Obtiene un mapa de tiles
std::vector<int> *Resource::getTileMap(std::string name)
{
for (auto tileMap : tile_maps_)
{
// if (tileMap.name.find(name) != std::string::npos)
if (tileMap.name == name)
{
return tileMap.tileMap;
}
}
if (options.console)
{
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
}
return nullptr;
}
// Obtiene una habitacion
room_t *Resource::getRoom(std::string name)
{
for (auto room : rooms_)
{
// if (room.name.find(name) != std::string::npos)
if (room.name == name)
{
return room.room;
}
}
if (options.console)
{
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
}
return nullptr;
}
// Obtiene todas las habitaciones
std::vector<res_room_t> *Resource::getAllRooms()
{
return &rooms_;
}

View File

@@ -1,142 +0,0 @@
#pragma once
#include <SDL2/SDL_render.h> // Para SDL_Renderer
#include <string> // Para string, basic_string
#include <vector> // Para vector
#include <memory> // Para shared_ptr
class Asset;
class Texture;
struct animatedSprite_t;
struct Options;
struct room_t;
struct textFile_t;
struct res_texture_t
{
std::string name; // Nombre de la textura
std::shared_ptr<Texture> texture; // La textura
};
struct res_animation_t
{
std::string name; // Nombre de la textura
std::shared_ptr<animatedSprite_t> animation; // La animación
};
struct res_textOffset_t
{
std::string name; // Nombre del offset
std::shared_ptr<textFile_t> textFile; // Los offsets de la fuente
};
struct res_tileMap_t
{
std::string name; // Nombre del mapa de tiles
std::vector<int> *tileMap; // Vector con los indices del mapa de tiles
};
struct res_room_t
{
std::string name; // Nombre de la habitación
std::shared_ptr<room_t> room; // Vector con las habitaciones
};
// Clase Resource. Almacena recursos de disco en memoria
class Resource
{
private:
// [SINGLETON] Objeto privado
static Resource *resource_;
// Variables
std::vector<res_texture_t> textures_;
std::vector<res_animation_t> animations_;
std::vector<res_textOffset_t> offsets_;
std::vector<res_tileMap_t> tile_maps_;
std::vector<res_room_t> rooms_;
// Constructor
Resource() = default;
// Destructor
~Resource() = default;
public:
// [SINGLETON] Crearemos el objeto con esta función estática
static void init();
// [SINGLETON] Destruiremos el objeto con esta función estática
static void destroy();
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
static Resource *get();
// Carga las texturas de una lista
void loadTextures(std::vector<std::string> list);
// Vuelve a cargar las texturas
void reLoadTextures();
// Carga las animaciones desde una lista
void loadAnimations(std::vector<std::string> list);
// Vuelve a cargar las animaciones
void reLoadAnimations();
// Carga los offsets desde una lista
void loadOffsets(std::vector<std::string> list);
// Vuelve a cargar los offsets
void reLoadOffsets();
// Carga los mapas de tiles desde una lista
void loadTileMaps(std::vector<std::string> list);
// Vuelve a cargar los mapas de tiles
void reLoadTileMaps();
// Carga las habitaciones desde una lista
void loadRooms(std::vector<std::string> list);
// Vuelve a cargar las habitaciones
void reLoadRooms();
// Vuelve a cargar todos los recursos
void reLoad();
// Libera las texturas
void freeTextures();
// Libera las animaciones
void freeAnimations();
// Libera los offsets
void freeOffsets();
// Libera los mapas de tiles
void freeTileMaps();
// Libera las habitaciones
void freeRooms();
// Libera todos los recursos
void free();
// Obtiene una textura
std::shared_ptr<Texture> getTexture(std::string name);
// Obtiene una animación
std::shared_ptr<animatedSprite_t> getAnimation(std::string name);
// Obtiene un offset
textFile_t *getOffset(std::string name);
// Obtiene un mapa de tiles
std::vector<int> *getTileMap(std::string name);
// Obtiene una habitacion
room_t *getRoom(std::string name);
// Obtiene todas las habitaciones
std::vector<res_room_t> *getAllRooms();
};

View File

@@ -7,7 +7,7 @@
#include <iostream> // Para cout #include <iostream> // Para cout
#include <sstream> // Para basic_stringstream #include <sstream> // Para basic_stringstream
#include "asset.h" // Para Asset #include "asset.h" // Para Asset
#include "const.h" // Para BLOCK, PLAY_AREA_HEIGHT, PLAY_AREA_W... #include "defines.h" // Para BLOCK, PLAY_AREA_HEIGHT, PLAY_AREA_W...
#include "debug.h" // Para Debug #include "debug.h" // Para Debug
#include "item_tracker.h" // Para ItemTracker #include "item_tracker.h" // Para ItemTracker
#include "jail_audio.h" // Para JA_DeleteSound, JA_LoadSound, JA_Pla... #include "jail_audio.h" // Para JA_DeleteSound, JA_LoadSound, JA_Pla...
@@ -91,11 +91,10 @@ room_t loadRoomFile(std::string file_path, bool verbose)
// Si la linea contiene el texto [enemy] se realiza el proceso de carga de un enemigo // Si la linea contiene el texto [enemy] se realiza el proceso de carga de un enemigo
if (line == "[enemy]") if (line == "[enemy]")
{ {
enemy_t enemy; EnemyData enemy;
enemy.flip = false; enemy.flip = false;
enemy.mirror = false; enemy.mirror = false;
enemy.frame = -1; enemy.frame = -1;
enemy.palette = Palette::ZXSPECTRUM;
do do
{ {
@@ -268,12 +267,17 @@ bool setVars(room_t *room, std::string var, std::string value)
} }
// Asigna variables a una estructura enemy_t // Asigna variables a una estructura enemy_t
bool setEnemy(enemy_t *enemy, std::string var, std::string value) bool setEnemy(EnemyData *enemy, std::string var, std::string value)
{ {
// Indicador de éxito en la asignación // Indicador de éxito en la asignación
bool success = true; bool success = true;
if (var == "animation") if (var == "tileSetFile")
{
enemy->texture_path = value;
}
else if (var == "animation")
{ {
enemy->animation_path = value; enemy->animation_path = value;
} }
@@ -440,11 +444,9 @@ Room::Room(std::shared_ptr<room_t> room, std::shared_ptr<ItemTracker> itemTracke
counter = 0; counter = 0;
// Crea los enemigos // Crea los enemigos
for (auto &enemy : room->enemies) for (auto &enemy_data : room->enemies)
{ {
enemy.renderer = renderer; enemies.emplace_back(std::make_shared<Enemy>(enemy_data));
enemy.palette = options.video.palette;
enemies.push_back(new Enemy(enemy));
} }
// Crea los items // Crea los items
@@ -457,7 +459,7 @@ Room::Room(std::shared_ptr<room_t> room, std::shared_ptr<ItemTracker> itemTracke
item.renderer = renderer; item.renderer = renderer;
item.color1 = stringToColor(options.video.palette, itemColor1); item.color1 = stringToColor(options.video.palette, itemColor1);
item.color2 = stringToColor(options.video.palette, itemColor2); item.color2 = stringToColor(options.video.palette, itemColor2);
items.push_back(new Item(item)); items.emplace_back(std::make_shared<Item>(item));
} }
} }
@@ -504,23 +506,7 @@ Room::Room(std::shared_ptr<room_t> room, std::shared_ptr<ItemTracker> itemTracke
Room::~Room() Room::~Room()
{ {
// Reclama la memoria utilizada por los objetos // Reclama la memoria utilizada por los objetos
JA_DeleteSound(itemSound);
SDL_DestroyTexture(mapTexture); SDL_DestroyTexture(mapTexture);
for (auto enemy : enemies)
{
delete enemy;
}
for (auto item : items)
{
delete item;
}
for (auto a : aTile)
{
delete a.sprite;
}
} }
// Devuelve el nombre de la habitación // Devuelve el nombre de la habitación
@@ -835,7 +821,6 @@ bool Room::itemCollision(SDL_Rect &rect)
if (checkCollision(rect, items[i]->getCollider())) if (checkCollision(rect, items[i]->getCollider()))
{ {
itemTracker->addItem(name, items[i]->getPos()); itemTracker->addItem(name, items[i]->getPos());
delete items[i];
items.erase(items.begin() + i); items.erase(items.begin() + i);
JA_PlaySound(itemSound); JA_PlaySound(itemSound);
*itemsPicked = *itemsPicked + 1; *itemsPicked = *itemsPicked + 1;
@@ -1316,7 +1301,7 @@ void Room::setAnimatedTiles()
const int yc = (tileMap[i] / tileSetWidth) * tileSize; const int yc = (tileMap[i] / tileSetWidth) * tileSize;
aTile_t at; aTile_t at;
at.sprite = new Sprite(x, y, 8, 8, texture, renderer); at.sprite = std::make_shared<Sprite>(texture, x, y, 8, 8);
at.sprite->setClip(xc, yc, 8, 8); at.sprite->setClip(xc, yc, 8, 8);
at.xcOrig = xc; at.xcOrig = xc;
aTile.push_back(at); aTile.push_back(at);
@@ -1535,7 +1520,6 @@ void Room::openTheJail()
if (name == "THE JAIL") if (name == "THE JAIL")
{ {
// Elimina el último enemigo (Bry debe ser el ultimo enemigo definido en el fichero) // Elimina el último enemigo (Bry debe ser el ultimo enemigo definido en el fichero)
delete enemies.back();
enemies.pop_back(); enemies.pop_back();
// Abre las puertas // Abre las puertas

View File

@@ -7,10 +7,10 @@
#include "enemy.h" // Para enemy_t #include "enemy.h" // Para enemy_t
#include "item.h" // Para item_t #include "item.h" // Para item_t
#include "utils.h" // Para h_line_t, color_t, d_line_t, v_line_t #include "utils.h" // Para h_line_t, color_t, d_line_t, v_line_t
#include "item_tracker.h" // Para ItemTracker
#include <memory> // Para shared_ptr #include <memory> // Para shared_ptr
class Asset; class Asset;
class Debug; class Debug;
class ItemTracker;
class Screen; class Screen;
class Sprite; class Sprite;
class Texture; class Texture;
@@ -49,7 +49,7 @@ struct room_t
std::string tileMapFile; // Fichero con el mapa de indices de tile std::string tileMapFile; // Fichero con el mapa de indices de tile
std::vector<int> tileMap; // Indice de los tiles a dibujar en la habitación std::vector<int> tileMap; // Indice de los tiles a dibujar en la habitación
int autoSurfaceDirection; // Sentido en el que arrastran las superficies automáticas de la habitación int autoSurfaceDirection; // Sentido en el que arrastran las superficies automáticas de la habitación
std::vector<enemy_t> enemies; // Listado con los enemigos de la habitación std::vector<EnemyData> enemies; // Listado con los enemigos de la habitación
std::vector<item_t> items; // Listado con los items que hay en la habitación std::vector<item_t> items; // Listado con los items que hay en la habitación
std::shared_ptr<Texture> textureA; // Textura con los graficos de la habitación std::shared_ptr<Texture> textureA; // Textura con los graficos de la habitación
std::shared_ptr<Texture> textureB; // Textura con los graficos de la habitación std::shared_ptr<Texture> textureB; // Textura con los graficos de la habitación
@@ -65,7 +65,7 @@ std::vector<int> loadRoomTileFile(std::string file_path, bool verbose = false);
bool setVars(room_t *room, std::string var, std::string value); bool setVars(room_t *room, std::string var, std::string value);
// Asigna variables a una estructura enemy_t // Asigna variables a una estructura enemy_t
bool setEnemy(enemy_t *enemy, std::string var, std::string value); bool setEnemy(EnemyData *enemy, std::string var, std::string value);
// Asigna variables a una estructura item_t // Asigna variables a una estructura item_t
bool setItem(item_t *item, std::string var, std::string value); bool setItem(item_t *item, std::string var, std::string value);
@@ -74,18 +74,18 @@ class Room
{ {
private: private:
// Objetos y punteros // Objetos y punteros
Screen *screen; // Objeto encargado de dibujar en pantalla Screen *screen; // Objeto encargado de dibujar en pantalla
SDL_Renderer *renderer; // El renderizador de la ventana SDL_Renderer *renderer; // El renderizador de la ventana
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
Debug *debug; // Objeto para gestionar la información de debug Debug *debug; // Objeto para gestionar la información de debug
std::vector<Enemy *> enemies; // Listado con los enemigos de la habitación std::vector<std::shared_ptr<Enemy>> enemies; // Listado con los enemigos de la habitación
std::vector<Item *> items; // Listado con los items que hay en la habitación std::vector<std::shared_ptr<Item>> items; // Listado con los items que hay en la habitación
std::shared_ptr<Texture> texture; // Textura con los graficos de la habitación std::shared_ptr<Texture> texture; // Textura con los graficos de la habitación
std::shared_ptr<Texture> textureA; // Textura con los graficos de la habitación std::shared_ptr<Texture> textureA; // Textura con los graficos de la habitación
std::shared_ptr<Texture> textureB; // Textura con los graficos de la habitación std::shared_ptr<Texture> textureB; // Textura con los graficos de la habitación
std::shared_ptr<ItemTracker> itemTracker; // Lleva el control de los objetos recogidos std::shared_ptr<ItemTracker> itemTracker; // Lleva el control de los objetos recogidos
SDL_Texture *mapTexture; // Textura para dibujar el mapa de la habitación SDL_Texture *mapTexture; // Textura para dibujar el mapa de la habitación
int *itemsPicked; // Puntero a la cantidad de items recogidos que lleva el juego int *itemsPicked; // Puntero a la cantidad de items recogidos que lleva el juego
// Variables // Variables
std::string number; // Numero de la habitación std::string number; // Numero de la habitación

View File

@@ -2,7 +2,7 @@
#include <SDL2/SDL_rect.h> // Para SDL_Rect #include <SDL2/SDL_rect.h> // Para SDL_Rect
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks #include <SDL2/SDL_timer.h> // Para SDL_GetTicks
#include "animated_sprite.h" // Para AnimatedSprite #include "animated_sprite.h" // Para AnimatedSprite
#include "const.h" // Para BLOCK, PLAY_AREA_HEIGHT, PLAY_AREA_WIDTH #include "defines.h" // Para BLOCK, PLAY_AREA_HEIGHT, PLAY_AREA_WIDTH
#include "resource.h" // Para Resource #include "resource.h" // Para Resource
#include "text.h" // Para Text #include "text.h" // Para Text
#include "texture.h" // Para Texture #include "texture.h" // Para Texture
@@ -21,10 +21,11 @@ Scoreboard::Scoreboard(board_t *board)
{ {
// Reserva memoria para los objetos // Reserva memoria para los objetos
itemTexture = resource->getTexture("items.png"); itemTexture = resource->getTexture("items.png");
const std::string playerJPG = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.jpg" : "player.jpg";
const std::string playerANI = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani"; const std::string playerANI = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani";
sprite = std::make_shared<AnimatedSprite>(falta_la_textura, resource->getAnimation(playerANI)); sprite = std::make_shared<AnimatedSprite>(resource->getTexture(playerJPG), resource->getAnimation(playerANI));
sprite->setCurrentAnimation("walk_menu"); sprite->setCurrentAnimation("walk_menu");
text = Resource::get()->getText("smb2.txt"); text = resource->getText("smb2.txt");
// Inicializa las variables // Inicializa las variables
counter = 0; counter = 0;

View File

@@ -35,10 +35,10 @@ private:
}; };
// Objetos y punteros // Objetos y punteros
SDL_Renderer *renderer; // El renderizador de la ventana SDL_Renderer *renderer; // El renderizador de la ventana
Resource *resource; // Objeto con los recursos Resource *resource; // Objeto con los recursos
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
Text *text; // Objeto para escribir texto std::shared_ptr<Text> text; // Objeto para escribir texto
std::shared_ptr<AnimatedSprite> sprite; // Sprite para mostrar las vidas en el marcador std::shared_ptr<AnimatedSprite> sprite; // Sprite para mostrar las vidas en el marcador
std::shared_ptr<Texture> itemTexture; // Textura con los graficos para las vidas std::shared_ptr<Texture> itemTexture; // Textura con los graficos para las vidas
std::shared_ptr<board_t> board; // Contiene las variables a mostrar en el marcador std::shared_ptr<board_t> board; // Contiene las variables a mostrar en el marcador

View File

@@ -7,7 +7,7 @@
#include <iostream> // Para basic_ostream, operator<<, basic_ios #include <iostream> // Para basic_ostream, operator<<, basic_ios
#include "asset.h" // Para Asset #include "asset.h" // Para Asset
#include "cheevos.h" // Para cheevos_t, Cheevos #include "cheevos.h" // Para cheevos_t, Cheevos
#include "const.h" // Para PLAY_AREA_CENTER_X, GAMECANVAS_WIDTH #include "defines.h" // Para PLAY_AREA_CENTER_X, GAMECANVAS_WIDTH
#include "input.h" // Para Input, inputs_e, REPEAT_FALSE, REPEA... #include "input.h" // Para Input, inputs_e, REPEAT_FALSE, REPEA...
#include "resource.h" // Para Resource #include "resource.h" // Para Resource
#include "screen.h" // Para Screen #include "screen.h" // Para Screen
@@ -35,7 +35,7 @@ Title::Title()
{ {
texture_ = resource_->getTexture("title_logo.png"); texture_ = resource_->getTexture("title_logo.png");
} }
sprite_ = std::make_shared<Sprite>(0, 0, texture_->getWidth(), texture_->getHeight(), texture_, renderer_); sprite_ = std::make_shared<Sprite>(texture_, 0, 0, texture_->getWidth(), texture_->getHeight());
text_ = resource_->getText("smb2.txt"); text_ = resource_->getText("smb2.txt");
info_text_ = resource_->getText("subatomic.txt"); info_text_ = resource_->getText("subatomic.txt");
@@ -438,7 +438,7 @@ void Title::createCheevosTexture()
} }
// Crea el sprite para el listado de logros // Crea el sprite para el listado de logros
cheevos_sprite_ = std::make_shared<Sprite>((GAMECANVAS_WIDTH - cheevos_texture_->getWidth()) / 2, cheevosTexturePosY, cheevos_texture_->getWidth(), cheevos_texture_->getHeight(), cheevos_texture_, renderer_); cheevos_sprite_ = std::make_shared<Sprite>(cheevos_texture_, (GAMECANVAS_WIDTH - cheevos_texture_->getWidth()) / 2, cheevosTexturePosY, cheevos_texture_->getWidth(), cheevos_texture_->getHeight());
cheevos_texture_view_ = {0, 0, cheevos_texture_->getWidth(), cheevosTextureViewHeight}; cheevos_texture_view_ = {0, 0, cheevos_texture_->getWidth(), cheevosTextureViewHeight};
cheevos_sprite_->setClip(cheevos_texture_view_); cheevos_sprite_->setClip(cheevos_texture_view_);
} }