diff --git a/source/game_logo.cpp b/source/game_logo.cpp index 89b7595..503357a 100644 --- a/source/game_logo.cpp +++ b/source/game_logo.cpp @@ -51,7 +51,6 @@ void GameLogo::init() shake_.origin = xp; // Inicializa el bitmap de 'Coffee' - coffee_sprite_->init(); coffee_sprite_->setPosX(xp); coffee_sprite_->setPosY(y_ - coffee_texture_->getHeight() - desp); coffee_sprite_->setWidth(coffee_texture_->getWidth()); @@ -67,7 +66,6 @@ void GameLogo::init() coffee_sprite_->setDestY(y_ - coffee_texture_->getHeight()); // Inicializa el bitmap de 'Crisis' - crisis_sprite_->init(); crisis_sprite_->setPosX(xp + 15); crisis_sprite_->setPosY(y_ + desp); crisis_sprite_->setWidth(crisis_texture_->getWidth()); diff --git a/source/scoreboard.cpp b/source/scoreboard.cpp index 18d2f66..5b4cae5 100644 --- a/source/scoreboard.cpp +++ b/source/scoreboard.cpp @@ -37,19 +37,9 @@ Scoreboard *Scoreboard::get() // Constructor Scoreboard::Scoreboard() : renderer_(Screen::get()->getRenderer()), - game_power_meter_texture_(Resource::get()->getTexture("game_power_meter.png")), power_meter_sprite_(std::make_unique(game_power_meter_texture_)), - text_scoreboard_(std::make_unique(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt"))), - - stage_(1), - hi_score_(0), - power_(0), - hi_score_name_(std::string()), - color_(Color(0, 0, 0)), - rect_({0, 0, 320, 40}), - ticks_(SDL_GetTicks()), - counter_(0) + text_scoreboard_(std::make_unique(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt"))) { // Inicializa variables for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i) diff --git a/source/scoreboard.h b/source/scoreboard.h index f1e152b..8e8c7ba 100644 --- a/source/scoreboard.h +++ b/source/scoreboard.h @@ -3,6 +3,7 @@ #include // for SDL_Point, SDL_Rect #include // for SDL_Renderer, SDL_Texture #include // for Uint32 +#include // for SDL_GetTicks #include // for unique_ptr, shared_ptr #include // for string #include // for vector @@ -54,25 +55,25 @@ private: std::unique_ptr power_meter_sprite_; // Sprite para el medidor de poder de la fase std::unique_ptr text_scoreboard_; // Fuente para el marcador del juego - SDL_Texture *background_; // Textura para dibujar el marcador + SDL_Texture *background_ = nullptr; // Textura para dibujar el marcador std::vector panel_texture_; // Texturas para dibujar cada panel // Variables - std::string name_[SCOREBOARD_MAX_PANELS]; // Nom de cada jugador - std::string record_name_[SCOREBOARD_MAX_PANELS]; // Nombre introducido para la tabla de records - int selector_pos_[SCOREBOARD_MAX_PANELS]; // Posición del selector de letra para introducir el nombre - int score_[SCOREBOARD_MAX_PANELS]; // Puntuación de los jugadores - float mult_[SCOREBOARD_MAX_PANELS]; // Multiplicador de los jugadores - int continue_counter_[SCOREBOARD_MAX_PANELS]; // Tiempo para continuar de los jugadores - Panel panel_[SCOREBOARD_MAX_PANELS]; // Lista con todos los paneles del marcador - int stage_; // Número de fase actual - int hi_score_; // Máxima puntuación - float power_; // Poder actual de la fase - std::string hi_score_name_; // Nombre del jugador con la máxima puntuación - Color color_; // Color del marcador - SDL_Rect rect_; // Posición y dimensiones del marcador - Uint32 ticks_; // Variable donde almacenar el valor de SDL_GetTiks() - int counter_; // Contador + std::string name_[SCOREBOARD_MAX_PANELS] = {}; // Nom de cada jugador + std::string record_name_[SCOREBOARD_MAX_PANELS] = {}; // Nombre introducido para la tabla de records + int selector_pos_[SCOREBOARD_MAX_PANELS] = {}; // Posición del selector de letra para introducir el nombre + int score_[SCOREBOARD_MAX_PANELS] = {}; // Puntuación de los jugadores + float mult_[SCOREBOARD_MAX_PANELS] = {}; // Multiplicador de los jugadores + int continue_counter_[SCOREBOARD_MAX_PANELS] = {}; // Tiempo para continuar de los jugadores + Panel panel_[SCOREBOARD_MAX_PANELS] = {}; // Lista con todos los paneles del marcador + int stage_ = 1; // Número de fase actual + int hi_score_ = 0; // Máxima puntuación + float power_ = 0; // Poder actual de la fase + std::string hi_score_name_ = std::string(); // Nombre del jugador con la máxima puntuación + Color color_ = Color(); // Color del marcador + SDL_Rect rect_ = {0, 0, 320, 40}; // Posición y dimensiones del marcador + Uint32 ticks_ = SDL_GetTicks(); // Variable donde almacenar el valor de SDL_GetTiks() + int counter_ = 0; // Contador // Puntos predefinidos para colocar elementos en los paneles SDL_Point slot4_1_, slot4_2_, slot4_3_, slot4_4_; diff --git a/source/screen.cpp b/source/screen.cpp index d7d7c18..deed993 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -51,17 +51,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer) shader_canvas_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)), src_rect_({0, 0, param.game.width, param.game.height}), - dst_rect_({0, 0, param.game.width, param.game.height}), - border_color_(Color(0x00, 0x00, 0x00)), - attenuate_effect_(false), - fps_ticks_(0), - fps_counter_(0), - fps_(0), -#ifdef DEBUG - show_info_(true) -#else - show_info_(false) -#endif + dst_rect_({0, 0, param.game.width, param.game.height}) { // Inicializa variables flash_effect_.enabled = false; diff --git a/source/screen.h b/source/screen.h index f25e397..653a3a0 100644 --- a/source/screen.h +++ b/source/screen.h @@ -34,15 +34,19 @@ private: SDL_Texture *shader_canvas_; // Textura para pasarle al shader desde gameCanvas // Variables - SDL_Rect src_rect_; // Coordenadas de donde va a pillar la textura del juego para dibujarla - SDL_Rect dst_rect_; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana - Color border_color_; // Color del borde añadido a la textura de juego para rellenar la pantalla - bool attenuate_effect_; // Indica si la pantalla ha de estar atenuada - Uint32 fps_ticks_; // Ticks para contar los frames por segundo - int fps_counter_; // Contador de frames por segundo - int fps_; // Frames calculados en el último segundo - bool show_info_; // Indica si ha de mostrar/ocultar la información de la pantalla - std::string info_resolution_; // Texto con la informacion de la pantalla + SDL_Rect src_rect_; // Coordenadas de donde va a pillar la textura del juego para dibujarla + SDL_Rect dst_rect_; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana + Color border_color_ = Color(); // Color del borde añadido a la textura de juego para rellenar la pantalla + bool attenuate_effect_ = false; // Indica si la pantalla ha de estar atenuada + Uint32 fps_ticks_ = 0; // Ticks para contar los frames por segundo + int fps_counter_ = 0; // Contador de frames por segundo + int fps_; // Frames calculados en el último segundo + std::string info_resolution_; // Texto con la informacion de la pantalla +#ifdef DEBUG + bool show_info_ = true; // Indica si ha de mostrar/ocultar la información de la pantalla +#else + bool show_info_ = false; // Indica si ha de mostrar/ocultar la información de la pantalla +#endif struct FlashEffect { diff --git a/source/smart_sprite.cpp b/source/smart_sprite.cpp index 34cce0d..5030b0d 100644 --- a/source/smart_sprite.cpp +++ b/source/smart_sprite.cpp @@ -3,20 +3,7 @@ class Texture; // Constructor SmartSprite::SmartSprite(std::shared_ptr texture) - : AnimatedSprite(texture) -{ - init(); -} - -// Inicializa el objeto -void SmartSprite::init() -{ - finished_counter_ = 0; - on_destination_ = false; - dest_x_ = dest_y_ = 0; - finished_ = false; - enabled_ = false; -} + : AnimatedSprite(texture) {} // Actualiza la posición y comprueba si ha llegado a su destino void SmartSprite::update() diff --git a/source/smart_sprite.h b/source/smart_sprite.h index 67abad4..c92bb5d 100644 --- a/source/smart_sprite.h +++ b/source/smart_sprite.h @@ -9,12 +9,12 @@ class SmartSprite : public AnimatedSprite { private: // Variables - bool on_destination_; // Indica si está en el destino - int dest_x_; // Posicion de destino en el eje X - int dest_y_; // Posicion de destino en el eje Y - int finished_counter_; // Contador para deshabilitarlo - bool finished_; // Indica si ya ha terminado - bool enabled_; // Indica si el objeto está habilitado + bool on_destination_ = false; // Indica si está en el destino + int dest_x_ = 0; // Posicion de destino en el eje X + int dest_y_ = 0; // Posicion de destino en el eje Y + int finished_counter_ = 0; // Contador para deshabilitarlo + bool finished_ = false; // Indica si ya ha terminado + bool enabled_ = false; // Indica si el objeto está habilitado // Comprueba si ha terminado void checkFinished(); @@ -29,9 +29,6 @@ public: // Destructor ~SmartSprite() = default; - // Inicializa el objeto - void init(); - // Actualiza la posición y comprueba si ha llegado a su destino void update() override; diff --git a/source/text.h b/source/text.h index 4c218a4..57e15dd 100644 --- a/source/text.h +++ b/source/text.h @@ -33,13 +33,13 @@ class Text { private: // Objetos y punteros - std::unique_ptr sprite_; // Objeto con los graficos para el texto + std::unique_ptr sprite_ = nullptr; // Objeto con los graficos para el texto // Variables - int box_width_; // Anchura de la caja de cada caracter en el png - int box_height_; // Altura de la caja de cada caracter en el png - bool fixed_width_; // Indica si el texto se ha de escribir con longitud fija en todas las letras - TextOffset offset_[128]; // Vector con las posiciones y ancho de cada letra + int box_width_ = 0; // Anchura de la caja de cada caracter en el png + int box_height_ = 0; // Altura de la caja de cada caracter en el png + bool fixed_width_ = false; // Indica si el texto se ha de escribir con longitud fija en todas las letras + TextOffset offset_[128] = {}; // Vector con las posiciones y ancho de cada letra public: // Constructor diff --git a/source/texture.cpp b/source/texture.cpp index 4191add..50b9820 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -15,13 +15,8 @@ // Constructor Texture::Texture(SDL_Renderer *renderer, const std::string &path) - : texture_(nullptr), - renderer_(renderer), - surface_(nullptr), - width_(0), - height_(0), - path_(path), - current_palette_(0) + : renderer_(renderer), + path_(path) { // Carga el fichero en la textura if (!path_.empty()) @@ -40,10 +35,10 @@ Texture::Texture(SDL_Renderer *renderer, const std::string &path) { // Crea la surface desde un fichero surface_ = loadSurface(path_); - + // Añade la propia paleta del fichero a la lista - addPaletteFromFile(path_); - //setPaletteColor(0, 0, 0x00000000); + addPaletteFromFile(path_); + // setPaletteColor(0, 0, 0x00000000); // Crea la textura, establece el BlendMode y copia la surface a la textura createBlank(width_, height_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING); diff --git a/source/texture.h b/source/texture.h index e3783a1..f184cd5 100644 --- a/source/texture.h +++ b/source/texture.h @@ -24,16 +24,16 @@ class Texture { private: // Objetos y punteros - SDL_Texture *texture_; // La textura - SDL_Renderer *renderer_; // Renderizador donde dibujar la textura - std::shared_ptr surface_; // Surface para usar imagenes en formato gif con paleta + SDL_Renderer *renderer_; // Renderizador donde dibujar la textura + SDL_Texture *texture_ = nullptr; // La textura + std::shared_ptr surface_ = nullptr; // Surface para usar imagenes en formato gif con paleta // Variables - int width_; // Ancho de la imagen - int height_; // Alto de la imagen std::string path_; // Ruta de la imagen de la textura + int width_ = 0; // Ancho de la imagen + int height_ = 0; // Alto de la imagen std::vector> palettes_; // Vector con las diferentes paletas - int current_palette_; // Indice de la paleta en uso + int current_palette_ = 0; // Indice de la paleta en uso // Crea una surface desde un fichero .gif std::shared_ptr loadSurface(const std::string &file_name); diff --git a/source/tiled_bg.cpp b/source/tiled_bg.cpp index 363b182..208cb08 100644 --- a/source/tiled_bg.cpp +++ b/source/tiled_bg.cpp @@ -11,15 +11,14 @@ // Constructor TiledBG::TiledBG(SDL_Rect pos, TiledBGMode mode) : renderer_(Screen::get()->getRenderer()), - // Crea la textura para el mosaico de fondo - canvas_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, pos_.w * 2, pos_.h * 2)), + pos_(pos), // Coloca la ventana que recorre el mosaico de fondo de manera que coincida // con el mosaico que hay pintado en el titulo al iniciar window_({128, 96, pos_.w, pos_.h}), - pos_(pos), - counter_(0), mode_(mode == TiledBGMode::RANDOM ? static_cast(rand() % 2) : mode) { + // Crea la textura para el mosaico de fondo + canvas_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, pos_.w * 2, pos_.h * 2); // Rellena la textura con el contenido fillTexture(); diff --git a/source/tiled_bg.h b/source/tiled_bg.h index 1c24b4d..3d170f9 100644 --- a/source/tiled_bg.h +++ b/source/tiled_bg.h @@ -34,7 +34,7 @@ private: // Variables SDL_Rect pos_; // Posición y tamaño del mosaico SDL_Rect window_; // Ventana visible para la textura de fondo del titulo - int counter_; // Contador + int counter_ = 0; // Contador TiledBGMode mode_; // Tipo de movimiento del mosaico double sin_[360]; // Vector con los valores del seno precalculados diff --git a/source/title.cpp b/source/title.cpp index 7d3cd1e..57d0e9e 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -32,11 +32,6 @@ Title::Title() mini_logo_texture_(Resource::get()->getTexture("logo_jailgames_mini.png")), mini_logo_sprite_(std::make_unique(mini_logo_texture_, param.game.game_area.center_x - mini_logo_texture_->getWidth() / 2, 0, mini_logo_texture_->getWidth(), mini_logo_texture_->getHeight())), define_buttons_(std::make_unique(std::move(text2_))), - counter_(0), - ticks_(0), - demo_(true), - next_section_(section::Name::GAME), - post_fade_(0), num_controllers_(Input::get()->getNumControllers()) { // Configura objetos diff --git a/source/title.h b/source/title.h index d236476..0a85380 100644 --- a/source/title.h +++ b/source/title.h @@ -9,6 +9,7 @@ #include "text.h" // for Text #include "tiled_bg.h" // for TiledBG class Input; // lines 17-17 +#include "section.h" // for Options, options, Name, name class Screen; // lines 18-18 class Texture; // lines 20-20 namespace section @@ -56,12 +57,12 @@ private: std::unique_ptr define_buttons_; // Objeto para definir los botones del joystic // Variable - int counter_; // Temporizador para la pantalla de titulo - Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa - bool demo_; // Indica si el modo demo estará activo - section::Name next_section_; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo - int post_fade_; // Opción a realizar cuando termina el fundido - int num_controllers_; // Número de mandos conectados + int counter_ = 0; // Temporizador para la pantalla de titulo + Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa + bool demo_ = true; // Indica si el modo demo estará activo + section::Name next_section_ = section::Name::GAME; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo + int post_fade_ = 0; // Opción a realizar cuando termina el fundido + int num_controllers_; // Número de mandos conectados // Actualiza las variables del objeto void update(); diff --git a/source/writer.h b/source/writer.h index 0820d22..e78bac0 100644 --- a/source/writer.h +++ b/source/writer.h @@ -12,35 +12,23 @@ private: std::shared_ptr text_; // Objeto encargado de escribir el texto // Variables - int pos_x_; // Posicion en el eje X donde empezar a escribir el texto - int pos_y_; // Posicion en el eje Y donde empezar a escribir el texto - int kerning_; // Kerning del texto, es decir, espaciado entre caracteres - std::string caption_; // El texto para escribir - int speed_; // Velocidad de escritura - int writing_counter_; // Temporizador de escritura para cada caracter - int index_; // Posición del texto que se está escribiendo - int lenght_; // Longitud de la cadena a escribir - bool completed_; // Indica si se ha escrito todo el texto - bool enabled_; // Indica si el objeto está habilitado - int enabled_counter_; // Temporizador para deshabilitar el objeto - bool finished_; // Indica si ya ha terminado + int pos_x_ = 0; // Posicion en el eje X donde empezar a escribir el texto + int pos_y_ = 0; // Posicion en el eje Y donde empezar a escribir el texto + int kerning_ = 0; // Kerning del texto, es decir, espaciado entre caracteres + std::string caption_ = std::string(); // El texto para escribir + int speed_ = 0; // Velocidad de escritura + int writing_counter_ = 0; // Temporizador de escritura para cada caracter + int index_ = 0; // Posición del texto que se está escribiendo + int lenght_ = 0; // Longitud de la cadena a escribir + bool completed_ = false; // Indica si se ha escrito todo el texto + bool enabled_ = false; // Indica si el objeto está habilitado + int enabled_counter_ = 0; // Temporizador para deshabilitar el objeto + bool finished_ = false; // Indica si ya ha terminado public: // Constructor explicit Writer(std::shared_ptr text) - : text_(text), - pos_x_(0), - pos_y_(0), - kerning_(0), - caption_(std::string()), - speed_(0), - writing_counter_(0), - index_(0), - lenght_(0), - completed_(false), - enabled_(false), - enabled_counter_(0), - finished_(false) {} + : text_(text) {} // Destructor ~Writer() = default;