Añadido el cambio de borde, tamaño de ventana y paleta a todas las secciones del juego

This commit is contained in:
2022-10-27 11:49:47 +02:00
parent abbff605c0
commit 4133dfd7c9
11 changed files with 162 additions and 57 deletions

View File

@@ -29,35 +29,6 @@ Credits::Credits(SDL_Renderer *renderer, Screen *screen, Resource *resource, Ass
// Cambia el color del borde
screen->setBorderColor(stringToColor(options->palette, "black"));
// Inicializa los textos
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"INSTRUCTIONS:", stringToColor(options->palette, "yellow")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"HELP JAILDOC TO GET BACK ALL HIS", stringToColor(options->palette, "white")});
texts.push_back({"PROJECTS AND GO TO THE JAIL TO", stringToColor(options->palette, "white")});
texts.push_back({"FINISH THEM", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"KEYS:", stringToColor(options->palette, "yellow")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"USE 'CURSORS' TO MOVE AND JUMP", stringToColor(options->palette, "white")});
texts.push_back({"'F1-F4' TO CHANGE WINDOWS SIZE", stringToColor(options->palette, "white")});
texts.push_back({"'F' TO SWITCH TO FULLSCREEN", stringToColor(options->palette, "white")});
texts.push_back({"'B' TO SWITCH THE BORDER SCREEN", stringToColor(options->palette, "white")});
texts.push_back({"'M' TO TURN ON/OFF THE MUSIC", stringToColor(options->palette, "white")});
texts.push_back({"'ESC' TO LEAVE THE GAME", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"A GAME BY JAILDESIGNER", stringToColor(options->palette, "yellow")});
texts.push_back({"MADE ON SUMMER/FALL 2022", stringToColor(options->palette, "yellow")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"I LOVE JAILGAMES! ", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
// Crea la textura para el texto que se escribe en pantalla
textTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
if (textTexture == nullptr)
@@ -101,8 +72,8 @@ void Credits::checkEventHandler()
break;
}
// Comprueba si se ha pulsado alguna tecla
else if ((eventHandler->type == SDL_KEYDOWN) and (eventHandler->key.repeat == 0))
// Comprueba las teclas que se han pulsado
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
{
switch (eventHandler->key.keysym.scancode)
{
@@ -110,6 +81,40 @@ void Credits::checkEventHandler()
section.name = SECTION_PROG_QUIT;
break;
case SDL_SCANCODE_B:
screen->switchBorder();
resource->reLoadTextures();
break;
case SDL_SCANCODE_F:
screen->switchVideoMode();
resource->reLoadTextures();
break;
case SDL_SCANCODE_F1:
screen->setWindowSize(1);
resource->reLoadTextures();
break;
case SDL_SCANCODE_F2:
screen->setWindowSize(2);
resource->reLoadTextures();
break;
case SDL_SCANCODE_F3:
screen->setWindowSize(3);
resource->reLoadTextures();
break;
case SDL_SCANCODE_F4:
screen->setWindowSize(4);
resource->reLoadTextures();
break;
case SDL_SCANCODE_F5:
switchPalette();
break;
default:
section.name = SECTION_PROG_TITLE;
section.subsection = 0;
@@ -122,6 +127,36 @@ void Credits::checkEventHandler()
// Escribe el texto en la textura
void Credits::fillTexture()
{
// Inicializa los textos
texts.clear();
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"INSTRUCTIONS:", stringToColor(options->palette, "yellow")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"HELP JAILDOC TO GET BACK ALL HIS", stringToColor(options->palette, "white")});
texts.push_back({"PROJECTS AND GO TO THE JAIL TO", stringToColor(options->palette, "white")});
texts.push_back({"FINISH THEM", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"KEYS:", stringToColor(options->palette, "yellow")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"USE 'CURSORS' TO MOVE AND JUMP", stringToColor(options->palette, "white")});
texts.push_back({"'F1-F4' TO CHANGE WINDOWS SIZE", stringToColor(options->palette, "white")});
texts.push_back({"'F' TO SWITCH TO FULLSCREEN", stringToColor(options->palette, "white")});
texts.push_back({"'B' TO SWITCH THE BORDER SCREEN", stringToColor(options->palette, "white")});
texts.push_back({"'M' TO TURN ON/OFF THE MUSIC", stringToColor(options->palette, "white")});
texts.push_back({"'ESC' TO LEAVE THE GAME", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"A GAME BY JAILDESIGNER", stringToColor(options->palette, "yellow")});
texts.push_back({"MADE ON SUMMER/FALL 2022", stringToColor(options->palette, "yellow")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"I LOVE JAILGAMES! ", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
// Rellena la textura de texto
SDL_SetRenderTarget(renderer, textTexture);
const color_t c = stringToColor(options->palette, "black");
@@ -267,3 +302,18 @@ section_t Credits::run()
return section;
}
// Cambia la paleta
void Credits::switchPalette()
{
if (options->palette == p_zxspectrum)
{
options->palette = p_zxarne;
}
else
{
options->palette = p_zxspectrum;
}
fillTexture();
}

View File

@@ -62,6 +62,9 @@ private:
// Escribe el texto en la textura
void fillTexture();
// Cambia la paleta
void switchPalette();
public:
// Constructor
Credits(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options);

View File

@@ -68,42 +68,53 @@ void Demo::checkEventHandler()
screen->setBorderColor(stringToColor(options->palette, "black"));
break;
}
else if ((eventHandler->type == SDL_KEYDOWN) and (eventHandler->key.repeat == 0))
// Comprueba las teclas que se han pulsado
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
{
switch (eventHandler->key.keysym.scancode)
{
case SDL_SCANCODE_ESCAPE:
section.name = SECTION_PROG_QUIT;
break;
case SDL_SCANCODE_B:
screen->switchBorder();
reLoadTextures();
resource->reLoadTextures();
break;
case SDL_SCANCODE_F:
screen->switchVideoMode();
reLoadTextures();
resource->reLoadTextures();
break;
case SDL_SCANCODE_F1:
screen->setWindowSize(1);
reLoadTextures();
resource->reLoadTextures();
break;
case SDL_SCANCODE_F2:
screen->setWindowSize(2);
reLoadTextures();
resource->reLoadTextures();
break;
case SDL_SCANCODE_F3:
screen->setWindowSize(3);
reLoadTextures();
resource->reLoadTextures();
break;
case SDL_SCANCODE_F4:
screen->setWindowSize(4);
reLoadTextures();
resource->reLoadTextures();
break;
case SDL_SCANCODE_F5:
switchPalette();
break;
default:
section.name = SECTION_PROG_TITLE;
section.subsection = 0;
break;
}
}
@@ -180,6 +191,26 @@ void Demo::reLoadTextures()
text->reLoadTexture();
}
// Cambia la paleta
void Demo::switchPalette()
{
// Modifica la variable
if (options->palette == p_zxspectrum)
{
options->palette = p_zxarne;
}
else
{
options->palette = p_zxspectrum;
}
room->reLoadPalette();
scoreboard->reLoadPalette();
const color_t c = room->getBorderColor();
board.color = (c.r + c.g + c.b == 0) ? stringToColor(options->palette, "white") : c; // Si el color es negro lo cambia a blanco
}
// Cambia de habitación
bool Demo::changeRoom(std::string file)
{

View File

@@ -60,6 +60,9 @@ private:
// Recarga todas las texturas
void reLoadTextures();
// Cambia la paleta
void switchPalette();
// Cambia de habitación
bool changeRoom(std::string file);

View File

@@ -9,7 +9,7 @@ Director::Director(std::string path)
section.name = SECTION_PROG_LOGO;
section.subsection = SUBSECTION_LOGO_TO_INTRO;
section.name = SECTION_PROG_TITLE;
section.name = SECTION_PROG_LOGO;
// Crea el objeto que controla los ficheros de recursos
asset = new Asset(path.substr(0, path.find_last_of("\\/")));

View File

@@ -87,7 +87,8 @@ void Game::checkEventHandler()
screen->setBorderColor(stringToColor(options->palette, "black"));
break;
}
else if ((eventHandler->type == SDL_KEYDOWN) and (eventHandler->key.repeat == 0))
if ((eventHandler->type == SDL_KEYDOWN) and (eventHandler->key.repeat == 0))
{
switch (eventHandler->key.keysym.scancode)
{
@@ -420,6 +421,10 @@ void Game::switchPalette()
room->reLoadPalette();
player->reLoadPalette();
scoreboard->reLoadPalette();
const color_t c = room->getBorderColor();
board.color = (c.r + c.g + c.b == 0) ? stringToColor(options->palette, "white") : c; // Si el color es negro lo cambia a blanco
}
// Establece la pantalla en negro

View File

@@ -94,11 +94,15 @@ void Intro::checkEventHandler()
break;
}
// Cualquier tecla pulsada
if ((eventHandler->type == SDL_KEYDOWN) || (eventHandler->type == SDL_JOYBUTTONDOWN))
// Comprueba las teclas que se han pulsado
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
{
switch (eventHandler->key.keysym.scancode)
{
case SDL_SCANCODE_ESCAPE:
section.name = SECTION_PROG_QUIT;
break;
case SDL_SCANCODE_B:
screen->switchBorder();
resource->reLoadTextures();
@@ -135,6 +139,7 @@ void Intro::checkEventHandler()
default:
section.name = SECTION_PROG_TITLE;
section.subsection = 0;
break;
}
}
@@ -293,13 +298,13 @@ void Intro::switchPalette()
if (options->palette == p_zxspectrum)
{
options->palette = p_zxarne;
loadingScreenTexture1 = resource->getTexture("loading_screen_bn_zxarne.png");
loadingScreenTexture2 = resource->getTexture("loading_screen_color_zxarne.png");
sprite1->setTexture(resource->getTexture("loading_screen_bn_zxarne.png"));
sprite2->setTexture(resource->getTexture("loading_screen_color_zxarne.png"));
}
else
{
options->palette = p_zxspectrum;
loadingScreenTexture1 = resource->getTexture("loading_screen_bn.png");
loadingScreenTexture2 = resource->getTexture("loading_screen_color.png");
sprite1->setTexture(resource->getTexture("loading_screen_bn.png"));
sprite2->setTexture(resource->getTexture("loading_screen_color.png"));
}
}

View File

@@ -1,4 +1,5 @@
#include "logo.h"
#include <iostream>
// Constructor
Logo::Logo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, int subsection)
@@ -78,12 +79,13 @@ void Logo::checkEventHandler()
break;
}
// Cualquier tecla pulsada
if ((eventHandler->type == SDL_KEYDOWN) || (eventHandler->type == SDL_JOYBUTTONDOWN))
// Comprueba las teclas que se han pulsado
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
{
switch (eventHandler->key.keysym.scancode)
{
case SDL_SCANCODE_ESCAPE:
std::cout << "PULSADO ESCAPE" << std::endl;
section.name = SECTION_PROG_QUIT;
break;

View File

@@ -120,7 +120,11 @@ void ScoreBoard::reLoadTexture()
playerTexture->reLoad();
itemTexture->reLoad();
text->reLoadTexture();
}
// Recarga la paleta
void ScoreBoard::reLoadPalette()
{
// Reinicia el vector de colores
const std::vector<std::string> vColors = {"blue", "magenta", "green", "cyan", "yellow", "white", "bright_blue", "bright_magenta", "bright_green", "bright_cyan", "bright_yellow", "bright_white"};
color.clear();

View File

@@ -72,6 +72,9 @@ public:
// Recarga la textura
void reLoadTexture();
// Recarga la paleta
void reLoadPalette();
// Pone el marcador en modo pausa
void pause();

View File

@@ -66,8 +66,8 @@ void Title::checkEventHandler()
break;
}
// Comprueba si se ha pulsado alguna tecla
else if ((eventHandler->type == SDL_KEYDOWN) and (eventHandler->key.repeat == 0))
// Comprueba las teclas que se han pulsado
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
{
switch (eventHandler->key.keysym.scancode)
{
@@ -82,32 +82,31 @@ void Title::checkEventHandler()
case SDL_SCANCODE_F:
screen->switchVideoMode();
//reLoadTextures();
resource->reLoadTextures();
break;
case SDL_SCANCODE_F1:
screen->setWindowSize(1);
//reLoadTextures();
resource->reLoadTextures();
break;
case SDL_SCANCODE_F2:
screen->setWindowSize(2);
//reLoadTextures();
resource->reLoadTextures();
break;
case SDL_SCANCODE_F3:
screen->setWindowSize(3);
//reLoadTextures();
resource->reLoadTextures();
break;
case SDL_SCANCODE_F4:
screen->setWindowSize(4);
//reLoadTextures();
resource->reLoadTextures();
break;
case SDL_SCANCODE_F5:
switchPalette();
// reLoadTextures();
break;
default: