Afegida musica als credits

Els globos ara tenen definida una play_area
Opció de canviar la paleta al text
This commit is contained in:
2024-11-24 19:07:19 +01:00
parent b8d4c8f17c
commit ad221243cb
12 changed files with 141 additions and 24 deletions

BIN
data/music/credits.ogg Normal file

Binary file not shown.

View File

@@ -7,7 +7,7 @@
#include "texture.h" // Para Texture #include "texture.h" // Para Texture
// Constructor // Constructor
Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel_x, float speed, Uint16 creation_timer, std::shared_ptr<Texture> texture, const std::vector<std::string> &animation) Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel_x, float speed, Uint16 creation_timer, SDL_Rect play_area, std::shared_ptr<Texture> texture, const std::vector<std::string> &animation)
: sprite_(std::make_unique<AnimatedSprite>(texture, animation)), : sprite_(std::make_unique<AnimatedSprite>(texture, animation)),
x_(x), x_(x),
y_(y), y_(y),
@@ -19,7 +19,8 @@ Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel
creation_counter_ini_(creation_timer), creation_counter_ini_(creation_timer),
type_(type), type_(type),
size_(size), size_(size),
speed_(speed) speed_(speed),
play_area_(play_area)
{ {
switch (type_) switch (type_)
{ {
@@ -91,8 +92,8 @@ Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel
void Balloon::alignTo(int x) void Balloon::alignTo(int x)
{ {
x_ = static_cast<float>(x - (w_ / 2)); x_ = static_cast<float>(x - (w_ / 2));
const int min_x = param.game.play_area.rect.x; const int min_x = play_area_.x;
const int max_x = param.game.play_area.rect.w - w_; const int max_x = play_area_.w - w_;
x_ = std::clamp(x_, static_cast<float>(min_x), static_cast<float>(max_x)); x_ = std::clamp(x_, static_cast<float>(min_x), static_cast<float>(max_x));
} }
@@ -149,8 +150,8 @@ void Balloon::move()
// Colisión en las partes laterales de la zona de juego // Colisión en las partes laterales de la zona de juego
const int clip = 2; const int clip = 2;
const float min_x = param.game.play_area.rect.x - clip; const float min_x = play_area_.x - clip;
const float max_x = param.game.play_area.rect.w - w_ + clip; const float max_x = play_area_.w - w_ + clip;
if (x_ < min_x || x_ > max_x) if (x_ < min_x || x_ > max_x)
{ {
x_ = std::clamp(x_, min_x, max_x); x_ = std::clamp(x_, min_x, max_x);
@@ -172,7 +173,7 @@ void Balloon::move()
// Colisión en la parte superior de la zona de juego excepto para la PowerBall // Colisión en la parte superior de la zona de juego excepto para la PowerBall
if (type_ != BalloonType::POWERBALL) if (type_ != BalloonType::POWERBALL)
{ {
const int min_y = param.game.play_area.rect.y; const int min_y = play_area_.y;
if (y_ < min_y) if (y_ < min_y)
{ {
y_ = min_y; y_ = min_y;
@@ -182,7 +183,7 @@ void Balloon::move()
} }
// Colisión en la parte inferior de la zona de juego // Colisión en la parte inferior de la zona de juego
const int max_y = param.game.play_area.rect.h - h_; const int max_y = play_area_.h - h_;
if (y_ > max_y) if (y_ > max_y)
{ {
y_ = max_y; y_ = max_y;
@@ -254,8 +255,8 @@ void Balloon::updateState()
x_ += vx_; x_ += vx_;
// Comprueba no se salga por los laterales // Comprueba no se salga por los laterales
const int min_x = param.game.play_area.rect.x; const int min_x = play_area_.x;
const int max_x = param.game.play_area.rect.w - w_; const int max_x = play_area_.w - w_;
if (x_ < min_x || x_ > max_x) if (x_ < min_x || x_ > max_x)
{ {

View File

@@ -111,6 +111,7 @@ private:
float travel_y_ = 1.0f; // Distancia que ha de recorrer el globo en el eje Y antes de que se le aplique la gravedad float travel_y_ = 1.0f; // Distancia que ha de recorrer el globo en el eje Y antes de que se le aplique la gravedad
float speed_; // Velocidad a la que se mueven los globos float speed_; // Velocidad a la que se mueven los globos
Uint8 power_; // Cantidad de poder que alberga el globo Uint8 power_; // Cantidad de poder que alberga el globo
SDL_Rect play_area_; // Zona por donde se puede mover el globo
// Alinea el circulo de colisión con la posición del objeto globo // Alinea el circulo de colisión con la posición del objeto globo
void shiftColliders(); void shiftColliders();
@@ -138,7 +139,17 @@ private:
public: public:
// Constructor // Constructor
Balloon(float x, float y, BalloonType type, BalloonSize size, float vel_x, float speed, Uint16 creation_timer, std::shared_ptr<Texture> texture, const std::vector<std::string> &animation); Balloon(
float x,
float y,
BalloonType type,
BalloonSize size,
float vel_x,
float speed,
Uint16 creation_timer,
SDL_Rect play_area,
std::shared_ptr<Texture> texture,
const std::vector<std::string> &animation);
// Destructor // Destructor
~Balloon() = default; ~Balloon() = default;

View File

@@ -150,7 +150,7 @@ int BalloonManager::calculateScreenPower()
std::shared_ptr<Balloon> BalloonManager::createBalloon(float x, int y, BalloonType type, BalloonSize size, float velx, float speed, int creation_timer) std::shared_ptr<Balloon> BalloonManager::createBalloon(float x, int y, BalloonType type, BalloonSize size, float velx, float speed, int creation_timer)
{ {
const int index = static_cast<int>(size); const int index = static_cast<int>(size);
balloons_.emplace_back(std::make_shared<Balloon>(x, y, type, size, velx, speed, creation_timer, balloon_textures_.at(index), balloon_animations_.at(index))); balloons_.emplace_back(std::make_shared<Balloon>(x, y, type, size, velx, speed, creation_timer, play_area_, balloon_textures_.at(index), balloon_animations_.at(index)));
return balloons_.back(); return balloons_.back();
} }
@@ -188,7 +188,7 @@ void BalloonManager::createPowerBall()
const int x[values] = {left, left, center, center, right, right}; const int x[values] = {left, left, center, center, right, right};
const float vx[values] = {BALLOON_VELX_POSITIVE, BALLOON_VELX_POSITIVE, BALLOON_VELX_POSITIVE, BALLOON_VELX_NEGATIVE, BALLOON_VELX_NEGATIVE, BALLOON_VELX_NEGATIVE}; const float vx[values] = {BALLOON_VELX_POSITIVE, BALLOON_VELX_POSITIVE, BALLOON_VELX_POSITIVE, BALLOON_VELX_NEGATIVE, BALLOON_VELX_NEGATIVE, BALLOON_VELX_NEGATIVE};
balloons_.emplace_back(std::make_unique<Balloon>(x[luck], pos_y, BalloonType::POWERBALL, BalloonSize::SIZE4, vx[luck], balloon_speed_, creation_time, balloon_textures_[4], balloon_animations_[4])); balloons_.emplace_back(std::make_unique<Balloon>(x[luck], pos_y, BalloonType::POWERBALL, BalloonSize::SIZE4, vx[luck], balloon_speed_, creation_time, play_area_, balloon_textures_[4], balloon_animations_[4]));
power_ball_enabled_ = true; power_ball_enabled_ = true;
power_ball_counter_ = POWERBALL_COUNTER; power_ball_counter_ = POWERBALL_COUNTER;

View File

@@ -6,6 +6,7 @@
#include "balloon.h" // Para BALLOON_SPEED, Balloon #include "balloon.h" // Para BALLOON_SPEED, Balloon
#include "balloon_formations.h" // Para BalloonFormations #include "balloon_formations.h" // Para BalloonFormations
#include "explosions.h" // Para Explosions #include "explosions.h" // Para Explosions
#include "param.h"
class Texture; class Texture;
using Balloons = std::vector<std::shared_ptr<Balloon>>; using Balloons = std::vector<std::shared_ptr<Balloon>>;
@@ -29,6 +30,7 @@ private:
bool power_ball_enabled_ = false; // Indica si hay una powerball ya activa bool power_ball_enabled_ = false; // Indica si hay una powerball ya activa
int power_ball_counter_ = 0; // Contador de formaciones enemigas entre la aparicion de una PowerBall y otra int power_ball_counter_ = 0; // Contador de formaciones enemigas entre la aparicion de una PowerBall y otra
int last_balloon_deploy_ = 0; // Guarda cual ha sido la última formación desplegada para no repetir; int last_balloon_deploy_ = 0; // Guarda cual ha sido la última formación desplegada para no repetir;
SDL_Rect play_area_ = param.game.play_area.rect; // Zona por donde se moveran los globos
// Inicializa // Inicializa
void init(); void init();
@@ -110,4 +112,5 @@ public:
// Setters // Setters
void setDefaultBalloonSpeed(float speed) { default_balloon_speed_ = speed; } void setDefaultBalloonSpeed(float speed) { default_balloon_speed_ = speed; }
void resetBalloonSpeed() { setBalloonSpeed(default_balloon_speed_); } void resetBalloonSpeed() { setBalloonSpeed(default_balloon_speed_); }
void setPlayArea(SDL_Rect play_area) { play_area_ = play_area; }
}; };

View File

@@ -5,19 +5,28 @@
#include "jail_audio.h" // Para JA_StopMusic #include "jail_audio.h" // Para JA_StopMusic
#include "screen.h" // Para Screen #include "screen.h" // Para Screen
#include "balloon_manager.h" // Para BalloonManager #include "balloon_manager.h" // Para BalloonManager
#include "param.h"
#include "resource.h"
#include "text.h"
// Constructor // Constructor
Credits::Credits() Credits::Credits()
: balloon_manager_(std::make_unique<BalloonManager>()) : balloon_manager_(std::make_unique<BalloonManager>()),
text_texture_(SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
tiled_bg_(std::make_unique<TiledBG>((SDL_Rect){0, 0, param.game.width, param.game.height}, TiledBGMode::DIAGONAL))
{ {
section::name = section::Name::CREDITS; section::name = section::Name::CREDITS;
balloon_manager_->setPlayArea(param.game.game_area.rect);
balloon_manager_->createTwoBigBalloons(); balloon_manager_->createTwoBigBalloons();
SDL_SetTextureBlendMode(text_texture_, SDL_BLENDMODE_BLEND);
fillTextTexture();
JA_PlayMusic(Resource::get()->getMusic("credits.ogg"));
} }
// Destructor // Destructor
Credits::~Credits() Credits::~Credits()
{ {
SDL_DestroyTexture(text_texture_);
} }
// Bucle principal // Bucle principal
@@ -40,7 +49,9 @@ void Credits::update()
if (SDL_GetTicks() - ticks_ > TICKS_SPEED) if (SDL_GetTicks() - ticks_ > TICKS_SPEED)
{ {
ticks_ = SDL_GetTicks(); ticks_ = SDL_GetTicks();
tiled_bg_->update();
balloon_manager_->update(); balloon_manager_->update();
Screen::get()->update();
} }
} }
@@ -53,7 +64,9 @@ void Credits::render()
// Limpia la pantalla // Limpia la pantalla
Screen::get()->clean(); Screen::get()->clean();
tiled_bg_->render();
balloon_manager_->render(); balloon_manager_->render();
SDL_RenderCopy(Screen::get()->getRenderer(), text_texture_, nullptr, nullptr);
// Vuelca el contenido del renderizador en pantalla // Vuelca el contenido del renderizador en pantalla
Screen::get()->blit(); Screen::get()->blit();
@@ -84,11 +97,74 @@ void Credits::checkInput()
if (Input::get()->checkAnyButtonPressed()) if (Input::get()->checkAnyButtonPressed())
{ {
JA_StopMusic(); JA_StopMusic();
section::name = section::Name::TITLE; section::name = section::Name::LOGO;
section::options = section::Options::TITLE_1;
return; return;
} }
// Comprueba los inputs que se pueden introducir en cualquier sección del juego // Comprueba los inputs que se pueden introducir en cualquier sección del juego
globalInputs::check(); globalInputs::check();
}
// Crea la textura con el texto
void Credits::fillTextTexture()
{
auto text = Resource::get()->getText("smb2");
SDL_SetRenderTarget(Screen::get()->getRenderer(), text_texture_);
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0);
SDL_RenderClear(Screen::get()->getRenderer());
std::vector<std::string> texts = {
"PROGRAMACIO I DISSENY",
"GRAFICS",
"MUSICA",
"SONS",
"JAILDESIGNER",
"JAILDOCTOR (INTRO)",
"ERIC MATYAS (SOUNDIMAGE.ORG)",
"WWW.THEMOTIONMONKEY.CO.UK",
"WWW.KENNEY.NL",
"JAILDOCTOR"};
const int space_post_title = 3 + text->getCharacterSize();
const int space_pre_title = text->getCharacterSize() * 3;
const int texts_height = 1 * text->getCharacterSize() + 7 * space_post_title + 3 * space_pre_title;
int y = (param.game.height - texts_height) / 2;
text->setPalette(1);
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.width / 2, y, texts.at(0), 1, no_color, 1, shdw_txt_color);
text->setPalette(0);
y += space_post_title;
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.width / 2, y, texts.at(4), 1, no_color, 1, shdw_txt_color);
y += space_pre_title;
text->setPalette(1);
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.width / 2, y, texts.at(1), 1, no_color, 1, shdw_txt_color);
text->setPalette(0);
y += space_post_title;
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.width / 2, y, texts.at(4), 1, no_color, 1, shdw_txt_color);
y += space_pre_title;
text->setPalette(1);
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.width / 2, y, texts.at(2), 1, no_color, 1, shdw_txt_color);
text->setPalette(0);
y += space_post_title;
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.width / 2, y, texts.at(5), 1, no_color, 1, shdw_txt_color);
y += space_post_title;
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.width / 2, y, texts.at(6), 1, no_color, 1, shdw_txt_color);
y += space_pre_title;
text->setPalette(1);
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.width / 2, y, texts.at(3), 1, no_color, 1, shdw_txt_color);
text->setPalette(0);
y += space_post_title;
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.width / 2, y, texts.at(7), 1, no_color, 1, shdw_txt_color);
y += space_post_title;
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.width / 2, y, texts.at(8), 1, no_color, 1, shdw_txt_color);
y += space_post_title;
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.width / 2, y, texts.at(9), 1, no_color, 1, shdw_txt_color);
SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr);
} }

View File

@@ -2,12 +2,16 @@
#include "SDL2/SDL.h" #include "SDL2/SDL.h"
#include <memory> #include <memory>
#include "balloon_manager.h" #include "balloon_manager.h"
#include "texture.h"
#include "tiled_bg.h"
class Credits class Credits
{ {
private: private:
// Objetos // Objetos
std::unique_ptr<BalloonManager> balloon_manager_; // Objeto para gestionar los globos std::unique_ptr<BalloonManager> balloon_manager_; // Objeto para gestionar los globos
SDL_Texture *text_texture_; // Textura con el texto
std::unique_ptr<TiledBG> tiled_bg_; // Objeto para dibujar el mosaico animado de fondo
// 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
@@ -24,6 +28,9 @@ private:
// Comprueba las entradas // Comprueba las entradas
void checkInput(); void checkInput();
// Crea la textura con el texto
void fillTextTexture();
public: public:
// Constructor // Constructor
Credits(); Credits();

View File

@@ -362,6 +362,7 @@ void Director::setFileList()
Asset::get()->add(prefix + "/data/music/intro.ogg", AssetType::MUSIC); Asset::get()->add(prefix + "/data/music/intro.ogg", AssetType::MUSIC);
Asset::get()->add(prefix + "/data/music/playing.ogg", AssetType::MUSIC); Asset::get()->add(prefix + "/data/music/playing.ogg", AssetType::MUSIC);
Asset::get()->add(prefix + "/data/music/title.ogg", AssetType::MUSIC); Asset::get()->add(prefix + "/data/music/title.ogg", AssetType::MUSIC);
Asset::get()->add(prefix + "/data/music/credits.ogg", AssetType::MUSIC);
// Sonidos // Sonidos
Asset::get()->add(prefix + "/data/sound/balloon.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/balloon.wav", AssetType::SOUND);

View File

@@ -30,10 +30,8 @@ Instructions::Instructions()
tiled_bg_(std::make_unique<TiledBG>((SDL_Rect){0, 0, param.game.width, param.game.height}, TiledBGMode::STATIC)), tiled_bg_(std::make_unique<TiledBG>((SDL_Rect){0, 0, param.game.width, param.game.height}, TiledBGMode::STATIC)),
fade_(std::make_unique<Fade>()) fade_(std::make_unique<Fade>())
{ {
// Crea un backbuffer para el renderizador // Configura las texturas
SDL_SetTextureBlendMode(backbuffer_, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(backbuffer_, SDL_BLENDMODE_BLEND);
// Crea una textura para el texto fijo
SDL_SetTextureBlendMode(texture_, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(texture_, SDL_BLENDMODE_BLEND);
// Inicializa variables // Inicializa variables
@@ -211,7 +209,9 @@ void Instructions::update()
// Mantiene la música sonando // Mantiene la música sonando
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
{
JA_PlayMusic(Resource::get()->getMusic("title.ogg")); JA_PlayMusic(Resource::get()->getMusic("title.ogg"));
}
// Actualiza el objeto screen // Actualiza el objeto screen
Screen::get()->update(); Screen::get()->update();

View File

@@ -164,7 +164,7 @@ void Player::move()
pos_x_ += vel_x_; pos_x_ += vel_x_;
// Si el jugador abandona el area de juego por los laterales, restaura su posición // Si el jugador abandona el area de juego por los laterales, restaura su posición
const float min_x = param.game.play_area.rect.x - 5; const float min_x = play_area_.x - 5;
const float max_x = play_area_.w + 5 - WIDTH_; const float max_x = play_area_.w + 5 - WIDTH_;
pos_x_ = std::clamp(pos_x_, min_x, max_x); pos_x_ = std::clamp(pos_x_, min_x, max_x);
@@ -174,13 +174,13 @@ void Player::move()
case PlayerState::DYING: case PlayerState::DYING:
{ {
// Si el cadaver abandona el area de juego por los laterales lo hace rebotar // Si el cadaver abandona el area de juego por los laterales lo hace rebotar
if ((player_sprite_->getPosX() < param.game.play_area.rect.x) || (player_sprite_->getPosX() + WIDTH_ > play_area_.w)) if ((player_sprite_->getPosX() < play_area_.x) || (player_sprite_->getPosX() + WIDTH_ > play_area_.w))
{ {
player_sprite_->setVelX(-player_sprite_->getVelX()); player_sprite_->setVelX(-player_sprite_->getVelX());
} }
// Si el cadaver toca el suelo cambia el estado // Si el cadaver toca el suelo cambia el estado
if (player_sprite_->getPosY() > param.game.play_area.rect.h - HEIGHT_) if (player_sprite_->getPosY() > play_area_.h - HEIGHT_)
{ {
if (player_sprite_->getVelY() < 2.0f) if (player_sprite_->getVelY() < 2.0f)
{ {
@@ -194,7 +194,7 @@ void Player::move()
else else
{ {
// Decrementa las velocidades de rebote // Decrementa las velocidades de rebote
player_sprite_->setPosY(param.game.play_area.rect.h - HEIGHT_); player_sprite_->setPosY(play_area_.h - HEIGHT_);
player_sprite_->setVelY(player_sprite_->getVelY() * -0.5f); player_sprite_->setVelY(player_sprite_->getVelY() * -0.5f);
player_sprite_->setVelX(player_sprite_->getVelX() * 0.75f); player_sprite_->setVelX(player_sprite_->getVelX() * 0.75f);
} }
@@ -615,9 +615,13 @@ void Player::decEnterNameCounter()
{ {
enter_name_counter_ = param.game.enter_name_seconds; enter_name_counter_ = param.game.enter_name_seconds;
if (playing_state_ == PlayerState::ENTERING_NAME) if (playing_state_ == PlayerState::ENTERING_NAME)
{
setPlayingState(PlayerState::CONTINUE); setPlayingState(PlayerState::CONTINUE);
}
else else
{
setPlayingState(PlayerState::LEAVING_SCREEN); setPlayingState(PlayerState::LEAVING_SCREEN);
}
} }
} }
@@ -625,7 +629,9 @@ void Player::decEnterNameCounter()
int Player::getRecordNamePos() const int Player::getRecordNamePos() const
{ {
if (enter_name_) if (enter_name_)
{
return enter_name_->getPosition(); return enter_name_->getPosition();
}
return 0; return 0;
} }

View File

@@ -264,4 +264,13 @@ void Text::reLoadTexture()
void Text::setFixedWidth(bool value) void Text::setFixedWidth(bool value)
{ {
fixed_width_ = value; fixed_width_ = value;
}
// Establece una paleta
void Text::setPalette(int number)
{
auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr);
sprite_->getTexture()->setPalette(number);
SDL_SetRenderTarget(Screen::get()->getRenderer(), temp);
} }

View File

@@ -78,4 +78,7 @@ public:
// Establece si se usa un tamaño fijo de letra // Establece si se usa un tamaño fijo de letra
void setFixedWidth(bool value); void setFixedWidth(bool value);
// Establece una paleta
void setPalette(int number);
}; };