forked from jaildesigner-jailgames/jaildoctors_dilemma
canvi de pc
This commit is contained in:
217
source/logo.cpp
217
source/logo.cpp
@@ -9,86 +9,79 @@
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "texture.h" // for Texture
|
||||
#include "utils.h" // for color_t, section_t, options_t, stringToC...
|
||||
class Asset; // lines 11-11
|
||||
#include "asset.h"
|
||||
class Asset; // lines 11-11
|
||||
|
||||
// Constructor
|
||||
Logo::Logo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section)
|
||||
Logo::Logo(Resource *resource, options_t *options, section_t *section)
|
||||
: resource_(resource),
|
||||
screen_(Screen::get()),
|
||||
renderer_(Screen::get()->getRenderer()),
|
||||
asset_(Asset::get()),
|
||||
input_(Input::get()),
|
||||
options_(options),
|
||||
section_(section)
|
||||
{
|
||||
// Copia la dirección de los objetos
|
||||
this->resource = resource;
|
||||
this->renderer = renderer;
|
||||
this->screen = screen;
|
||||
this->asset = asset;
|
||||
this->input = input;
|
||||
this->options = options;
|
||||
this->section = section;
|
||||
|
||||
// Reserva memoria para los punteros
|
||||
eventHandler = new SDL_Event();
|
||||
texture = resource->getTexture("jailgames.png");
|
||||
texture2 = resource->getTexture("since_1998.png");
|
||||
sprite2 = new Sprite((256 - texture2->getWidth()) / 2, 83 + texture->getHeight() + 5, texture2->getWidth(), texture2->getHeight(), texture2, renderer);
|
||||
sprite2->setSpriteClip(0, 0, texture2->getWidth(), texture2->getHeight());
|
||||
texture2->setColor(0, 0, 0);
|
||||
event_handler_ = new SDL_Event();
|
||||
jailgames_texture_ = resource->getTexture("jailgames.png");
|
||||
since_1998_texture_ = resource->getTexture("since_1998.png");
|
||||
since_1998_sprite_ = new Sprite((256 - since_1998_texture_->getWidth()) / 2, 83 + jailgames_texture_->getHeight() + 5, since_1998_texture_->getWidth(), since_1998_texture_->getHeight(), since_1998_texture_, renderer_);
|
||||
since_1998_sprite_->setSpriteClip(0, 0, since_1998_texture_->getWidth(), since_1998_texture_->getHeight());
|
||||
since_1998_texture_->setColor(0, 0, 0);
|
||||
|
||||
// Crea los sprites de cada linea
|
||||
for (int i = 0; i < texture->getHeight(); ++i)
|
||||
for (int i = 0; i < jailgames_texture_->getHeight(); ++i)
|
||||
{
|
||||
sprite.push_back(new Sprite(0, i, texture->getWidth(), 1, texture, renderer));
|
||||
sprite.back()->setSpriteClip(0, i, texture->getWidth(), 1);
|
||||
jailgames_sprite_.push_back(new Sprite(0, i, jailgames_texture_->getWidth(), 1, jailgames_texture_, renderer_));
|
||||
jailgames_sprite_.back()->setSpriteClip(0, i, jailgames_texture_->getWidth(), 1);
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
sprite[i]->setPosX(256 + (i * 3));
|
||||
jailgames_sprite_[i]->setPosX(256 + (i * 3));
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite[i]->setPosX(-181 - (i * 3));
|
||||
jailgames_sprite_[i]->setPosX(-181 - (i * 3));
|
||||
}
|
||||
sprite[i]->setPosY(83 + i);
|
||||
jailgames_sprite_[i]->setPosY(83 + i);
|
||||
}
|
||||
|
||||
// Inicializa variables
|
||||
counter = 0;
|
||||
section->name = SECTION_LOGO;
|
||||
ticks = 0;
|
||||
ticksSpeed = 15;
|
||||
initFade = 300;
|
||||
endLogo = 400;
|
||||
postLogo = 20;
|
||||
|
||||
// Inicializa el vector de colores
|
||||
const std::vector<std::string> vColors = {"black", "blue", "red", "magenta", "green", "cyan", "yellow", "bright_white"};
|
||||
for (auto v : vColors)
|
||||
{
|
||||
color.push_back(stringToColor(options->palette, v));
|
||||
color_.push_back(stringToColor(options->palette, v));
|
||||
}
|
||||
|
||||
// Cambia el color del borde
|
||||
screen->setBorderColor(stringToColor(options->palette, "black"));
|
||||
screen_->setBorderColor(stringToColor(options->palette, "black"));
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Logo::~Logo()
|
||||
{
|
||||
for (auto s : sprite)
|
||||
for (auto s : jailgames_sprite_)
|
||||
{
|
||||
delete s;
|
||||
}
|
||||
|
||||
delete sprite2;
|
||||
delete eventHandler;
|
||||
delete since_1998_sprite_;
|
||||
delete event_handler_;
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void Logo::checkEvents()
|
||||
{
|
||||
// Comprueba los eventos que hay en la cola
|
||||
while (SDL_PollEvent(eventHandler) != 0)
|
||||
while (SDL_PollEvent(event_handler_) != 0)
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (eventHandler->type == SDL_QUIT)
|
||||
if (event_handler_->type == SDL_QUIT)
|
||||
{
|
||||
section->name = SECTION_QUIT;
|
||||
section_->name = SECTION_QUIT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -97,39 +90,39 @@ void Logo::checkEvents()
|
||||
// Comprueba las entradas
|
||||
void Logo::checkInput()
|
||||
{
|
||||
if (input->checkInput(input_exit, REPEAT_FALSE))
|
||||
if (input_->checkInput(input_exit, REPEAT_FALSE))
|
||||
{
|
||||
section->name = SECTION_TITLE;
|
||||
section_->name = SECTION_TITLE;
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_toggle_border, REPEAT_FALSE))
|
||||
else if (input_->checkInput(input_toggle_border, REPEAT_FALSE))
|
||||
{
|
||||
screen->toggleBorder();
|
||||
screen_->toggleBorder();
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_toggle_videomode, REPEAT_FALSE))
|
||||
else if (input_->checkInput(input_toggle_videomode, REPEAT_FALSE))
|
||||
{
|
||||
screen->toggleVideoMode();
|
||||
screen_->toggleVideoMode();
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
|
||||
else if (input_->checkInput(input_window_dec_size, REPEAT_FALSE))
|
||||
{
|
||||
screen->decWindowSize();
|
||||
screen_->decWindowSize();
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
|
||||
else if (input_->checkInput(input_window_inc_size, REPEAT_FALSE))
|
||||
{
|
||||
screen->incWindowSize();
|
||||
screen_->incWindowSize();
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_toggle_palette, REPEAT_FALSE))
|
||||
else if (input_->checkInput(input_toggle_palette, REPEAT_FALSE))
|
||||
{
|
||||
switchPalette();
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_jump, REPEAT_FALSE))
|
||||
else if (input_->checkInput(input_pause, REPEAT_FALSE) || input_->checkInput(input_accept, REPEAT_FALSE) || input_->checkInput(input_jump, REPEAT_FALSE))
|
||||
{
|
||||
section->subsection = SUBSECTION_LOGO_TO_TITLE;
|
||||
section_->subsection = SUBSECTION_LOGO_TO_TITLE;
|
||||
endSection();
|
||||
}
|
||||
}
|
||||
@@ -137,28 +130,28 @@ void Logo::checkInput()
|
||||
// Gestiona el logo de JAILGAME
|
||||
void Logo::updateJAILGAMES()
|
||||
{
|
||||
if (counter > 30)
|
||||
if (counter_ > 30)
|
||||
{
|
||||
for (int i = 1; i < (int)sprite.size(); ++i)
|
||||
for (int i = 1; i < (int)jailgames_sprite_.size(); ++i)
|
||||
{
|
||||
const int speed = 8;
|
||||
const int dest = 37;
|
||||
if (sprite[i]->getPosX() != 37)
|
||||
if (jailgames_sprite_[i]->getPosX() != 37)
|
||||
{
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
sprite[i]->incPosX(-speed);
|
||||
if (sprite[i]->getPosX() < dest)
|
||||
jailgames_sprite_[i]->incPosX(-speed);
|
||||
if (jailgames_sprite_[i]->getPosX() < dest)
|
||||
{
|
||||
sprite[i]->setPosX(dest);
|
||||
jailgames_sprite_[i]->setPosX(dest);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite[i]->incPosX(speed);
|
||||
if (sprite[i]->getPosX() > dest)
|
||||
jailgames_sprite_[i]->incPosX(speed);
|
||||
if (jailgames_sprite_[i]->getPosX() > dest)
|
||||
{
|
||||
sprite[i]->setPosX(dest);
|
||||
jailgames_sprite_[i]->setPosX(dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -172,86 +165,86 @@ void Logo::updateTextureColors()
|
||||
const int ini = 70;
|
||||
const int inc = 4;
|
||||
|
||||
if (counter == ini + inc * 0)
|
||||
if (counter_ == ini + inc * 0)
|
||||
{
|
||||
texture2->setColor(color[0].r, color[0].g, color[0].b);
|
||||
since_1998_texture_->setColor(color_[0].r, color_[0].g, color_[0].b);
|
||||
}
|
||||
|
||||
else if (counter == ini + inc * 1)
|
||||
else if (counter_ == ini + inc * 1)
|
||||
{
|
||||
texture2->setColor(color[1].r, color[1].g, color[1].b);
|
||||
since_1998_texture_->setColor(color_[1].r, color_[1].g, color_[1].b);
|
||||
}
|
||||
|
||||
else if (counter == ini + inc * 2)
|
||||
else if (counter_ == ini + inc * 2)
|
||||
{
|
||||
texture2->setColor(color[2].r, color[2].g, color[2].b);
|
||||
since_1998_texture_->setColor(color_[2].r, color_[2].g, color_[2].b);
|
||||
}
|
||||
|
||||
else if (counter == ini + inc * 3)
|
||||
else if (counter_ == ini + inc * 3)
|
||||
{
|
||||
texture2->setColor(color[3].r, color[3].g, color[3].b);
|
||||
since_1998_texture_->setColor(color_[3].r, color_[3].g, color_[3].b);
|
||||
}
|
||||
|
||||
else if (counter == ini + inc * 4)
|
||||
else if (counter_ == ini + inc * 4)
|
||||
{
|
||||
texture2->setColor(color[4].r, color[4].g, color[4].b);
|
||||
since_1998_texture_->setColor(color_[4].r, color_[4].g, color_[4].b);
|
||||
}
|
||||
|
||||
else if (counter == ini + inc * 5)
|
||||
else if (counter_ == ini + inc * 5)
|
||||
{
|
||||
texture2->setColor(color[5].r, color[5].g, color[5].b);
|
||||
since_1998_texture_->setColor(color_[5].r, color_[5].g, color_[5].b);
|
||||
}
|
||||
|
||||
else if (counter == ini + inc * 6)
|
||||
else if (counter_ == ini + inc * 6)
|
||||
{
|
||||
texture2->setColor(color[6].r, color[6].g, color[6].b);
|
||||
since_1998_texture_->setColor(color_[6].r, color_[6].g, color_[6].b);
|
||||
}
|
||||
|
||||
else if (counter == ini + inc * 7)
|
||||
else if (counter_ == ini + inc * 7)
|
||||
{
|
||||
texture2->setColor(color[7].r, color[7].g, color[7].b);
|
||||
since_1998_texture_->setColor(color_[7].r, color_[7].g, color_[7].b);
|
||||
}
|
||||
|
||||
else if (counter == initFade + inc * 0)
|
||||
else if (counter_ == init_fade_ + inc * 0)
|
||||
{
|
||||
texture->setColor(color[6].r, color[6].g, color[6].b);
|
||||
texture2->setColor(color[6].r, color[6].g, color[6].b);
|
||||
jailgames_texture_->setColor(color_[6].r, color_[6].g, color_[6].b);
|
||||
since_1998_texture_->setColor(color_[6].r, color_[6].g, color_[6].b);
|
||||
}
|
||||
|
||||
else if (counter == initFade + inc * 1)
|
||||
else if (counter_ == init_fade_ + inc * 1)
|
||||
{
|
||||
texture->setColor(color[5].r, color[5].g, color[5].b);
|
||||
texture2->setColor(color[5].r, color[5].g, color[5].b);
|
||||
jailgames_texture_->setColor(color_[5].r, color_[5].g, color_[5].b);
|
||||
since_1998_texture_->setColor(color_[5].r, color_[5].g, color_[5].b);
|
||||
}
|
||||
|
||||
else if (counter == initFade + inc * 2)
|
||||
else if (counter_ == init_fade_ + inc * 2)
|
||||
{
|
||||
texture->setColor(color[4].r, color[4].g, color[4].b);
|
||||
texture2->setColor(color[4].r, color[4].g, color[4].b);
|
||||
jailgames_texture_->setColor(color_[4].r, color_[4].g, color_[4].b);
|
||||
since_1998_texture_->setColor(color_[4].r, color_[4].g, color_[4].b);
|
||||
}
|
||||
|
||||
else if (counter == initFade + inc * 3)
|
||||
else if (counter_ == init_fade_ + inc * 3)
|
||||
{
|
||||
texture->setColor(color[3].r, color[3].g, color[3].b);
|
||||
texture2->setColor(color[3].r, color[3].g, color[3].b);
|
||||
jailgames_texture_->setColor(color_[3].r, color_[3].g, color_[3].b);
|
||||
since_1998_texture_->setColor(color_[3].r, color_[3].g, color_[3].b);
|
||||
}
|
||||
|
||||
else if (counter == initFade + inc * 4)
|
||||
else if (counter_ == init_fade_ + inc * 4)
|
||||
{
|
||||
texture->setColor(color[2].r, color[2].g, color[2].b);
|
||||
texture2->setColor(color[2].r, color[2].g, color[2].b);
|
||||
jailgames_texture_->setColor(color_[2].r, color_[2].g, color_[2].b);
|
||||
since_1998_texture_->setColor(color_[2].r, color_[2].g, color_[2].b);
|
||||
}
|
||||
|
||||
else if (counter == initFade + inc * 5)
|
||||
else if (counter_ == init_fade_ + inc * 5)
|
||||
{
|
||||
texture->setColor(color[1].r, color[1].g, color[1].b);
|
||||
texture2->setColor(color[1].r, color[1].g, color[1].b);
|
||||
jailgames_texture_->setColor(color_[1].r, color_[1].g, color_[1].b);
|
||||
since_1998_texture_->setColor(color_[1].r, color_[1].g, color_[1].b);
|
||||
}
|
||||
|
||||
else if (counter == initFade + inc * 6)
|
||||
else if (counter_ == init_fade_ + inc * 6)
|
||||
{
|
||||
texture->setColor(color[0].r, color[0].g, color[0].b);
|
||||
texture2->setColor(color[0].r, color[0].g, color[0].b);
|
||||
jailgames_texture_->setColor(color_[0].r, color_[0].g, color_[0].b);
|
||||
since_1998_texture_->setColor(color_[0].r, color_[0].g, color_[0].b);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,16 +252,16 @@ void Logo::updateTextureColors()
|
||||
void Logo::update()
|
||||
{
|
||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||
if (SDL_GetTicks() - ticks > ticksSpeed)
|
||||
if (SDL_GetTicks() - ticks_ > ticks_speed_)
|
||||
{
|
||||
// Actualiza el contador de ticks
|
||||
ticks = SDL_GetTicks();
|
||||
ticks_ = SDL_GetTicks();
|
||||
|
||||
// Comprueba las entradas
|
||||
checkInput();
|
||||
|
||||
// Incrementa el contador
|
||||
counter++;
|
||||
counter_++;
|
||||
|
||||
// Gestiona el logo de JAILGAME
|
||||
updateJAILGAMES();
|
||||
@@ -277,10 +270,10 @@ void Logo::update()
|
||||
updateTextureColors();
|
||||
|
||||
// Actualiza las notificaciones
|
||||
screen->updateNotifier();
|
||||
screen_->updateNotifier();
|
||||
|
||||
// Comprueba si ha terminado el logo
|
||||
if (counter == endLogo + postLogo)
|
||||
if (counter_ == end_logo_ + post_logo_)
|
||||
{
|
||||
endSection();
|
||||
}
|
||||
@@ -291,20 +284,20 @@ void Logo::update()
|
||||
void Logo::render()
|
||||
{
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
screen->start();
|
||||
screen_->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
screen->clean();
|
||||
screen_->clean();
|
||||
|
||||
// Dibuja los objetos
|
||||
for (auto s : sprite)
|
||||
for (auto s : jailgames_sprite_)
|
||||
{
|
||||
s->render();
|
||||
}
|
||||
sprite2->render();
|
||||
since_1998_sprite_->render();
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
screen->render();
|
||||
screen_->render();
|
||||
}
|
||||
|
||||
// Bucle para el logo del juego
|
||||
@@ -313,7 +306,7 @@ void Logo::run()
|
||||
// Detiene la música
|
||||
JA_StopMusic();
|
||||
|
||||
while (section->name == SECTION_LOGO)
|
||||
while (section_->name == SECTION_LOGO)
|
||||
{
|
||||
update();
|
||||
checkEvents();
|
||||
@@ -324,19 +317,19 @@ void Logo::run()
|
||||
// Cambia la paleta
|
||||
void Logo::switchPalette()
|
||||
{
|
||||
options->palette = options->palette == p_zxspectrum ? p_zxarne : p_zxspectrum;
|
||||
options_->palette = options_->palette == p_zxspectrum ? p_zxarne : p_zxspectrum;
|
||||
}
|
||||
|
||||
// Termina la sección
|
||||
void Logo::endSection()
|
||||
{
|
||||
if (section->subsection == SUBSECTION_LOGO_TO_TITLE)
|
||||
if (section_->subsection == SUBSECTION_LOGO_TO_TITLE)
|
||||
{
|
||||
section->name = SECTION_TITLE;
|
||||
section_->name = SECTION_TITLE;
|
||||
}
|
||||
|
||||
else if (section->subsection == SUBSECTION_LOGO_TO_INTRO)
|
||||
else if (section_->subsection == SUBSECTION_LOGO_TO_INTRO)
|
||||
{
|
||||
section->name = SECTION_LOADING_SCREEN;
|
||||
section_->name = SECTION_LOADING_SCREEN;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user