Compare commits

...

2 Commits

15 changed files with 334 additions and 86 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@@ -32,7 +32,7 @@ IDIOMA
[ CANCELAR ] [ CANCELAR ]
## 11 - INSTRUCCIONES ## 11 - INSTRUCCIONES
OBJECTIU Objectiu
## 12 - INSTRUCCIONES ## 12 - INSTRUCCIONES
HAS D'EXPLOTAR HAS D'EXPLOTAR
@@ -47,7 +47,7 @@ LA DIFICULTAT AUGMENTA
A MESURA QUE VAS PUNTUANT A MESURA QUE VAS PUNTUANT
## 16 - INSTRUCCIONES ## 16 - INSTRUCCIONES
OBJECTES Objectes
## 17 - INSTRUCCIONES ## 17 - INSTRUCCIONES
1.000 PUNTS 1.000 PUNTS

View File

@@ -52,7 +52,7 @@ Director::Director(int argc, const char *argv[])
section::name = section::Name::GAME; section::name = section::Name::GAME;
section::options = section::Options::GAME_PLAY_1P; section::options = section::Options::GAME_PLAY_1P;
#elif DEBUG #elif DEBUG
section::name = section::Name::HI_SCORE_TABLE; section::name = section::Name::INSTRUCTIONS;
#else // NORMAL GAME #else // NORMAL GAME
section::name = section::Name::LOGO; section::name = section::Name::LOGO;
section::attract_mode = section::AttractMode::TITLE_TO_DEMO; section::attract_mode = section::AttractMode::TITLE_TO_DEMO;

View File

@@ -283,6 +283,13 @@ void Game::updateStage()
createMessage(paths, text->writeToTexture(caption, 1, -4)); createMessage(paths, text->writeToTexture(caption, 1, -4));
} }
} }
// Modifica el color de fondo al llegar a la Fase 10
if (Stage::number == 9)
{
background_->setColor(Color(0xdd, 0x19, 0x1d).darken());
background_->setAlpha(96);
}
} }
} }
@@ -365,6 +372,7 @@ void Game::updateGameStateCompleted()
balloon_manager_->destroyAllBalloons(); // Destruye a todos los globos balloon_manager_->destroyAllBalloons(); // Destruye a todos los globos
destroyAllItems(); // Destruye todos los items destroyAllItems(); // Destruye todos los items
Stage::power = 0; // Vuelve a dejar el poder a cero, por lo que hubiera podido subir al destruir todos los globos Stage::power = 0; // Vuelve a dejar el poder a cero, por lo que hubiera podido subir al destruir todos los globos
background_->setAlpha(0); // Elimina el tono rojo de las últimas pantallas
} }
// Comienza las celebraciones // Comienza las celebraciones
@@ -1261,7 +1269,8 @@ void Game::checkEvents()
{ {
auto_pop_balloons_ = !auto_pop_balloons_; auto_pop_balloons_ = !auto_pop_balloons_;
Notifier::get()->showText({"auto advance: " + boolToString(auto_pop_balloons_)}); Notifier::get()->showText({"auto advance: " + boolToString(auto_pop_balloons_)});
balloon_manager_->destroyAllBalloons(); if (auto_pop_balloons_)
balloon_manager_->destroyAllBalloons();
balloon_manager_->setDeployBalloons(!auto_pop_balloons_); balloon_manager_->setDeployBalloons(!auto_pop_balloons_);
break; break;
} }

View File

@@ -4,23 +4,28 @@
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888 #include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks #include <SDL2/SDL_timer.h> // Para SDL_GetTicks
#include <SDL2/SDL_video.h> // Para SDL_WINDOWEVENT_SIZE_CHANGED #include <SDL2/SDL_video.h> // Para SDL_WINDOWEVENT_SIZE_CHANGED
#include <stdlib.h> // Para rand
#include <algorithm> // Para max #include <algorithm> // Para max
#include <functional> // Para function
#include <vector> // Para vector #include <vector> // Para vector
#include "background.h" // Para Background #include "background.h" // Para Background
#include "fade.h" // Para Fade, FadeMode, FadeType #include "fade.h" // Para Fade, FadeMode, FadeType
#include "global_inputs.h" // Para check #include "global_inputs.h" // Para check, update
#include "input.h" // Para Input #include "input.h" // Para Input
#include "jail_audio.h" // Para JA_GetMusicState, JA_Music_state #include "jail_audio.h" // Para JA_GetMusicState, JA_Music_state
#include "lang.h" // Para getText #include "lang.h" // Para getText
#include "manage_hiscore_table.h" // Para HiScoreEntry #include "manage_hiscore_table.h" // Para HiScoreEntry
#include "mouse.h" // Para handleEvent
#include "options.h" // Para Options, OptionsGame, options #include "options.h" // Para Options, OptionsGame, options
#include "param.h" // Para Param, param, ParamGame, ParamFade #include "param.h" // Para Param, param, ParamGame, ParamFade
#include "path_sprite.h" // Para PathSprite, Path, PathType
#include "resource.h" // Para Resource #include "resource.h" // Para Resource
#include "screen.h" // Para Screen #include "screen.h" // Para Screen
#include "section.h" // Para Name, name, Options, options #include "section.h" // Para Name, name, Options, options, Attr...
#include "text.h" // Para Text, TEXT_CENTER, TEXT_SHADOW #include "sprite.h" // Para Sprite
#include "utils.h" // Para Color, Zone, fade_color, orange_color #include "text.h" // Para Text, TEXT_COLOR, TEXT_SHADOW
#include "mouse.h" #include "texture.h" // Para Texture
#include "utils.h" // Para Color, easeOutQuint, fade_color
// Constructor // Constructor
HiScoreTable::HiScoreTable() HiScoreTable::HiScoreTable()
@@ -28,30 +33,17 @@ HiScoreTable::HiScoreTable()
backbuffer_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)), backbuffer_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
fade_(std::make_unique<Fade>()), fade_(std::make_unique<Fade>()),
background_(std::make_unique<Background>()), background_(std::make_unique<Background>()),
text_(Resource::get()->getText("smb2")),
counter_(0), counter_(0),
ticks_(0), ticks_(0),
view_area_({0, 0, param.game.width, param.game.height}), view_area_({0, 0, param.game.width, param.game.height}),
fade_mode_(FadeMode::IN) fade_mode_(FadeMode::IN),
background_fade_color_(Color(0, 0, 0))
{ {
// Inicializa el resto de variables // Inicializa el resto
section::name = section::Name::HI_SCORE_TABLE; section::name = section::Name::HI_SCORE_TABLE;
// Inicializa objetos
SDL_SetTextureBlendMode(backbuffer_, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(backbuffer_, SDL_BLENDMODE_BLEND);
background_->setPos(param.game.game_area.rect); initFade();
background_->setCloudsSpeed(-0.1f); initBackground();
background_->setGradientNumber(1);
background_->setTransition(0.8f);
background_->setSunProgression(1.0f);
background_->setMoonProgression(0.6f);
fade_->setColor(fade_color.r, fade_color.g, fade_color.b);
fade_->setType(FadeType::RANDOM_SQUARE);
fade_->setPostDuration(param.fade.post_duration);
fade_->setMode(fade_mode_);
fade_->activate();
// Crea los sprites con los textos
createSprites(); createSprites();
} }
@@ -97,7 +89,7 @@ void HiScoreTable::update()
if (counter_ == 150) if (counter_ == 150)
{ {
background_->setColor(Color(0, 0, 0)); background_->setColor(background_fade_color_.darken());
background_->setAlpha(96); background_->setAlpha(96);
} }
@@ -161,8 +153,6 @@ void HiScoreTable::render()
// Recarga todas las texturas // Recarga todas las texturas
void HiScoreTable::reloadTextures() void HiScoreTable::reloadTextures()
{ {
text_->reLoadTexture();
fillTexture();
} }
// Comprueba los eventos // Comprueba los eventos
@@ -268,6 +258,9 @@ std::string HiScoreTable::format(int number)
// Crea los sprites con los textos // Crea los sprites con los textos
void HiScoreTable::createSprites() void HiScoreTable::createSprites()
{ {
auto header_text = Resource::get()->getText("04b_25");
auto entry_text = Resource::get()->getText("smb2");
// Obtiene el tamaño de la textura // Obtiene el tamaño de la textura
int backbuffer_width; int backbuffer_width;
int backbuffer_height; int backbuffer_height;
@@ -276,32 +269,34 @@ void HiScoreTable::createSprites()
// Hay 27 letras - 7 de puntos quedan 20 caracteres 20 - name_lenght 0 num_dots // Hay 27 letras - 7 de puntos quedan 20 caracteres 20 - name_lenght 0 num_dots
constexpr int max_names = 10; constexpr int max_names = 10;
constexpr int space_between_header = 32; constexpr int space_between_header = 32;
const int space_between_lines = text_->getCharacterSize() * 2; const int space_between_lines = entry_text->getCharacterSize() * 2;
const int size = space_between_header + space_between_lines * (max_names - 1) + text_->getCharacterSize(); const int size = space_between_header + space_between_lines * (max_names - 1) + entry_text->getCharacterSize();
const int first_line = (param.game.height - size) / 2; const int first_line = (param.game.height - size) / 2;
// Crea el sprite para el texto de cabecera // Crea el sprite para el texto de cabecera
header_ = std::make_unique<Sprite>(text_->writeDXToTexture(TEXT_COLOR | TEXT_SHADOW, lang::getText(42), 1, orange_color, 1, shdw_txt_color)); header_ = std::make_unique<Sprite>(header_text->writeDXToTexture(TEXT_COLOR, lang::getText(42), -2, background_fade_color_.getInverse().lighten(25)));
header_->setPosition(param.game.game_area.center_x - (header_->getWidth() / 2), first_line); header_->setPosition(param.game.game_area.center_x - (header_->getWidth() / 2), first_line);
// Crea los sprites para las entradas en la tabla de puntuaciones // Crea los sprites para las entradas en la tabla de puntuaciones
const int animation = rand() % 4;
for (int i = 0; i < max_names; ++i) for (int i = 0; i < max_names; ++i)
{ {
const auto name_lenght = options.game.hi_score_table.at(i).name.length(); const auto table_position = (i + 1 >= 10) ? format(i + 1) + ". " : " " + format(i + 1) + ". ";
const auto score = format(options.game.hi_score_table.at(i).score); const auto score = format(options.game.hi_score_table.at(i).score);
const auto score_lenght = score.size(); const auto num_dots = 25 - table_position.size() - options.game.hi_score_table.at(i).name.size() - score.size();
const auto num_dots = 25 - name_lenght - score_lenght;
std::string dots; std::string dots;
for (int j = 0; j < (int)num_dots; ++j) for (int j = 0; j < (int)num_dots; ++j)
{ {
dots = dots + "."; dots = dots + ".";
} }
const auto line = options.game.hi_score_table.at(i).name + dots + score; const auto line = table_position + options.game.hi_score_table.at(i).name + dots + score;
entry_names_.emplace_back(std::make_shared<PathSprite>(text_->writeDXToTexture(TEXT_SHADOW, line, 1, orange_color, 1, shdw_txt_color))); entry_names_.emplace_back(std::make_shared<PathSprite>(entry_text->writeDXToTexture(TEXT_SHADOW, line, 1, orange_color, 1, shdw_txt_color)));
if (false) switch (animation)
{ {
if (i % 1 == 0) case 0: // Ambos lados alternativamente
{
if (i % 2 == 0)
{ {
entry_names_.back()->addPath( entry_names_.back()->addPath(
-entry_names_.back()->getWidth(), -entry_names_.back()->getWidth(),
@@ -325,9 +320,38 @@ void HiScoreTable::createSprites()
0); 0);
entry_names_.back()->setPosition(backbuffer_width, 0); entry_names_.back()->setPosition(backbuffer_width, 0);
} }
break;
} }
if (true) case 1: // Entran por la izquierda
{
entry_names_.back()->addPath(
-entry_names_.back()->getWidth(),
(backbuffer_width - entry_names_.back()->getWidth()) / 2,
PathType::HORIZONTAL,
(i * space_between_lines) + first_line + space_between_header,
80,
easeOutQuint,
0);
entry_names_.back()->setPosition(-entry_names_.back()->getWidth(), 0);
break;
}
case 2: // Entran por la derecha
{
entry_names_.back()->addPath(
backbuffer_width,
(backbuffer_width - entry_names_.back()->getWidth()) / 2,
PathType::HORIZONTAL,
(i * space_between_lines) + first_line + space_between_header,
80,
easeOutQuint,
0);
entry_names_.back()->setPosition(backbuffer_width, 0);
break;
}
case 3: // Entran desde la parte inferior
{ {
entry_names_.back()->addPath( entry_names_.back()->addPath(
backbuffer_height, backbuffer_height,
@@ -339,14 +363,18 @@ void HiScoreTable::createSprites()
0); 0);
entry_names_.back()->setPosition(0, backbuffer_height); entry_names_.back()->setPosition(0, backbuffer_height);
} }
default:
break;
}
} }
} }
// Actualiza las posiciones de los sprites de texto // Actualiza las posiciones de los sprites de texto
void HiScoreTable::updateSprites() void HiScoreTable::updateSprites()
{ {
constexpr int init_counter = 220; constexpr int init_counter = 190;
const int counter_between_entries = text_->getCharacterSize() * 2; const int counter_between_entries = 16;
if (counter_ >= init_counter) if (counter_ >= init_counter)
{ {
const int counter2 = counter_ - init_counter; const int counter2 = counter_ - init_counter;
@@ -363,4 +391,59 @@ void HiScoreTable::updateSprites()
{ {
entry->update(); entry->update();
} }
}
// Inicializa el fade
void HiScoreTable::initFade()
{
fade_->setColor(fade_color.r, fade_color.g, fade_color.b);
fade_->setType(FadeType::RANDOM_SQUARE);
fade_->setPostDuration(param.fade.post_duration);
fade_->setMode(fade_mode_);
fade_->activate();
}
// Inicializa el fondo
void HiScoreTable::initBackground()
{
background_->setPos(param.game.game_area.rect);
background_->setCloudsSpeed(-0.1f);
const int lucky = rand() % 3;
//const int lucky = 2;
switch (lucky)
{
case 0: // Fondo verde
{
background_->setGradientNumber(2);
background_->setTransition(0.0f);
background_->setSunProgression(1.0f);
background_->setMoonProgression(0.4f);
background_fade_color_ = Color(0x00, 0x79, 0x6b);
break;
}
case 1: // Fondo naranja
{
background_->setGradientNumber(1);
background_->setTransition(0.0f);
background_->setSunProgression(0.65f);
background_->setMoonProgression(0.0f);
background_fade_color_ = Color(0xff, 0x6b, 0x97);
break;
}
case 2: // Fondo azul
{
background_->setGradientNumber(0);
background_->setTransition(0.0f);
background_->setSunProgression(0.0f);
background_->setMoonProgression(0.0f);
background_fade_color_ = Color(0x02, 0x88, 0xd1);
break;
}
default:
break;
}
} }

View File

@@ -1,16 +1,18 @@
#pragma once #pragma once
#include <SDL2/SDL_rect.h> // para SDL_Rect #include <SDL2/SDL_rect.h> // Para SDL_Rect
#include <SDL2/SDL_render.h> // para SDL_Renderer, SDL_Texture #include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_Texture
#include <SDL2/SDL_stdinc.h> // para Uint16, Uint32, Uint8 #include <SDL2/SDL_stdinc.h> // Para Uint16, Uint32, Uint8
#include <memory> // para unique_ptr #include <memory> // Para unique_ptr, shared_ptr
#include <string> // para string #include <string> // Para string
#include "sprite.h" #include <vector> // Para vector
#include "path_sprite.h" #include "utils.h"
class Background; // lines 8-8 class Background; // lines 10-10
class Fade; // lines 9-9 class Fade; // lines 11-11
class Text; // lines 10-10 class PathSprite;
enum class FadeMode : Uint8; // lines 11-11 class Sprite;
enum class FadeMode : Uint8; // lines 13-13
struct Path;
/* /*
Esta clase gestiona un estado del programa. Se encarga de mostrar la tabla con las puntuaciones Esta clase gestiona un estado del programa. Se encarga de mostrar la tabla con las puntuaciones
@@ -35,16 +37,16 @@ private:
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
std::unique_ptr<Background> background_; // Objeto para dibujar el fondo del juego std::unique_ptr<Background> background_; // Objeto para dibujar el fondo del juego
std::shared_ptr<Text> text_; // Objeto para escribir texto
std::unique_ptr<Sprite> header_; // Sprite con la cabecera del texto std::unique_ptr<Sprite> header_; // Sprite con la cabecera del texto
std::vector<std::shared_ptr<PathSprite>> entry_names_; // Lista con los spritres de cada uno de los nombres de la tabla de records std::vector<std::shared_ptr<PathSprite>> entry_names_; // Lista con los spritres de cada uno de los nombres de la tabla de records
std::vector<Path> paths_; // Vector con los recorridos precalculados std::vector<Path> paths_; // Vector con los recorridos precalculados
// Variables // Variables
Uint16 counter_; // Contador Uint16 counter_ = 0; // Contador
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
SDL_Rect view_area_; // Parte de la textura que se muestra en pantalla SDL_Rect view_area_; // Parte de la textura que se muestra en pantalla
FadeMode fade_mode_; // Modo de fade a utilizar FadeMode fade_mode_; // Modo de fade a utilizar
Color background_fade_color_; // Color de atenuación del fondo
// Actualiza las variables // Actualiza las variables
void update(); void update();
@@ -76,6 +78,12 @@ private:
// Actualiza las posiciones de los sprites de texto // Actualiza las posiciones de los sprites de texto
void updateSprites(); void updateSprites();
// Inicializa el fade
void initFade();
// Inicializa el fondo
void initBackground();
public: public:
// Constructor // Constructor
HiScoreTable(); HiScoreTable();

View File

@@ -22,6 +22,10 @@
#include "utils.h" // Para Color, shdw_txt_color, Zone, no_color #include "utils.h" // Para Color, shdw_txt_color, Zone, no_color
#include "mouse.h" #include "mouse.h"
#include <SDL2/SDL.h>
#include <vector>
#include <cmath>
// Constructor // Constructor
Instructions::Instructions() Instructions::Instructions()
: renderer_(Screen::get()->getRenderer()), : renderer_(Screen::get()->getRenderer()),
@@ -46,6 +50,9 @@ Instructions::Instructions()
fade_->setMode(FadeMode::IN); fade_->setMode(FadeMode::IN);
fade_->activate(); fade_->activate();
// Inicializa las líneas con un retraso progresivo de 50 ms
lines_ = initializeLines(256);
// Rellena la textura de texto // Rellena la textura de texto
fillTexture(); fillTexture();
@@ -159,7 +166,6 @@ void Instructions::fillTexture()
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, anchor2, lang::getText(16), 1, orange_color, 1, shdw_txt_color); text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, anchor2, lang::getText(16), 1, orange_color, 1, shdw_txt_color);
const int anchor3 = anchor2 + space_post_header; const int anchor3 = anchor2 + space_post_header;
// const int anchor4 = anchor3 + ((param.game.item_size + text->getCharacterSize()) / 2);
text_->writeShadowed(anchor_item + desp_x, anchor3 + space_between_item_lines * 0, lang::getText(17), shdw_txt_color); text_->writeShadowed(anchor_item + desp_x, anchor3 + space_between_item_lines * 0, lang::getText(17), shdw_txt_color);
text_->writeShadowed(anchor_item + desp_x, anchor3 + space_between_item_lines * 1, lang::getText(18), shdw_txt_color); text_->writeShadowed(anchor_item + desp_x, anchor3 + space_between_item_lines * 1, lang::getText(18), shdw_txt_color);
text_->writeShadowed(anchor_item + desp_x, anchor3 + space_between_item_lines * 2, lang::getText(19), shdw_txt_color); text_->writeShadowed(anchor_item + desp_x, anchor3 + space_between_item_lines * 2, lang::getText(19), shdw_txt_color);
@@ -226,14 +232,36 @@ void Instructions::update()
// Actualiza los sprites // Actualiza los sprites
updateSprites(); updateSprites();
// Establece la ventana del backbuffer
view_.y = std::max(0, param.game.height - counter_ + 100);
// Verifica si view_.y == 0 y gestiona el temporizador
if (view_.y == 0)
{
if (!start_delay_triggered_)
{
// Activa el temporizador si no ha sido activado
start_delay_triggered_ = true;
start_delay_time_ = SDL_GetTicks();
}
else if (SDL_GetTicks() - start_delay_time_ >= 4000)
{
// Han pasado tres segundos, mover líneas
all_lines_off_screen_ = moveLines(lines_, 320, 1.0f, 5);
}
}
// Actualiza el mosaico de fondo // Actualiza el mosaico de fondo
tiled_bg_->update(); tiled_bg_->update();
// Actualiza el objeto "fade" // Actualiza el objeto "fade"
fade_->update(); fade_->update();
// Rellena el backbuffer
fillBackbuffer();
// Comprueba si el contador ha llegado al final // Comprueba si el contador ha llegado al final
if (counter_ == counter_end_) if (all_lines_off_screen_)
{ {
section::name = section::Name::TITLE; section::name = section::Name::TITLE;
section::options = section::Options::TITLE_1; section::options = section::Options::TITLE_1;
@@ -244,9 +272,6 @@ void Instructions::update()
// Pinta en pantalla // Pinta en pantalla
void Instructions::render() void Instructions::render()
{ {
// Rellena el backbuffer
fillBackbuffer();
// Prepara para empezar a dibujar en la textura de juego // Prepara para empezar a dibujar en la textura de juego
Screen::get()->start(); Screen::get()->start();
@@ -256,11 +281,11 @@ void Instructions::render()
// Dibuja el mosacico de fondo // Dibuja el mosacico de fondo
tiled_bg_->render(); tiled_bg_->render();
// Establece la ventana del backbuffer
view_.y = std::max(0, param.game.height - counter_ + 100);
// Copia la textura y el backbuffer al renderizador // Copia la textura y el backbuffer al renderizador
SDL_RenderCopy(renderer_, backbuffer_, nullptr, &view_); if (view_.y == 0)
renderLines(renderer_, backbuffer_, lines_);
else
SDL_RenderCopy(renderer_, backbuffer_, nullptr, &view_);
fade_->render(); fade_->render();
@@ -335,4 +360,61 @@ void Instructions::run()
checkEvents(); // Tiene que ir antes del render checkEvents(); // Tiene que ir antes del render
render(); render();
} }
}
// Método para inicializar las líneas
std::vector<Line> Instructions::initializeLines(int height)
{
std::vector<Line> lines;
for (int y = 0; y < height; y++)
{
int direction = (y % 2 == 0) ? -1 : 1; // Pares a la izquierda, impares a la derecha
lines.emplace_back(y, 0.0f, direction);
}
return lines;
}
// Método para mover las líneas con suavizado
bool Instructions::moveLines(std::vector<Line> &lines, int width, float duration, Uint32 startDelay)
{
Uint32 currentTime = SDL_GetTicks();
bool allLinesOffScreen = true;
for (auto &line : lines)
{
// Establecer startTime en el primer cuadro de animación
if (line.startTime == 0)
{
line.startTime = currentTime + line.y * startDelay;
}
float elapsedTime = (currentTime - line.startTime) / 1000.0f; // Convertir a segundos
if (elapsedTime < 0)
{
allLinesOffScreen = false; // Si aún no se debe mover esta línea, no están todas fuera de pantalla
continue;
}
if (elapsedTime >= duration)
{
continue; // Si la línea ha salido de los límites, no la muevas más
}
float t = elapsedTime / duration;
float smoothFactor = easeInOutQuint(t);
line.x = line.direction * smoothFactor * width;
allLinesOffScreen = false; // Si alguna línea aún se está moviendo, no están todas fuera de pantalla
}
return allLinesOffScreen;
}
// Método para renderizar las líneas
void Instructions::renderLines(SDL_Renderer *renderer, SDL_Texture *texture, const std::vector<Line> &lines)
{
for (const auto &line : lines)
{
SDL_Rect srcRect = {0, line.y, 320, 1};
SDL_Rect dstRect = {static_cast<int>(line.x), line.y, 320, 1};
SDL_RenderCopy(renderer, texture, &srcRect, &dstRect);
}
} }

View File

@@ -24,6 +24,19 @@ class TiledBG; // lines 12-12
por la pantalla sobre el mosaico de fondo (gestionado por el correspondiente objeto) por la pantalla sobre el mosaico de fondo (gestionado por el correspondiente objeto)
*/ */
// Estructura para almacenar información de línea
struct Line
{
int y; // Coordenada Y de la línea
float x; // Coordenada X inicial (usamos float para mayor precisión en el suavizado)
int direction; // Dirección de movimiento: -1 para izquierda, 1 para derecha
Uint32 startTime; // Tiempo de inicio del movimiento
// Constructor de Line
Line(int y, float x, int direction)
: y(y), x(x), direction(direction), startTime(0) {}
};
// Clase Instructions // Clase Instructions
class Instructions class Instructions
{ {
@@ -40,12 +53,15 @@ private:
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
// Variables // Variables
int counter_ = 0; // Contador int counter_ = 0; // Contador para manejar el progreso en la pantalla de instrucciones
int counter_end_ = 700; // Valor final para el contador Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa SDL_Rect view_; // Vista del backbuffer que se va a mostrar por pantalla
SDL_Rect view_; // Vista del backbuffer que se va amostrar por pantalla SDL_Point sprite_pos_ = {0, 0}; // Posición del primer sprite en la lista
SDL_Point sprite_pos_ = {0, 0}; // Posición del primer sprite int item_space_ = 2; // Espacio entre los items en pantalla
int item_space_ = 2; // Espacio entre los items std::vector<Line> lines_; // Vector que contiene las líneas animadas en la pantalla
bool all_lines_off_screen_ = false; // Indica si todas las líneas han salido de la pantalla
Uint32 start_delay_time_ = 0; // Tiempo de inicio del retraso para mover las líneas
bool start_delay_triggered_ = false; // Bandera para determinar si el retraso ha comenzado
// Actualiza las variables // Actualiza las variables
void update(); void update();
@@ -74,6 +90,15 @@ private:
// Recarga todas las texturas // Recarga todas las texturas
void reloadTextures(); void reloadTextures();
// Método para inicializar las líneas
std::vector<Line> initializeLines(int height);
// Método para mover las líneas
bool moveLines(std::vector<Line> &lines, int width, float duration, Uint32 startDelay);
// Método para renderizar las líneas
void renderLines(SDL_Renderer *renderer, SDL_Texture *texture, const std::vector<Line> &lines);
public: public:
// Constructor // Constructor
Instructions(); Instructions();

View File

@@ -2,6 +2,7 @@
#include "tabe.h" #include "tabe.h"
#include <SDL2/SDL_render.h> // Para SDL_FLIP_HORIZONTAL, SDL_FLIP_NONE #include <SDL2/SDL_render.h> // Para SDL_FLIP_HORIZONTAL, SDL_FLIP_NONE
#include <stdlib.h> // Para rand, abs #include <stdlib.h> // Para rand, abs
#include <algorithm> // Para max
#include "jail_audio.h" // Para JA_PlaySound #include "jail_audio.h" // Para JA_PlaySound
#include "param.h" // Para Param, ParamGame, param #include "param.h" // Para Param, ParamGame, param
#include "resource.h" // Para Resource #include "resource.h" // Para Resource

View File

@@ -1,7 +1,8 @@
#pragma once #pragma once
#include "animated_sprite.h" #include <SDL2/SDL_rect.h> // Para SDL_Rect
#include <memory> #include <memory> // Para unique_ptr
#include "animated_sprite.h" // Para AnimatedSprite
enum class TabeDirection : int enum class TabeDirection : int
{ {

View File

@@ -178,7 +178,7 @@ std::shared_ptr<Texture> Text::writeDXToTexture(Uint8 flags, const std::string &
{ {
auto renderer = Screen::get()->getRenderer(); auto renderer = Screen::get()->getRenderer();
auto texture = std::make_shared<Texture>(renderer); auto texture = std::make_shared<Texture>(renderer);
auto width = Text::lenght(text, kerning); auto width = Text::lenght(text, kerning) + shadow_distance;
auto height = box_height_ + shadow_distance; auto height = box_height_ + shadow_distance;
auto temp = SDL_GetRenderTarget(renderer); auto temp = SDL_GetRenderTarget(renderer);
texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET); texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);

View File

@@ -164,6 +164,10 @@ void Texture::setColor(Uint8 red, Uint8 green, Uint8 blue)
{ {
SDL_SetTextureColorMod(texture_, red, green, blue); SDL_SetTextureColorMod(texture_, red, green, blue);
} }
void Texture::setColor(Color color)
{
SDL_SetTextureColorMod(texture_, color.r, color.g, color.b);
}
// Establece el blending // Establece el blending
void Texture::setBlendMode(SDL_BlendMode blending) void Texture::setBlendMode(SDL_BlendMode blending)

View File

@@ -1,13 +1,14 @@
#pragma once #pragma once
#include <SDL2/SDL_blendmode.h> // para SDL_BlendMode #include <SDL2/SDL_blendmode.h> // Para SDL_BlendMode
#include <SDL2/SDL_pixels.h> // para SDL_PIXELFORMAT_RGBA8888, SDL_PixelF... #include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888, SDL_PixelF...
#include <SDL2/SDL_rect.h> // para SDL_Point, SDL_Rect #include <SDL2/SDL_rect.h> // Para SDL_Point, SDL_Rect
#include <SDL2/SDL_render.h> // para SDL_Renderer, SDL_FLIP_NONE, SDL_TEX... #include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_FLIP_NONE, SDL_TEX...
#include <SDL2/SDL_stdinc.h> // para Uint8, Uint32, Uint16 #include <SDL2/SDL_stdinc.h> // Para Uint8, Uint16, Uint32
#include <string> // para string, basic_string #include <memory> // Para shared_ptr
#include <vector> // para vector #include <string> // Para string
#include <memory> #include <vector> // Para vector
struct Color;
// Definiciones de tipos // Definiciones de tipos
struct Surface struct Surface
@@ -65,6 +66,7 @@ public:
// 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);
void setColor(Color color);
// Establece el blending // Establece el blending
void setBlendMode(SDL_BlendMode blending); void setBlendMode(SDL_BlendMode blending);

View File

@@ -23,6 +23,7 @@ const Color scoreboard_hard_color = Color(0x76, 0x42, 0x8A);
const Color flash_color = Color(0xFF, 0xFF, 0xFF); const Color flash_color = Color(0xFF, 0xFF, 0xFF);
const Color fade_color = Color(0x27, 0x27, 0x36); const Color fade_color = Color(0x27, 0x27, 0x36);
const Color orange_color = Color(0xFF, 0x7A, 0x00); const Color orange_color = Color(0xFF, 0x7A, 0x00);
const Color orange_soft_color = Color(0xFF, 0xA0, 0x33);
// 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)
@@ -212,6 +213,12 @@ double easeInOutSine(double t)
return -0.5 * (std::cos(M_PI * t) - 1); return -0.5 * (std::cos(M_PI * t) - 1);
} }
// Función de suavizado
double easeInOut(double t)
{
return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
}
// Comprueba si una vector contiene una cadena // Comprueba si una vector contiene una cadena
bool stringInVector(const std::vector<std::string> &vec, const std::string &str) bool stringInVector(const std::vector<std::string> &vec, const std::string &str)
{ {

View File

@@ -44,6 +44,30 @@ struct Color
Uint8 r, g, b; Uint8 r, g, b;
constexpr Color() : r(0), g(0), b(0) {} constexpr Color() : r(0), g(0), b(0) {}
explicit constexpr Color(int red, int green, int blue) : r(red), g(green), b(blue) {} explicit constexpr Color(int red, int green, int blue) : r(red), g(green), b(blue) {}
// Método para obtener el color inverso
constexpr Color getInverse() const
{
return Color(255 - r, 255 - g, 255 - b);
}
// Método para aclarar el color
Color lighten(int amount = 50) const
{
return Color(
std::min(255, r + amount),
std::min(255, g + amount),
std::min(255, b + amount));
}
// Método para oscurecer el color
Color darken(int amount = 50) const
{
return Color(
std::max(0, r - amount),
std::max(0, g - amount),
std::max(0, b - amount));
}
}; };
// Posiciones de las notificaciones // Posiciones de las notificaciones
@@ -146,6 +170,7 @@ double easeInOutQuint(double t);
double easeInQuad(double t); double easeInQuad(double t);
double easeOutQuad(double t); double easeOutQuad(double t);
double easeInOutSine(double t); double easeInOutSine(double t);
double easeInOut(double t);
// Comprueba si una vector contiene una cadena // Comprueba si una vector contiene una cadena
bool stringInVector(const std::vector<std::string> &vec, const std::string &str); bool stringInVector(const std::vector<std::string> &vec, const std::string &str);
@@ -177,4 +202,5 @@ extern const Color scoreboard_normal_color;
extern const Color scoreboard_hard_color; extern const Color scoreboard_hard_color;
extern const Color flash_color; extern const Color flash_color;
extern const Color fade_color; extern const Color fade_color;
extern const Color orange_color; extern const Color orange_color;
extern const Color orange_soft_color;