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_stdinc.h> // Para SDL_bool, Uint32
|
||||
#include <errno.h> // Para errno, EEXIST, EACCES, ENAMETOO...
|
||||
#ifndef _WIN32
|
||||
#include <pwd.h> // Para getpwuid, passwd
|
||||
#endif
|
||||
#include <stdio.h> // Para printf, perror
|
||||
#include <sys/stat.h> // Para mkdir, stat, S_IRWXU
|
||||
#include <unistd.h> // Para getuid
|
||||
@@ -45,6 +42,10 @@
|
||||
#include "title.h" // Para Title
|
||||
#include "utils.h" // Para Overrides, overrides
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <pwd.h> // Para getpwuid, passwd
|
||||
#endif
|
||||
|
||||
// Constructor
|
||||
Director::Director(int argc, const char *argv[])
|
||||
{
|
||||
@@ -52,7 +53,7 @@ Director::Director(int argc, const char *argv[])
|
||||
section::name = section::Name::GAME;
|
||||
section::options = section::Options::GAME_PLAY_1P;
|
||||
#elif DEBUG
|
||||
section::name = section::Name::LOGO;
|
||||
section::name = section::Name::INTRO;
|
||||
#else // NORMAL GAME
|
||||
section::name = section::Name::LOGO;
|
||||
section::options = section::Options::NONE;
|
||||
|
||||
@@ -17,10 +17,12 @@
|
||||
#include "utils.h" // Para Zone, BLOCK, Color, bg_color
|
||||
#include "writer.h" // Para Writer
|
||||
#include "global_events.h"
|
||||
#include "tiled_bg.h"
|
||||
#include <array>
|
||||
|
||||
// Constructor
|
||||
Intro::Intro()
|
||||
: tiled_bg_(std::make_unique<TiledBG>(param.game.game_area.rect, TiledBGMode::DIAGONAL))
|
||||
{
|
||||
// Inicializa variables
|
||||
section::name = section::Name::INTRO;
|
||||
@@ -31,6 +33,9 @@ Intro::Intro()
|
||||
|
||||
// Inicializa los textos
|
||||
initTexts();
|
||||
|
||||
// Configura el fondo
|
||||
tiled_bg_->setSpeed(0.3f);
|
||||
}
|
||||
|
||||
// Comprueba los eventos
|
||||
@@ -61,6 +66,7 @@ void Intro::updateScenes()
|
||||
if (sprites_.at(0)->hasFinished() && !texts_.at(0)->hasFinished())
|
||||
{
|
||||
texts_.at(0)->setEnabled(true);
|
||||
tiled_bg_->stopGracefully();
|
||||
}
|
||||
|
||||
// Segundo texto de la primera imagen
|
||||
@@ -165,7 +171,7 @@ void Intro::updateScenes()
|
||||
shadow_sprites_.at(4)->enable();
|
||||
|
||||
// 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);
|
||||
}
|
||||
@@ -189,6 +195,7 @@ void Intro::updateScenes()
|
||||
if (!texts_.at(8)->hasFinished())
|
||||
{
|
||||
texts_.at(8)->setEnabled(true);
|
||||
tiled_bg_->stopGracefully();
|
||||
}
|
||||
|
||||
// Acaba el último texto
|
||||
@@ -216,8 +223,8 @@ void Intro::update()
|
||||
// Actualiza el contador de ticks
|
||||
ticks_ = SDL_GetTicks();
|
||||
|
||||
// Actualiza el objeto screen
|
||||
Screen::get()->update();
|
||||
// Actualiza el fondo
|
||||
tiled_bg_->update();
|
||||
|
||||
// Actualiza los sprites
|
||||
updateSprites();
|
||||
@@ -228,6 +235,9 @@ void Intro::update()
|
||||
// Actualiza las escenas de la intro
|
||||
updateScenes();
|
||||
|
||||
// Actualiza el objeto screen
|
||||
Screen::get()->update();
|
||||
|
||||
// Actualiza las variables de globalInputs
|
||||
globalInputs::update();
|
||||
}
|
||||
@@ -242,6 +252,12 @@ void Intro::render()
|
||||
// Limpia la pantalla
|
||||
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
|
||||
renderSprites();
|
||||
|
||||
@@ -295,7 +311,7 @@ void Intro::initSprites()
|
||||
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(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);
|
||||
@@ -328,16 +344,12 @@ void Intro::initSprites()
|
||||
SDL_Rect rect = {BORDER / 2, BORDER / 2, SPRITE_WIDTH, SPRITE_HEIGHT};
|
||||
auto texture = Resource::get()->getTexture(TEXTURE_LIST.at(i))->getSDLTexture();
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_MOD);
|
||||
//SDL_SetTextureAlphaMod(texture, 128);
|
||||
SDL_RenderCopy(Screen::get()->getRenderer(), texture, nullptr, &rect);
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_NONE);
|
||||
|
||||
// SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0x54, 0x31, 0x49, 0xFF);
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0xFF, 0xFF, 0xFF, 192);
|
||||
//SDL_RenderFillRect(Screen::get()->getRenderer(), &rect);
|
||||
shadow_texture->setAlpha(160);
|
||||
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), temp);
|
||||
|
||||
shadow_textures.push_back(shadow_texture);
|
||||
}
|
||||
|
||||
@@ -351,7 +363,7 @@ void Intro::initSprites()
|
||||
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(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);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <vector> // Para vector
|
||||
#include "path_sprite.h" // Para PathSprite
|
||||
#include "writer.h" // Para Writer
|
||||
#include "tiled_bg.h"
|
||||
class Text; // lines 8-8
|
||||
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>> shadow_sprites_; // Vector con los sprites inteligentes para las sombras
|
||||
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
|
||||
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
|
||||
|
||||
@@ -11,9 +11,6 @@
|
||||
TiledBG::TiledBG(SDL_Rect pos, TiledBGMode mode)
|
||||
: renderer_(Screen::get()->getRenderer()),
|
||||
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)
|
||||
{
|
||||
// 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
|
||||
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
|
||||
for (int i = 0; i < 360; ++i)
|
||||
{
|
||||
@@ -72,22 +85,57 @@ void TiledBG::render()
|
||||
// Actualiza la lógica de la clase
|
||||
void TiledBG::update()
|
||||
{
|
||||
updateDesp();
|
||||
updateStop();
|
||||
|
||||
switch (mode_)
|
||||
{
|
||||
case TiledBGMode::DIAGONAL:
|
||||
{ // El tileado de fondo se desplaza en diagonal
|
||||
++window_.x %= TILE_WIDTH_;
|
||||
++window_.y %= TILE_HEIGHT_;
|
||||
{
|
||||
// El tileado de fondo se desplaza en diagonal
|
||||
window_.x = static_cast<int>(desp_) % TILE_WIDTH_;
|
||||
window_.y = static_cast<int>(desp_) % TILE_HEIGHT_;
|
||||
|
||||
break;
|
||||
}
|
||||
case TiledBGMode::CIRCLE:
|
||||
{ // El tileado de fondo se desplaza en circulo
|
||||
++counter_ %= 360;
|
||||
window_.x = 128 + (int(sin_[(counter_ + 270) % 360] * 128));
|
||||
window_.y = 96 + (int(sin_[(360 - counter_) % 360] * 96));
|
||||
{
|
||||
// El tileado de fondo se desplaza en circulo
|
||||
const int INDEX = static_cast<int>(desp_) % 360;
|
||||
|
||||
window_.x = 128 + (static_cast<int>(sin_[(INDEX + 270) % 360] * 128));
|
||||
window_.y = 96 + (static_cast<int>(sin_[(360 - INDEX) % 360] * 96));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
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"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,15 +31,24 @@ private:
|
||||
SDL_Texture *canvas_; // Textura donde dibujar el fondo formado por tiles
|
||||
|
||||
// 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_ = 0; // Contador
|
||||
TiledBGMode mode_; // Tipo de movimiento del mosaico
|
||||
double sin_[360]; // Vector con los valores del seno precalculados
|
||||
SDL_Rect pos_; // Posición y tamaño del mosaico
|
||||
SDL_Rect window_; // Ventana visible para la textura de fondo del titulo
|
||||
int counter_ = 0; // Contador
|
||||
TiledBGMode mode_; // Tipo de movimiento del mosaico
|
||||
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
|
||||
void fillTexture();
|
||||
|
||||
// Actualiza el desplazamiento
|
||||
void updateDesp() { desp_ += speed_; }
|
||||
|
||||
// Detiene el desplazamiento de forma ordenada
|
||||
void updateStop();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
TiledBG(SDL_Rect pos, TiledBGMode mode);
|
||||
@@ -52,4 +61,10 @@ public:
|
||||
|
||||
// Actualiza la lógica de la clase
|
||||
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