Ya va pasando del titulo a las instrucciones, a la demo, etc..

This commit is contained in:
2022-10-06 10:31:48 +02:00
parent 83103ddfea
commit 50d2a5d1c7
6 changed files with 420 additions and 384 deletions

Binary file not shown.

View File

@@ -3,112 +3,87 @@
const Uint8 SELF = 0; const Uint8 SELF = 0;
// Constructor // Constructor
Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *mAsset, Lang *lang) Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang)
{ {
// Copia los punteros // Copia los punteros
mRenderer = renderer; this->renderer = renderer;
mScreen = screen; this->screen = screen;
this->mAsset = mAsset; this->asset = asset;
mLang = lang; this->lang = lang;
// Reserva memoria para los punteros // Reserva memoria para los punteros
mEventHandler = new SDL_Event(); eventHandler = new SDL_Event();
mItemTexture = new LTexture(mRenderer, mAsset->get("items.png")); itemTexture = new LTexture(renderer, asset->get("items.png"));
mSprite = new Sprite(0, 0, GAME_WIDTH, GAME_HEIGHT, mItemTexture, mRenderer); sprite = new Sprite(0, 0, GAME_WIDTH, GAME_HEIGHT, itemTexture, renderer);
mText = new Text(mAsset->get("smb2.png"), mAsset->get("smb2.txt"), mRenderer); text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer);
// Crea un backbuffer para el renderizador // Crea un backbuffer para el renderizador
mBackbuffer = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAME_WIDTH, GAME_HEIGHT); backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAME_WIDTH, GAME_HEIGHT);
if (mBackbuffer == nullptr) if (backbuffer == nullptr)
{ {
printf("Backbuffer could not be created!\nSDL Error: %s\n", SDL_GetError()); printf("Backbuffer could not be created!\nSDL Error: %s\n", SDL_GetError());
} }
// Inicializa variables
section.name = SELF;
ticks = 0;
ticksSpeed = 15;
manualQuit = false;
counter = 0;
counterEnd = 600;
} }
// Destructor // Destructor
Instructions::~Instructions() Instructions::~Instructions()
{ {
mItemTexture->unload(); itemTexture->unload();
delete mItemTexture; delete itemTexture;
delete mSprite; delete sprite;
delete mEventHandler; delete eventHandler;
delete mText; delete text;
SDL_DestroyTexture(mBackbuffer); SDL_DestroyTexture(backbuffer);
}
// Inicializa las variables necesarias para la sección 'Instructions'
void Instructions::init()
{
// Inicializa variables
mSection.name = SELF;
mTicks = 0;
mTicksSpeed = 15;
mManualQuit = false;
mCounter = 0;
}
// Bucle para la pantalla de instrucciones
void Instructions::run(Uint8 mode)
{
init();
while (mSection.name == SELF)
{
// Comprueba los eventos que hay en la cola
while (SDL_PollEvent(mEventHandler) != 0)
{
// Evento de salida de la aplicación
if (mEventHandler->type == SDL_QUIT)
{
mSection.name = PROG_SECTION_QUIT;
break;
}
if ((mEventHandler->type == SDL_KEYDOWN) || (mEventHandler->type == SDL_JOYBUTTONDOWN))
{
if (mode == INSTRUCTIONS_MODE_AUTO)
{
JA_StopMusic();
mSection.name = PROG_SECTION_TITLE;
mSection.subsection = TITLE_SECTION_1;
}
else
{
mManualQuit = true;
}
}
} }
// Actualiza las variables // Actualiza las variables
if (SDL_GetTicks() - mTicks > mTicksSpeed) void Instructions::update()
{
// Comprueba los eventos
checkEventHandler();
// Actualiza las variables
if (SDL_GetTicks() - ticks > ticksSpeed)
{ {
// Actualiza el contador de ticks // Actualiza el contador de ticks
mTicks = SDL_GetTicks(); ticks = SDL_GetTicks();
if (mode == INSTRUCTIONS_MODE_AUTO) if (mode == m_auto)
{ // Modo automático { // Modo automático
mCounter++; counter++;
if (mCounter == INSTRUCTIONS_COUNTER) if (counter == counterEnd)
{ {
mSection.name = PROG_SECTION_TITLE; section.name = PROG_SECTION_TITLE;
mSection.subsection = TITLE_SECTION_1; section.subsection = TITLE_SECTION_1;
} }
} }
else else
{ // Modo manual { // Modo manual
++mCounter %= 60000; ++counter %= 60000;
if (mManualQuit) if (manualQuit)
{ {
mSection.name = PROG_SECTION_TITLE; section.name = PROG_SECTION_TITLE;
mSection.subsection = TITLE_SECTION_3; section.subsection = TITLE_SECTION_3;
}
} }
} }
} }
// Pinta en pantalla
void Instructions::render()
{
// Pinta en pantalla // Pinta en pantalla
SDL_Rect window = {0, 0, GAME_WIDTH, GAME_HEIGHT}; SDL_Rect window = {0, 0, GAME_WIDTH, GAME_HEIGHT};
SDL_Rect srcRect = {0, 0, 16, 16}; SDL_Rect srcRect = {0, 0, 16, 16};
@@ -122,77 +97,77 @@ void Instructions::run(Uint8 mode)
const SDL_Rect destRect5 = {60, 88 + (16 * 4), 16, 16}; // Coffee const SDL_Rect destRect5 = {60, 88 + (16 * 4), 16, 16}; // Coffee
// Pinta en el backbuffer el texto y los sprites // Pinta en el backbuffer el texto y los sprites
SDL_SetRenderTarget(mRenderer, mBackbuffer); SDL_SetRenderTarget(renderer, backbuffer);
SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, 255); SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
SDL_RenderClear(mRenderer); SDL_RenderClear(renderer);
// Escribe el texto // Escribe el texto
mText->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, 8, mLang->getText(11), 1, orangeColor, 1, shdwTxtColor); text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, 8, lang->getText(11), 1, orangeColor, 1, shdwTxtColor);
mText->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, 24, mLang->getText(12), 1, noColor, 1, shdwTxtColor); text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, 24, lang->getText(12), 1, noColor, 1, shdwTxtColor);
mText->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, 34, mLang->getText(13), 1, noColor, 1, shdwTxtColor); text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, 34, lang->getText(13), 1, noColor, 1, shdwTxtColor);
mText->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, 48, mLang->getText(14), 1, noColor, 1, shdwTxtColor); text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, 48, lang->getText(14), 1, noColor, 1, shdwTxtColor);
mText->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, 58, mLang->getText(15), 1, noColor, 1, shdwTxtColor); text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, 58, lang->getText(15), 1, noColor, 1, shdwTxtColor);
mText->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, 75, mLang->getText(16), 1, orangeColor, 1, shdwTxtColor); text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, 75, lang->getText(16), 1, orangeColor, 1, shdwTxtColor);
mText->writeShadowed(84, 92, mLang->getText(17), shdwTxtColor); text->writeShadowed(84, 92, lang->getText(17), shdwTxtColor);
mText->writeShadowed(84, 108, mLang->getText(18), shdwTxtColor); text->writeShadowed(84, 108, lang->getText(18), shdwTxtColor);
mText->writeShadowed(84, 124, mLang->getText(19), shdwTxtColor); text->writeShadowed(84, 124, lang->getText(19), shdwTxtColor);
mText->writeShadowed(84, 140, mLang->getText(20), shdwTxtColor); text->writeShadowed(84, 140, lang->getText(20), shdwTxtColor);
mText->writeShadowed(84, 156, mLang->getText(21), shdwTxtColor); text->writeShadowed(84, 156, lang->getText(21), shdwTxtColor);
if ((mode == INSTRUCTIONS_MODE_MANUAL) && (mCounter % 50 > 14)) if ((mode == m_manual) && (counter % 50 > 14))
{ {
mText->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, GAME_HEIGHT - 12, mLang->getText(22), 1, orangeColor, 1, shdwTxtColor); text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, GAME_HEIGHT - 12, lang->getText(22), 1, orangeColor, 1, shdwTxtColor);
} }
// Disquito // Disquito
mSprite->setPos(destRect1); sprite->setPos(destRect1);
srcRect.x = 0; srcRect.x = 0;
srcRect.y = 16 * (((mCounter + 12) / 36) % 2); srcRect.y = 16 * (((counter + 12) / 36) % 2);
mSprite->setSpriteClip(srcRect); sprite->setSpriteClip(srcRect);
mSprite->render(); sprite->render();
// Gavineixon // Gavineixon
mSprite->setPos(destRect2); sprite->setPos(destRect2);
srcRect.x += srcRect.w; srcRect.x += srcRect.w;
srcRect.y = 16 * (((mCounter + 9) / 36) % 2); srcRect.y = 16 * (((counter + 9) / 36) % 2);
mSprite->setSpriteClip(srcRect); sprite->setSpriteClip(srcRect);
mSprite->render(); sprite->render();
// Pacmar // Pacmar
mSprite->setPos(destRect3); sprite->setPos(destRect3);
srcRect.x += srcRect.w; srcRect.x += srcRect.w;
srcRect.y = 16 * (((mCounter + 6) / 36) % 2); srcRect.y = 16 * (((counter + 6) / 36) % 2);
mSprite->setSpriteClip(srcRect); sprite->setSpriteClip(srcRect);
mSprite->render(); sprite->render();
// Time Stopper // Time Stopper
mSprite->setPos(destRect4); sprite->setPos(destRect4);
srcRect.x += srcRect.w; srcRect.x += srcRect.w;
srcRect.y = 16 * (((mCounter + 3) / 36) % 2); srcRect.y = 16 * (((counter + 3) / 36) % 2);
mSprite->setSpriteClip(srcRect); sprite->setSpriteClip(srcRect);
mSprite->render(); sprite->render();
// Coffee // Coffee
mSprite->setPos(destRect5); sprite->setPos(destRect5);
srcRect.x += (srcRect.w * 2); // Se salta el icono del TNT srcRect.x += (srcRect.w * 2); // Se salta el icono del TNT
srcRect.y = 16 * (((mCounter + 0) / 36) % 2); srcRect.y = 16 * (((counter + 0) / 36) % 2);
mSprite->setSpriteClip(srcRect); sprite->setSpriteClip(srcRect);
mSprite->render(); sprite->render();
// Cambia el destino de renderizado // Cambia el destino de renderizado
SDL_SetRenderTarget(mRenderer, nullptr); SDL_SetRenderTarget(renderer, nullptr);
// Prepara para empezar a dibujar en la textura de juego // Prepara para empezar a dibujar en la textura de juego
mScreen->start(); screen->start();
// Limpia la pantalla // Limpia la pantalla
mScreen->clean(bgColor); screen->clean(bgColor);
// Establece la ventana del backbuffer // Establece la ventana del backbuffer
if (mode == INSTRUCTIONS_MODE_AUTO) if (mode == m_auto)
{ {
window.y = std::max(8, GAME_HEIGHT - mCounter + 100); window.y = std::max(8, GAME_HEIGHT - counter + 100);
} }
else else
{ {
@@ -200,9 +175,49 @@ void Instructions::run(Uint8 mode)
} }
// Copia el backbuffer al renderizador // Copia el backbuffer al renderizador
SDL_RenderCopy(mRenderer, mBackbuffer, nullptr, &window); SDL_RenderCopy(renderer, backbuffer, nullptr, &window);
// Vuelca el contenido del renderizador en pantalla // Vuelca el contenido del renderizador en pantalla
mScreen->blit(); screen->blit();
}
// Comprueba los eventos
void Instructions::checkEventHandler()
{
// 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 = PROG_SECTION_QUIT;
break;
}
if ((eventHandler->type == SDL_KEYUP) || (eventHandler->type == SDL_JOYBUTTONUP))
{
if (mode == m_auto)
{
JA_StopMusic();
section.name = PROG_SECTION_TITLE;
section.subsection = TITLE_SECTION_1;
}
else
{
manualQuit = true;
}
}
}
}
// Bucle para la pantalla de instrucciones
void Instructions::run(mode_e mode)
{
this->mode = mode;
while (section.name == SELF)
{
update();
render();
} }
} }

View File

@@ -12,31 +12,35 @@
#ifndef INSTRUCTIONS_H #ifndef INSTRUCTIONS_H
#define INSTRUCTIONS_H #define INSTRUCTIONS_H
// Contadores enum mode_e
#define INSTRUCTIONS_COUNTER 600 {
m_manual,
// Modo para las instrucciones m_auto
#define INSTRUCTIONS_MODE_MANUAL 0 };
#define INSTRUCTIONS_MODE_AUTO 1
// Clase Instructions // Clase Instructions
class Instructions class Instructions
{ {
private: private:
SDL_Renderer *mRenderer; // El renderizador de la ventana // Objetos
Screen *mScreen; // Objeto encargado de dibujar en pantalla SDL_Renderer *renderer; // El renderizador de la ventana
LTexture *mItemTexture; // Textura con los graficos Screen *screen; // Objeto encargado de dibujar en pantalla
SDL_Event *mEventHandler; // Manejador de eventos LTexture *itemTexture; // Textura con los graficos
SDL_Texture *mBackbuffer; // Textura para usar como backbuffer SDL_Event *eventHandler; // Manejador de eventos
Sprite *mSprite; // Sprite con la textura de las instrucciones SDL_Texture *backbuffer; // Textura para usar como backbuffer
Asset *mAsset; // Objeto que gestiona todos los ficheros de recursos Sprite *sprite; // Sprite con la textura de las instrucciones
Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas Asset *asset; // Objeto que gestiona todos los ficheros de recursos
Text *mText; // Objeto para escribir texto Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
Uint16 mCounter; // Contador Text *text; // Objeto para escribir texto
section_t mSection; // Estado del bucle principal para saber si continua o se sale
Uint32 mTicks; // Contador de ticks para ajustar la velocidad del programa // Variables
Uint32 mTicksSpeed; // Velocidad a la que se repiten los bucles del programa Uint16 counter; // Contador
bool mManualQuit; // Indica si se quiere salir del modo manual 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 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
bool manualQuit; // Indica si se quiere salir del modo manual
mode_e mode; // Modo en el que se van a ejecutar las instrucciones
// Actualiza las variables // Actualiza las variables
void update(); void update();
@@ -44,8 +48,8 @@ private:
// Pinta en pantalla // Pinta en pantalla
void render(); void render();
// Inicializa las variables // Comprueba los eventos
void init(); void checkEventHandler();
public: public:
// Constructor // Constructor
@@ -55,7 +59,7 @@ public:
~Instructions(); ~Instructions();
// Bucle principal // Bucle principal
void run(Uint8 mode); void run(mode_e mode);
}; };
#endif #endif

View File

@@ -50,7 +50,7 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset,
ticks = 0; ticks = 0;
ticksSpeed = 15; ticksSpeed = 15;
fade->init(0x17, 0x17, 0x26); fade->init(0x17, 0x17, 0x26);
demo = false; demo = true;
// Pone valores por defecto a las opciones de control // Pone valores por defecto a las opciones de control
options->input.clear(); options->input.clear();
@@ -246,7 +246,8 @@ void Title::update()
// 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 TITLE_SECTION_3:
{ {
// Reproduce la música if (counter > 0)
{ // Reproduce la música
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
{ {
JA_PlayMusic(titleMusic); JA_PlayMusic(titleMusic);
@@ -285,7 +286,7 @@ void Title::update()
if (demo) if (demo)
{ {
runDemoGame(); runDemoGame();
runInstructions(INSTRUCTIONS_MODE_AUTO); runInstructions(m_auto);
} }
else else
section.name = PROG_SECTION_LOGO; section.name = PROG_SECTION_LOGO;
@@ -406,7 +407,7 @@ void Title::update()
break; break;
case 11: // HOW TO PLAY case 11: // HOW TO PLAY
runInstructions(INSTRUCTIONS_MODE_MANUAL); runInstructions(m_manual);
break; break;
case 12: // ACCEPT case 12: // ACCEPT
@@ -432,6 +433,29 @@ void Title::update()
counter--; counter--;
} }
} }
else if (counter == 0)
{
if (demo)
{
runDemoGame();
runInstructions(m_auto);
demo = false;
counter = TITLE_COUNTER;
}
else
{
section.name = PROG_SECTION_LOGO;
}
}
// Sección Instrucciones
if (section.subsection == TITLE_SECTION_INSTRUCTIONS)
{
runInstructions(m_auto);
counter = TITLE_COUNTER;
demo = true;
}
}
break; break;
@@ -821,20 +845,13 @@ section_t Title::run()
{ {
update(); update();
render(); render();
// Sección 3 - La pantalla de titulo con el menú y la música
// Sección Instrucciones
// if (section.subsection == TITLE_SECTION_INSTRUCTIONS)
//{
// runInstructions(INSTRUCTIONS_MODE_AUTO);
//}
} }
return section; return section;
} }
// Ejecuta la parte donde se muestran las instrucciones // Ejecuta la parte donde se muestran las instrucciones
void Title::runInstructions(Uint8 mode) void Title::runInstructions(mode_e mode)
{ {
instructions = new Instructions(renderer, screen, asset, lang); instructions = new Instructions(renderer, screen, asset, lang);
instructions->run(mode); instructions->run(mode);

View File

@@ -113,7 +113,7 @@ private:
void applyOptions(); void applyOptions();
// Ejecuta la parte donde se muestran las instrucciones // Ejecuta la parte donde se muestran las instrucciones
void runInstructions(Uint8 mode); void runInstructions(mode_e mode);
// Ejecuta el juego en modo demo // Ejecuta el juego en modo demo
void runDemoGame(); void runDemoGame();

View File

@@ -3,7 +3,7 @@ x la maquina de cafe no toca el suelo
x las bolas verdes nacen naranja al explotarlas x las bolas verdes nacen naranja al explotarlas
falta el aura de superguerrero al pillar la maquina de cafe falta el aura de superguerrero al pillar la maquina de cafe
x la powerball deja la mascara al explotarlas x la powerball deja la mascara al explotarlas
los menus de pausa y game over falta poner bien los textos x los menus de pausa y game over falta poner bien los textos
x cuando continuas la partida sigues muerto x cuando continuas la partida sigues muerto
poder elegir el personaje para jugar poder elegir el personaje para jugar
arreglar los smart sprites de muerte y de perder el cafe arreglar los smart sprites de muerte y de perder el cafe