forked from jaildesigner-jailgames/jaildoctors_dilemma
Añadida la clase credits
This commit is contained in:
@@ -51,8 +51,18 @@ const int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3;
|
||||
#define SECTION_PROG_LOGO 0
|
||||
#define SECTION_PROG_INTRO 1
|
||||
#define SECTION_PROG_TITLE 2
|
||||
#define SECTION_PROG_GAME 3
|
||||
#define SECTION_PROG_QUIT 4
|
||||
#define SECTION_PROG_CREDITS 3
|
||||
#define SECTION_PROG_GAME 4
|
||||
#define SECTION_PROG_QUIT 5
|
||||
|
||||
// Subsecciones
|
||||
#define SUBSECTION_GAME_PLAY 0
|
||||
#define SUBSECTION_GAME_PAUSE 1
|
||||
#define SUBSECTION_GAME_GAMEOVER 2
|
||||
#define SUBSECTION_TITLE_1 3
|
||||
#define SUBSECTION_TITLE_2 4
|
||||
#define SUBSECTION_TITLE_3 5
|
||||
#define SUBSECTION_TITLE_INSTRUCTIONS 6
|
||||
|
||||
// Colores
|
||||
const color_t borderColor = {0x27, 0x27, 0x36};
|
||||
|
||||
126
source/credits.cpp
Normal file
126
source/credits.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
#include "credits.h"
|
||||
|
||||
// Constructor
|
||||
Credits::Credits(SDL_Renderer *renderer, Screen *screen, Asset *asset)
|
||||
{
|
||||
// Copia la dirección de los objetos
|
||||
this->renderer = renderer;
|
||||
this->screen = screen;
|
||||
this->asset = asset;
|
||||
|
||||
// Reserva memoria para los punteros
|
||||
eventHandler = new SDL_Event();
|
||||
text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer);
|
||||
|
||||
// Inicializa variables
|
||||
counter = 0;
|
||||
section.name = SECTION_PROG_CREDITS;
|
||||
section.subsection = 0;
|
||||
ticks = 0;
|
||||
ticksSpeed = 15;
|
||||
|
||||
// Cambia el color del borde
|
||||
screen->setBorderColor(stringToColor("black"));
|
||||
|
||||
// Inicializa los textos
|
||||
texts.push_back("ESTE ES UN TEXTO DE PRUEBA");
|
||||
texts.push_back("PARA VER COMO FUNCIONA LA CLASE");
|
||||
texts.push_back("Y TENGO QUE PONER ALGUN TEXTO PARA PROBAR");
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Credits::~Credits()
|
||||
{
|
||||
delete eventHandler;
|
||||
delete text;
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void Credits::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 si se ha pulsado alguna tecla
|
||||
else if ((eventHandler->type == SDL_KEYDOWN) and (eventHandler->key.repeat == 0))
|
||||
{
|
||||
switch (eventHandler->key.keysym.scancode)
|
||||
{
|
||||
case SDL_SCANCODE_ESCAPE:
|
||||
section.name = SECTION_PROG_QUIT;
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_RETURN:
|
||||
section.name = SECTION_PROG_TITLE;
|
||||
section.subsection = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza las variables
|
||||
void Credits::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();
|
||||
|
||||
// Incrementa el contador
|
||||
counter++;
|
||||
|
||||
// Comprueba si ha terminado la sección
|
||||
if (counter>1000)
|
||||
{
|
||||
section.name = SECTION_PROG_LOGO;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja en pantalla
|
||||
void Credits::render()
|
||||
{
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
screen->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
screen->clean();
|
||||
|
||||
// Dibuja el contenido de la sección
|
||||
//const color_t color = stringToColor("black");
|
||||
//SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 255);
|
||||
//SDL_RenderFillRect(renderer)
|
||||
text->write(8,8,texts[0]);
|
||||
text->write(8,16,texts[1]);
|
||||
text->write(8,24,texts[2]);
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
screen->blit();
|
||||
}
|
||||
|
||||
// Bucle para el logo del juego
|
||||
section_t Credits::run()
|
||||
{
|
||||
while (section.name == SECTION_PROG_CREDITS)
|
||||
{
|
||||
update();
|
||||
render();
|
||||
}
|
||||
|
||||
return section;
|
||||
}
|
||||
64
source/credits.h
Normal file
64
source/credits.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "const.h"
|
||||
#include "utils.h"
|
||||
#include "sprite.h"
|
||||
#include "screen.h"
|
||||
#include "asset.h"
|
||||
#include "text.h"
|
||||
#include "jail_audio.h"
|
||||
#include <vector>
|
||||
|
||||
#ifndef CREDITS_H
|
||||
#define CREDITS_H
|
||||
|
||||
// Clase Credits
|
||||
class Credits
|
||||
{
|
||||
private:
|
||||
struct letter_t
|
||||
{
|
||||
std::string letter; // Letra a escribir
|
||||
int x; // Posición en el eje x
|
||||
bool enabled; // Solo se escriben y mueven si estan habilitadas
|
||||
};
|
||||
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||
Asset *asset; // Objeto con los ficheros de recursos
|
||||
SDL_Event *eventHandler; // Manejador de eventos
|
||||
Text *text; // Objeto para escribir texto en pantalla
|
||||
int counter; // Contador
|
||||
section_t section; // Estado del bucle principal para saber si continua o se sale
|
||||
int ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
int ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
std::vector<std::string> texts; // Vector con las letras de la marquesina
|
||||
|
||||
// Actualiza las variables
|
||||
void update();
|
||||
|
||||
// Dibuja en pantalla
|
||||
void render();
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void checkEventHandler();
|
||||
|
||||
// Actualiza la marquesina
|
||||
void updateMarquee();
|
||||
|
||||
// Dibuja la marquesina
|
||||
void renderMarquee();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Credits(SDL_Renderer *renderer, Screen *screen, Asset *asset);
|
||||
|
||||
// Destructor
|
||||
~Credits();
|
||||
|
||||
// Bucle principal
|
||||
section_t run();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -476,6 +476,14 @@ void Director::runTitle()
|
||||
delete title;
|
||||
}
|
||||
|
||||
// Ejecuta la seccion de los creditos del juego
|
||||
void Director::runCredits()
|
||||
{
|
||||
credits = new Credits(renderer, screen, asset);
|
||||
setSection(credits->run());
|
||||
delete credits;
|
||||
}
|
||||
|
||||
// Ejecuta la seccion de juego donde se juega
|
||||
void Director::runGame()
|
||||
{
|
||||
@@ -500,6 +508,9 @@ void Director::run()
|
||||
case SECTION_PROG_TITLE:
|
||||
runTitle();
|
||||
break;
|
||||
case SECTION_PROG_CREDITS:
|
||||
runCredits();
|
||||
break;
|
||||
case SECTION_PROG_GAME:
|
||||
runGame();
|
||||
break;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "game.h"
|
||||
#include "logo.h"
|
||||
#include "title.h"
|
||||
#include "credits.h"
|
||||
#include "intro.h"
|
||||
#include "asset.h"
|
||||
#include "debug.h"
|
||||
@@ -28,7 +29,8 @@ private:
|
||||
Game *game; // Objeto para gestionar la sección del juego
|
||||
Logo *logo; // Objeto para gestionar la sección del logo del programa
|
||||
Title *title; // Objeto para gestionar la pantalla de título
|
||||
Intro *intro; // Onjeto para gestionar la introducción del juego
|
||||
Intro *intro; // Objeto para gestionar la introducción del juego
|
||||
Credits *credits; // Objeto para gestionar los creditos del juego
|
||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
||||
Debug *debug; // Objeto para getsionar la información de debug
|
||||
|
||||
@@ -76,6 +78,9 @@ private:
|
||||
// Ejecuta la seccion de juego con el titulo y los menus
|
||||
void runTitle();
|
||||
|
||||
// Ejecuta la seccion de los creditos del juego
|
||||
void runCredits();
|
||||
|
||||
// Ejecuta la seccion de juego donde se juega
|
||||
void runGame();
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "const.h"
|
||||
#include "sprite.h"
|
||||
#include "animatedsprite.h"
|
||||
#include "text.h"
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
#ifndef SCREEN_H
|
||||
#define SCREEN_H
|
||||
|
||||
#define FILTER_NEAREST 0
|
||||
#define FILTER_LINEAL 1
|
||||
|
||||
struct anchor_t
|
||||
{
|
||||
int left; // Parte izquierda de la pantalla de juego
|
||||
|
||||
@@ -22,6 +22,7 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Asset *asset)
|
||||
ticks = 0;
|
||||
ticksSpeed = 15;
|
||||
longText = "HEY JAILERS!! IT'S 2022 AND WE'RE STILL ROCKING LIKE IT'S 1998!!! HAVE YOU HEARD IT? JAILGAMES ARE BACK!! YEEESSS BACK!! MORE THAN 10 TITLES ON JAILDOC'S KITCHEN!! THATS A LOOOOOOT OF JAILGAMES, BUT WHICH ONE WILL STRIKE FIRST? THERE IS ALSO A NEW DEVICE TO COME P.A.C.O. THAT WILL BLOW YOUR MIND WITH JAILGAMES ON THE GO. BUT WAIT! WHAT'S THAT BEAUTY I'M SEEING RIGHT OVER THERE?? OOOH THAT TINY MINIASCII IS PURE LOVE!! I WANT TO LICK EVERY BYTE OF IT!! OH SHIT! AND DON'T FORGET TO BRING BACK THOSE OLD AND FAT MS-DOS JAILGAMES TO GITHUB TO KEEP THEM ALIVE!! WHAT WILL BE THE NEXT JAILDOC RELEASE? WHAT WILL BE THE NEXT PROJECT TO COME ALIVE?? OH BABY WE DON'T KNOW BUT HERE YOU CAN FIND THE ANSWER, YOU JUST HAVE TO COMPLETE JAILDOCTOR'S DILEMMA ... COULD YOU?";
|
||||
longText = "HEY YOU!";
|
||||
for (int i = 0; i < longText.length(); i++)
|
||||
{
|
||||
letter_t l;
|
||||
@@ -159,13 +160,10 @@ void Title::update()
|
||||
// Actualiza la marquesina
|
||||
updateMarquee();
|
||||
|
||||
// Comprueba si ha pasado mucho tiempo y acaba el titulo
|
||||
// if (counter == 1000)
|
||||
|
||||
// Comprueba si ha terminado la marquesina y acaba con el titulo
|
||||
if (letters[letters.size() - 1].x < -10)
|
||||
{
|
||||
section.name = SECTION_PROG_LOGO;
|
||||
section.name = SECTION_PROG_CREDITS;
|
||||
section.subsection = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,25 +7,6 @@
|
||||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
#define FILTER_NEAREST 0
|
||||
#define FILTER_LINEAL 1
|
||||
|
||||
// Secciones del programa
|
||||
#define SECTION_PROG_LOGO 0
|
||||
#define SECTION_PROG_INTRO 1
|
||||
#define SECTION_PROG_TITLE 2
|
||||
#define SECTION_PROG_GAME 3
|
||||
#define SECTION_PROG_QUIT 4
|
||||
|
||||
// Subsecciones
|
||||
#define SUBSECTION_GAME_PLAY 0
|
||||
#define SUBSECTION_GAME_PAUSE 1
|
||||
#define SUBSECTION_GAME_GAMEOVER 2
|
||||
#define SUBSECTION_TITLE_1 3
|
||||
#define SUBSECTION_TITLE_2 4
|
||||
#define SUBSECTION_TITLE_3 5
|
||||
#define SUBSECTION_TITLE_INSTRUCTIONS 6
|
||||
|
||||
// Estructura para definir un circulo
|
||||
struct circle_t
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user