7 Commits

18 changed files with 665 additions and 221 deletions

View File

@@ -126,11 +126,9 @@ namespace jscore {
return score.size(); return score.size();
} }
string getUserName(const int index) { string getUserName(const int index) {
if (score.size()==0 || index >= (int)score.size()) return "";
return score[index].name; return score[index].name;
} }
const int getPoints(const int index) { const int getPoints(const int index) {
if (score.size()==0 || index >= (int)score.size()) return 0;
return score[index].points; return score[index].points;
} }

View File

@@ -38,21 +38,21 @@ const int GAMECANVAS_FIRST_QUARTER_Y = GAMECANVAS_HEIGHT / 4;
const int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3; const int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3;
// Secciones del programa // Secciones del programa
#define PROG_SECTION_LOGO 0 #define SECTION_PROG_LOGO 0
#define PROG_SECTION_INTRO 1 #define SECTION_PROG_INTRO 1
#define PROG_SECTION_TITLE 2 #define SECTION_PROG_TITLE 2
#define PROG_SECTION_GAME 3 #define SECTION_PROG_GAME 3
#define PROG_SECTION_QUIT 4 #define SECTION_PROG_QUIT 4
// Subsecciones // Subsecciones
#define GAME_SECTION_PLAY_1P 0 #define SUBSECTION_GAME_PLAY_1P 0
#define GAME_SECTION_PLAY_2P 1 #define SUBSECTION_GAME_PLAY_2P 1
#define GAME_SECTION_PAUSE 2 #define SUBSECTION_GAME_PAUSE 2
#define GAME_SECTION_GAMEOVER 3 #define SUBSECTION_GAME_GAMEOVER 3
#define TITLE_SECTION_1 3 #define SUBSECTION_TITLE_1 3
#define TITLE_SECTION_2 4 #define SUBSECTION_TITLE_2 4
#define TITLE_SECTION_3 5 #define SUBSECTION_TITLE_3 5
#define TITLE_SECTION_INSTRUCTIONS 6 #define SUBSECTION_TITLE_INSTRUCTIONS 6
// Ningun tipo // Ningun tipo
#define NO_KIND 0 #define NO_KIND 0

View File

@@ -16,7 +16,8 @@
Director::Director(int argc, char *argv[]) Director::Director(int argc, char *argv[])
{ {
// Inicializa variables // Inicializa variables
section.name = PROG_SECTION_LOGO; section = new section_t();
section->name = SECTION_PROG_LOGO;
// Inicializa las opciones del programa // Inicializa las opciones del programa
initOptions(); initOptions();
@@ -73,6 +74,7 @@ Director::~Director()
delete screen; delete screen;
delete lang; delete lang;
delete options; delete options;
delete section;
SDL_DestroyRenderer(renderer); SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window); SDL_DestroyWindow(window);
@@ -662,61 +664,55 @@ bool Director::saveConfigFile()
return success; return success;
} }
// Establece el valor de la variable
void Director::setSection(section_t section)
{
this->section = section;
}
void Director::runLogo() void Director::runLogo()
{ {
logo = new Logo(renderer, screen, asset, input); logo = new Logo(renderer, screen, asset, input, section);
setSection(logo->run()); logo->run();
delete logo; delete logo;
} }
void Director::runIntro() void Director::runIntro()
{ {
intro = new Intro(renderer, screen, asset, input, lang); intro = new Intro(renderer, screen, asset, input, lang, section);
setSection(intro->run()); intro->run();
delete intro; delete intro;
} }
void Director::runTitle() void Director::runTitle()
{ {
title = new Title(renderer, screen, input, asset, options, lang, section); title = new Title(renderer, screen, input, asset, options, lang, section);
setSection(title->run()); title->run();
delete title; delete title;
} }
void Director::runGame() void Director::runGame()
{ {
const int numPlayers = section.subsection == GAME_SECTION_PLAY_1P ? 1 : 2; const int numPlayers = section->subsection == SUBSECTION_GAME_PLAY_1P ? 1 : 2;
game = new Game(numPlayers, 0, renderer, screen, asset, lang, input, false, options); game = new Game(numPlayers, 0, renderer, screen, asset, lang, input, false, options, section);
setSection(game->run()); game->run();
delete game; delete game;
} }
void Director::run() void Director::run()
{ {
// Bucle principal // Bucle principal
while (section.name != PROG_SECTION_QUIT) while (section->name != SECTION_PROG_QUIT)
{ {
switch (section.name) switch (section->name)
{ {
case PROG_SECTION_LOGO: case SECTION_PROG_LOGO:
runLogo(); runLogo();
break; break;
case PROG_SECTION_INTRO: case SECTION_PROG_INTRO:
runIntro(); runIntro();
break; break;
case PROG_SECTION_TITLE: case SECTION_PROG_TITLE:
runTitle(); runTitle();
break; break;
case PROG_SECTION_GAME: case SECTION_PROG_GAME:
runGame(); runGame();
break; break;
} }

View File

@@ -43,10 +43,10 @@ private:
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
section_t *section; // Sección y subsección actual del programa;
// Variables // Variables
struct options_t *options; // Variable con todas las opciones del programa struct options_t *options; // Variable con todas las opciones del programa
section_t section; // Sección y subsección actual del programa;
std::string executablePath; // Path del ejecutable std::string executablePath; // Path del ejecutable
std::string systemFolder; // Carpeta del sistema donde guardar datos std::string systemFolder; // Carpeta del sistema donde guardar datos

353
source/enter_id.cpp Normal file
View File

@@ -0,0 +1,353 @@
#include "common/jail_audio.h"
#include "common/jscore.h"
#include "const.h"
#include "enter_id.h"
#include <iostream>
// Constructor
EnterID::EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, options_t *options, section_t *section)
{
// Copia la dirección de los objetos
this->renderer = renderer;
this->screen = screen;
this->asset = asset;
this->lang = lang;
this->options = options;
this->section = section;
// Reserva memoria para los punteros
eventHandler = new SDL_Event();
texture = new Texture(renderer, asset->get("smb2.png"));
text = new Text(asset->get("smb2.txt"), texture, renderer);
// 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)
{
if (options->console)
{
std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
SDL_SetTextureBlendMode(textTexture, SDL_BLENDMODE_BLEND);
// Inicializa variables
loopRunning = true;
counter = 0;
ticks = 0;
ticksSpeed = 15;
initName();
// Escribe el texto en la textura
fillTexture();
}
// Destructor
EnterID::~EnterID()
{
delete eventHandler;
delete text;
delete texture;
}
// Bucle principal
void EnterID::run()
{
while (loopRunning)
{
update();
checkEvents();
render();
}
}
// Comprueba el manejador de eventos
void EnterID::checkEvents()
{
// Comprueba los eventos que hay en la cola
while (SDL_PollEvent(eventHandler) != 0)
{
// Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT)
{
section->name = SECTION_PROG_QUIT;
loopRunning = false;
break;
}
// El ENTER solo se comprueba cuando se suelta, para no saltarse la siguiente sección
if ((eventHandler->type == SDL_KEYUP && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONUP))
{
if (eventHandler->key.keysym.scancode == SDL_SCANCODE_RETURN)
{
options->online.jailerID = (std::string)name;
endSection();
break;
}
}
// Comprueba las teclas que se han pulsado
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
{
if (eventHandler->key.keysym.scancode >= SDL_SCANCODE_A && eventHandler->key.keysym.scancode <= SDL_SCANCODE_Z)
{ // Si pulsa una letra
if (pos < maxLenght)
{
name[pos++] = eventHandler->key.keysym.scancode + 61;
name[pos] = 0;
}
}
else if (eventHandler->key.keysym.scancode >= SDL_SCANCODE_1 && eventHandler->key.keysym.scancode <= SDL_SCANCODE_9)
{ // Si pulsa un número
if (pos < maxLenght)
{ // En ascii el '0' va antes del '1', pero en scancode el '0' va despues de '9'
name[pos++] = eventHandler->key.keysym.scancode + 19;
name[pos] = 0;
}
}
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_0)
{
if (pos < maxLenght)
{
name[pos++] = 48;
name[pos] = 0;
}
}
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_BACKSPACE)
{
if (pos > 0)
{
name[--pos] = 0;
}
}
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_ESCAPE)
{
section->name = SECTION_PROG_QUIT;
break;
}
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_F1)
{
screen->setWindowSize(1);
break;
}
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_F2)
{
screen->setWindowSize(2);
break;
}
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_F3)
{
screen->setWindowSize(3);
break;
}
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_F4)
{
screen->setWindowSize(4);
break;
}
}
}
}
// Actualiza las variables
void EnterID::update()
{
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
if (SDL_GetTicks() - ticks > ticksSpeed)
{
// Actualiza el contador de ticks
ticks = SDL_GetTicks();
// Actualiza el contador
counter++;
// Actualiza el cursor
cursor = (counter % 20 >= 10) ? " " : "_";
// Actualiza las notificaciones
screen->updateNotifier();
}
}
// Dibuja en pantalla
void EnterID::render()
{
// Prepara para empezar a dibujar en la textura de juego
screen->start();
// Limpia la pantalla
screen->clean();
// Dibuja la textura con el texto en pantalla
SDL_RenderCopy(renderer, textTexture, nullptr, nullptr);
// Escribe el jailerID
const std::string jailerID = (std::string)name + cursor;
const color_t color = stringToColor(options->palette, "white");
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, (16 * 8 + 1), jailerID, 1, color);
// Vuelca el contenido del renderizador en pantalla
screen->blit();
}
// Inicializa los textos
void EnterID::iniTexts()
{
texts.clear();
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"ONLINE CONFIGURATION:", stringToColor(options->palette, "red")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"YOU HAVE NOT SPECIFIED ANY ID", stringToColor(options->palette, "white")});
texts.push_back({"FOR THE ONLINE SERVICE", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"PLEASE ENTER AN ID OR", stringToColor(options->palette, "white")});
texts.push_back({"LEAVE BLANK FOR OFFLINE MODE", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"JAILER_ID:", stringToColor(options->palette, "red")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
}
// Escribe el texto en la textura
void EnterID::fillTexture()
{
// Inicializa los textos
iniTexts();
// Rellena la textura de texto
SDL_SetRenderTarget(renderer, textTexture);
color_t c = stringToColor(options->palette, "black");
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
SDL_RenderClear(renderer);
// Escribe el texto en la textura
const int size = text->getCharacterSize();
int i = 0;
for (auto t : texts)
{
text->writeDX(TXT_CENTER | TXT_COLOR, PLAY_AREA_CENTER_X, i * size, t.label, 1, t.color);
i++;
}
SDL_SetRenderTarget(renderer, nullptr);
}
// Inicializa los servicios online
void EnterID::initOnline()
{
if (options->online.sessionEnabled)
{ // Si ya ha iniciado la sesión, que no continue
return;
}
if (options->online.jailerID == "")
{ // Jailer ID no definido
options->online.enabled = false;
}
else
{ // Jailer ID iniciado
options->online.enabled = options->online.sessionEnabled = true;
// Establece el servidor y el puerto
jscore::init(options->online.server, options->online.port);
#ifdef DEBUG
const std::string caption = options->online.jailerID + " (DEBUG)";
#else
const std::string caption = options->online.jailerID;
#endif
screen->showNotification(caption, lang->getText(85), 12);
if (options->console)
{
std::cout << caption << std::endl;
}
// Obtiene la información de puntuaciones online
if (!jscore::initOnlineScore(options->online.gameID))
{
screen->showNotification(lang->getText(80), options->online.server);
if (options->console)
{
std::cout << "Can't connect to " << options->online.server << std::endl;
}
options->online.enabled = false;
return;
}
// Obten la puntuación online para el jailerID
const int points = jscore::getUserPoints(options->online.gameID, options->online.jailerID);
if (points == 0)
{ // Fallo de conexión o no hay registros
screen->showNotification(lang->getText(81), lang->getText(82));
if (options->console)
{
std::cout << "Can't get online scores" << std::endl;
}
}
else
{
options->online.score = points;
}
}
}
// Termina la sección
void EnterID::endSection()
{
loopRunning = false;
initOnline();
}
// Inicializa el vector utilizado para almacenar el texto que se escribe en pantalla
void EnterID::initName()
{
std::cout << options->online.jailerID << std::endl;
// Calcula el tamaño del vector
name[0] = 0;
maxLenght = sizeof(name) / sizeof(name[pos]);
// Inicializa el vector con ceros
for (int i = 0; i < maxLenght; ++i)
{
name[i] = 0;
}
// Si no hay definido ningun JailerID, coloca el cursor en primera posición
if (options->online.jailerID == "")
{
pos = 0;
}
else
{ // En caso contrario, copia el texto al vector y coloca el cursor en posición
const int len = std::min((int)options->online.jailerID.size(), maxLenght);
for (int i = 0; i < len; ++i)
{
name[i] = (char)options->online.jailerID[i];
}
pos = len;
}
std::cout << (std::string)name << std::endl;
}

83
source/enter_id.h Normal file
View File

@@ -0,0 +1,83 @@
#pragma once
#include <SDL2/SDL.h>
#include "common/asset.h"
#include "common/screen.h"
#include "common/utils.h"
#include "common/text.h"
#include "common/texture.h"
#include <string>
#include <vector>
#ifndef ENTER_ID_H
#define ENTER_ID_H
class EnterID
{
private:
struct captions_t
{
std::string label; // Texto a escribir
color_t color; // Color del texto
};
// Punteros y objetos
Asset *asset; // Objeto con los ficheros de recursos
options_t *options; // Puntero a las opciones del juego
Screen *screen; // Objeto encargado de dibujar en pantalla
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
SDL_Event *eventHandler; // Manejador de eventos
SDL_Renderer *renderer; // El renderizador de la ventana
SDL_Texture *textTexture; // Textura para dibujar el texto
Text *text; // Objeto para escribir texto en pantalla
Texture *texture; // Textura para la fuente para el texto
section_t *section; // Estado del bucle principal para saber si continua o se sale
// Variables
bool loopRunning; // Indica si ha de terminar el bucle principal
int counter; // Contador
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
std::vector<captions_t> texts; // Vector con los textos
std::string cursor; // Contiene el caracter que se muestra como cursor
char name[15]; // Aqui se guardan los caracteres de las teclas que se van pulsando
int pos; // Posición actual en el vector name
int maxLenght; // Tamaño máximo del jailerID
// Actualiza las variables
void update();
// Dibuja en pantalla
void render();
// Comprueba el manejador de eventos
void checkEvents();
// Inicializa los textos
void iniTexts();
// Escribe el texto en la textura
void fillTexture();
// Inicializa los servicios online
void initOnline();
// Termina la sección
void endSection();
// Inicializa el vector utilizado para almacenar el texto que se escribe en pantalla
void initName();
public:
// Constructor
EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, options_t *options, section_t *section);
// Destructor
~EnterID();
// Bucle principal
void run();
};
#endif

View File

@@ -2,7 +2,7 @@
#include "common/jscore.h" #include "common/jscore.h"
// Constructor // Constructor
Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, options_t *options) Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, options_t *options, section_t *section)
{ {
// Copia los punteros // Copia los punteros
this->renderer = renderer; this->renderer = renderer;
@@ -11,6 +11,7 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr
this->lang = lang; this->lang = lang;
this->input = input; this->input = input;
this->options = options; this->options = options;
this->section = section;
// Pasa variables // Pasa variables
this->demo.enabled = demo; this->demo.enabled = demo;
@@ -246,8 +247,8 @@ void Game::init()
gameCompleted = false; gameCompleted = false;
gameCompletedCounter = 0; gameCompletedCounter = 0;
section.name = PROG_SECTION_GAME; section->name = SECTION_PROG_GAME;
section.subsection = GAME_SECTION_PLAY_1P; section->subsection = SUBSECTION_GAME_PLAY_1P;
menaceCurrent = 0; menaceCurrent = 0;
menaceThreshold = 0; menaceThreshold = 0;
hiScoreAchieved = false; hiScoreAchieved = false;
@@ -1767,7 +1768,8 @@ void Game::updatePlayers()
{ {
if (demo.enabled) if (demo.enabled)
{ {
section = {PROG_SECTION_TITLE, TITLE_SECTION_INSTRUCTIONS}; section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_INSTRUCTIONS;
} }
else else
{ {
@@ -1866,7 +1868,7 @@ void Game::updateDeath()
} }
else else
{ {
section.subsection = GAME_SECTION_GAMEOVER; section->subsection = SUBSECTION_GAME_GAMEOVER;
} }
} }
} }
@@ -3089,7 +3091,7 @@ void Game::checkGameInput()
// Comprueba el input de pausa // Comprueba el input de pausa
if (input->checkInput(input_pause, REPEAT_FALSE)) if (input->checkInput(input_pause, REPEAT_FALSE))
{ {
section.name = PROG_SECTION_TITLE; section->name = SECTION_PROG_TITLE;
} }
// Incrementa el contador de la demo // Incrementa el contador de la demo
@@ -3099,7 +3101,8 @@ void Game::checkGameInput()
} }
else else
{ {
section = {PROG_SECTION_TITLE, TITLE_SECTION_INSTRUCTIONS}; section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_INSTRUCTIONS;
} }
} }
// Modo Demo no activo // Modo Demo no activo
@@ -3182,7 +3185,7 @@ void Game::checkGameInput()
// Comprueba el input de pausa // Comprueba el input de pausa
if (input->checkInput(input_cancel, REPEAT_FALSE, options->input[i].deviceType, options->input[i].id)) if (input->checkInput(input_cancel, REPEAT_FALSE, options->input[i].deviceType, options->input[i].id))
{ {
section.subsection = GAME_SECTION_PAUSE; section->subsection = SUBSECTION_GAME_PAUSE;
} }
if (demo.counter < TOTAL_DEMO_DATA) if (demo.counter < TOTAL_DEMO_DATA)
@@ -3195,7 +3198,7 @@ void Game::checkGameInput()
} }
else if (demo.recording) else if (demo.recording)
{ {
section.name = PROG_SECTION_QUIT; section->name = SECTION_PROG_QUIT;
} }
i++; i++;
@@ -3339,24 +3342,24 @@ void Game::shakeScreen()
} }
// Bucle para el juego // Bucle para el juego
section_t Game::run() void Game::run()
{ {
while (section.name == PROG_SECTION_GAME) while (section->name == SECTION_PROG_GAME)
{ {
// Sección juego en pausa // Sección juego en pausa
if (section.subsection == GAME_SECTION_PAUSE) if (section->subsection == SUBSECTION_GAME_PAUSE)
{ {
runPausedGame(); runPausedGame();
} }
// Sección Game Over // Sección Game Over
if (section.subsection == GAME_SECTION_GAMEOVER) if (section->subsection == SUBSECTION_GAME_GAMEOVER)
{ {
runGameOverScreen(); runGameOverScreen();
} }
// Sección juego jugando // Sección juego jugando
if ((section.subsection == GAME_SECTION_PLAY_1P) || (section.subsection == GAME_SECTION_PLAY_2P)) if ((section->subsection == SUBSECTION_GAME_PLAY_1P) || (section->subsection == SUBSECTION_GAME_PLAY_2P))
{ {
// Si la música no está sonando // Si la música no está sonando
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
@@ -3381,8 +3384,6 @@ section_t Game::run()
render(); render();
} }
} }
return section;
} }
// Actualiza las variables del menu de pausa del juego // Actualiza las variables del menu de pausa del juego
@@ -3412,8 +3413,8 @@ void Game::updatePausedGame()
} }
else else
{ // Ha finalizado el contador { // Ha finalizado el contador
section.name = PROG_SECTION_GAME; section->name = SECTION_PROG_GAME;
section.subsection = numPlayers == 1 ? GAME_SECTION_PLAY_1P : GAME_SECTION_PLAY_2P; section->subsection = numPlayers == 1 ? SUBSECTION_GAME_PLAY_1P : SUBSECTION_GAME_PLAY_2P;
if (JA_GetMusicState() == JA_MUSIC_PAUSED) if (JA_GetMusicState() == JA_MUSIC_PAUSED)
{ {
@@ -3448,8 +3449,8 @@ void Game::updatePausedGame()
fade->update(); fade->update();
if (fade->hasEnded()) if (fade->hasEnded())
{ {
section.name = PROG_SECTION_TITLE; section->name = SECTION_PROG_TITLE;
section.subsection = TITLE_SECTION_1; section->subsection = SUBSECTION_TITLE_1;
JA_StopMusic(); JA_StopMusic();
} }
} }
@@ -3519,7 +3520,7 @@ void Game::runPausedGame()
// Inicializa variables // Inicializa variables
pauseCounter = 90; pauseCounter = 90;
while ((section.subsection == GAME_SECTION_PAUSE) && (section.name == PROG_SECTION_GAME)) while ((section->subsection == SUBSECTION_GAME_PAUSE) && (section->name == SECTION_PROG_GAME))
{ {
updatePausedGame(); updatePausedGame();
checkEvents(); checkEvents();
@@ -3554,15 +3555,15 @@ void Game::updateGameOverScreen()
switch (postFade) switch (postFade)
{ {
case 0: // YES case 0: // YES
section.name = PROG_SECTION_GAME; section->name = SECTION_PROG_GAME;
deleteAllVectorObjects(); deleteAllVectorObjects();
init(); init();
section.subsection = numPlayers == 1 ? GAME_SECTION_PLAY_1P : GAME_SECTION_PLAY_2P; section->subsection = numPlayers == 1 ? SUBSECTION_GAME_PLAY_1P : SUBSECTION_GAME_PLAY_2P;
break; break;
case 1: // NO case 1: // NO
section.name = PROG_SECTION_TITLE; section->name = SECTION_PROG_TITLE;
section.subsection = TITLE_SECTION_1; section->subsection = SUBSECTION_TITLE_1;
break; break;
default: default:
@@ -3600,7 +3601,7 @@ void Game::updateGameOverScreen()
// Evento de salida de la aplicación // Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT) if (eventHandler->type == SDL_QUIT)
{ {
section.name = PROG_SECTION_QUIT; section->name = SECTION_PROG_QUIT;
break; break;
} }
else if (eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) else if (eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0)
@@ -3693,7 +3694,7 @@ void Game::runGameOverScreen()
// Reinicia el menu // Reinicia el menu
gameOverMenu->reset(); gameOverMenu->reset();
while ((section.subsection == GAME_SECTION_GAMEOVER) && (section.name == PROG_SECTION_GAME)) while ((section->subsection == SUBSECTION_GAME_GAMEOVER) && (section->name == SECTION_PROG_GAME))
{ {
updateGameOverScreen(); updateGameOverScreen();
renderGameOverScreen(); renderGameOverScreen();
@@ -3806,7 +3807,7 @@ void Game::updateGameCompleted()
if (gameCompletedCounter == GAME_COMPLETED_END) if (gameCompletedCounter == GAME_COMPLETED_END)
{ {
section.subsection = GAME_SECTION_GAMEOVER; section->subsection = SUBSECTION_GAME_GAMEOVER;
} }
} }
@@ -3864,7 +3865,7 @@ void Game::checkEvents()
// Evento de salida de la aplicación // Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT) if (eventHandler->type == SDL_QUIT)
{ {
section.name = PROG_SECTION_QUIT; section->name = SECTION_PROG_QUIT;
break; break;
} }
@@ -3872,7 +3873,7 @@ void Game::checkEvents()
{ {
if (eventHandler->window.event == SDL_WINDOWEVENT_FOCUS_LOST) if (eventHandler->window.event == SDL_WINDOWEVENT_FOCUS_LOST)
{ {
section.subsection = GAME_SECTION_PAUSE; section->subsection = SUBSECTION_GAME_PAUSE;
} }
} }
} }

View File

@@ -120,6 +120,7 @@ private:
Asset *asset; // Objeto que gestiona todos los ficheros de recursos Asset *asset; // Objeto que gestiona todos los ficheros de recursos
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
Input *input; // Manejador de entrada Input *input; // Manejador de entrada
section_t *section; // Seccion actual dentro del juego
std::vector<Player *> players; // Vector con los jugadores std::vector<Player *> players; // Vector con los jugadores
std::vector<Balloon *> balloons; // Vector con los globos std::vector<Balloon *> balloons; // Vector con los globos
@@ -127,21 +128,21 @@ private:
std::vector<Item *> items; // Vector con los items std::vector<Item *> items; // Vector con los items
std::vector<SmartSprite *> smartSprites; // Vector con los smartsprites std::vector<SmartSprite *> smartSprites; // Vector con los smartsprites
Texture *bulletTexture; // Textura para las balas Texture *bulletTexture; // Textura para las balas
std::vector<Texture *> itemTextures; // Vector con las texturas de los items std::vector<Texture *> itemTextures; // Vector con las texturas de los items
std::vector<Texture *> balloonTextures; // Vector con las texturas de los globos std::vector<Texture *> balloonTextures; // Vector con las texturas de los globos
std::vector<Texture *> player1Textures; // Vector con las texturas del jugador std::vector<Texture *> player1Textures; // Vector con las texturas del jugador
std::vector<Texture *> player2Textures; // Vector con las texturas del jugador std::vector<Texture *> player2Textures; // Vector con las texturas del jugador
std::vector<std::vector<Texture *>> playerTextures; // Vector con todas las texturas de los jugadores; std::vector<std::vector<Texture *>> playerTextures; // Vector con todas las texturas de los jugadores;
Texture *gameBuildingsTexture; // Textura con los edificios de fondo Texture *gameBuildingsTexture; // Textura con los edificios de fondo
Texture *gameCloudsTexture; // Textura con las nubes de fondo Texture *gameCloudsTexture; // Textura con las nubes de fondo
Texture *gameGrassTexture; // Textura con la hierba del suelo Texture *gameGrassTexture; // Textura con la hierba del suelo
Texture *gamePowerMeterTexture; // Textura con el marcador de poder de la fase Texture *gamePowerMeterTexture; // Textura con el marcador de poder de la fase
Texture *gameSkyColorsTexture; // Textura con los diferentes colores de fondo del juego Texture *gameSkyColorsTexture; // Textura con los diferentes colores de fondo del juego
Texture *gameTextTexture; // Textura para los sprites con textos Texture *gameTextTexture; // Textura para los sprites con textos
Texture *gameOverTexture; // Textura para la pantalla de game over Texture *gameOverTexture; // Textura para la pantalla de game over
Texture *gameOverEndTexture; // Textura para la pantalla de game over de acabar el juego Texture *gameOverEndTexture; // Textura para la pantalla de game over de acabar el juego
std::vector<std::vector<std::string> *> itemAnimations; // Vector con las animaciones de los items std::vector<std::vector<std::string> *> itemAnimations; // Vector con las animaciones de los items
std::vector<std::vector<std::string> *> playerAnimations; // Vector con las animaciones del jugador std::vector<std::vector<std::string> *> playerAnimations; // Vector con las animaciones del jugador
@@ -174,23 +175,23 @@ private:
Sprite *gameOverSprite; // Sprite para dibujar los graficos del game over Sprite *gameOverSprite; // Sprite para dibujar los graficos del game over
Sprite *gameOverEndSprite; // Sprite para dibujar los graficos del game over de acabar el juego Sprite *gameOverEndSprite; // Sprite para dibujar los graficos del game over de acabar el juego
JA_Sound_t* balloonSound; // Sonido para la explosión del globo JA_Sound_t *balloonSound; // Sonido para la explosión del globo
JA_Sound_t* bulletSound; // Sonido para los disparos JA_Sound_t *bulletSound; // Sonido para los disparos
JA_Sound_t* playerCollisionSound; // Sonido para la colisión del jugador con un enemigo JA_Sound_t *playerCollisionSound; // Sonido para la colisión del jugador con un enemigo
JA_Sound_t* hiScoreSound; // Sonido para cuando se alcanza la máxima puntuación JA_Sound_t *hiScoreSound; // Sonido para cuando se alcanza la máxima puntuación
JA_Sound_t* itemDropSound; // Sonido para cuando se genera un item JA_Sound_t *itemDropSound; // Sonido para cuando se genera un item
JA_Sound_t* itemPickUpSound; // Sonido para cuando se recoge un item JA_Sound_t *itemPickUpSound; // Sonido para cuando se recoge un item
JA_Sound_t* coffeeOutSound; // Sonido para cuando el jugador pierde el café al recibir un impacto JA_Sound_t *coffeeOutSound; // Sonido para cuando el jugador pierde el café al recibir un impacto
JA_Sound_t* stageChangeSound; // Sonido para cuando se cambia de fase JA_Sound_t *stageChangeSound; // Sonido para cuando se cambia de fase
JA_Sound_t* bubble1Sound; // Sonido para cuando el jugador muere JA_Sound_t *bubble1Sound; // Sonido para cuando el jugador muere
JA_Sound_t* bubble2Sound; // Sonido para cuando el jugador muere JA_Sound_t *bubble2Sound; // Sonido para cuando el jugador muere
JA_Sound_t* bubble3Sound; // Sonido para cuando el jugador muere JA_Sound_t *bubble3Sound; // Sonido para cuando el jugador muere
JA_Sound_t* bubble4Sound; // Sonido para cuando el jugador muere JA_Sound_t *bubble4Sound; // Sonido para cuando el jugador muere
JA_Sound_t* clockSound; // Sonido para cuando se detiene el tiempo con el item reloj JA_Sound_t *clockSound; // Sonido para cuando se detiene el tiempo con el item reloj
JA_Sound_t* powerBallSound; // Sonido para cuando se explota una Power Ball JA_Sound_t *powerBallSound; // Sonido para cuando se explota una Power Ball
JA_Sound_t* coffeeMachineSound; // Sonido para cuando la máquina de café toca el suelo JA_Sound_t *coffeeMachineSound; // Sonido para cuando la máquina de café toca el suelo
JA_Music_t* gameMusic; // Musica de fondo JA_Music_t *gameMusic; // Musica de fondo
// Variables // Variables
int numPlayers; // Numero de jugadores int numPlayers; // Numero de jugadores
@@ -198,7 +199,6 @@ private:
Uint8 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint8 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
Uint32 hiScore; // Puntuación máxima Uint32 hiScore; // Puntuación máxima
bool hiScoreAchieved; // Indica si se ha superado la puntuación máxima bool hiScoreAchieved; // Indica si se ha superado la puntuación máxima
section_t section; // Seccion actual dentro del juego
stage_t stage[10]; // Variable con los datos de cada pantalla stage_t stage[10]; // Variable con los datos de cada pantalla
Uint8 currentStage; // Indica la fase actual Uint8 currentStage; // Indica la fase actual
Uint8 stageBitmapCounter; // Contador para el tiempo visible del texto de Stage Uint8 stageBitmapCounter; // Contador para el tiempo visible del texto de Stage
@@ -513,13 +513,13 @@ private:
public: public:
// Constructor // Constructor
Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, options_t *options); Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, options_t *options, section_t *section);
// Destructor // Destructor
~Game(); ~Game();
// Bucle para el juego // Bucle para el juego
section_t run(); void run();
}; };
#endif #endif

View File

@@ -5,7 +5,7 @@
const Uint8 SELF = 0; const Uint8 SELF = 0;
// Constructor // Constructor
HiScoreTable::HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options) HiScoreTable::HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, section_t *section)
{ {
// Copia los punteros // Copia los punteros
this->renderer = renderer; this->renderer = renderer;
@@ -13,6 +13,7 @@ HiScoreTable::HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset,
this->asset = asset; this->asset = asset;
this->input = input; this->input = input;
this->lang = lang; this->lang = lang;
this->section = section;
// Reserva memoria para los punteros // Reserva memoria para los punteros
eventHandler = new SDL_Event(); eventHandler = new SDL_Event();
@@ -30,7 +31,7 @@ HiScoreTable::HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset,
} }
// Inicializa variables // Inicializa variables
section.name = SELF; section->name = SELF;
ticks = 0; ticks = 0;
ticksSpeed = 15; ticksSpeed = 15;
manualQuit = false; manualQuit = false;
@@ -68,8 +69,8 @@ void HiScoreTable::update()
if (counter == counterEnd) if (counter == counterEnd)
{ {
section.name = PROG_SECTION_TITLE; section->name = SECTION_PROG_TITLE;
section.subsection = TITLE_SECTION_1; section->subsection = SUBSECTION_TITLE_1;
} }
} }
else else
@@ -78,8 +79,8 @@ void HiScoreTable::update()
if (manualQuit) if (manualQuit)
{ {
section.name = PROG_SECTION_TITLE; section->name = SECTION_PROG_TITLE;
section.subsection = TITLE_SECTION_3; section->subsection = SUBSECTION_TITLE_3;
} }
} }
} }
@@ -180,7 +181,7 @@ void HiScoreTable::checkEventHandler()
// Evento de salida de la aplicación // Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT) if (eventHandler->type == SDL_QUIT)
{ {
section.name = PROG_SECTION_QUIT; section->name = SECTION_PROG_QUIT;
break; break;
} }
} }
@@ -191,7 +192,7 @@ void HiScoreTable::checkInput()
{ {
if (input->checkInput(input_exit, REPEAT_FALSE)) if (input->checkInput(input_exit, REPEAT_FALSE))
{ {
section.name = PROG_SECTION_QUIT; section->name = SECTION_PROG_QUIT;
} }
else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE)) else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
@@ -214,8 +215,8 @@ void HiScoreTable::checkInput()
if (mode == mhst_auto) if (mode == mhst_auto)
{ {
JA_StopMusic(); JA_StopMusic();
section.name = PROG_SECTION_TITLE; section->name = SECTION_PROG_TITLE;
section.subsection = TITLE_SECTION_1; section->subsection = SUBSECTION_TITLE_1;
} }
else else
{ {
@@ -228,17 +229,15 @@ void HiScoreTable::checkInput()
} }
// Bucle para la pantalla de instrucciones // Bucle para la pantalla de instrucciones
section_t HiScoreTable::run(mode_hiScoreTable_e mode) void HiScoreTable::run(mode_hiScoreTable_e mode)
{ {
this->mode = mode; this->mode = mode;
while (section.name == SELF) while (section->name == SELF)
{ {
update(); update();
render(); render();
} }
return section;
} }
// Transforma un valor numérico en una cadena de 6 cifras // Transforma un valor numérico en una cadena de 6 cifras

View File

@@ -32,11 +32,11 @@ private:
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
Text *text; // Objeto para escribir texto Text *text; // Objeto para escribir texto
options_t *options; // Opciones y parametyros del programa options_t *options; // Opciones y parametyros del programa
section_t *section; // Estado del bucle principal para saber si continua o se sale
// Variables // Variables
Uint16 counter; // Contador Uint16 counter; // Contador
Uint16 counterEnd; // Valor final para el contador Uint16 counterEnd; // Valor final para el contador
section_t section; // Estado del bucle principal para saber si continua o se sale
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
@@ -59,13 +59,13 @@ private:
public: public:
// Constructor // Constructor
HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options); HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, section_t *section);
// Destructor // Destructor
~HiScoreTable(); ~HiScoreTable();
// Bucle principal // Bucle principal
section_t run(mode_hiScoreTable_e mode); void run(mode_hiScoreTable_e mode);
}; };
#endif #endif

View File

@@ -4,7 +4,7 @@
const Uint8 SELF = 0; const Uint8 SELF = 0;
// Constructor // Constructor
Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang) Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, section_t *section)
{ {
// Copia los punteros // Copia los punteros
this->renderer = renderer; this->renderer = renderer;
@@ -12,6 +12,7 @@ Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset,
this->asset = asset; this->asset = asset;
this->input = input; this->input = input;
this->lang = lang; this->lang = lang;
this->section = section;
// Reserva memoria para los punteros // Reserva memoria para los punteros
Texture *item1 = new Texture(renderer, asset->get("item_points1_disk.png")); Texture *item1 = new Texture(renderer, asset->get("item_points1_disk.png"));
@@ -45,7 +46,7 @@ Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset,
} }
// Inicializa variables // Inicializa variables
section.name = SELF; section->name = SELF;
ticks = 0; ticks = 0;
ticksSpeed = 15; ticksSpeed = 15;
manualQuit = false; manualQuit = false;
@@ -88,8 +89,8 @@ void Instructions::update()
if (counter == counterEnd) if (counter == counterEnd)
{ {
section.name = PROG_SECTION_TITLE; section->name = SECTION_PROG_TITLE;
section.subsection = TITLE_SECTION_1; section->subsection = SUBSECTION_TITLE_1;
} }
} }
else else
@@ -98,8 +99,8 @@ void Instructions::update()
if (manualQuit) if (manualQuit)
{ {
section.name = PROG_SECTION_TITLE; section->name = SECTION_PROG_TITLE;
section.subsection = TITLE_SECTION_3; section->subsection = SUBSECTION_TITLE_3;
} }
} }
} }
@@ -214,7 +215,7 @@ void Instructions::checkEvents()
// Evento de salida de la aplicación // Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT) if (eventHandler->type == SDL_QUIT)
{ {
section.name = PROG_SECTION_QUIT; section->name = SECTION_PROG_QUIT;
break; break;
} }
} }
@@ -225,7 +226,7 @@ void Instructions::checkInput()
{ {
if (input->checkInput(input_exit, REPEAT_FALSE)) if (input->checkInput(input_exit, REPEAT_FALSE))
{ {
section.name = PROG_SECTION_QUIT; section->name = SECTION_PROG_QUIT;
} }
else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE)) else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
@@ -248,8 +249,8 @@ void Instructions::checkInput()
if (mode == m_auto) if (mode == m_auto)
{ {
JA_StopMusic(); JA_StopMusic();
section.name = PROG_SECTION_TITLE; section->name = SECTION_PROG_TITLE;
section.subsection = TITLE_SECTION_1; section->subsection = SUBSECTION_TITLE_1;
} }
else else
{ {
@@ -262,16 +263,14 @@ void Instructions::checkInput()
} }
// Bucle para la pantalla de instrucciones // Bucle para la pantalla de instrucciones
section_t Instructions::run(mode_e mode) void Instructions::run(mode_e mode)
{ {
this->mode = mode; this->mode = mode;
while (section.name == SELF) while (section->name == SELF)
{ {
update(); update();
checkEvents(); checkEvents();
render(); render();
} }
return section;
} }

View File

@@ -34,11 +34,11 @@ private:
Input *input; // Objeto pata gestionar la entrada Input *input; // Objeto pata gestionar la entrada
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
Text *text; // Objeto para escribir texto Text *text; // Objeto para escribir texto
section_t *section; // Estado del bucle principal para saber si continua o se sale
// Variables // Variables
Uint16 counter; // Contador Uint16 counter; // Contador
Uint16 counterEnd; // Valor final para el contador Uint16 counterEnd; // Valor final para el contador
section_t section; // Estado del bucle principal para saber si continua o se sale
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
@@ -58,13 +58,13 @@ private:
public: public:
// Constructor // Constructor
Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang); Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, section_t *section);
// Destructor // Destructor
~Instructions(); ~Instructions();
// Bucle principal // Bucle principal
section_t run(mode_e mode); void run(mode_e mode);
}; };
#endif #endif

View File

@@ -1,7 +1,7 @@
#include "intro.h" #include "intro.h"
// Constructor // Constructor
Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang) Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, section_t *section)
{ {
// Copia los punteros // Copia los punteros
this->renderer = renderer; this->renderer = renderer;
@@ -9,6 +9,7 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input,
this->lang = lang; this->lang = lang;
this->asset = asset; this->asset = asset;
this->input = input; this->input = input;
this->section = section;
// Reserva memoria para los objetos // Reserva memoria para los objetos
eventHandler = new SDL_Event(); eventHandler = new SDL_Event();
@@ -19,8 +20,8 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input,
loadMedia(); loadMedia();
// Inicializa variables // Inicializa variables
section.name = PROG_SECTION_INTRO; section->name = SECTION_PROG_INTRO;
section.subsection = 0; section->subsection = 0;
ticks = 0; ticks = 0;
ticksSpeed = 15; ticksSpeed = 15;
scene = 1; scene = 1;
@@ -181,7 +182,7 @@ void Intro::checkEvents()
// Evento de salida de la aplicación // Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT) if (eventHandler->type == SDL_QUIT)
{ {
section.name = PROG_SECTION_QUIT; section->name = SECTION_PROG_QUIT;
break; break;
} }
} }
@@ -192,7 +193,7 @@ void Intro::checkInput()
{ {
if (input->checkInput(input_exit, REPEAT_FALSE)) if (input->checkInput(input_exit, REPEAT_FALSE))
{ {
section.name = PROG_SECTION_QUIT; section->name = SECTION_PROG_QUIT;
} }
else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE)) else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
@@ -213,8 +214,8 @@ void Intro::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))
{ {
JA_StopMusic(); JA_StopMusic();
section.name = PROG_SECTION_TITLE; section->name = SECTION_PROG_TITLE;
section.subsection = TITLE_SECTION_1; section->subsection = SUBSECTION_TITLE_1;
} }
} }
@@ -363,8 +364,8 @@ void Intro::updateScenes()
bitmaps[5]->setEnabled(false); bitmaps[5]->setEnabled(false);
texts[8]->setEnabled(false); texts[8]->setEnabled(false);
JA_StopMusic(); JA_StopMusic();
section.name = PROG_SECTION_TITLE; section->name = SECTION_PROG_TITLE;
section.subsection = TITLE_SECTION_1; section->subsection = SUBSECTION_TITLE_1;
} }
break; break;
@@ -428,16 +429,14 @@ void Intro::render()
} }
// Bucle principal // Bucle principal
section_t Intro::run() void Intro::run()
{ {
JA_PlayMusic(music, 0); JA_PlayMusic(music, 0);
while (section.name == PROG_SECTION_INTRO) while (section->name == SECTION_PROG_INTRO)
{ {
update(); update();
checkEvents(); checkEvents();
render(); render();
} }
return section;
} }

View File

@@ -29,11 +29,11 @@ private:
std::vector<SmartSprite *> bitmaps; // Vector con los sprites inteligentes para los dibujos de la intro std::vector<SmartSprite *> bitmaps; // Vector con los sprites inteligentes para los dibujos de la intro
std::vector<Writer *> texts; // Textos de la intro std::vector<Writer *> texts; // Textos de la intro
Text *text; // Textos de la intro Text *text; // Textos de la intro
section_t *section; // Estado del bucle principal para saber si continua o se sale
// Variables // Variables
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint8 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint8 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
section_t section; // Estado del bucle principal para saber si continua o se sale
JA_Music_t *music; // Musica para la intro JA_Music_t *music; // Musica para la intro
int scene; // Indica que escena está activa int scene; // Indica que escena está activa
@@ -57,13 +57,13 @@ private:
public: public:
// Constructor // Constructor
Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang); Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, section_t *section);
// Destructor // Destructor
~Intro(); ~Intro();
// Bucle principal // Bucle principal
section_t run(); void run();
}; };
#endif #endif

View File

@@ -4,13 +4,14 @@
#define END_LOGO 200 #define END_LOGO 200
// Constructor // Constructor
Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input) Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, section_t *section)
{ {
// Copia la dirección de los objetos // Copia la dirección de los objetos
this->renderer = renderer; this->renderer = renderer;
this->screen = screen; this->screen = screen;
this->asset = asset; this->asset = asset;
this->input = input; this->input = input;
this->section = section;
// Reserva memoria para los punteros // Reserva memoria para los punteros
eventHandler = new SDL_Event(); eventHandler = new SDL_Event();
@@ -19,8 +20,8 @@ Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input)
// Inicializa variables // Inicializa variables
counter = 0; counter = 0;
section.name = PROG_SECTION_LOGO; section->name = SECTION_PROG_LOGO;
section.subsection = 0; section->subsection = 0;
ticks = 0; ticks = 0;
ticksSpeed = 15; ticksSpeed = 15;
} }
@@ -40,8 +41,8 @@ void Logo::checkLogoEnd()
{ {
if (counter >= END_LOGO + 20) if (counter >= END_LOGO + 20)
{ {
section.name = PROG_SECTION_INTRO; section->name = SECTION_PROG_INTRO;
section.subsection = 0; section->subsection = 0;
} }
} }
@@ -54,7 +55,7 @@ void Logo::checkEvents()
// Evento de salida de la aplicación // Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT) if (eventHandler->type == SDL_QUIT)
{ {
section.name = PROG_SECTION_QUIT; section->name = SECTION_PROG_QUIT;
break; break;
} }
} }
@@ -65,7 +66,7 @@ void Logo::checkInput()
{ {
if (input->checkInput(input_exit, REPEAT_FALSE)) if (input->checkInput(input_exit, REPEAT_FALSE))
{ {
section.name = PROG_SECTION_QUIT; section->name = SECTION_PROG_QUIT;
} }
else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE)) else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
@@ -85,8 +86,8 @@ void Logo::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))
{ {
section.name = PROG_SECTION_TITLE; section->name = SECTION_PROG_TITLE;
section.subsection = TITLE_SECTION_1; section->subsection = SUBSECTION_TITLE_1;
} }
} }
@@ -144,16 +145,14 @@ void Logo::render()
} }
// Bucle para el logo del juego // Bucle para el logo del juego
section_t Logo::run() void Logo::run()
{ {
JA_StopMusic(); JA_StopMusic();
while (section.name == PROG_SECTION_LOGO) while (section->name == SECTION_PROG_LOGO)
{ {
update(); update();
checkEvents(); checkEvents();
render(); render();
} }
return section;
} }

View File

@@ -24,11 +24,11 @@ private:
Texture *texture; // Textura con los graficos Texture *texture; // Textura con los graficos
SDL_Event *eventHandler; // Manejador de eventos SDL_Event *eventHandler; // Manejador de eventos
Sprite *sprite; // Sprite con la textura del logo Sprite *sprite; // Sprite con la textura del logo
section_t *section; // Estado del bucle principal para saber si continua o se sale
// Variables // Variables
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
section_t section; // Estado del bucle principal para saber si continua o se sale
int counter; // Contador int counter; // Contador
// Actualiza las variables del objeto // Actualiza las variables del objeto
@@ -51,13 +51,13 @@ private:
public: public:
// Constructor // Constructor
Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input); Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, section_t *section);
// Destructor // Destructor
~Logo(); ~Logo();
// Bucle principal // Bucle principal
section_t run(); void run();
}; };
#endif #endif

View File

@@ -2,7 +2,7 @@
#include "common/jscore.h" #include "common/jscore.h"
// Constructor // Constructor
Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, section_t section) Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, section_t *section)
{ {
// Copia las direcciones de los punteros // Copia las direcciones de los punteros
this->renderer = renderer; this->renderer = renderer;
@@ -11,7 +11,6 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset,
this->asset = asset; this->asset = asset;
this->options = options; this->options = options;
this->lang = lang; this->lang = lang;
this->section = section; this->section = section;
// Reserva memoria para los punteros // Reserva memoria para los punteros
@@ -95,13 +94,13 @@ Title::~Title()
void Title::init() void Title::init()
{ {
// Inicializa variables // Inicializa variables
section.subsection = TITLE_SECTION_1; section->subsection = SUBSECTION_TITLE_1;
counter = TITLE_COUNTER; counter = TITLE_COUNTER;
backgroundCounter = 0; backgroundCounter = 0;
backgroundMode = rand() % 2; backgroundMode = rand() % 2;
menuVisible = false; menuVisible = false;
menu.active = menu.title; menu.active = menu.title;
nextSection.name = PROG_SECTION_GAME; nextSection.name = SECTION_PROG_GAME;
postFade = 0; postFade = 0;
ticks = 0; ticks = 0;
ticksSpeed = 15; ticksSpeed = 15;
@@ -227,10 +226,10 @@ void Title::update()
// Actualiza las notificaciones // Actualiza las notificaciones
screen->updateNotifier(); screen->updateNotifier();
switch (section.subsection) switch (section->subsection)
{ {
// Sección 1 - Titulo desplazandose // Sección 1 - Titulo desplazandose
case TITLE_SECTION_1: case SUBSECTION_TITLE_1:
{ {
// Actualiza los objetos // Actualiza los objetos
coffeeBitmap->update(); coffeeBitmap->update();
@@ -239,7 +238,7 @@ void Title::update()
// Si los objetos han llegado a su destino, cambiamos de Sección // Si los objetos han llegado a su destino, cambiamos de Sección
if (coffeeBitmap->hasFinished() && crisisBitmap->hasFinished()) if (coffeeBitmap->hasFinished() && crisisBitmap->hasFinished())
{ {
section.subsection = TITLE_SECTION_2; section->subsection = SUBSECTION_TITLE_2;
// Pantallazo blanco // Pantallazo blanco
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF); SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
@@ -253,7 +252,7 @@ void Title::update()
break; break;
// Sección 2 - Titulo vibrando // Sección 2 - Titulo vibrando
case TITLE_SECTION_2: case SUBSECTION_TITLE_2:
{ {
// Agita la pantalla // Agita la pantalla
static const int v[] = {-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 0}; static const int v[] = {-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 0};
@@ -270,13 +269,13 @@ void Title::update()
if (step == 33) if (step == 33)
{ {
section.subsection = TITLE_SECTION_3; section->subsection = SUBSECTION_TITLE_3;
} }
} }
break; break;
// Sección 3 - La pantalla de titulo con el menú y la música // Sección 3 - La pantalla de titulo con el menú y la música
case TITLE_SECTION_3: case SUBSECTION_TITLE_3:
{ {
if (counter > 0) if (counter > 0)
{ // Reproduce la música { // Reproduce la música
@@ -296,19 +295,19 @@ void Title::update()
switch (postFade) switch (postFade)
{ {
case 0: // 1 PLAYER case 0: // 1 PLAYER
section.name = PROG_SECTION_GAME; section->name = SECTION_PROG_GAME;
section.subsection = GAME_SECTION_PLAY_1P; section->subsection = SUBSECTION_GAME_PLAY_1P;
JA_StopMusic(); JA_StopMusic();
break; break;
case 1: // 2 PLAYERS case 1: // 2 PLAYERS
section.name = PROG_SECTION_GAME; section->name = SECTION_PROG_GAME;
section.subsection = GAME_SECTION_PLAY_2P; section->subsection = SUBSECTION_GAME_PLAY_2P;
JA_StopMusic(); JA_StopMusic();
break; break;
case 2: // QUIT case 2: // QUIT
section.name = PROG_SECTION_QUIT; section->name = SECTION_PROG_QUIT;
JA_StopMusic(); JA_StopMusic();
break; break;
@@ -318,17 +317,17 @@ void Title::update()
if (demo) if (demo)
{ {
runDemoGame(); runDemoGame();
if (section.name != PROG_SECTION_QUIT) if (section->name != SECTION_PROG_QUIT)
{ {
runInstructions(m_auto); runInstructions(m_auto);
} }
if (section.name != PROG_SECTION_QUIT) if (section->name != SECTION_PROG_QUIT)
{ {
runHiScoreTable(mhst_auto); runHiScoreTable(mhst_auto);
} }
} }
else else
section.name = PROG_SECTION_LOGO; section->name = SECTION_PROG_LOGO;
break; break;
default: default:
@@ -507,11 +506,11 @@ void Title::update()
if (demo) if (demo)
{ {
runDemoGame(); runDemoGame();
if (section.name != PROG_SECTION_QUIT) if (section->name != SECTION_PROG_QUIT)
{ {
runInstructions(m_auto); runInstructions(m_auto);
} }
if (section.name != PROG_SECTION_QUIT) if (section->name != SECTION_PROG_QUIT)
{ {
runHiScoreTable(mhst_auto); runHiScoreTable(mhst_auto);
} }
@@ -521,12 +520,12 @@ void Title::update()
} }
else else
{ {
section.name = PROG_SECTION_LOGO; section->name = SECTION_PROG_LOGO;
} }
} }
// Sección Instrucciones // Sección Instrucciones
if (section.subsection == TITLE_SECTION_INSTRUCTIONS) if (section->subsection == SUBSECTION_TITLE_INSTRUCTIONS)
{ {
runInstructions(m_auto); runInstructions(m_auto);
counter = TITLE_COUNTER; counter = TITLE_COUNTER;
@@ -545,10 +544,10 @@ void Title::update()
// Dibuja el objeto en pantalla // Dibuja el objeto en pantalla
void Title::render() void Title::render()
{ {
switch (section.subsection) switch (section->subsection)
{ {
// Sección 1 - Titulo desplazandose // Sección 1 - Titulo desplazandose
case TITLE_SECTION_1: case SUBSECTION_TITLE_1:
{ {
// Prepara para empezar a dibujar en la textura de juego // Prepara para empezar a dibujar en la textura de juego
screen->start(); screen->start();
@@ -572,7 +571,7 @@ void Title::render()
break; break;
// Sección 2 - Titulo vibrando // Sección 2 - Titulo vibrando
case TITLE_SECTION_2: case SUBSECTION_TITLE_2:
{ // Reproduce el efecto sonoro { // Reproduce el efecto sonoro
JA_PlaySound(crashSound); JA_PlaySound(crashSound);
@@ -609,13 +608,13 @@ void Title::render()
screen->blit(); screen->blit();
} }
section.subsection = TITLE_SECTION_3; section->subsection = SUBSECTION_TITLE_3;
} }
break; break;
// Sección 3 - La pantalla de titulo con el menú y la música // Sección 3 - La pantalla de titulo con el menú y la música
case TITLE_SECTION_3: case SUBSECTION_TITLE_3:
{ // Prepara para empezar a dibujar en la textura de juego { // Prepara para empezar a dibujar en la textura de juego
screen->start(); screen->start();
@@ -675,7 +674,7 @@ void Title::checkEvents()
// Evento de salida de la aplicación // Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT) if (eventHandler->type == SDL_QUIT)
{ {
section.name = PROG_SECTION_QUIT; section->name = SECTION_PROG_QUIT;
break; break;
} }
@@ -684,7 +683,7 @@ void Title::checkEvents()
reLoadTextures(); reLoadTextures();
} }
if (section.subsection == TITLE_SECTION_3) if (section->subsection == SUBSECTION_TITLE_3)
{ // Si se pulsa alguna tecla durante la tercera sección del titulo { // Si se pulsa alguna tecla durante la tercera sección del titulo
if ((eventHandler->type == SDL_KEYUP) || (eventHandler->type == SDL_JOYBUTTONUP)) if ((eventHandler->type == SDL_KEYUP) || (eventHandler->type == SDL_JOYBUTTONUP))
{ {
@@ -694,6 +693,19 @@ void Title::checkEvents()
// Reinicia el contador // Reinicia el contador
counter = TITLE_COUNTER; counter = TITLE_COUNTER;
} }
if (eventHandler->type == SDL_KEYDOWN)
{
switch (eventHandler->key.keysym.scancode)
{
case SDL_SCANCODE_A:
runEnterID();
break;
default:
break;
}
}
} }
} }
} }
@@ -703,7 +715,7 @@ void Title::checkInput()
{ {
if (input->checkInput(input_exit, REPEAT_FALSE)) if (input->checkInput(input_exit, REPEAT_FALSE))
{ {
section.name = PROG_SECTION_QUIT; section->name = SECTION_PROG_QUIT;
} }
else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE)) else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
@@ -968,54 +980,54 @@ void Title::applyOptions()
} }
// Bucle para el titulo del juego // Bucle para el titulo del juego
section_t Title::run() void Title::run()
{ {
while (section.name == PROG_SECTION_TITLE) while (section->name == SECTION_PROG_TITLE)
{ {
update(); update();
checkEvents(); checkEvents();
render(); render();
} }
return section;
} }
// Ejecuta la parte donde se muestran las instrucciones // Ejecuta la parte donde se muestran las instrucciones
section_t Title::runInstructions(mode_e mode) void Title::runInstructions(mode_e mode)
{ {
instructions = new Instructions(renderer, screen, asset, input, lang); instructions = new Instructions(renderer, screen, asset, input, lang, section);
section = instructions->run(mode); instructions->run(mode);
delete instructions; delete instructions;
return section;
} }
// Ejecuta la parte donde se muestra la tabla de puntuaciones // Ejecuta la parte donde se muestra la tabla de puntuaciones
section_t Title::runHiScoreTable(mode_hiScoreTable_e mode) void Title::runHiScoreTable(mode_hiScoreTable_e mode)
{ {
if (!options->online.enabled) if (!options->online.enabled)
{ {
section.name = PROG_SECTION_TITLE; section->name = SECTION_PROG_TITLE;
section.subsection = TITLE_SECTION_1; section->subsection = SUBSECTION_TITLE_1;
return section; return;
} }
hiScoreTable = new HiScoreTable(renderer, screen, asset, input, lang, options); hiScoreTable = new HiScoreTable(renderer, screen, asset, input, lang, options, section);
section = hiScoreTable->run(mode); hiScoreTable->run(mode);
delete hiScoreTable; delete hiScoreTable;
return section;
} }
// Ejecuta el juego en modo demo // Ejecuta el juego en modo demo
section_t Title::runDemoGame() void Title::runDemoGame()
{ {
demoGame = new Game(1, 0, renderer, screen, asset, lang, input, true, options); demoGame = new Game(1, 0, renderer, screen, asset, lang, input, true, options, section);
section = demoGame->run(); demoGame->run();
delete demoGame; delete demoGame;
}
return section; // Introduce el JailerID
void Title::runEnterID()
{
enterID = new EnterID(renderer, screen, asset, lang, options, section);
enterID->run();
delete enterID;
} }
// Modifica las opciones para los controles de los jugadores // Modifica las opciones para los controles de los jugadores

View File

@@ -14,6 +14,7 @@
#include "const.h" #include "const.h"
#include "fade.h" #include "fade.h"
#include "game.h" #include "game.h"
#include "enter_id.h"
#include "hiscore_table.h" #include "hiscore_table.h"
#include "instructions.h" #include "instructions.h"
#include "item.h" #include "item.h"
@@ -51,7 +52,9 @@ private:
Instructions *instructions; // Objeto para la sección de las instrucciones Instructions *instructions; // Objeto para la sección de las instrucciones
HiScoreTable *hiScoreTable; // Objeto para mostrar las mejores puntuaciones online HiScoreTable *hiScoreTable; // Objeto para mostrar las mejores puntuaciones online
Game *demoGame; // Objeto para lanzar la demo del juego Game *demoGame; // Objeto para lanzar la demo del juego
EnterID *enterID; // Objeto para introducir o modificar el JailerID
SDL_Event *eventHandler; // Manejador de eventos SDL_Event *eventHandler; // Manejador de eventos
section_t *section; // Indicador para el bucle del titulo
Texture *dustTexture; // Textura con los graficos del polvo Texture *dustTexture; // Textura con los graficos del polvo
Texture *coffeeTexture; // Textura con los graficos de la palabra coffee Texture *coffeeTexture; // Textura con los graficos de la palabra coffee
@@ -83,7 +86,6 @@ private:
float sin[360]; // Vector con los valores del seno precalculados float sin[360]; // Vector con los valores del seno precalculados
bool menuVisible; // Indicador para saber si se muestra el menu del titulo o la frase intermitente bool menuVisible; // Indicador para saber si se muestra el menu del titulo o la frase intermitente
bool demo; // Indica si el modo demo estará activo bool demo; // Indica si el modo demo estará activo
section_t section; // Indicador para el bucle del titulo
section_t nextSection; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo section_t nextSection; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
Uint8 postFade; // Opción a realizar cuando termina el fundido Uint8 postFade; // Opción a realizar cuando termina el fundido
@@ -121,13 +123,16 @@ private:
void applyOptions(); void applyOptions();
// Ejecuta la parte donde se muestran las instrucciones // Ejecuta la parte donde se muestran las instrucciones
section_t runInstructions(mode_e mode); void runInstructions(mode_e mode);
// Ejecuta la parte donde se muestra la tabla de puntuaciones // Ejecuta la parte donde se muestra la tabla de puntuaciones
section_t runHiScoreTable(mode_hiScoreTable_e mode); void runHiScoreTable(mode_hiScoreTable_e mode);
// Ejecuta el juego en modo demo // Ejecuta el juego en modo demo
section_t runDemoGame(); void runDemoGame();
// Introduce el JailerID
void runEnterID();
// 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);
@@ -146,13 +151,13 @@ private:
public: public:
// Constructor // Constructor
Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, section_t section); Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, section_t *section);
// Destructor // Destructor
~Title(); ~Title();
// Bucle para el titulo del juego // Bucle para el titulo del juego
section_t run(); void run();
}; };
#endif #endif