ad221243cb
Els globos ara tenen definida una play_area Opció de canviar la paleta al text
170 lines
5.5 KiB
C++
170 lines
5.5 KiB
C++
#include "credits.h"
|
|
#include "section.h" // Para Name, name, Options, options
|
|
#include "global_inputs.h" // Para check
|
|
#include "input.h" // Para Input
|
|
#include "jail_audio.h" // Para JA_StopMusic
|
|
#include "screen.h" // Para Screen
|
|
#include "balloon_manager.h" // Para BalloonManager
|
|
#include "param.h"
|
|
#include "resource.h"
|
|
#include "text.h"
|
|
|
|
// Constructor
|
|
Credits::Credits()
|
|
: 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;
|
|
balloon_manager_->setPlayArea(param.game.game_area.rect);
|
|
balloon_manager_->createTwoBigBalloons();
|
|
SDL_SetTextureBlendMode(text_texture_, SDL_BLENDMODE_BLEND);
|
|
fillTextTexture();
|
|
JA_PlayMusic(Resource::get()->getMusic("credits.ogg"));
|
|
}
|
|
|
|
// Destructor
|
|
Credits::~Credits()
|
|
{
|
|
SDL_DestroyTexture(text_texture_);
|
|
}
|
|
|
|
// Bucle principal
|
|
void Credits::run()
|
|
{
|
|
while (section::name == section::Name::CREDITS)
|
|
{
|
|
checkInput();
|
|
update();
|
|
checkEvents(); // Tiene que ir antes del render
|
|
render();
|
|
}
|
|
}
|
|
|
|
// Actualiza las variables
|
|
void Credits::update()
|
|
{
|
|
constexpr int TICKS_SPEED = 15;
|
|
|
|
if (SDL_GetTicks() - ticks_ > TICKS_SPEED)
|
|
{
|
|
ticks_ = SDL_GetTicks();
|
|
tiled_bg_->update();
|
|
balloon_manager_->update();
|
|
Screen::get()->update();
|
|
}
|
|
}
|
|
|
|
// Dibuja Credits::en patalla
|
|
void Credits::render()
|
|
{
|
|
// Prepara para empezar a dibujar en la textura de juego
|
|
Screen::get()->start();
|
|
|
|
// Limpia la pantalla
|
|
Screen::get()->clean();
|
|
|
|
tiled_bg_->render();
|
|
balloon_manager_->render();
|
|
SDL_RenderCopy(Screen::get()->getRenderer(), text_texture_, nullptr, nullptr);
|
|
|
|
// Vuelca el contenido del renderizador en pantalla
|
|
Screen::get()->blit();
|
|
}
|
|
|
|
// Comprueba el manejador de eventos
|
|
void Credits::checkEvents()
|
|
{
|
|
SDL_Event event;
|
|
|
|
// Comprueba los eventos que hay en la cola
|
|
while (SDL_PollEvent(&event))
|
|
{
|
|
// Evento de salida de la aplicación
|
|
if (event.type == SDL_QUIT)
|
|
{
|
|
section::name = section::Name::QUIT;
|
|
section::options = section::Options::QUIT_FROM_EVENT;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Comprueba las entradas
|
|
void Credits::checkInput()
|
|
{
|
|
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
|
|
if (Input::get()->checkAnyButtonPressed())
|
|
{
|
|
JA_StopMusic();
|
|
section::name = section::Name::LOGO;
|
|
return;
|
|
}
|
|
|
|
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
|
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);
|
|
} |