Compare commits
5 Commits
v2.3.3
...
85a47c1a2b
| Author | SHA1 | Date | |
|---|---|---|---|
| 85a47c1a2b | |||
| 06d4712493 | |||
| 18c4d6032d | |||
| 9365f80e8b | |||
| 4bd07216f3 |
2
Makefile
2
Makefile
@@ -103,7 +103,7 @@ windows_release:
|
|||||||
@powershell -Command "Copy-Item 'LICENSE' -Destination '$(RELEASE_FOLDER)'"
|
@powershell -Command "Copy-Item 'LICENSE' -Destination '$(RELEASE_FOLDER)'"
|
||||||
@powershell -Command "Copy-Item 'README.md' -Destination '$(RELEASE_FOLDER)'"
|
@powershell -Command "Copy-Item 'README.md' -Destination '$(RELEASE_FOLDER)'"
|
||||||
@powershell -Command "Copy-Item 'release\windows\dll\*.dll' -Destination '$(RELEASE_FOLDER)'"
|
@powershell -Command "Copy-Item 'release\windows\dll\*.dll' -Destination '$(RELEASE_FOLDER)'"
|
||||||
@powershell -Command "Copy-Item -Path '$(TARGET_FILE)' -Destination '\"$(WIN_RELEASE_FILE).exe\"'"
|
@powershell -Command "Copy-Item -Path '$(TARGET_FILE).exe' -Destination '$(WIN_RELEASE_FILE).exe'"
|
||||||
strip -s -R .comment -R .gnu.version "$(WIN_RELEASE_FILE).exe" --strip-unneeded
|
strip -s -R .comment -R .gnu.version "$(WIN_RELEASE_FILE).exe" --strip-unneeded
|
||||||
|
|
||||||
# Crea el fichero .zip
|
# Crea el fichero .zip
|
||||||
|
|||||||
@@ -81,6 +81,8 @@ Director::Director(int argc, const char *argv[]) {
|
|||||||
initInput();
|
initInput();
|
||||||
|
|
||||||
screen = new Screen(window, renderer, asset, options);
|
screen = new Screen(window, renderer, asset, options);
|
||||||
|
|
||||||
|
activeSection = ActiveSection::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
Director::~Director() {
|
Director::~Director() {
|
||||||
@@ -568,50 +570,113 @@ bool Director::saveConfigFile() {
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Director::runLogo() {
|
// Gestiona las transiciones entre secciones
|
||||||
auto logo = std::make_unique<Logo>(renderer, screen, asset, input, section);
|
void Director::handleSectionTransition() {
|
||||||
logo->run();
|
// Determina qué sección debería estar activa
|
||||||
}
|
ActiveSection targetSection = ActiveSection::None;
|
||||||
|
switch (section->name) {
|
||||||
void Director::runIntro() {
|
case SECTION_PROG_LOGO:
|
||||||
auto intro = std::make_unique<Intro>(renderer, screen, asset, input, lang, section);
|
targetSection = ActiveSection::Logo;
|
||||||
intro->run();
|
break;
|
||||||
}
|
case SECTION_PROG_INTRO:
|
||||||
|
targetSection = ActiveSection::Intro;
|
||||||
void Director::runTitle() {
|
break;
|
||||||
auto title = std::make_unique<Title>(renderer, screen, input, asset, options, lang, section);
|
case SECTION_PROG_TITLE:
|
||||||
title->run();
|
targetSection = ActiveSection::Title;
|
||||||
}
|
break;
|
||||||
|
case SECTION_PROG_GAME:
|
||||||
void Director::runGame() {
|
targetSection = ActiveSection::Game;
|
||||||
const int numPlayers = section->subsection == SUBSECTION_GAME_PLAY_1P ? 1 : 2;
|
break;
|
||||||
auto game = std::make_unique<Game>(numPlayers, 0, renderer, screen, asset, lang, input, false, options, section);
|
|
||||||
game->run();
|
|
||||||
}
|
|
||||||
|
|
||||||
int Director::run() {
|
|
||||||
// Bucle principal
|
|
||||||
while (section->name != SECTION_PROG_QUIT) {
|
|
||||||
switch (section->name) {
|
|
||||||
case SECTION_PROG_LOGO:
|
|
||||||
runLogo();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SECTION_PROG_INTRO:
|
|
||||||
runIntro();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SECTION_PROG_TITLE:
|
|
||||||
runTitle();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SECTION_PROG_GAME:
|
|
||||||
runGame();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
// Si no ha cambiado, no hay nada que hacer
|
||||||
|
if (targetSection == activeSection) return;
|
||||||
|
|
||||||
|
// Destruye la sección anterior
|
||||||
|
logo.reset();
|
||||||
|
intro.reset();
|
||||||
|
title.reset();
|
||||||
|
game.reset();
|
||||||
|
|
||||||
|
// Crea la nueva sección
|
||||||
|
activeSection = targetSection;
|
||||||
|
switch (activeSection) {
|
||||||
|
case ActiveSection::Logo:
|
||||||
|
logo = std::make_unique<Logo>(renderer, screen, asset, input, section);
|
||||||
|
break;
|
||||||
|
case ActiveSection::Intro:
|
||||||
|
intro = std::make_unique<Intro>(renderer, screen, asset, input, lang, section);
|
||||||
|
break;
|
||||||
|
case ActiveSection::Title:
|
||||||
|
title = std::make_unique<Title>(renderer, screen, input, asset, options, lang, section);
|
||||||
|
break;
|
||||||
|
case ActiveSection::Game: {
|
||||||
|
const int numPlayers = section->subsection == SUBSECTION_GAME_PLAY_1P ? 1 : 2;
|
||||||
|
game = std::make_unique<Game>(numPlayers, 0, renderer, screen, asset, lang, input, false, options, section);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ActiveSection::None:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ejecuta un frame del juego
|
||||||
|
SDL_AppResult Director::iterate() {
|
||||||
|
if (section->name == SECTION_PROG_QUIT) {
|
||||||
|
return SDL_APP_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gestiona las transiciones entre secciones
|
||||||
|
handleSectionTransition();
|
||||||
|
|
||||||
|
// Ejecuta un frame de la sección activa
|
||||||
|
switch (activeSection) {
|
||||||
|
case ActiveSection::Logo:
|
||||||
|
logo->iterate();
|
||||||
|
break;
|
||||||
|
case ActiveSection::Intro:
|
||||||
|
intro->iterate();
|
||||||
|
break;
|
||||||
|
case ActiveSection::Title:
|
||||||
|
title->iterate();
|
||||||
|
break;
|
||||||
|
case ActiveSection::Game:
|
||||||
|
game->iterate();
|
||||||
|
break;
|
||||||
|
case ActiveSection::None:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SDL_APP_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Procesa un evento
|
||||||
|
SDL_AppResult Director::handleEvent(SDL_Event *event) {
|
||||||
|
// Evento de salida de la aplicación
|
||||||
|
if (event->type == SDL_EVENT_QUIT) {
|
||||||
|
section->name = SECTION_PROG_QUIT;
|
||||||
|
return SDL_APP_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reenvía el evento a la sección activa
|
||||||
|
switch (activeSection) {
|
||||||
|
case ActiveSection::Logo:
|
||||||
|
logo->handleEvent(event);
|
||||||
|
break;
|
||||||
|
case ActiveSection::Intro:
|
||||||
|
intro->handleEvent(event);
|
||||||
|
break;
|
||||||
|
case ActiveSection::Title:
|
||||||
|
title->handleEvent(event);
|
||||||
|
break;
|
||||||
|
case ActiveSection::Game:
|
||||||
|
game->handleEvent(event);
|
||||||
|
break;
|
||||||
|
case ActiveSection::None:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SDL_APP_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Asigna variables a partir de dos cadenas
|
// Asigna variables a partir de dos cadenas
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <string> // for string, basic_string
|
#include <string> // for string, basic_string
|
||||||
class Asset;
|
class Asset;
|
||||||
class Game;
|
class Game;
|
||||||
@@ -17,6 +18,9 @@ struct section_t;
|
|||||||
// Textos
|
// Textos
|
||||||
constexpr const char *WINDOW_CAPTION = "© 2020 Coffee Crisis — JailDesigner";
|
constexpr const char *WINDOW_CAPTION = "© 2020 Coffee Crisis — JailDesigner";
|
||||||
|
|
||||||
|
// Secciones activas del Director
|
||||||
|
enum class ActiveSection { None, Logo, Intro, Title, Game };
|
||||||
|
|
||||||
class Director {
|
class Director {
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
@@ -28,6 +32,13 @@ class Director {
|
|||||||
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;
|
section_t *section; // Sección y subsección actual del programa;
|
||||||
|
|
||||||
|
// Secciones del juego
|
||||||
|
ActiveSection activeSection;
|
||||||
|
std::unique_ptr<Logo> logo;
|
||||||
|
std::unique_ptr<Intro> intro;
|
||||||
|
std::unique_ptr<Title> title;
|
||||||
|
std::unique_ptr<Game> game;
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
struct options_t *options; // Variable con todas las opciones del programa
|
struct options_t *options; // Variable con todas las opciones del programa
|
||||||
std::string executablePath; // Path del ejecutable
|
std::string executablePath; // Path del ejecutable
|
||||||
@@ -63,17 +74,8 @@ class Director {
|
|||||||
// Crea la carpeta del sistema donde guardar datos
|
// Crea la carpeta del sistema donde guardar datos
|
||||||
void createSystemFolder(const std::string &folder);
|
void createSystemFolder(const std::string &folder);
|
||||||
|
|
||||||
// Ejecuta la seccion de juego con el logo
|
// Gestiona las transiciones entre secciones
|
||||||
void runLogo();
|
void handleSectionTransition();
|
||||||
|
|
||||||
// Ejecuta la seccion de juego de la introducción
|
|
||||||
void runIntro();
|
|
||||||
|
|
||||||
// Ejecuta la seccion de juego con el titulo y los menus
|
|
||||||
void runTitle();
|
|
||||||
|
|
||||||
// Ejecuta la seccion de juego donde se juega
|
|
||||||
void runGame();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
@@ -82,6 +84,9 @@ class Director {
|
|||||||
// Destructor
|
// Destructor
|
||||||
~Director();
|
~Director();
|
||||||
|
|
||||||
// Bucle principal
|
// Ejecuta un frame del juego
|
||||||
int run();
|
SDL_AppResult iterate();
|
||||||
|
|
||||||
|
// Procesa un evento
|
||||||
|
SDL_AppResult handleEvent(SDL_Event *event);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -35,6 +35,12 @@ void Fade::init(Uint8 r, Uint8 g, Uint8 b) {
|
|||||||
mR = r;
|
mR = r;
|
||||||
mG = g;
|
mG = g;
|
||||||
mB = b;
|
mB = b;
|
||||||
|
mROriginal = r;
|
||||||
|
mGOriginal = g;
|
||||||
|
mBOriginal = b;
|
||||||
|
mLastSquareTicks = 0;
|
||||||
|
mSquaresDrawn = 0;
|
||||||
|
mFullscreenDone = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta una transición en pantalla
|
// Pinta una transición en pantalla
|
||||||
@@ -42,30 +48,35 @@ void Fade::render() {
|
|||||||
if (mEnabled && !mFinished) {
|
if (mEnabled && !mFinished) {
|
||||||
switch (mFadeType) {
|
switch (mFadeType) {
|
||||||
case FADE_FULLSCREEN: {
|
case FADE_FULLSCREEN: {
|
||||||
SDL_FRect fRect1 = {0, 0, (float)GAMECANVAS_WIDTH, (float)GAMECANVAS_HEIGHT};
|
if (!mFullscreenDone) {
|
||||||
|
SDL_FRect fRect1 = {0, 0, (float)GAMECANVAS_WIDTH, (float)GAMECANVAS_HEIGHT};
|
||||||
|
|
||||||
for (int i = 0; i < 256; i += 4) {
|
int alpha = mCounter * 4;
|
||||||
// Dibujamos sobre el renderizador
|
if (alpha >= 255) {
|
||||||
SDL_SetRenderTarget(mRenderer, nullptr);
|
alpha = 255;
|
||||||
|
mFullscreenDone = true;
|
||||||
|
|
||||||
// Copia el backbuffer con la imagen que había al renderizador
|
// Deja todos los buffers del mismo color
|
||||||
SDL_RenderTexture(mRenderer, mBackbuffer, nullptr, nullptr);
|
SDL_SetRenderTarget(mRenderer, mBackbuffer);
|
||||||
|
SDL_SetRenderDrawColor(mRenderer, mR, mG, mB, 255);
|
||||||
|
SDL_RenderClear(mRenderer);
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(mRenderer, mR, mG, mB, i);
|
SDL_SetRenderTarget(mRenderer, nullptr);
|
||||||
SDL_RenderFillRect(mRenderer, &fRect1);
|
SDL_SetRenderDrawColor(mRenderer, mR, mG, mB, 255);
|
||||||
|
SDL_RenderClear(mRenderer);
|
||||||
|
|
||||||
// Vuelca el renderizador en pantalla
|
mFinished = true;
|
||||||
SDL_RenderPresent(mRenderer);
|
} else {
|
||||||
|
// Dibujamos sobre el renderizador
|
||||||
|
SDL_SetRenderTarget(mRenderer, nullptr);
|
||||||
|
|
||||||
|
// Copia el backbuffer con la imagen que había al renderizador
|
||||||
|
SDL_RenderTexture(mRenderer, mBackbuffer, nullptr, nullptr);
|
||||||
|
|
||||||
|
SDL_SetRenderDrawColor(mRenderer, mR, mG, mB, alpha);
|
||||||
|
SDL_RenderFillRect(mRenderer, &fRect1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deja todos los buffers del mismo color
|
|
||||||
SDL_SetRenderTarget(mRenderer, mBackbuffer);
|
|
||||||
SDL_SetRenderDrawColor(mRenderer, mR, mG, mB, 255);
|
|
||||||
SDL_RenderClear(mRenderer);
|
|
||||||
|
|
||||||
SDL_SetRenderTarget(mRenderer, nullptr);
|
|
||||||
SDL_SetRenderDrawColor(mRenderer, mR, mG, mB, 255);
|
|
||||||
SDL_RenderClear(mRenderer);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,14 +100,17 @@ void Fade::render() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case FADE_RANDOM_SQUARE: {
|
case FADE_RANDOM_SQUARE: {
|
||||||
SDL_FRect fRs = {0, 0, 32, 32};
|
Uint32 now = SDL_GetTicks();
|
||||||
|
if (mSquaresDrawn < 50 && now - mLastSquareTicks >= 100) {
|
||||||
|
mLastSquareTicks = now;
|
||||||
|
|
||||||
|
SDL_FRect fRs = {0, 0, 32, 32};
|
||||||
|
|
||||||
for (Uint16 i = 0; i < 50; i++) {
|
|
||||||
// Crea un color al azar
|
// Crea un color al azar
|
||||||
mR = 255 * (rand() % 2);
|
Uint8 r = 255 * (rand() % 2);
|
||||||
mG = 255 * (rand() % 2);
|
Uint8 g = 255 * (rand() % 2);
|
||||||
mB = 255 * (rand() % 2);
|
Uint8 b = 255 * (rand() % 2);
|
||||||
SDL_SetRenderDrawColor(mRenderer, mR, mG, mB, 64);
|
SDL_SetRenderDrawColor(mRenderer, r, g, b, 64);
|
||||||
|
|
||||||
// Dibujamos sobre el backbuffer
|
// Dibujamos sobre el backbuffer
|
||||||
SDL_SetRenderTarget(mRenderer, mBackbuffer);
|
SDL_SetRenderTarget(mRenderer, mBackbuffer);
|
||||||
@@ -108,12 +122,14 @@ void Fade::render() {
|
|||||||
// Volvemos a usar el renderizador de forma normal
|
// Volvemos a usar el renderizador de forma normal
|
||||||
SDL_SetRenderTarget(mRenderer, nullptr);
|
SDL_SetRenderTarget(mRenderer, nullptr);
|
||||||
|
|
||||||
// Copiamos el backbuffer al renderizador
|
mSquaresDrawn++;
|
||||||
SDL_RenderTexture(mRenderer, mBackbuffer, nullptr, nullptr);
|
}
|
||||||
|
|
||||||
// Volcamos el renderizador en pantalla
|
// Copiamos el backbuffer al renderizador
|
||||||
SDL_RenderPresent(mRenderer);
|
SDL_RenderTexture(mRenderer, mBackbuffer, nullptr, nullptr);
|
||||||
SDL_Delay(100);
|
|
||||||
|
if (mSquaresDrawn >= 50) {
|
||||||
|
mFinished = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -140,6 +156,12 @@ void Fade::activateFade() {
|
|||||||
mEnabled = true;
|
mEnabled = true;
|
||||||
mFinished = false;
|
mFinished = false;
|
||||||
mCounter = 0;
|
mCounter = 0;
|
||||||
|
mSquaresDrawn = 0;
|
||||||
|
mLastSquareTicks = 0;
|
||||||
|
mFullscreenDone = false;
|
||||||
|
mR = mROriginal;
|
||||||
|
mG = mGOriginal;
|
||||||
|
mB = mBOriginal;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si está activo
|
// Comprueba si está activo
|
||||||
|
|||||||
@@ -10,15 +10,19 @@ constexpr int FADE_RANDOM_SQUARE = 2;
|
|||||||
// Clase Fade
|
// Clase Fade
|
||||||
class Fade {
|
class Fade {
|
||||||
private:
|
private:
|
||||||
SDL_Renderer *mRenderer; // El renderizador de la ventana
|
SDL_Renderer *mRenderer; // El renderizador de la ventana
|
||||||
SDL_Texture *mBackbuffer; // Textura para usar como backbuffer
|
SDL_Texture *mBackbuffer; // Textura para usar como backbuffer
|
||||||
Uint8 mFadeType; // Tipo de fade a realizar
|
Uint8 mFadeType; // Tipo de fade a realizar
|
||||||
Uint16 mCounter; // Contador interno
|
Uint16 mCounter; // Contador interno
|
||||||
bool mEnabled; // Indica si el fade está activo
|
bool mEnabled; // Indica si el fade está activo
|
||||||
bool mFinished; // Indica si ha terminado la transición
|
bool mFinished; // Indica si ha terminado la transición
|
||||||
Uint8 mR, mG, mB; // Colores para el fade
|
Uint8 mR, mG, mB; // Colores para el fade
|
||||||
SDL_Rect mRect1; // Rectangulo usado para crear los efectos de transición
|
Uint8 mROriginal, mGOriginal, mBOriginal; // Colores originales para FADE_RANDOM_SQUARE
|
||||||
SDL_Rect mRect2; // Rectangulo usado para crear los efectos de transición
|
Uint32 mLastSquareTicks; // Ticks del último cuadrado dibujado (FADE_RANDOM_SQUARE)
|
||||||
|
Uint16 mSquaresDrawn; // Número de cuadrados dibujados (FADE_RANDOM_SQUARE)
|
||||||
|
bool mFullscreenDone; // Indica si el fade fullscreen ha terminado la fase de fundido
|
||||||
|
SDL_Rect mRect1; // Rectangulo usado para crear los efectos de transición
|
||||||
|
SDL_Rect mRect2; // Rectangulo usado para crear los efectos de transición
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
|
|||||||
280
source/game.cpp
280
source/game.cpp
@@ -284,6 +284,12 @@ void Game::init() {
|
|||||||
effect.flash = false;
|
effect.flash = false;
|
||||||
effect.shake = false;
|
effect.shake = false;
|
||||||
effect.shakeCounter = SHAKE_COUNTER;
|
effect.shakeCounter = SHAKE_COUNTER;
|
||||||
|
deathShake.active = false;
|
||||||
|
deathShake.step = 0;
|
||||||
|
deathShake.lastStepTicks = 0;
|
||||||
|
deathSequence.phase = DeathPhase::None;
|
||||||
|
deathSequence.phaseStartTicks = 0;
|
||||||
|
deathSequence.player = nullptr;
|
||||||
helper.needCoffee = false;
|
helper.needCoffee = false;
|
||||||
helper.needCoffeeMachine = false;
|
helper.needCoffeeMachine = false;
|
||||||
helper.needPowerBall = false;
|
helper.needPowerBall = false;
|
||||||
@@ -299,6 +305,9 @@ void Game::init() {
|
|||||||
coffeeMachineEnabled = false;
|
coffeeMachineEnabled = false;
|
||||||
pauseCounter = 0;
|
pauseCounter = 0;
|
||||||
leavingPauseMenu = false;
|
leavingPauseMenu = false;
|
||||||
|
pauseInitialized = false;
|
||||||
|
gameOverInitialized = false;
|
||||||
|
gameOverPostFade = 0;
|
||||||
|
|
||||||
if (demo.enabled) {
|
if (demo.enabled) {
|
||||||
const int num = rand() % 2;
|
const int num = rand() % 2;
|
||||||
@@ -2363,23 +2372,50 @@ void Game::killPlayer(Player *player) {
|
|||||||
player->removeExtraHit();
|
player->removeExtraHit();
|
||||||
throwCoffee(player->getPosX() + (player->getWidth() / 2), player->getPosY() + (player->getHeight() / 2));
|
throwCoffee(player->getPosX() + (player->getWidth() / 2), player->getPosY() + (player->getHeight() / 2));
|
||||||
JA_PlaySound(coffeeOutSound);
|
JA_PlaySound(coffeeOutSound);
|
||||||
} else {
|
} else if (deathSequence.phase == DeathPhase::None) {
|
||||||
JA_PauseMusic();
|
JA_PauseMusic();
|
||||||
stopAllBalloons(10);
|
stopAllBalloons(10);
|
||||||
JA_PlaySound(playerCollisionSound);
|
JA_PlaySound(playerCollisionSound);
|
||||||
shakeScreen();
|
shakeScreen();
|
||||||
SDL_Delay(500);
|
deathSequence.phase = DeathPhase::Shaking;
|
||||||
JA_PlaySound(coffeeOutSound);
|
deathSequence.phaseStartTicks = SDL_GetTicks();
|
||||||
player->setAlive(false);
|
deathSequence.player = player;
|
||||||
if (allPlayersAreDead()) {
|
|
||||||
JA_StopMusic();
|
|
||||||
} else {
|
|
||||||
JA_ResumeMusic();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actualiza la secuencia de muerte del jugador
|
||||||
|
void Game::updateDeathSequence() {
|
||||||
|
switch (deathSequence.phase) {
|
||||||
|
case DeathPhase::None:
|
||||||
|
case DeathPhase::Done:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DeathPhase::Shaking:
|
||||||
|
// Espera a que termine el efecto de agitación
|
||||||
|
if (!isDeathShaking()) {
|
||||||
|
deathSequence.phase = DeathPhase::Waiting;
|
||||||
|
deathSequence.phaseStartTicks = SDL_GetTicks();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DeathPhase::Waiting:
|
||||||
|
// Espera 500ms antes de completar la muerte
|
||||||
|
if (SDL_GetTicks() - deathSequence.phaseStartTicks >= 500) {
|
||||||
|
JA_PlaySound(coffeeOutSound);
|
||||||
|
deathSequence.player->setAlive(false);
|
||||||
|
if (allPlayersAreDead()) {
|
||||||
|
JA_StopMusic();
|
||||||
|
} else {
|
||||||
|
JA_ResumeMusic();
|
||||||
|
}
|
||||||
|
deathSequence.phase = DeathPhase::Done;
|
||||||
|
deathSequence.player = nullptr;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Calcula y establece el valor de amenaza en funcion de los globos activos
|
// Calcula y establece el valor de amenaza en funcion de los globos activos
|
||||||
void Game::evaluateAndSetMenace() {
|
void Game::evaluateAndSetMenace() {
|
||||||
menaceCurrent = 0;
|
menaceCurrent = 0;
|
||||||
@@ -2439,6 +2475,15 @@ void Game::update() {
|
|||||||
// Actualiza el audio
|
// Actualiza el audio
|
||||||
JA_Update();
|
JA_Update();
|
||||||
|
|
||||||
|
// Actualiza los efectos basados en tiempo real (no en el throttle del juego)
|
||||||
|
updateDeathShake();
|
||||||
|
updateDeathSequence();
|
||||||
|
|
||||||
|
// Durante la secuencia de muerte, congela el resto del juego
|
||||||
|
if (deathSequence.phase == DeathPhase::Shaking || deathSequence.phase == DeathPhase::Waiting) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||||
if (SDL_GetTicks() - ticks > ticksSpeed) {
|
if (SDL_GetTicks() - ticks > ticksSpeed) {
|
||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
@@ -2550,7 +2595,10 @@ void Game::updateBackground() {
|
|||||||
grassSprite->setSpriteClip(0, (6 * (counter / 20 % 2)), 256, 6);
|
grassSprite->setSpriteClip(0, (6 * (counter / 20 % 2)), 256, 6);
|
||||||
|
|
||||||
// Mueve los edificios en funcion de si está activo el efecto de agitarlos
|
// Mueve los edificios en funcion de si está activo el efecto de agitarlos
|
||||||
if (effect.shake) {
|
if (deathShake.active) {
|
||||||
|
const int v[] = {-1, 1, -1, 1, -1, 1, -1, 0};
|
||||||
|
buildingsSprite->setPosX(v[deathShake.step]);
|
||||||
|
} else if (effect.shake) {
|
||||||
buildingsSprite->setPosX(((effect.shakeCounter % 2) * 2) - 1);
|
buildingsSprite->setPosX(((effect.shakeCounter % 2) * 2) - 1);
|
||||||
} else {
|
} else {
|
||||||
buildingsSprite->setPosX(0);
|
buildingsSprite->setPosX(0);
|
||||||
@@ -2868,83 +2916,130 @@ void Game::disableTimeStopItem() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Agita la pantalla
|
// Inicia el efecto de agitación intensa de la pantalla
|
||||||
void Game::shakeScreen() {
|
void Game::shakeScreen() {
|
||||||
const int v[] = {-1, 1, -1, 1, -1, 1, -1, 0};
|
deathShake.active = true;
|
||||||
for (int n = 0; n < 8; ++n) {
|
deathShake.step = 0;
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
deathShake.lastStepTicks = SDL_GetTicks();
|
||||||
screen->start();
|
}
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Actualiza el efecto de agitación intensa
|
||||||
screen->clean(bgColor);
|
void Game::updateDeathShake() {
|
||||||
|
if (!deathShake.active) return;
|
||||||
|
|
||||||
|
Uint32 now = SDL_GetTicks();
|
||||||
|
if (now - deathShake.lastStepTicks >= 50) {
|
||||||
|
deathShake.lastStepTicks = now;
|
||||||
|
deathShake.step++;
|
||||||
|
if (deathShake.step >= 8) {
|
||||||
|
deathShake.active = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Indica si el efecto de agitación intensa está activo
|
||||||
|
bool Game::isDeathShaking() {
|
||||||
|
return deathShake.active;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ejecuta un frame del juego
|
||||||
|
void Game::iterate() {
|
||||||
|
// En modo demo, no hay pausa ni game over
|
||||||
|
if (demo.enabled) {
|
||||||
|
if (section->subsection == SUBSECTION_GAME_PAUSE || section->subsection == SUBSECTION_GAME_GAMEOVER) {
|
||||||
|
section->name = SECTION_PROG_TITLE;
|
||||||
|
section->subsection = SUBSECTION_TITLE_INSTRUCTIONS;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sección juego en pausa
|
||||||
|
if (section->subsection == SUBSECTION_GAME_PAUSE) {
|
||||||
|
if (!pauseInitialized) {
|
||||||
|
enterPausedGame();
|
||||||
|
}
|
||||||
|
updatePausedGame();
|
||||||
|
renderPausedGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sección Game Over
|
||||||
|
else if (section->subsection == SUBSECTION_GAME_GAMEOVER) {
|
||||||
|
if (!gameOverInitialized) {
|
||||||
|
enterGameOverScreen();
|
||||||
|
}
|
||||||
|
updateGameOverScreen();
|
||||||
|
renderGameOverScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sección juego jugando
|
||||||
|
else if ((section->subsection == SUBSECTION_GAME_PLAY_1P) || (section->subsection == SUBSECTION_GAME_PLAY_2P)) {
|
||||||
|
// Resetea los flags de inicialización de sub-estados
|
||||||
|
pauseInitialized = false;
|
||||||
|
gameOverInitialized = false;
|
||||||
|
|
||||||
|
// Si la música no está sonando
|
||||||
|
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) {
|
||||||
|
// Reproduce la música
|
||||||
|
if (!gameCompleted) {
|
||||||
|
if (players[0]->isAlive()) {
|
||||||
|
JA_PlayMusic(gameMusic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef PAUSE
|
||||||
|
if (!pause)
|
||||||
|
update();
|
||||||
|
#else
|
||||||
|
// Actualiza la lógica del juego
|
||||||
|
update();
|
||||||
|
#endif
|
||||||
|
|
||||||
// Dibuja los objetos
|
// Dibuja los objetos
|
||||||
buildingsSprite->setPosX(0);
|
render();
|
||||||
buildingsSprite->setWidth(1);
|
}
|
||||||
buildingsSprite->setSpriteClip(0, 0, 1, 160);
|
}
|
||||||
renderBackground();
|
|
||||||
|
|
||||||
buildingsSprite->setPosX(255);
|
// Indica si el juego ha terminado
|
||||||
buildingsSprite->setSpriteClip(255, 0, 1, 160);
|
bool Game::hasFinished() const {
|
||||||
buildingsSprite->render();
|
return section->name != SECTION_PROG_GAME;
|
||||||
|
}
|
||||||
|
|
||||||
buildingsSprite->setPosX(v[n]);
|
// Procesa un evento individual
|
||||||
buildingsSprite->setWidth(256);
|
void Game::handleEvent(SDL_Event *event) {
|
||||||
buildingsSprite->setSpriteClip(0, 0, 256, 160);
|
// SDL_EVENT_QUIT ya lo maneja Director
|
||||||
buildingsSprite->render();
|
|
||||||
|
|
||||||
grassSprite->render();
|
if (event->type == SDL_EVENT_WINDOW_FOCUS_LOST) {
|
||||||
renderBalloons();
|
// Solo pausar durante el juego activo (no en demo, game over, ni ya en pausa)
|
||||||
renderBullets();
|
if (!demo.enabled && (section->subsection == SUBSECTION_GAME_PLAY_1P || section->subsection == SUBSECTION_GAME_PLAY_2P)) {
|
||||||
renderItems();
|
section->subsection = SUBSECTION_GAME_PAUSE;
|
||||||
renderPlayers();
|
}
|
||||||
renderScoreBoard();
|
}
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
#ifdef PAUSE
|
||||||
screen->blit();
|
if (event->type == SDL_EVENT_KEY_DOWN) {
|
||||||
SDL_Delay(50);
|
if (event->key.scancode == SDL_SCANCODE_P) {
|
||||||
|
pause = !pause;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Eventos específicos de la pantalla de game over
|
||||||
|
if (section->subsection == SUBSECTION_GAME_GAMEOVER) {
|
||||||
|
if (event->type == SDL_EVENT_KEY_DOWN && event->key.repeat == 0) {
|
||||||
|
if (gameCompleted) {
|
||||||
|
gameOverPostFade = 1;
|
||||||
|
fade->activateFade();
|
||||||
|
JA_PlaySound(itemPickUpSound);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucle para el juego
|
// Bucle para el juego
|
||||||
void Game::run() {
|
void Game::run() {
|
||||||
while (section->name == SECTION_PROG_GAME) {
|
while (!hasFinished()) {
|
||||||
// Sección juego en pausa
|
iterate();
|
||||||
if (section->subsection == SUBSECTION_GAME_PAUSE) {
|
|
||||||
runPausedGame();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sección Game Over
|
|
||||||
if (section->subsection == SUBSECTION_GAME_GAMEOVER) {
|
|
||||||
runGameOverScreen();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sección juego jugando
|
|
||||||
if ((section->subsection == SUBSECTION_GAME_PLAY_1P) || (section->subsection == SUBSECTION_GAME_PLAY_2P)) {
|
|
||||||
// Si la música no está sonando
|
|
||||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) {
|
|
||||||
// Reproduce la música
|
|
||||||
if (!gameCompleted) {
|
|
||||||
if (players[0]->isAlive()) {
|
|
||||||
JA_PlayMusic(gameMusic);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef PAUSE
|
|
||||||
if (!pause)
|
|
||||||
update();
|
|
||||||
#else
|
|
||||||
// Actualiza la lógica del juego
|
|
||||||
update();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Comprueba los eventos que hay en cola
|
|
||||||
checkEvents();
|
|
||||||
|
|
||||||
// Dibuja los objetos
|
|
||||||
render();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3045,8 +3140,8 @@ void Game::renderPausedGame() {
|
|||||||
screen->blit();
|
screen->blit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucle para el menu de pausa del juego
|
// Inicializa el estado de pausa del juego
|
||||||
void Game::runPausedGame() {
|
void Game::enterPausedGame() {
|
||||||
// Pone en pausa la música
|
// Pone en pausa la música
|
||||||
if (JA_GetMusicState() == JA_MUSIC_PLAYING) {
|
if (JA_GetMusicState() == JA_MUSIC_PLAYING) {
|
||||||
JA_PauseMusic();
|
JA_PauseMusic();
|
||||||
@@ -3058,19 +3153,11 @@ void Game::runPausedGame() {
|
|||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
pauseCounter = 90;
|
pauseCounter = 90;
|
||||||
|
pauseInitialized = true;
|
||||||
while ((section->subsection == SUBSECTION_GAME_PAUSE) && (section->name == SECTION_PROG_GAME)) {
|
|
||||||
updatePausedGame();
|
|
||||||
checkEvents();
|
|
||||||
renderPausedGame();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza los elementos de la pantalla de game over
|
// Actualiza los elementos de la pantalla de game over
|
||||||
void Game::updateGameOverScreen() {
|
void Game::updateGameOverScreen() {
|
||||||
// Variables
|
|
||||||
static int postFade = 0;
|
|
||||||
|
|
||||||
// Calcula la lógica de los objetos
|
// Calcula la lógica de los objetos
|
||||||
if (SDL_GetTicks() - ticks > ticksSpeed) {
|
if (SDL_GetTicks() - ticks > ticksSpeed) {
|
||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
@@ -3084,7 +3171,7 @@ void Game::updateGameOverScreen() {
|
|||||||
|
|
||||||
// Si ha terminado el fade, actua segun se haya operado
|
// Si ha terminado el fade, actua segun se haya operado
|
||||||
if (fade->hasEnded()) {
|
if (fade->hasEnded()) {
|
||||||
switch (postFade) {
|
switch (gameOverPostFade) {
|
||||||
case 0: // YES
|
case 0: // YES
|
||||||
section->name = SECTION_PROG_GAME;
|
section->name = SECTION_PROG_GAME;
|
||||||
deleteAllVectorObjects();
|
deleteAllVectorObjects();
|
||||||
@@ -3109,12 +3196,12 @@ void Game::updateGameOverScreen() {
|
|||||||
// Comprueba si se ha seleccionado algún item del menú
|
// Comprueba si se ha seleccionado algún item del menú
|
||||||
switch (gameOverMenu->getItemSelected()) {
|
switch (gameOverMenu->getItemSelected()) {
|
||||||
case 0: // YES
|
case 0: // YES
|
||||||
postFade = 0;
|
gameOverPostFade = 0;
|
||||||
fade->activateFade();
|
fade->activateFade();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1: // NO
|
case 1: // NO
|
||||||
postFade = 1;
|
gameOverPostFade = 1;
|
||||||
fade->activateFade();
|
fade->activateFade();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -3123,8 +3210,10 @@ void Game::updateGameOverScreen() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Comprueba los eventos que hay en la cola
|
// Comprueba los eventos de la pantalla de game over
|
||||||
|
void Game::checkGameOverEvents() {
|
||||||
while (SDL_PollEvent(eventHandler) != 0) {
|
while (SDL_PollEvent(eventHandler) != 0) {
|
||||||
// Evento de salida de la aplicación
|
// Evento de salida de la aplicación
|
||||||
if (eventHandler->type == SDL_EVENT_QUIT) {
|
if (eventHandler->type == SDL_EVENT_QUIT) {
|
||||||
@@ -3132,7 +3221,7 @@ void Game::updateGameOverScreen() {
|
|||||||
break;
|
break;
|
||||||
} else if (eventHandler->type == SDL_EVENT_KEY_DOWN && eventHandler->key.repeat == 0) {
|
} else if (eventHandler->type == SDL_EVENT_KEY_DOWN && eventHandler->key.repeat == 0) {
|
||||||
if (gameCompleted) {
|
if (gameCompleted) {
|
||||||
postFade = 1;
|
gameOverPostFade = 1;
|
||||||
fade->activateFade();
|
fade->activateFade();
|
||||||
JA_PlaySound(itemPickUpSound);
|
JA_PlaySound(itemPickUpSound);
|
||||||
}
|
}
|
||||||
@@ -3196,18 +3285,15 @@ void Game::renderGameOverScreen() {
|
|||||||
screen->blit();
|
screen->blit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucle para la pantalla de game over
|
// Inicializa el estado de game over
|
||||||
void Game::runGameOverScreen() {
|
void Game::enterGameOverScreen() {
|
||||||
// Guarda los puntos
|
// Guarda los puntos
|
||||||
saveScoreFile();
|
saveScoreFile();
|
||||||
|
|
||||||
// Reinicia el menu
|
// Reinicia el menu
|
||||||
gameOverMenu->reset();
|
gameOverMenu->reset();
|
||||||
|
gameOverPostFade = 0;
|
||||||
while ((section->subsection == SUBSECTION_GAME_GAMEOVER) && (section->name == SECTION_PROG_GAME)) {
|
gameOverInitialized = true;
|
||||||
updateGameOverScreen();
|
|
||||||
renderGameOverScreen();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Indica si se puede crear una powerball
|
// Indica si se puede crear una powerball
|
||||||
|
|||||||
@@ -88,6 +88,26 @@ class Game {
|
|||||||
Uint8 shakeCounter; // Contador para medir el tiempo que dura el efecto
|
Uint8 shakeCounter; // Contador para medir el tiempo que dura el efecto
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Estado para el efecto de agitación intensa (muerte del jugador)
|
||||||
|
struct deathShake_t {
|
||||||
|
bool active; // Indica si el efecto está activo
|
||||||
|
Uint8 step; // Paso actual del efecto (0-7)
|
||||||
|
Uint32 lastStepTicks; // Ticks del último paso
|
||||||
|
};
|
||||||
|
|
||||||
|
// Fases de la secuencia de muerte del jugador
|
||||||
|
enum class DeathPhase { None,
|
||||||
|
Shaking,
|
||||||
|
Waiting,
|
||||||
|
Done };
|
||||||
|
|
||||||
|
// Estado de la secuencia de muerte del jugador
|
||||||
|
struct deathSequence_t {
|
||||||
|
DeathPhase phase; // Fase actual
|
||||||
|
Uint32 phaseStartTicks; // Ticks del inicio de la fase actual
|
||||||
|
Player *player; // Jugador que está muriendo
|
||||||
|
};
|
||||||
|
|
||||||
struct helper_t {
|
struct helper_t {
|
||||||
bool needCoffee; // Indica si se necesitan cafes
|
bool needCoffee; // Indica si se necesitan cafes
|
||||||
bool needCoffeeMachine; // Indica si se necesita PowerUp
|
bool needCoffeeMachine; // Indica si se necesita PowerUp
|
||||||
@@ -214,6 +234,8 @@ class Game {
|
|||||||
float enemySpeed; // Velocidad a la que se mueven los enemigos
|
float enemySpeed; // Velocidad a la que se mueven los enemigos
|
||||||
float defaultEnemySpeed; // Velocidad base de los enemigos, sin incrementar
|
float defaultEnemySpeed; // Velocidad base de los enemigos, sin incrementar
|
||||||
effect_t effect; // Variable para gestionar los efectos visuales
|
effect_t effect; // Variable para gestionar los efectos visuales
|
||||||
|
deathShake_t deathShake; // Variable para gestionar el efecto de agitación intensa
|
||||||
|
deathSequence_t deathSequence; // Variable para gestionar la secuencia de muerte
|
||||||
helper_t helper; // Variable para gestionar las ayudas
|
helper_t helper; // Variable para gestionar las ayudas
|
||||||
bool powerBallEnabled; // Indica si hay una powerball ya activa
|
bool powerBallEnabled; // Indica si hay una powerball ya activa
|
||||||
Uint8 powerBallCounter; // Contador de formaciones enemigas entre la aparicion de una PowerBall y otra
|
Uint8 powerBallCounter; // Contador de formaciones enemigas entre la aparicion de una PowerBall y otra
|
||||||
@@ -233,6 +255,9 @@ class Game {
|
|||||||
int cloudsSpeed; // Velocidad a la que se desplazan las nubes
|
int cloudsSpeed; // Velocidad a la que se desplazan las nubes
|
||||||
int pauseCounter; // Contador para salir del menu de pausa y volver al juego
|
int pauseCounter; // Contador para salir del menu de pausa y volver al juego
|
||||||
bool leavingPauseMenu; // Indica si esta saliendo del menu de pausa para volver al juego
|
bool leavingPauseMenu; // Indica si esta saliendo del menu de pausa para volver al juego
|
||||||
|
bool pauseInitialized; // Indica si la pausa ha sido inicializada
|
||||||
|
bool gameOverInitialized; // Indica si el game over ha sido inicializado
|
||||||
|
int gameOverPostFade; // Opción a realizar cuando termina el fundido del game over
|
||||||
#ifdef PAUSE
|
#ifdef PAUSE
|
||||||
bool pause;
|
bool pause;
|
||||||
#endif
|
#endif
|
||||||
@@ -459,17 +484,26 @@ class Game {
|
|||||||
// Deshabilita el efecto del item de detener el tiempo
|
// Deshabilita el efecto del item de detener el tiempo
|
||||||
void disableTimeStopItem();
|
void disableTimeStopItem();
|
||||||
|
|
||||||
// Agita la pantalla
|
// Inicia el efecto de agitación intensa de la pantalla
|
||||||
void shakeScreen();
|
void shakeScreen();
|
||||||
|
|
||||||
|
// Actualiza el efecto de agitación intensa
|
||||||
|
void updateDeathShake();
|
||||||
|
|
||||||
|
// Indica si el efecto de agitación intensa está activo
|
||||||
|
bool isDeathShaking();
|
||||||
|
|
||||||
|
// Actualiza la secuencia de muerte del jugador
|
||||||
|
void updateDeathSequence();
|
||||||
|
|
||||||
// Actualiza las variables del menu de pausa del juego
|
// Actualiza las variables del menu de pausa del juego
|
||||||
void updatePausedGame();
|
void updatePausedGame();
|
||||||
|
|
||||||
// Dibuja el menu de pausa del juego
|
// Dibuja el menu de pausa del juego
|
||||||
void renderPausedGame();
|
void renderPausedGame();
|
||||||
|
|
||||||
// Bucle para el menu de pausa del juego
|
// Inicializa el estado de pausa del juego
|
||||||
void runPausedGame();
|
void enterPausedGame();
|
||||||
|
|
||||||
// Actualiza los elementos de la pantalla de game over
|
// Actualiza los elementos de la pantalla de game over
|
||||||
void updateGameOverScreen();
|
void updateGameOverScreen();
|
||||||
@@ -477,8 +511,11 @@ class Game {
|
|||||||
// Dibuja los elementos de la pantalla de game over
|
// Dibuja los elementos de la pantalla de game over
|
||||||
void renderGameOverScreen();
|
void renderGameOverScreen();
|
||||||
|
|
||||||
// Bucle para la pantalla de game over
|
// Inicializa el estado de game over
|
||||||
void runGameOverScreen();
|
void enterGameOverScreen();
|
||||||
|
|
||||||
|
// Comprueba los eventos de la pantalla de game over
|
||||||
|
void checkGameOverEvents();
|
||||||
|
|
||||||
// Indica si se puede crear una powerball
|
// Indica si se puede crear una powerball
|
||||||
bool canPowerBallBeCreated();
|
bool canPowerBallBeCreated();
|
||||||
@@ -519,4 +556,13 @@ class Game {
|
|||||||
|
|
||||||
// Bucle para el juego
|
// Bucle para el juego
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
// Ejecuta un frame del juego
|
||||||
|
void iterate();
|
||||||
|
|
||||||
|
// Indica si el juego ha terminado
|
||||||
|
bool hasFinished() const;
|
||||||
|
|
||||||
|
// Procesa un evento
|
||||||
|
void handleEvent(SDL_Event *event);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,8 +17,6 @@
|
|||||||
#include "texture.h" // for Texture
|
#include "texture.h" // for Texture
|
||||||
#include "utils.h" // for color_t, section_t
|
#include "utils.h" // for color_t, section_t
|
||||||
|
|
||||||
const Uint8 SELF = 0;
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, section_t *section) {
|
Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, section_t *section) {
|
||||||
// Copia los punteros
|
// Copia los punteros
|
||||||
@@ -62,12 +60,13 @@ Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
section->name = SELF;
|
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
ticksSpeed = 15;
|
ticksSpeed = 15;
|
||||||
manualQuit = false;
|
manualQuit = false;
|
||||||
counter = 0;
|
counter = 0;
|
||||||
counterEnd = 600;
|
counterEnd = 600;
|
||||||
|
finished = false;
|
||||||
|
quitRequested = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -99,15 +98,13 @@ void Instructions::update() {
|
|||||||
counter++;
|
counter++;
|
||||||
|
|
||||||
if (counter == counterEnd) {
|
if (counter == counterEnd) {
|
||||||
section->name = SECTION_PROG_TITLE;
|
finished = true;
|
||||||
section->subsection = SUBSECTION_TITLE_1;
|
|
||||||
}
|
}
|
||||||
} else { // Modo manual
|
} else { // Modo manual
|
||||||
++counter %= 60000;
|
++counter %= 60000;
|
||||||
|
|
||||||
if (manualQuit) {
|
if (manualQuit) {
|
||||||
section->name = SECTION_PROG_TITLE;
|
finished = true;
|
||||||
section->subsection = SUBSECTION_TITLE_3;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -215,7 +212,8 @@ void Instructions::checkEvents() {
|
|||||||
while (SDL_PollEvent(eventHandler) != 0) {
|
while (SDL_PollEvent(eventHandler) != 0) {
|
||||||
// Evento de salida de la aplicación
|
// Evento de salida de la aplicación
|
||||||
if (eventHandler->type == SDL_EVENT_QUIT) {
|
if (eventHandler->type == SDL_EVENT_QUIT) {
|
||||||
section->name = SECTION_PROG_QUIT;
|
quitRequested = true;
|
||||||
|
finished = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -224,7 +222,8 @@ void Instructions::checkEvents() {
|
|||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
void Instructions::checkInput() {
|
void Instructions::checkInput() {
|
||||||
if (input->checkInput(input_exit, REPEAT_FALSE)) {
|
if (input->checkInput(input_exit, REPEAT_FALSE)) {
|
||||||
section->name = SECTION_PROG_QUIT;
|
quitRequested = true;
|
||||||
|
finished = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE)) {
|
else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE)) {
|
||||||
@@ -242,8 +241,7 @@ 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) {
|
if (mode == m_auto) {
|
||||||
JA_StopMusic();
|
JA_StopMusic();
|
||||||
section->name = SECTION_PROG_TITLE;
|
finished = true;
|
||||||
section->subsection = SUBSECTION_TITLE_1;
|
|
||||||
} else {
|
} else {
|
||||||
if (counter > 30) {
|
if (counter > 30) {
|
||||||
manualQuit = true;
|
manualQuit = true;
|
||||||
@@ -252,13 +250,41 @@ void Instructions::checkInput() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucle para la pantalla de instrucciones
|
// Bucle para la pantalla de instrucciones (compatibilidad)
|
||||||
void Instructions::run(mode_e mode) {
|
void Instructions::run(mode_e mode) {
|
||||||
this->mode = mode;
|
start(mode);
|
||||||
|
|
||||||
while (section->name == SELF) {
|
while (!finished) {
|
||||||
update();
|
update();
|
||||||
checkEvents();
|
checkEvents();
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Aplica los cambios de sección según el resultado
|
||||||
|
if (quitRequested) {
|
||||||
|
section->name = SECTION_PROG_QUIT;
|
||||||
|
} else {
|
||||||
|
section->name = SECTION_PROG_TITLE;
|
||||||
|
section->subsection = (mode == m_auto) ? SUBSECTION_TITLE_1 : SUBSECTION_TITLE_3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicia las instrucciones (sin bucle)
|
||||||
|
void Instructions::start(mode_e mode) {
|
||||||
|
this->mode = mode;
|
||||||
|
finished = false;
|
||||||
|
quitRequested = false;
|
||||||
|
manualQuit = false;
|
||||||
|
counter = 0;
|
||||||
|
ticks = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Indica si las instrucciones han terminado
|
||||||
|
bool Instructions::hasFinished() const {
|
||||||
|
return finished;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Indica si se ha solicitado salir de la aplicación
|
||||||
|
bool Instructions::isQuitRequested() const {
|
||||||
|
return quitRequested;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,21 +34,14 @@ class Instructions {
|
|||||||
section_t *section; // Estado del bucle principal para saber si continua o se sale
|
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
|
||||||
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
|
mode_e mode; // Modo en el que se van a ejecutar las instrucciones
|
||||||
|
bool finished; // Indica si las instrucciones han terminado
|
||||||
// Actualiza las variables
|
bool quitRequested; // Indica si se ha solicitado salir de la aplicación
|
||||||
void update();
|
|
||||||
|
|
||||||
// Pinta en pantalla
|
|
||||||
void render();
|
|
||||||
|
|
||||||
// Comprueba los eventos
|
|
||||||
void checkEvents();
|
|
||||||
|
|
||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
void checkInput();
|
void checkInput();
|
||||||
@@ -62,4 +55,22 @@ class Instructions {
|
|||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
void run(mode_e mode);
|
void run(mode_e mode);
|
||||||
|
|
||||||
|
// Inicia las instrucciones (sin bucle)
|
||||||
|
void start(mode_e mode);
|
||||||
|
|
||||||
|
// Actualiza las variables
|
||||||
|
void update();
|
||||||
|
|
||||||
|
// Pinta en pantalla
|
||||||
|
void render();
|
||||||
|
|
||||||
|
// Comprueba los eventos
|
||||||
|
void checkEvents();
|
||||||
|
|
||||||
|
// Indica si las instrucciones han terminado
|
||||||
|
bool hasFinished() const;
|
||||||
|
|
||||||
|
// Indica si se ha solicitado salir de la aplicación
|
||||||
|
bool isQuitRequested() const;
|
||||||
};
|
};
|
||||||
@@ -153,6 +153,8 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input,
|
|||||||
for (auto text : texts) {
|
for (auto text : texts) {
|
||||||
text->center(GAMECANVAS_CENTER_X);
|
text->center(GAMECANVAS_CENTER_X);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JA_PlayMusic(music, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -403,8 +405,17 @@ void Intro::run() {
|
|||||||
JA_PlayMusic(music, 0);
|
JA_PlayMusic(music, 0);
|
||||||
|
|
||||||
while (section->name == SECTION_PROG_INTRO) {
|
while (section->name == SECTION_PROG_INTRO) {
|
||||||
update();
|
iterate();
|
||||||
checkEvents();
|
|
||||||
render();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ejecuta un frame
|
||||||
|
void Intro::iterate() {
|
||||||
|
update();
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Procesa un evento individual
|
||||||
|
void Intro::handleEvent(SDL_Event *event) {
|
||||||
|
// SDL_EVENT_QUIT ya lo maneja Director
|
||||||
|
}
|
||||||
|
|||||||
@@ -63,4 +63,10 @@ class Intro {
|
|||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
// Ejecuta un frame
|
||||||
|
void iterate();
|
||||||
|
|
||||||
|
// Procesa un evento
|
||||||
|
void handleEvent(SDL_Event *event);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, s
|
|||||||
section->subsection = 0;
|
section->subsection = 0;
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
ticksSpeed = 15;
|
ticksSpeed = 15;
|
||||||
|
|
||||||
|
JA_StopMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -144,8 +146,17 @@ void Logo::run() {
|
|||||||
JA_StopMusic();
|
JA_StopMusic();
|
||||||
|
|
||||||
while (section->name == SECTION_PROG_LOGO) {
|
while (section->name == SECTION_PROG_LOGO) {
|
||||||
update();
|
iterate();
|
||||||
checkEvents();
|
|
||||||
render();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ejecuta un frame
|
||||||
|
void Logo::iterate() {
|
||||||
|
update();
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Procesa un evento individual
|
||||||
|
void Logo::handleEvent(SDL_Event *event) {
|
||||||
|
// SDL_EVENT_QUIT ya lo maneja Director
|
||||||
|
}
|
||||||
|
|||||||
@@ -53,4 +53,10 @@ class Logo {
|
|||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
// Ejecuta un frame
|
||||||
|
void iterate();
|
||||||
|
|
||||||
|
// Procesa un evento
|
||||||
|
void handleEvent(SDL_Event *event);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -39,15 +39,26 @@ Reescribiendo el código el 27/09/2022
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <memory>
|
#define SDL_MAIN_USE_CALLBACKS 1
|
||||||
|
#include <SDL3/SDL_main.h>
|
||||||
|
|
||||||
#include "director.h"
|
#include "director.h"
|
||||||
#include "stb_vorbis.c"
|
#include "stb_vorbis.c"
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) {
|
||||||
// Crea el objeto Director
|
auto *director = new Director(argc, const_cast<const char **>(argv));
|
||||||
auto director = std::make_unique<Director>(argc, const_cast<const char **>(argv));
|
*appstate = director;
|
||||||
|
return SDL_APP_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
// Bucle principal
|
SDL_AppResult SDL_AppIterate(void *appstate) {
|
||||||
return director->run();
|
return static_cast<Director *>(appstate)->iterate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) {
|
||||||
|
return static_cast<Director *>(appstate)->handleEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SDL_AppQuit(void *appstate, SDL_AppResult result) {
|
||||||
|
delete static_cast<Director *>(appstate);
|
||||||
|
}
|
||||||
|
|||||||
218
source/title.cpp
218
source/title.cpp
@@ -120,6 +120,11 @@ void Title::init() {
|
|||||||
ticksSpeed = 15;
|
ticksSpeed = 15;
|
||||||
fade->init(0x17, 0x17, 0x26);
|
fade->init(0x17, 0x17, 0x26);
|
||||||
demo = true;
|
demo = true;
|
||||||
|
vibrationStep = 0;
|
||||||
|
vibrationInitialized = false;
|
||||||
|
instructionsActive = false;
|
||||||
|
demoGameActive = false;
|
||||||
|
demoThenInstructions = false;
|
||||||
|
|
||||||
// Pone valores por defecto a las opciones de control
|
// Pone valores por defecto a las opciones de control
|
||||||
options->input.clear();
|
options->input.clear();
|
||||||
@@ -257,21 +262,27 @@ void Title::update() {
|
|||||||
|
|
||||||
// Sección 2 - Titulo vibrando
|
// Sección 2 - Titulo vibrando
|
||||||
case SUBSECTION_TITLE_2: {
|
case SUBSECTION_TITLE_2: {
|
||||||
// Agita la pantalla
|
// Captura las posiciones base y reproduce el sonido la primera vez
|
||||||
static const int v[] = {-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 0};
|
if (!vibrationInitialized) {
|
||||||
static const int a = coffeeBitmap->getPosX();
|
vibrationCoffeeBaseX = coffeeBitmap->getPosX();
|
||||||
static const int b = crisisBitmap->getPosX();
|
vibrationCrisisBaseX = crisisBitmap->getPosX();
|
||||||
static int step = 0;
|
vibrationInitialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
coffeeBitmap->setPosX(a + v[step / 3]);
|
// Agita la pantalla
|
||||||
crisisBitmap->setPosX(b + v[step / 3]);
|
const int v[] = {-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 0};
|
||||||
|
|
||||||
|
coffeeBitmap->setPosX(vibrationCoffeeBaseX + v[vibrationStep / 3]);
|
||||||
|
crisisBitmap->setPosX(vibrationCrisisBaseX + v[vibrationStep / 3]);
|
||||||
dustBitmapR->update();
|
dustBitmapR->update();
|
||||||
dustBitmapL->update();
|
dustBitmapL->update();
|
||||||
|
|
||||||
step++;
|
vibrationStep++;
|
||||||
|
|
||||||
if (step == 33) {
|
if (vibrationStep >= 33) {
|
||||||
section->subsection = SUBSECTION_TITLE_3;
|
section->subsection = SUBSECTION_TITLE_3;
|
||||||
|
vibrationStep = 0;
|
||||||
|
vibrationInitialized = false;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
@@ -311,10 +322,8 @@ void Title::update() {
|
|||||||
counter = TITLE_COUNTER;
|
counter = TITLE_COUNTER;
|
||||||
menu.active->reset();
|
menu.active->reset();
|
||||||
if (demo) {
|
if (demo) {
|
||||||
|
demoThenInstructions = true;
|
||||||
runDemoGame();
|
runDemoGame();
|
||||||
if (section->name != SECTION_PROG_QUIT) {
|
|
||||||
runInstructions(m_auto);
|
|
||||||
}
|
|
||||||
} else
|
} else
|
||||||
section->name = SECTION_PROG_LOGO;
|
section->name = SECTION_PROG_LOGO;
|
||||||
break;
|
break;
|
||||||
@@ -482,13 +491,8 @@ void Title::update() {
|
|||||||
}
|
}
|
||||||
} else if (counter == 0) {
|
} else if (counter == 0) {
|
||||||
if (demo) {
|
if (demo) {
|
||||||
|
demoThenInstructions = true;
|
||||||
runDemoGame();
|
runDemoGame();
|
||||||
if (section->name != SECTION_PROG_QUIT) {
|
|
||||||
runInstructions(m_auto);
|
|
||||||
}
|
|
||||||
init();
|
|
||||||
demo = false;
|
|
||||||
counter = TITLE_COUNTER;
|
|
||||||
} else {
|
} else {
|
||||||
section->name = SECTION_PROG_LOGO;
|
section->name = SECTION_PROG_LOGO;
|
||||||
}
|
}
|
||||||
@@ -497,8 +501,6 @@ void Title::update() {
|
|||||||
// Sección Instrucciones
|
// Sección Instrucciones
|
||||||
if (section->subsection == SUBSECTION_TITLE_INSTRUCTIONS) {
|
if (section->subsection == SUBSECTION_TITLE_INSTRUCTIONS) {
|
||||||
runInstructions(m_auto);
|
runInstructions(m_auto);
|
||||||
counter = TITLE_COUNTER;
|
|
||||||
demo = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -539,48 +541,32 @@ void Title::render() {
|
|||||||
} break;
|
} break;
|
||||||
|
|
||||||
// Sección 2 - Titulo vibrando
|
// Sección 2 - Titulo vibrando
|
||||||
case SUBSECTION_TITLE_2: { // Reproduce el efecto sonoro
|
case SUBSECTION_TITLE_2: {
|
||||||
JA_PlaySound(crashSound);
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
|
screen->start();
|
||||||
|
|
||||||
// Agita la pantalla
|
// Limpia la pantalla
|
||||||
const int v[] = {-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 0};
|
screen->clean(bgColor);
|
||||||
const int a = coffeeBitmap->getPosX();
|
|
||||||
const int b = crisisBitmap->getPosX();
|
|
||||||
for (int n = 0; n < 11 * 3; ++n) {
|
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
|
||||||
screen->start();
|
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Dibuja el tileado de fondo
|
||||||
screen->clean(bgColor);
|
{
|
||||||
|
SDL_FRect fSrc = {(float)backgroundWindow.x, (float)backgroundWindow.y, (float)backgroundWindow.w, (float)backgroundWindow.h};
|
||||||
|
SDL_RenderTexture(renderer, background, &fSrc, nullptr);
|
||||||
|
};
|
||||||
|
|
||||||
// Dibuja el tileado de fondo
|
// Dibuja el degradado
|
||||||
{
|
gradient->render();
|
||||||
SDL_FRect fSrc = {(float)backgroundWindow.x, (float)backgroundWindow.y, (float)backgroundWindow.w, (float)backgroundWindow.h};
|
|
||||||
SDL_RenderTexture(renderer, background, &fSrc, nullptr);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Dibuja el degradado
|
// Dibuja los objetos (posiciones ya actualizadas por update)
|
||||||
gradient->render();
|
coffeeBitmap->render();
|
||||||
|
crisisBitmap->render();
|
||||||
|
|
||||||
// Dibuja los objetos
|
dustBitmapR->render();
|
||||||
coffeeBitmap->setPosX(a + v[n / 3]);
|
dustBitmapL->render();
|
||||||
crisisBitmap->setPosX(b + v[n / 3]);
|
|
||||||
coffeeBitmap->render();
|
|
||||||
crisisBitmap->render();
|
|
||||||
|
|
||||||
dustBitmapR->update();
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
dustBitmapL->update();
|
screen->blit();
|
||||||
dustBitmapR->render();
|
} break;
|
||||||
dustBitmapL->render();
|
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
|
||||||
screen->blit();
|
|
||||||
}
|
|
||||||
|
|
||||||
section->subsection = SUBSECTION_TITLE_3;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 SUBSECTION_TITLE_3: { // Prepara para empezar a dibujar en la textura de juego
|
case SUBSECTION_TITLE_3: { // Prepara para empezar a dibujar en la textura de juego
|
||||||
@@ -900,27 +886,119 @@ void Title::applyOptions() {
|
|||||||
createTiledBackground();
|
createTiledBackground();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucle para el titulo del juego
|
// Ejecuta un frame
|
||||||
void Title::run() {
|
void Title::iterate() {
|
||||||
while (section->name == SECTION_PROG_TITLE) {
|
// Si las instrucciones están activas, delega el frame
|
||||||
update();
|
if (instructionsActive) {
|
||||||
checkEvents();
|
instructions->update();
|
||||||
render();
|
instructions->render();
|
||||||
|
|
||||||
|
if (instructions->hasFinished()) {
|
||||||
|
bool wasQuit = instructions->isQuitRequested();
|
||||||
|
delete instructions;
|
||||||
|
instructions = nullptr;
|
||||||
|
instructionsActive = false;
|
||||||
|
|
||||||
|
if (wasQuit) {
|
||||||
|
section->name = SECTION_PROG_QUIT;
|
||||||
|
} else if (instructionsMode == m_auto) {
|
||||||
|
section->name = SECTION_PROG_TITLE;
|
||||||
|
init();
|
||||||
|
demo = true;
|
||||||
|
} else {
|
||||||
|
section->name = SECTION_PROG_TITLE;
|
||||||
|
section->subsection = SUBSECTION_TITLE_3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si el juego demo está activo, delega el frame
|
||||||
|
if (demoGameActive) {
|
||||||
|
// El demo Game necesita section->name == SECTION_PROG_GAME para funcionar
|
||||||
|
section->name = SECTION_PROG_GAME;
|
||||||
|
demoGame->iterate();
|
||||||
|
|
||||||
|
if (demoGame->hasFinished()) {
|
||||||
|
bool wasQuit = (section->name == SECTION_PROG_QUIT);
|
||||||
|
delete demoGame;
|
||||||
|
demoGame = nullptr;
|
||||||
|
demoGameActive = false;
|
||||||
|
|
||||||
|
if (wasQuit) {
|
||||||
|
section->name = SECTION_PROG_QUIT;
|
||||||
|
} else if (demoThenInstructions) {
|
||||||
|
section->name = SECTION_PROG_TITLE;
|
||||||
|
section->subsection = SUBSECTION_TITLE_3;
|
||||||
|
demoThenInstructions = false;
|
||||||
|
runInstructions(m_auto);
|
||||||
|
} else {
|
||||||
|
section->name = SECTION_PROG_TITLE;
|
||||||
|
section->subsection = SUBSECTION_TITLE_1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Restaura section para que Director no transicione fuera de Title
|
||||||
|
section->name = SECTION_PROG_TITLE;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ejecución normal del título
|
||||||
|
update();
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Procesa un evento individual
|
||||||
|
void Title::handleEvent(SDL_Event *event) {
|
||||||
|
// Si hay un sub-estado activo, delega el evento
|
||||||
|
if (instructionsActive && instructions) {
|
||||||
|
// SDL_EVENT_QUIT ya lo maneja Director
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (demoGameActive && demoGame) {
|
||||||
|
demoGame->handleEvent(event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL_EVENT_QUIT ya lo maneja Director
|
||||||
|
|
||||||
|
if (event->type == SDL_EVENT_RENDER_DEVICE_RESET || event->type == SDL_EVENT_RENDER_TARGETS_RESET) {
|
||||||
|
reLoadTextures();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (section->subsection == SUBSECTION_TITLE_3) {
|
||||||
|
if ((event->type == SDL_EVENT_KEY_UP) || (event->type == SDL_EVENT_JOYSTICK_BUTTON_UP)) {
|
||||||
|
menuVisible = true;
|
||||||
|
counter = TITLE_COUNTER;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ejecuta la parte donde se muestran las instrucciones
|
// Bucle para el titulo del juego (compatibilidad)
|
||||||
void Title::runInstructions(mode_e mode) {
|
void Title::run() {
|
||||||
instructions = new Instructions(renderer, screen, asset, input, lang, section);
|
while (section->name == SECTION_PROG_TITLE || instructionsActive || demoGameActive) {
|
||||||
instructions->run(mode);
|
iterate();
|
||||||
delete instructions;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ejecuta el juego en modo demo
|
// Inicia la parte donde se muestran las instrucciones
|
||||||
|
void Title::runInstructions(mode_e mode) {
|
||||||
|
instructions = new Instructions(renderer, screen, asset, input, lang, section);
|
||||||
|
instructions->start(mode);
|
||||||
|
instructionsActive = true;
|
||||||
|
instructionsMode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicia el juego en modo demo
|
||||||
void Title::runDemoGame() {
|
void Title::runDemoGame() {
|
||||||
|
// Temporalmente ponemos section para que el constructor de Game funcione
|
||||||
|
section->name = SECTION_PROG_GAME;
|
||||||
|
section->subsection = SUBSECTION_GAME_PLAY_1P;
|
||||||
demoGame = new Game(1, 0, renderer, screen, asset, lang, input, true, options, section);
|
demoGame = new Game(1, 0, renderer, screen, asset, lang, input, true, options, section);
|
||||||
demoGame->run();
|
demoGameActive = true;
|
||||||
delete demoGame;
|
// Restauramos section para que Director no transicione fuera de Title
|
||||||
|
section->name = SECTION_PROG_TITLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modifica las opciones para los controles de los jugadores
|
// Modifica las opciones para los controles de los jugadores
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ struct JA_Music_t;
|
|||||||
struct JA_Sound_t;
|
struct JA_Sound_t;
|
||||||
|
|
||||||
// Textos
|
// Textos
|
||||||
constexpr const char *TEXT_COPYRIGHT = "@2020 JailDesigner (v2.3.3)";
|
constexpr const char *TEXT_COPYRIGHT = "@2020 JailDesigner (v2.3.4)";
|
||||||
|
|
||||||
// Contadores
|
// Contadores
|
||||||
constexpr int TITLE_COUNTER = 800;
|
constexpr int TITLE_COUNTER = 800;
|
||||||
@@ -90,6 +90,18 @@ class Title {
|
|||||||
std::vector<input_t> availableInputDevices; // Vector con todos los metodos de control disponibles
|
std::vector<input_t> availableInputDevices; // Vector con todos los metodos de control disponibles
|
||||||
std::vector<int> deviceIndex; // Indice para el jugador [i] del vector de dispositivos de entrada disponibles
|
std::vector<int> deviceIndex; // Indice para el jugador [i] del vector de dispositivos de entrada disponibles
|
||||||
|
|
||||||
|
// Variables para la vibración del título (SUBSECTION_TITLE_2)
|
||||||
|
int vibrationStep; // Paso actual de la vibración
|
||||||
|
int vibrationCoffeeBaseX; // Posición X base del bitmap Coffee
|
||||||
|
int vibrationCrisisBaseX; // Posición X base del bitmap Crisis
|
||||||
|
bool vibrationInitialized; // Indica si se han capturado las posiciones base
|
||||||
|
|
||||||
|
// Variables para sub-estados delegados (instrucciones y demo)
|
||||||
|
bool instructionsActive; // Indica si las instrucciones están activas
|
||||||
|
bool demoGameActive; // Indica si el juego demo está activo
|
||||||
|
mode_e instructionsMode; // Modo de las instrucciones activas
|
||||||
|
bool demoThenInstructions; // Indica si tras la demo hay que mostrar instrucciones
|
||||||
|
|
||||||
// Inicializa los valores
|
// Inicializa los valores
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
@@ -144,4 +156,10 @@ class Title {
|
|||||||
|
|
||||||
// Bucle para el titulo del juego
|
// Bucle para el titulo del juego
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
// Ejecuta un frame
|
||||||
|
void iterate();
|
||||||
|
|
||||||
|
// Procesa un evento
|
||||||
|
void handleEvent(SDL_Event *event);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user