Cambiada la lógica para el carrusel de secciones del modo demo

This commit is contained in:
2024-06-28 11:52:18 +02:00
parent 2650a64c80
commit 85a24e0100
13 changed files with 114 additions and 226 deletions

View File

@@ -17,3 +17,4 @@ scoreboard.h 32
#TITLE #TITLE
pressStart 160 pressStart 160
titleCounter 800

View File

@@ -170,6 +170,7 @@ struct param_t
int fadePostDuration; // Duración final del fade int fadePostDuration; // Duración final del fade
int pressStart; // Posición del texto para empezar a jugar int pressStart; // Posición del texto para empezar a jugar
int titleCounter; // Tiempo de inactividad del titulo
}; };
// Calcula el cuadrado de la distancia entre dos puntos // Calcula el cuadrado de la distancia entre dos puntos

View File

@@ -50,7 +50,9 @@ const int GAMECANVAS_THIRD_QUARTER_Y = (HEIGHT / 4) * 3;
#define SECTION_PROG_TITLE 2 #define SECTION_PROG_TITLE 2
#define SECTION_PROG_GAME 3 #define SECTION_PROG_GAME 3
#define SECTION_PROG_HI_SCORE_TABLE 4 #define SECTION_PROG_HI_SCORE_TABLE 4
#define SECTION_PROG_QUIT 5 #define SECTION_PROG_GAME_DEMO 5
#define SECTION_PROG_INSTRUCTIONS 6
#define SECTION_PROG_QUIT 7
// Subsecciones // Subsecciones
#define SUBSECTION_GAME_PLAY_1P 0 #define SUBSECTION_GAME_PLAY_1P 0
@@ -59,7 +61,6 @@ const int GAMECANVAS_THIRD_QUARTER_Y = (HEIGHT / 4) * 3;
#define SUBSECTION_GAME_GAMEOVER 3 #define SUBSECTION_GAME_GAMEOVER 3
#define SUBSECTION_TITLE_1 3 #define SUBSECTION_TITLE_1 3
#define SUBSECTION_TITLE_2 4 #define SUBSECTION_TITLE_2 4
#define SUBSECTION_TITLE_INSTRUCTIONS 5
// Ningun tipo // Ningun tipo
#define NO_KIND 0 #define NO_KIND 0

View File

@@ -638,6 +638,7 @@ bool Director::saveConfigFile()
return success; return success;
} }
// Ejecuta la seccion de juego con el logo
void Director::runLogo() void Director::runLogo()
{ {
logo = new Logo(renderer, screen, asset, input, param, section); logo = new Logo(renderer, screen, asset, input, param, section);
@@ -645,6 +646,7 @@ void Director::runLogo()
delete logo; delete logo;
} }
// Ejecuta la seccion de juego de la introducción
void Director::runIntro() void Director::runIntro()
{ {
intro = new Intro(renderer, screen, asset, input, lang, param, section); intro = new Intro(renderer, screen, asset, input, lang, param, section);
@@ -652,6 +654,7 @@ void Director::runIntro()
delete intro; delete intro;
} }
// Ejecuta la seccion de juego con el titulo y los menus
void Director::runTitle() void Director::runTitle()
{ {
title = new Title(renderer, screen, input, asset, options, lang, param, section); title = new Title(renderer, screen, input, asset, options, lang, param, section);
@@ -659,6 +662,7 @@ void Director::runTitle()
delete title; delete title;
} }
// Ejecuta la seccion de juego donde se juega
void Director::runGame() void Director::runGame()
{ {
const int numPlayers = section->subsection == SUBSECTION_GAME_PLAY_1P ? 1 : 2; const int numPlayers = section->subsection == SUBSECTION_GAME_PLAY_1P ? 1 : 2;
@@ -667,6 +671,30 @@ void Director::runGame()
delete game; delete game;
} }
// Ejecuta la parte donde se muestra la tabla de puntuaciones
void Director::runHiScoreTable()
{
hiScoreTable = new HiScoreTable(renderer, screen, asset, input, lang, param, options, section);
hiScoreTable->run();
delete hiScoreTable;
}
// Ejecuta la parte donde se muestran las instrucciones
void Director::runInstructions()
{
instructions = new Instructions(renderer, screen, asset, input, lang, param, section);
instructions->run();
delete instructions;
}
// Ejecuta el juego en modo demo
void Director::runDemoGame()
{
demoGame = new Game(1, 0, renderer, screen, asset, lang, input, true, param, options, section);
demoGame->run();
delete demoGame;
}
void Director::run() void Director::run()
{ {
// Bucle principal // Bucle principal
@@ -689,6 +717,18 @@ void Director::run()
case SECTION_PROG_GAME: case SECTION_PROG_GAME:
runGame(); runGame();
break; break;
case SECTION_PROG_HI_SCORE_TABLE:
runHiScoreTable();
break;
case SECTION_PROG_GAME_DEMO:
runDemoGame();
break;
case SECTION_PROG_INSTRUCTIONS:
runInstructions();
break;
} }
} }
} }

View File

@@ -41,6 +41,9 @@ private:
Intro *intro; // Objeto para la sección de la intro Intro *intro; // Objeto para la sección de la intro
Title *title; // Objeto para la sección del titulo y el menu de opciones Title *title; // Objeto para la sección del titulo y el menu de opciones
Game *game; // Objeto para la sección del juego Game *game; // Objeto para la sección del juego
Instructions *instructions; // Objeto para la sección de las instrucciones
HiScoreTable *hiScoreTable; // Objeto para mostrar las mejores puntuaciones online
Game *demoGame; // Objeto para lanzar la demo del juego
Input *input; // Objeto Input para gestionar las entradas Input *input; // Objeto Input para gestionar las entradas
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
Asset *asset; // Objeto que gestiona todos los ficheros de recursos Asset *asset; // Objeto que gestiona todos los ficheros de recursos
@@ -97,6 +100,15 @@ private:
// Ejecuta la seccion de juego donde se juega // Ejecuta la seccion de juego donde se juega
void runGame(); void runGame();
// Ejecuta la parte donde se muestran las instrucciones
void runInstructions();
// Ejecuta la parte donde se muestra la tabla de puntuaciones
void runHiScoreTable();
// Ejecuta el juego en modo demo
void runDemoGame();
public: public:
// Constructor // Constructor
Director(int argc, char *argv[]); Director(int argc, char *argv[]);

View File

@@ -1564,8 +1564,7 @@ void Game::updatePlayers()
{ {
if (demo.enabled) if (demo.enabled)
{ {
section->name = SECTION_PROG_TITLE; section->name = SECTION_PROG_HI_SCORE_TABLE;
section->subsection = SUBSECTION_TITLE_INSTRUCTIONS;
} }
else else
{ {
@@ -2817,8 +2816,13 @@ void Game::checkGameInput()
} }
} }
// Si pulsamos la tecla de salir, se acaba el programa
if (input->checkInput(input_exit))
{
section->name = SECTION_PROG_QUIT;
}
// Si se pulsa cualquier tecla, se sale del modo demo // Si se pulsa cualquier tecla, se sale del modo demo
if (input->checkAnyInput()) else if (input->checkAnyInput())
{ {
section->name = SECTION_PROG_TITLE; section->name = SECTION_PROG_TITLE;
} }
@@ -2830,8 +2834,7 @@ void Game::checkGameInput()
} }
else else
{ {
section->name = SECTION_PROG_TITLE; section->name = SECTION_PROG_HI_SCORE_TABLE;
section->subsection = SUBSECTION_TITLE_INSTRUCTIONS;
} }
} }
// Modo Demo no activo // Modo Demo no activo

View File

@@ -73,25 +73,11 @@ void HiScoreTable::update()
// Actualiza el fondo // Actualiza el fondo
background->update(); background->update();
if (mode == mhst_auto)
{ // Modo automático
counter++; counter++;
if (counter == counterEnd) if (counter == counterEnd)
{ {
section->name = SECTION_PROG_TITLE; section->name = SECTION_PROG_INSTRUCTIONS;
section->subsection = SUBSECTION_TITLE_1;
}
}
else
{ // Modo manual
++counter %= 60000;
if (manualQuit)
{
section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_2;
}
} }
} }
} }
@@ -130,11 +116,6 @@ void HiScoreTable::fillTexture()
text->writeDX(TXT_CENTER | TXT_SHADOW, GAMECANVAS_CENTER_X, (i * spaceBetweenLines) + spaceBetweenHeader, line, 1, orangeColor, 1, shdwTxtColor); text->writeDX(TXT_CENTER | TXT_SHADOW, GAMECANVAS_CENTER_X, (i * spaceBetweenLines) + spaceBetweenHeader, line, 1, orangeColor, 1, shdwTxtColor);
} }
if ((mode == mhst_manual) && (counter % 50 > 14))
{
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, param->gameHeight - 12, lang->getText(22), 1, orangeColor, 1, shdwTxtColor);
}
// Cambia el destino de renderizado // Cambia el destino de renderizado
SDL_SetRenderTarget(renderer, temp); SDL_SetRenderTarget(renderer, temp);
} }
@@ -152,7 +133,7 @@ void HiScoreTable::render()
background->render(); background->render();
// Establece la ventana del backbuffer // Establece la ventana del backbuffer
viewArea.y = mode == mhst_auto ? std::max(8, param->gameHeight - counter + 100) : 0; viewArea.y = std::max(8, param->gameHeight - counter + 100);
// Copia el backbuffer al renderizador // Copia el backbuffer al renderizador
SDL_RenderCopy(renderer, backbuffer, nullptr, &viewArea); SDL_RenderCopy(renderer, backbuffer, nullptr, &viewArea);
@@ -200,28 +181,16 @@ void HiScoreTable::checkInput()
} }
else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_fire_left, REPEAT_FALSE) || input->checkInput(input_fire_center, REPEAT_FALSE) || input->checkInput(input_fire_right, REPEAT_FALSE)) else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_fire_left, REPEAT_FALSE) || input->checkInput(input_fire_center, REPEAT_FALSE) || input->checkInput(input_fire_right, REPEAT_FALSE))
{
if (mode == mhst_auto)
{ {
JA_StopMusic(); JA_StopMusic();
section->name = SECTION_PROG_TITLE; section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_1; section->subsection = SUBSECTION_TITLE_1;
} }
else
{
if (counter > 30)
{
manualQuit = true;
}
}
}
} }
// Bucle para la pantalla de instrucciones // Bucle para la pantalla de instrucciones
void HiScoreTable::run(mode_hiScoreTable_e mode) void HiScoreTable::run()
{ {
this->mode = mode;
while (section->name == SECTION_PROG_HI_SCORE_TABLE) while (section->name == SECTION_PROG_HI_SCORE_TABLE)
{ {
update(); update();

View File

@@ -15,12 +15,7 @@
#ifndef HISCORE_TABLE_H #ifndef HISCORE_TABLE_H
#define HISCORE_TABLE_H #define HISCORE_TABLE_H
enum mode_hiScoreTable_e // Clase HiScoreTable
{
mhst_manual,
mhst_auto
};
class HiScoreTable class HiScoreTable
{ {
private: private:
@@ -44,7 +39,6 @@ private:
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
bool manualQuit; // Indica si se quiere salir del modo manual bool manualQuit; // Indica si se quiere salir del modo manual
mode_hiScoreTable_e mode; // Modo en el que se van a ejecutar las instrucciones
SDL_Rect viewArea; // Parte de la textura que se muestra en pantalla SDL_Rect viewArea; // Parte de la textura que se muestra en pantalla
// Actualiza las variables // Actualiza las variables
@@ -73,7 +67,7 @@ public:
~HiScoreTable(); ~HiScoreTable();
// Bucle principal // Bucle principal
void run(mode_hiScoreTable_e mode); void run();
}; };
#endif #endif

View File

@@ -1,8 +1,6 @@
#include "instructions.h" #include "instructions.h"
#include <iostream> #include <iostream>
const Uint8 SELF = 0;
// Constructor // Constructor
Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section) Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section)
{ {
@@ -41,13 +39,10 @@ Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset,
// Crea un backbuffer para el renderizador // Crea un backbuffer para el renderizador
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param->gameWidth, param->gameHeight); backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param->gameWidth, param->gameHeight);
if (backbuffer == nullptr) SDL_SetTextureBlendMode(backbuffer, SDL_BLENDMODE_BLEND);
{
std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
// Inicializa variables // Inicializa variables
section->name = SELF; section->name = SECTION_PROG_INSTRUCTIONS;
ticks = 0; ticks = 0;
ticksSpeed = 15; ticksSpeed = 15;
manualQuit = false; manualQuit = false;
@@ -84,8 +79,6 @@ void Instructions::update()
// Actualiza el contador de ticks // Actualiza el contador de ticks
ticks = SDL_GetTicks(); ticks = SDL_GetTicks();
if (mode == m_auto)
{ // Modo automático
counter++; counter++;
if (counter == counterEnd) if (counter == counterEnd)
@@ -94,17 +87,6 @@ void Instructions::update()
section->subsection = SUBSECTION_TITLE_1; section->subsection = SUBSECTION_TITLE_1;
} }
} }
else
{ // Modo manual
++counter %= 60000;
if (manualQuit)
{
section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_2;
}
}
}
} }
// Pinta en pantalla // Pinta en pantalla
@@ -141,11 +123,6 @@ void Instructions::render()
text->writeShadowed(84, 140, lang->getText(20), shdwTxtColor); text->writeShadowed(84, 140, lang->getText(20), shdwTxtColor);
text->writeShadowed(84, 156, lang->getText(21), shdwTxtColor); text->writeShadowed(84, 156, lang->getText(21), shdwTxtColor);
if ((mode == m_manual) && (counter % 50 > 14))
{
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, param->gameHeight - 12, lang->getText(22), 1, orangeColor, 1, shdwTxtColor);
}
// Disquito // Disquito
sprite->setTexture(itemTextures[0]); sprite->setTexture(itemTextures[0]);
sprite->setPos(destRect1); sprite->setPos(destRect1);
@@ -191,14 +168,7 @@ void Instructions::render()
screen->clean(bgColor); screen->clean(bgColor);
// Establece la ventana del backbuffer // Establece la ventana del backbuffer
if (mode == m_auto)
{
window.y = std::max(8, param->gameHeight - counter + 100); window.y = std::max(8, param->gameHeight - counter + 100);
}
else
{
window.y = 0;
}
// Copia el backbuffer al renderizador // Copia el backbuffer al renderizador
SDL_RenderCopy(renderer, backbuffer, nullptr, &window); SDL_RenderCopy(renderer, backbuffer, nullptr, &window);
@@ -246,29 +216,17 @@ void Instructions::checkInput()
} }
else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_fire_left, REPEAT_FALSE) || input->checkInput(input_fire_center, REPEAT_FALSE) || input->checkInput(input_fire_right, REPEAT_FALSE)) else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_fire_left, REPEAT_FALSE) || input->checkInput(input_fire_center, REPEAT_FALSE) || input->checkInput(input_fire_right, REPEAT_FALSE))
{
if (mode == m_auto)
{ {
JA_StopMusic(); JA_StopMusic();
section->name = SECTION_PROG_TITLE; section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_1; section->subsection = SUBSECTION_TITLE_1;
} }
else
{
if (counter > 30)
{
manualQuit = true;
}
}
}
} }
// Bucle para la pantalla de instrucciones // Bucle para la pantalla de instrucciones
void Instructions::run(mode_e mode) void Instructions::run()
{ {
this->mode = mode; while (section->name == SECTION_PROG_INSTRUCTIONS)
while (section->name == SELF)
{ {
update(); update();
checkEvents(); checkEvents();

View File

@@ -14,12 +14,6 @@
#ifndef INSTRUCTIONS_H #ifndef INSTRUCTIONS_H
#define INSTRUCTIONS_H #define INSTRUCTIONS_H
enum mode_e
{
m_manual,
m_auto
};
// Clase Instructions // Clase Instructions
class Instructions class Instructions
{ {
@@ -44,7 +38,6 @@ private:
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
bool manualQuit; // Indica si se quiere salir del modo manual bool manualQuit; // Indica si se quiere salir del modo manual
mode_e mode; // Modo en el que se van a ejecutar las instrucciones
// Actualiza las variables // Actualiza las variables
void update(); void update();
@@ -66,7 +59,7 @@ public:
~Instructions(); ~Instructions();
// Bucle principal // Bucle principal
void run(mode_e mode); void run();
}; };
#endif #endif

View File

@@ -180,6 +180,11 @@ bool setOptions(param_t *param, std::string var, std::string value)
param->pressStart = std::stoi(value); param->pressStart = std::stoi(value);
} }
else if (var == "titleCounter")
{
param->titleCounter = std::stoi(value);
}
else else
{ {
success = false; success = false;

View File

@@ -68,7 +68,7 @@ void Title::init()
{ {
// Inicializa variables // Inicializa variables
section->subsection = SUBSECTION_TITLE_1; section->subsection = SUBSECTION_TITLE_1;
counter = TITLE_COUNTER; counter = 0;
nextSection.name = SECTION_PROG_GAME; nextSection.name = SECTION_PROG_GAME;
postFade = 0; postFade = 0;
ticks = 0; ticks = 0;
@@ -134,9 +134,9 @@ void Title::update()
// Sección 2 - La pantalla con el titulo, el fondo animado y la música // Sección 2 - La pantalla con el titulo, el fondo animado y la música
else if (section->subsection == SUBSECTION_TITLE_2) else if (section->subsection == SUBSECTION_TITLE_2)
{ {
if (counter > 0) if (counter < param->titleCounter)
{ {
counter--; counter++;
// Reproduce la música // Reproduce la música
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
@@ -163,33 +163,8 @@ void Title::update()
JA_StopMusic(); JA_StopMusic();
break; break;
case 1: // 2 PLAYERS
section->name = SECTION_PROG_GAME;
section->subsection = SUBSECTION_GAME_PLAY_2P;
JA_StopMusic();
break;
case 2: // QUIT
section->name = SECTION_PROG_QUIT;
JA_StopMusic();
break;
case 3: // TIME OUT case 3: // TIME OUT
counter = TITLE_COUNTER; section->name = SECTION_PROG_GAME_DEMO;
if (demo)
{
runDemoGame();
if (section->name != SECTION_PROG_QUIT)
{
runInstructions(m_auto);
}
if (section->name != SECTION_PROG_QUIT)
{
runHiScoreTable(mhst_auto);
}
}
else
section->name = SECTION_PROG_LOGO;
break; break;
default: default:
@@ -197,35 +172,9 @@ void Title::update()
} }
} }
} }
else if (counter == 0) else if (counter >= param->titleCounter)
{ {
if (demo) section->name = SECTION_PROG_GAME_DEMO;
{
if (section->name != SECTION_PROG_QUIT)
{
runHiScoreTable(mhst_auto);
}
runDemoGame();
if (section->name != SECTION_PROG_QUIT)
{
runInstructions(m_auto);
}
init();
demo = false;
counter = TITLE_COUNTER;
}
else
{
section->name = SECTION_PROG_LOGO;
}
}
// Sección Instrucciones
if (section->subsection == SUBSECTION_TITLE_INSTRUCTIONS)
{
runInstructions(m_auto);
counter = TITLE_COUNTER;
demo = true;
} }
} }
} }
@@ -355,30 +304,6 @@ void Title::run()
} }
} }
// Ejecuta la parte donde se muestran las instrucciones
void Title::runInstructions(mode_e mode)
{
instructions = new Instructions(renderer, screen, asset, input, lang, param, section);
instructions->run(mode);
delete instructions;
}
// Ejecuta la parte donde se muestra la tabla de puntuaciones
void Title::runHiScoreTable(mode_hiScoreTable_e mode)
{
hiScoreTable = new HiScoreTable(renderer, screen, asset, input, lang, param, options, section);
hiScoreTable->run(mode);
delete hiScoreTable;
}
// Ejecuta el juego en modo demo
void Title::runDemoGame()
{
demoGame = new Game(1, 0, renderer, screen, asset, lang, input, true, param, options, section);
demoGame->run();
delete demoGame;
}
// Modifica las opciones para los controles de los jugadores // Modifica las opciones para los controles de los jugadores
bool Title::updatePlayerInputs(int numPlayer) bool Title::updatePlayerInputs(int numPlayer)
{ {

View File

@@ -28,12 +28,7 @@
// Textos // Textos
#define TEXT_COPYRIGHT "@2020,2024 JailDesigner" #define TEXT_COPYRIGHT "@2020,2024 JailDesigner"
// Contadores // Clase Title
#define TITLE_COUNTER 800
// Cantidad de eventos de la pantalla de titulo
#define TITLE_TOTAL_EVENTS 2
class Title class Title
{ {
private: private:
@@ -91,15 +86,6 @@ private:
// Cambia el valor de la variable de modo de pantalla completa // Cambia el valor de la variable de modo de pantalla completa
void switchFullScreenModeVar(); void switchFullScreenModeVar();
// Ejecuta la parte donde se muestran las instrucciones
void runInstructions(mode_e mode);
// Ejecuta la parte donde se muestra la tabla de puntuaciones
void runHiScoreTable(mode_hiScoreTable_e mode);
// Ejecuta el juego en modo demo
void runDemoGame();
// Modifica las opciones para los controles de los jugadores // Modifica las opciones para los controles de los jugadores
bool updatePlayerInputs(int numPlayer); bool updatePlayerInputs(int numPlayer);