forked from jaildesigner-jailgames/jaildoctors_dilemma
Preparado para empezar con el ending2
This commit is contained in:
@@ -56,7 +56,8 @@ const int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3;
|
||||
#define SECTION_PROG_DEMO 5
|
||||
#define SECTION_PROG_GAME_OVER 6
|
||||
#define SECTION_PROG_ENDING 7
|
||||
#define SECTION_PROG_QUIT 8
|
||||
#define SECTION_PROG_ENDING2 8
|
||||
#define SECTION_PROG_QUIT 9
|
||||
|
||||
// Subsecciones
|
||||
#define SUBSECTION_LOGO_TO_INTRO 0
|
||||
|
||||
@@ -318,6 +318,21 @@ void Director::loadResources(section_t section)
|
||||
resource->loadOffsets(offsetsList);
|
||||
}
|
||||
|
||||
else if (section.name == SECTION_PROG_ENDING2)
|
||||
{
|
||||
// Texturas
|
||||
std::vector<std::string> textureList;
|
||||
textureList.push_back("smb2.png");
|
||||
|
||||
resource->loadTextures(textureList);
|
||||
|
||||
// Offsets
|
||||
std::vector<std::string> offsetsList;
|
||||
offsetsList.push_back("smb2.txt");
|
||||
|
||||
resource->loadOffsets(offsetsList);
|
||||
}
|
||||
|
||||
else if (section.name == SECTION_PROG_GAME_OVER)
|
||||
{
|
||||
std::vector<std::string> textureList;
|
||||
@@ -1218,6 +1233,20 @@ void Director::runEnding()
|
||||
resource->free();
|
||||
}
|
||||
|
||||
// Ejecuta la seccion del final del juego
|
||||
void Director::runEnding2()
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "\n* SECTION: ENDING2" << std::endl;
|
||||
}
|
||||
loadResources(section);
|
||||
ending2 = new Ending2(renderer, screen, resource, asset, options);
|
||||
setSection(ending2->run());
|
||||
delete ending2;
|
||||
resource->free();
|
||||
}
|
||||
|
||||
// Ejecuta la seccion del final de la partida
|
||||
void Director::runGameOver()
|
||||
{
|
||||
@@ -1285,6 +1314,10 @@ void Director::run()
|
||||
case SECTION_PROG_ENDING:
|
||||
runEnding();
|
||||
break;
|
||||
|
||||
case SECTION_PROG_ENDING2:
|
||||
runEnding2();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "title.h"
|
||||
#include "game_over.h"
|
||||
#include "ending.h"
|
||||
#include "ending2.h"
|
||||
|
||||
#ifndef DIRECTOR_H
|
||||
#define DIRECTOR_H
|
||||
@@ -39,6 +40,7 @@ private:
|
||||
Credits *credits; // Objeto para gestionar los creditos del juego
|
||||
Demo *demo; // Objeto para gestionar el modo demo, en el que se ven pantallas del juego
|
||||
Ending *ending; // Objeto para gestionar el final del juego
|
||||
Ending2 *ending2; // Objeto para gestionar el final del juego
|
||||
GameOver *gameOver; // Objeto para gestionar el final de la partida
|
||||
Debug *debug; // Objeto para getsionar la información de debug
|
||||
struct options_t *options; // Variable con todas las opciones del programa
|
||||
@@ -105,6 +107,9 @@ private:
|
||||
// Ejecuta la seccion del final del juego
|
||||
void runEnding();
|
||||
|
||||
// Ejecuta la seccion del final del juego
|
||||
void runEnding2();
|
||||
|
||||
// Ejecuta la seccion del final de la partida
|
||||
void runGameOver();
|
||||
|
||||
|
||||
@@ -565,7 +565,7 @@ void Ending::checkChangeScene()
|
||||
if (scene == 5)
|
||||
{
|
||||
// Termina el bucle
|
||||
section.name = SECTION_PROG_LOGO;
|
||||
section.name = SECTION_PROG_ENDING2;
|
||||
|
||||
// Mantiene los valores anteriores
|
||||
scene = 4;
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
#pragma once
|
||||
#include <SDL2/SDL.h>
|
||||
#include "common/animatedsprite.h"
|
||||
#include "common/asset.h"
|
||||
#include "common/jail_audio.h"
|
||||
#include "common/resource.h"
|
||||
#include "common/screen.h"
|
||||
#include "common/sprite.h"
|
||||
#include "common/sprite.h"
|
||||
#include "common/text.h"
|
||||
#include "common/texture.h"
|
||||
#include "common/utils.h"
|
||||
#include "const.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#ifndef ENDING_H
|
||||
#define ENDING_H
|
||||
|
||||
167
source/ending2.cpp
Normal file
167
source/ending2.cpp
Normal file
@@ -0,0 +1,167 @@
|
||||
#include "ending2.h"
|
||||
|
||||
// Constructor
|
||||
Ending2::Ending2(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options)
|
||||
{
|
||||
// Copia los punteros
|
||||
this->renderer = renderer;
|
||||
this->screen = screen;
|
||||
this->resource = resource;
|
||||
this->asset = asset;
|
||||
this->options = options;
|
||||
|
||||
// Reserva memoria para los punteros a objetos
|
||||
eventHandler = new SDL_Event();
|
||||
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
|
||||
music = JA_LoadMusic(asset->get("ending2.ogg").c_str());
|
||||
|
||||
// Inicializa variables
|
||||
counter = -1;
|
||||
preCounter = 0;
|
||||
section.name = SECTION_PROG_ENDING2;
|
||||
section.subsection = 0;
|
||||
ticks = 0;
|
||||
ticksSpeed = 15;
|
||||
|
||||
// Cambia el color del borde
|
||||
screen->setBorderColor(stringToColor(options->palette, "black"));
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Ending2::~Ending2()
|
||||
{
|
||||
// Libera la memoria de los objetos
|
||||
delete eventHandler;
|
||||
delete text;
|
||||
JA_DeleteMusic(music);
|
||||
}
|
||||
|
||||
// Actualiza el objeto
|
||||
void Ending2::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();
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
checkEventHandler();
|
||||
|
||||
// Actualiza los contadores
|
||||
updateCounters();
|
||||
|
||||
if (counter > 400)
|
||||
{
|
||||
section.name = SECTION_PROG_LOGO;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja el final en pantalla
|
||||
void Ending2::render()
|
||||
{
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
screen->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
screen->clean(stringToColor(options->palette, "black"));
|
||||
|
||||
text->write(0,0,std::to_string(counter));
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
screen->blit();
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void Ending2::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 = SECTION_PROG_QUIT;
|
||||
break;
|
||||
}
|
||||
|
||||
// Comprueba las teclas que se han pulsado
|
||||
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
||||
{
|
||||
switch (eventHandler->key.keysym.scancode)
|
||||
{
|
||||
case SDL_SCANCODE_ESCAPE:
|
||||
section.name = SECTION_PROG_QUIT;
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_B:
|
||||
screen->switchBorder();
|
||||
resource->reLoadTextures();
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F:
|
||||
screen->switchVideoMode();
|
||||
resource->reLoadTextures();
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F1:
|
||||
screen->setWindowSize(1);
|
||||
resource->reLoadTextures();
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F2:
|
||||
screen->setWindowSize(2);
|
||||
resource->reLoadTextures();
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F3:
|
||||
screen->setWindowSize(3);
|
||||
resource->reLoadTextures();
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F4:
|
||||
screen->setWindowSize(4);
|
||||
resource->reLoadTextures();
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F5:
|
||||
// switchPalette();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Bucle principal
|
||||
section_t Ending2::run()
|
||||
{
|
||||
JA_PlayMusic(music);
|
||||
|
||||
while (section.name == SECTION_PROG_ENDING2)
|
||||
{
|
||||
update();
|
||||
render();
|
||||
}
|
||||
|
||||
JA_StopMusic();
|
||||
|
||||
return section;
|
||||
}
|
||||
|
||||
// Actualiza los contadores
|
||||
void Ending2::updateCounters()
|
||||
{
|
||||
// Incrementa el contador
|
||||
if (preCounter < 200)
|
||||
{
|
||||
preCounter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
62
source/ending2.h
Normal file
62
source/ending2.h
Normal file
@@ -0,0 +1,62 @@
|
||||
#pragma once
|
||||
#include <SDL2/SDL.h>
|
||||
#include "common/animatedsprite.h"
|
||||
#include "common/asset.h"
|
||||
#include "common/jail_audio.h"
|
||||
#include "common/resource.h"
|
||||
#include "common/screen.h"
|
||||
#include "common/sprite.h"
|
||||
#include "common/text.h"
|
||||
#include "common/texture.h"
|
||||
#include "common/utils.h"
|
||||
#include "const.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#ifndef ENDING2_H
|
||||
#define ENDING2_H
|
||||
|
||||
class Ending2
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
Asset *asset; // Objeto con los ficheros de recursos
|
||||
Resource *resource; // Objeto con los recursos
|
||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||
SDL_Event *eventHandler; // Manejador de eventos
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Text *text; // Objeto para escribir texto en pantalla
|
||||
options_t *options; // Puntero a las opciones del juego
|
||||
|
||||
// Variables
|
||||
int counter; // Contador
|
||||
int preCounter; // Contador previo
|
||||
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
|
||||
JA_Music music; // Musica que suena durante el final
|
||||
|
||||
// Actualiza el objeto
|
||||
void update();
|
||||
|
||||
// Dibuja el final en pantalla
|
||||
void render();
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void checkEventHandler();
|
||||
|
||||
// Actualiza los contadores
|
||||
void updateCounters();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Ending2(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options);
|
||||
|
||||
// Destructor
|
||||
~Ending2();
|
||||
|
||||
// Bucle principal
|
||||
section_t run();
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user