Treballant en la intro
This commit is contained in:
@@ -9,9 +9,6 @@
|
|||||||
#include <SDL2/SDL_scancode.h> // Para SDL_SCANCODE_0, SDL_SCANCODE_DOWN
|
#include <SDL2/SDL_scancode.h> // Para SDL_SCANCODE_0, SDL_SCANCODE_DOWN
|
||||||
#include <SDL2/SDL_stdinc.h> // Para SDL_bool, Uint32
|
#include <SDL2/SDL_stdinc.h> // Para SDL_bool, Uint32
|
||||||
#include <errno.h> // Para errno, EEXIST, EACCES, ENAMETOO...
|
#include <errno.h> // Para errno, EEXIST, EACCES, ENAMETOO...
|
||||||
#ifndef _WIN32
|
|
||||||
#include <pwd.h> // Para getpwuid, passwd
|
|
||||||
#endif
|
|
||||||
#include <stdio.h> // Para printf, perror
|
#include <stdio.h> // Para printf, perror
|
||||||
#include <sys/stat.h> // Para mkdir, stat, S_IRWXU
|
#include <sys/stat.h> // Para mkdir, stat, S_IRWXU
|
||||||
#include <unistd.h> // Para getuid
|
#include <unistd.h> // Para getuid
|
||||||
@@ -45,6 +42,10 @@
|
|||||||
#include "title.h" // Para Title
|
#include "title.h" // Para Title
|
||||||
#include "utils.h" // Para Overrides, overrides
|
#include "utils.h" // Para Overrides, overrides
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
#include <pwd.h> // Para getpwuid, passwd
|
||||||
|
#endif
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Director::Director(int argc, const char *argv[])
|
Director::Director(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
@@ -52,7 +53,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::LOGO;
|
section::name = section::Name::INTRO;
|
||||||
#else // NORMAL GAME
|
#else // NORMAL GAME
|
||||||
section::name = section::Name::LOGO;
|
section::name = section::Name::LOGO;
|
||||||
section::options = section::Options::NONE;
|
section::options = section::Options::NONE;
|
||||||
|
|||||||
@@ -17,10 +17,12 @@
|
|||||||
#include "utils.h" // Para Zone, BLOCK, Color, bg_color
|
#include "utils.h" // Para Zone, BLOCK, Color, bg_color
|
||||||
#include "writer.h" // Para Writer
|
#include "writer.h" // Para Writer
|
||||||
#include "global_events.h"
|
#include "global_events.h"
|
||||||
|
#include "tiled_bg.h"
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Intro::Intro()
|
Intro::Intro()
|
||||||
|
: tiled_bg_(std::make_unique<TiledBG>(param.game.game_area.rect, TiledBGMode::DIAGONAL))
|
||||||
{
|
{
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
section::name = section::Name::INTRO;
|
section::name = section::Name::INTRO;
|
||||||
@@ -31,6 +33,9 @@ Intro::Intro()
|
|||||||
|
|
||||||
// Inicializa los textos
|
// Inicializa los textos
|
||||||
initTexts();
|
initTexts();
|
||||||
|
|
||||||
|
// Configura el fondo
|
||||||
|
tiled_bg_->setSpeed(0.3f);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba los eventos
|
// Comprueba los eventos
|
||||||
@@ -61,6 +66,7 @@ void Intro::updateScenes()
|
|||||||
if (sprites_.at(0)->hasFinished() && !texts_.at(0)->hasFinished())
|
if (sprites_.at(0)->hasFinished() && !texts_.at(0)->hasFinished())
|
||||||
{
|
{
|
||||||
texts_.at(0)->setEnabled(true);
|
texts_.at(0)->setEnabled(true);
|
||||||
|
tiled_bg_->stopGracefully();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Segundo texto de la primera imagen
|
// Segundo texto de la primera imagen
|
||||||
@@ -165,7 +171,7 @@ void Intro::updateScenes()
|
|||||||
shadow_sprites_.at(4)->enable();
|
shadow_sprites_.at(4)->enable();
|
||||||
|
|
||||||
// Primer texto de la quinta imagen
|
// Primer texto de la quinta imagen
|
||||||
if (sprites_.at(4)->hasFinished() && !texts_.at(7)->hasFinished())
|
if (!texts_.at(7)->hasFinished())
|
||||||
{
|
{
|
||||||
texts_.at(7)->setEnabled(true);
|
texts_.at(7)->setEnabled(true);
|
||||||
}
|
}
|
||||||
@@ -189,6 +195,7 @@ void Intro::updateScenes()
|
|||||||
if (!texts_.at(8)->hasFinished())
|
if (!texts_.at(8)->hasFinished())
|
||||||
{
|
{
|
||||||
texts_.at(8)->setEnabled(true);
|
texts_.at(8)->setEnabled(true);
|
||||||
|
tiled_bg_->stopGracefully();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Acaba el último texto
|
// Acaba el último texto
|
||||||
@@ -216,8 +223,8 @@ void Intro::update()
|
|||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks_ = SDL_GetTicks();
|
ticks_ = SDL_GetTicks();
|
||||||
|
|
||||||
// Actualiza el objeto screen
|
// Actualiza el fondo
|
||||||
Screen::get()->update();
|
tiled_bg_->update();
|
||||||
|
|
||||||
// Actualiza los sprites
|
// Actualiza los sprites
|
||||||
updateSprites();
|
updateSprites();
|
||||||
@@ -228,6 +235,9 @@ void Intro::update()
|
|||||||
// Actualiza las escenas de la intro
|
// Actualiza las escenas de la intro
|
||||||
updateScenes();
|
updateScenes();
|
||||||
|
|
||||||
|
// Actualiza el objeto screen
|
||||||
|
Screen::get()->update();
|
||||||
|
|
||||||
// Actualiza las variables de globalInputs
|
// Actualiza las variables de globalInputs
|
||||||
globalInputs::update();
|
globalInputs::update();
|
||||||
}
|
}
|
||||||
@@ -242,6 +252,12 @@ void Intro::render()
|
|||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
Screen::get()->clean(bg_color);
|
Screen::get()->clean(bg_color);
|
||||||
|
|
||||||
|
// Dibuja el fondo
|
||||||
|
tiled_bg_->render();
|
||||||
|
|
||||||
|
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 128);
|
||||||
|
SDL_RenderFillRect(Screen::get()->getRenderer(), ¶m.game.game_area.rect);
|
||||||
|
|
||||||
// Dibuja los sprites
|
// Dibuja los sprites
|
||||||
renderSprites();
|
renderSprites();
|
||||||
|
|
||||||
@@ -295,7 +311,7 @@ void Intro::initSprites()
|
|||||||
sprites_.push_back(std::move(sprite));
|
sprites_.push_back(std::move(sprite));
|
||||||
}
|
}
|
||||||
|
|
||||||
sprites_.at(0)->addPath(-SPRITE_WIDTH, X_DEST, PathType::HORIZONTAL, Y_DEST, 100, easeInOutExpo, 0);
|
sprites_.at(0)->addPath(-SPRITE_WIDTH - 10, X_DEST, PathType::HORIZONTAL, Y_DEST, 100, easeInOutExpo, 0);
|
||||||
sprites_.at(1)->addPath(param.game.width, X_DEST, PathType::HORIZONTAL, Y_DEST, 100, easeOutBounce, 0);
|
sprites_.at(1)->addPath(param.game.width, X_DEST, PathType::HORIZONTAL, Y_DEST, 100, easeOutBounce, 0);
|
||||||
sprites_.at(2)->addPath(-SPRITE_HEIGHT, Y_DEST, PathType::VERTICAL, X_DEST, 40, easeOutQuint, 0);
|
sprites_.at(2)->addPath(-SPRITE_HEIGHT, Y_DEST, PathType::VERTICAL, X_DEST, 40, easeOutQuint, 0);
|
||||||
sprites_.at(3)->addPath(param.game.height, Y_DEST, PathType::VERTICAL, X_DEST, 800, easeOutQuint, 0);
|
sprites_.at(3)->addPath(param.game.height, Y_DEST, PathType::VERTICAL, X_DEST, 800, easeOutQuint, 0);
|
||||||
@@ -328,16 +344,12 @@ void Intro::initSprites()
|
|||||||
SDL_Rect rect = {BORDER / 2, BORDER / 2, SPRITE_WIDTH, SPRITE_HEIGHT};
|
SDL_Rect rect = {BORDER / 2, BORDER / 2, SPRITE_WIDTH, SPRITE_HEIGHT};
|
||||||
auto texture = Resource::get()->getTexture(TEXTURE_LIST.at(i))->getSDLTexture();
|
auto texture = Resource::get()->getTexture(TEXTURE_LIST.at(i))->getSDLTexture();
|
||||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_MOD);
|
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_MOD);
|
||||||
//SDL_SetTextureAlphaMod(texture, 128);
|
|
||||||
SDL_RenderCopy(Screen::get()->getRenderer(), texture, nullptr, &rect);
|
SDL_RenderCopy(Screen::get()->getRenderer(), texture, nullptr, &rect);
|
||||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_NONE);
|
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_NONE);
|
||||||
|
|
||||||
// SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0x54, 0x31, 0x49, 0xFF);
|
shadow_texture->setAlpha(160);
|
||||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0xFF, 0xFF, 0xFF, 192);
|
|
||||||
//SDL_RenderFillRect(Screen::get()->getRenderer(), &rect);
|
|
||||||
|
|
||||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), temp);
|
SDL_SetRenderTarget(Screen::get()->getRenderer(), temp);
|
||||||
|
|
||||||
shadow_textures.push_back(shadow_texture);
|
shadow_textures.push_back(shadow_texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,7 +363,7 @@ void Intro::initSprites()
|
|||||||
shadow_sprites_.push_back(std::move(sprite));
|
shadow_sprites_.push_back(std::move(sprite));
|
||||||
}
|
}
|
||||||
|
|
||||||
shadow_sprites_.at(0)->addPath(param.game.height, S_Y_DEST, PathType::VERTICAL, S_X_DEST, 100, easeInOutExpo, 0);
|
shadow_sprites_.at(0)->addPath(param.game.height + 10, S_Y_DEST, PathType::VERTICAL, S_X_DEST, 100, easeInOutExpo, 0);
|
||||||
shadow_sprites_.at(1)->addPath(-SHADOW_SPRITE_HEIGHT, S_Y_DEST, PathType::VERTICAL, S_X_DEST, 100, easeOutBounce, 0);
|
shadow_sprites_.at(1)->addPath(-SHADOW_SPRITE_HEIGHT, S_Y_DEST, PathType::VERTICAL, S_X_DEST, 100, easeOutBounce, 0);
|
||||||
shadow_sprites_.at(2)->addPath(-SHADOW_SPRITE_WIDTH, S_X_DEST, PathType::HORIZONTAL, S_Y_DEST, 40, easeOutQuint, 0);
|
shadow_sprites_.at(2)->addPath(-SHADOW_SPRITE_WIDTH, S_X_DEST, PathType::HORIZONTAL, S_Y_DEST, 40, easeOutQuint, 0);
|
||||||
shadow_sprites_.at(3)->addPath(param.game.width, S_X_DEST, PathType::HORIZONTAL, S_Y_DEST, 800, easeOutQuint, 0);
|
shadow_sprites_.at(3)->addPath(param.game.width, S_X_DEST, PathType::HORIZONTAL, S_Y_DEST, 800, easeOutQuint, 0);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <vector> // Para vector
|
#include <vector> // Para vector
|
||||||
#include "path_sprite.h" // Para PathSprite
|
#include "path_sprite.h" // Para PathSprite
|
||||||
#include "writer.h" // Para Writer
|
#include "writer.h" // Para Writer
|
||||||
|
#include "tiled_bg.h"
|
||||||
class Text; // lines 8-8
|
class Text; // lines 8-8
|
||||||
class Texture; // lines 9-9
|
class Texture; // lines 9-9
|
||||||
|
|
||||||
@@ -22,7 +23,7 @@ private:
|
|||||||
std::vector<std::unique_ptr<PathSprite>> sprites_; // Vector con los sprites inteligentes para los dibujos de la intro
|
std::vector<std::unique_ptr<PathSprite>> sprites_; // Vector con los sprites inteligentes para los dibujos de la intro
|
||||||
std::vector<std::unique_ptr<PathSprite>> shadow_sprites_; // Vector con los sprites inteligentes para las sombras
|
std::vector<std::unique_ptr<PathSprite>> shadow_sprites_; // Vector con los sprites inteligentes para las sombras
|
||||||
std::vector<std::unique_ptr<Writer>> texts_; // Textos de la intro
|
std::vector<std::unique_ptr<Writer>> texts_; // Textos de la intro
|
||||||
std::unique_ptr<Sprite> shadow_sprite_; // Sprite para la sombra de las imagenes
|
std::unique_ptr<TiledBG> tiled_bg_;
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
|
||||||
|
|||||||
@@ -11,9 +11,6 @@
|
|||||||
TiledBG::TiledBG(SDL_Rect pos, TiledBGMode mode)
|
TiledBG::TiledBG(SDL_Rect pos, TiledBGMode mode)
|
||||||
: renderer_(Screen::get()->getRenderer()),
|
: renderer_(Screen::get()->getRenderer()),
|
||||||
pos_(pos),
|
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}),
|
|
||||||
mode_(mode == TiledBGMode::RANDOM ? static_cast<TiledBGMode>(rand() % 2) : mode)
|
mode_(mode == TiledBGMode::RANDOM ? static_cast<TiledBGMode>(rand() % 2) : mode)
|
||||||
{
|
{
|
||||||
// Crea la textura para el mosaico de fondo
|
// Crea la textura para el mosaico de fondo
|
||||||
@@ -22,6 +19,22 @@ TiledBG::TiledBG(SDL_Rect pos, TiledBGMode mode)
|
|||||||
// Rellena la textura con el contenido
|
// Rellena la textura con el contenido
|
||||||
fillTexture();
|
fillTexture();
|
||||||
|
|
||||||
|
mode_ = TiledBGMode::DIAGONAL;
|
||||||
|
|
||||||
|
switch (mode)
|
||||||
|
{
|
||||||
|
case TiledBGMode::DIAGONAL:
|
||||||
|
window_ = {0, 0, pos_.w, pos_.h};
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TiledBGMode::CIRCLE:
|
||||||
|
window_ = {128, 96, pos_.w, pos_.h};
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Inicializa los valores del vector con los valores del seno
|
// Inicializa los valores del vector con los valores del seno
|
||||||
for (int i = 0; i < 360; ++i)
|
for (int i = 0; i < 360; ++i)
|
||||||
{
|
{
|
||||||
@@ -72,22 +85,57 @@ void TiledBG::render()
|
|||||||
// Actualiza la lógica de la clase
|
// Actualiza la lógica de la clase
|
||||||
void TiledBG::update()
|
void TiledBG::update()
|
||||||
{
|
{
|
||||||
|
updateDesp();
|
||||||
|
updateStop();
|
||||||
|
|
||||||
switch (mode_)
|
switch (mode_)
|
||||||
{
|
{
|
||||||
case TiledBGMode::DIAGONAL:
|
case TiledBGMode::DIAGONAL:
|
||||||
{ // El tileado de fondo se desplaza en diagonal
|
{
|
||||||
++window_.x %= TILE_WIDTH_;
|
// El tileado de fondo se desplaza en diagonal
|
||||||
++window_.y %= TILE_HEIGHT_;
|
window_.x = static_cast<int>(desp_) % TILE_WIDTH_;
|
||||||
|
window_.y = static_cast<int>(desp_) % TILE_HEIGHT_;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TiledBGMode::CIRCLE:
|
case TiledBGMode::CIRCLE:
|
||||||
{ // El tileado de fondo se desplaza en circulo
|
{
|
||||||
++counter_ %= 360;
|
// El tileado de fondo se desplaza en circulo
|
||||||
window_.x = 128 + (int(sin_[(counter_ + 270) % 360] * 128));
|
const int INDEX = static_cast<int>(desp_) % 360;
|
||||||
window_.y = 96 + (int(sin_[(360 - counter_) % 360] * 96));
|
|
||||||
|
window_.x = 128 + (static_cast<int>(sin_[(INDEX + 270) % 360] * 128));
|
||||||
|
window_.y = 96 + (static_cast<int>(sin_[(360 - INDEX) % 360] * 96));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Detiene el desplazamiento de forma ordenada
|
||||||
|
void TiledBG::updateStop()
|
||||||
|
{
|
||||||
|
if (stopping_)
|
||||||
|
{
|
||||||
|
const int UMBRAL = 20 * speed_; // Ajusta este valor según la precisión deseada
|
||||||
|
|
||||||
|
// Desacelerar si estamos cerca de completar el ciclo (ventana a punto de regresar a 0)
|
||||||
|
if (window_.x >= TILE_WIDTH_ - UMBRAL)
|
||||||
|
{
|
||||||
|
speed_ /= 1.05f; // Reduce gradualmente la velocidad
|
||||||
|
|
||||||
|
// Asegura que no baje demasiado
|
||||||
|
if (speed_ < 0.1f)
|
||||||
|
{
|
||||||
|
speed_ = 0.1f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si estamos en 0, detener
|
||||||
|
if (window_.x == 0)
|
||||||
|
{
|
||||||
|
speed_ = 0.0f;
|
||||||
|
stopping_ = false; // Desactivamos el estado de "stopping"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -36,10 +36,19 @@ private:
|
|||||||
int counter_ = 0; // Contador
|
int counter_ = 0; // Contador
|
||||||
TiledBGMode mode_; // Tipo de movimiento del mosaico
|
TiledBGMode mode_; // Tipo de movimiento del mosaico
|
||||||
double sin_[360]; // Vector con los valores del seno precalculados
|
double sin_[360]; // Vector con los valores del seno precalculados
|
||||||
|
float desp_ = 0.0f; // Desplazamiento aplicado
|
||||||
|
float speed_ = 1.0f; // Incremento que se añade al desplazamiento a cada bucle
|
||||||
|
bool stopping_ = false; // Indica si se está deteniendo
|
||||||
|
|
||||||
// Rellena la textura con el contenido
|
// Rellena la textura con el contenido
|
||||||
void fillTexture();
|
void fillTexture();
|
||||||
|
|
||||||
|
// Actualiza el desplazamiento
|
||||||
|
void updateDesp() { desp_ += speed_; }
|
||||||
|
|
||||||
|
// Detiene el desplazamiento de forma ordenada
|
||||||
|
void updateStop();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
TiledBG(SDL_Rect pos, TiledBGMode mode);
|
TiledBG(SDL_Rect pos, TiledBGMode mode);
|
||||||
@@ -52,4 +61,10 @@ public:
|
|||||||
|
|
||||||
// Actualiza la lógica de la clase
|
// Actualiza la lógica de la clase
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
// Establece la velocidad
|
||||||
|
void setSpeed(float speed) { speed_ = speed; }
|
||||||
|
|
||||||
|
// Detiene el desplazamiento de forma ordenada
|
||||||
|
void stopGracefully() { stopping_ = true; }
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user