Trabajando en la sección EnterID

This commit is contained in:
2022-11-23 09:54:08 +01:00
parent c955543d31
commit c71adfbac4
12 changed files with 332 additions and 21 deletions

13
source/ask_me.cpp Normal file
View File

@@ -0,0 +1,13 @@
#include "ask_me.h"
// Constructor
AskMe::AskMe(options_t *options)
{
this->options = options;
}
// Destructor
AskMe::~AskMe()
{
}

27
source/ask_me.h Normal file
View File

@@ -0,0 +1,27 @@
#pragma once
#include <SDL2/SDL.h>
#include "common/utils.h"
#include <string>
#include <vector>
#ifndef ASK_ME_H
#define ASK_ME_H
class AskMe
{
private:
// Punteros y objetos
options_t *options;
// Variables
public:
// Constructor
AskMe(options_t *options);
// Destructor
~AskMe();
};
#endif

13
source/cheevos.cpp Normal file
View File

@@ -0,0 +1,13 @@
#include "cheevos.h"
// Constructor
Cheevos::Cheevos(options_t *options)
{
this->options = options;
}
// Destructor
Cheevos::~Cheevos()
{
}

27
source/cheevos.h Normal file
View File

@@ -0,0 +1,27 @@
#pragma once
#include <SDL2/SDL.h>
#include "common/utils.h"
#include <string>
#include <vector>
#ifndef CHEEVOS_H
#define CHEEVOS_H
class Cheevos
{
private:
// Punteros y objetos
options_t *options;
// Variables
public:
// Constructor
Cheevos(options_t *options);
// Destructor
~Cheevos();
};
#endif

View File

@@ -135,7 +135,7 @@ void Notify::showText(std::string text)
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255); SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
n.texture->setBlendMode(SDL_BLENDMODE_BLEND); n.texture->setBlendMode(SDL_BLENDMODE_BLEND);
this->text->writeDX(TXT_CENTER | TXT_STROKE, width / 2, despV, text, 1, {255, 255, 255}, 1, {0, 0, 0}); this->text->writeDX(TXT_CENTER | TXT_STROKE, width / 2, despV, text, 1, {255, 255, 255}, 2, {0, 0, 0});
SDL_SetRenderTarget(renderer, nullptr); SDL_SetRenderTarget(renderer, nullptr);
// Crea el sprite // Crea el sprite

View File

@@ -29,7 +29,10 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight); gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight);
if (gameCanvas == nullptr) if (gameCanvas == nullptr)
{ {
std::cout << "TitleSurface could not be created!\nSDL Error: " << SDL_GetError() << std::endl; if (options->console)
{
std::cout << "TitleSurface could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
} }
// Establece el modo de video // Establece el modo de video

View File

@@ -57,7 +57,8 @@ const int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3;
#define SECTION_PROG_GAME_OVER 6 #define SECTION_PROG_GAME_OVER 6
#define SECTION_PROG_ENDING 7 #define SECTION_PROG_ENDING 7
#define SECTION_PROG_ENDING2 8 #define SECTION_PROG_ENDING2 8
#define SECTION_PROG_QUIT 9 #define SECTION_PROG_ENTER_ID 9
#define SECTION_PROG_QUIT 10
// Subsecciones // Subsecciones
#define SUBSECTION_LOGO_TO_INTRO 0 #define SUBSECTION_LOGO_TO_INTRO 0

View File

@@ -84,16 +84,22 @@ Director::~Director()
// Inicializa los servicios online // Inicializa los servicios online
void Director::initOnline() void Director::initOnline()
{ {
if (!options->online.enabled) //if (!options->online.enabled)
{ //{
return; // return;
} //}
options->online.enabled = true;
// Obten el Jailer ID // Obten el Jailer ID
if (options->online.jailerID == "") if (options->online.jailerID == "")
{ // Jailer ID no definido { // Jailer ID no definido
screen->showText("No ha especificado ningun Jailer ID"); screen->showText("No ha especificado ningun Jailer ID");
std::cout << "No ha especificado ningun Jailer ID" << std::endl; if (options->console)
{
std::cout << "No ha especificado ningun Jailer ID" << std::endl;
}
options->online.enabled = false;
} }
else else
{ // Jailer ID iniciado { // Jailer ID iniciado
@@ -105,12 +111,18 @@ void Director::initOnline()
if (jscore::initOnlineScore(options->online.gameID)) if (jscore::initOnlineScore(options->online.gameID))
{ {
screen->showText(options->online.jailerID + " ha iniciado sesion"); screen->showText(options->online.jailerID + " ha iniciado sesion");
std::cout << options->online.jailerID << " ha iniciado sesion" << std::endl; if (options->console)
{
std::cout << options->online.jailerID << " ha iniciado sesion" << std::endl;
}
} }
else else
{ {
screen->showText("Fallo al conectar a " + options->online.server); screen->showText("Fallo al conectar a " + options->online.server);
std::cout << "Fallo al conectar a " << options->online.server << std::endl; if (options->console)
{
std::cout << "Fallo al conectar a " << options->online.server << std::endl;
}
options->online.enabled = false; options->online.enabled = false;
@@ -358,9 +370,9 @@ void Director::createSystemFolder()
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
systemFolder = std::string(getenv("APPDATA")) + "/" + folderName; systemFolder = std::string(getenv("APPDATA")) + "/" + folderName;
#elif __APPLE__ #elif __APPLE__
struct passwd *pw = getpwuid(getuid()); struct passwd *pw = getpwuid(getuid());
const char *homedir = pw->pw_dir; const char *homedir = pw->pw_dir;
systemFolder = std::string(homedir) + "/Library/Application Support/" + folderName; systemFolder = std::string(homedir) + "/Library/Application Support/" + folderName;
#elif __linux__ #elif __linux__
@@ -386,15 +398,15 @@ void Director::createSystemFolder()
case EACCES: case EACCES:
printf("the parent directory does not allow write"); printf("the parent directory does not allow write");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
case EEXIST: case EEXIST:
printf("pathname already exists"); printf("pathname already exists");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
case ENAMETOOLONG: case ENAMETOOLONG:
printf("pathname is too long"); printf("pathname is too long");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
default: default:
perror("mkdir"); perror("mkdir");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@@ -1647,6 +1659,20 @@ void Director::runDemo()
resource->free(); resource->free();
} }
// Ejecuta la seccion en la que se solicita al usuario su ID online
void Director::runEnterID()
{
if (options->console)
{
std::cout << "\n* SECTION: ENTER_ID" << std::endl;
}
// loadResources(section);
enterID = new EnterID(renderer, screen, asset, options);
setSection(enterID->run());
delete enterID;
resource->free();
}
// Ejecuta la seccion del final del juego // Ejecuta la seccion del final del juego
void Director::runEnding() void Director::runEnding()
{ {
@@ -1731,6 +1757,10 @@ void Director::run()
runDemo(); runDemo();
break; break;
case SECTION_PROG_ENTER_ID:
runEnterID();
break;
case SECTION_PROG_GAME: case SECTION_PROG_GAME:
runGame(); runGame();
break; break;

View File

@@ -12,13 +12,14 @@
#include "const.h" #include "const.h"
#include "credits.h" #include "credits.h"
#include "demo.h" #include "demo.h"
#include "ending.h"
#include "ending2.h"
#include "enter_id.h"
#include "game_over.h"
#include "game.h" #include "game.h"
#include "intro.h" #include "intro.h"
#include "logo.h" #include "logo.h"
#include "title.h" #include "title.h"
#include "game_over.h"
#include "ending.h"
#include "ending2.h"
#ifndef DIRECTOR_H #ifndef DIRECTOR_H
#define DIRECTOR_H #define DIRECTOR_H
@@ -39,6 +40,7 @@ private:
Intro *intro; // Objeto 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 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 Demo *demo; // Objeto para gestionar el modo demo, en el que se ven pantallas del juego
EnterID *enterID; // Objeto para gestionar la sección donde se solicita el ID online al usuario
Ending *ending; // Objeto para gestionar el final del juego Ending *ending; // Objeto para gestionar el final del juego
Ending2 *ending2; // 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 GameOver *gameOver; // Objeto para gestionar el final de la partida
@@ -53,7 +55,7 @@ private:
// Crea e inicializa las opciones del programa // Crea e inicializa las opciones del programa
void initOptions(); void initOptions();
// Inicializa los servicios online // Inicializa los servicios online
void initOnline(); void initOnline();
@@ -111,6 +113,9 @@ private:
// Ejecuta la seccion de la demo, donde se ven pantallas del juego // Ejecuta la seccion de la demo, donde se ven pantallas del juego
void runDemo(); void runDemo();
// Ejecuta la seccion en la que se solicita al usuario su ID online
void runEnterID();
// Ejecuta la seccion del final del juego // Ejecuta la seccion del final del juego
void runEnding(); void runEnding();

135
source/enter_id.cpp Normal file
View File

@@ -0,0 +1,135 @@
#include "enter_id.h"
#include "const.h"
#include "common/jail_audio.h"
// Constructor
EnterID::EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options)
{
// Copia la dirección de los objetos
this->renderer = renderer;
this->screen = screen;
this->asset = asset;
this->options = options;
// Reserva memoria para los punteros
eventHandler = new SDL_Event();
texture = new Texture(renderer, asset->get("smb2.png"));
text = new Text(asset->get("smb2.txt"), texture, renderer);
// Inicializa variables
counter = 0;
section.name = SECTION_PROG_ENTER_ID;
ticks = 0;
ticksSpeed = 15;
}
// Destructor
EnterID::~EnterID()
{
delete eventHandler;
delete text;
delete texture;
}
// Bucle para el logo del juego
section_t EnterID::run()
{
// Detiene la música
JA_StopMusic();
while (section.name == SECTION_PROG_ENTER_ID)
{
update();
render();
}
return section;
}
// Comprueba el manejador de eventos
void EnterID::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_F1:
screen->setWindowSize(1);
break;
case SDL_SCANCODE_F2:
screen->setWindowSize(2);
break;
case SDL_SCANCODE_F3:
screen->setWindowSize(3);
break;
case SDL_SCANCODE_F4:
screen->setWindowSize(4);
break;
case SDL_SCANCODE_F5:
// switchPalette();
break;
default:
break;
}
}
}
}
// Actualiza las variables
void EnterID::update()
{
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
if (SDL_GetTicks() - ticks > ticksSpeed)
{
// Actualiza el contador de ticks
ticks = SDL_GetTicks();
// Comprueba el manejador de eventos
checkEventHandler();
// Actualiza el contador
counter++;
// Comprueba el contador
if (counter > 200)
{
section.name = SECTION_PROG_INTRO;
}
}
}
// Dibuja en pantalla
void EnterID::render()
{
// Prepara para empezar a dibujar en la textura de juego
screen->start();
// Limpia la pantalla
screen->clean();
// Escribe texto
text->writeCentered(GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y, "SECCION ENTER_ID");
// Vuelca el contenido del renderizador en pantalla
screen->blit();
}

52
source/enter_id.h Normal file
View File

@@ -0,0 +1,52 @@
#pragma once
#include <SDL2/SDL.h>
#include "common/asset.h"
#include "common/screen.h"
#include "common/utils.h"
#include "common/text.h"
#include "common/texture.h"
#include <string>
#include <vector>
#ifndef ENTER_ID_H
#define ASK_ME_H
class EnterID
{
private:
// Punteros y objetos
Asset *asset; // Objeto con los ficheros de recursos
options_t *options; // Puntero a las opciones del juego
Screen *screen; // Objeto encargado de dibujar en pantalla
SDL_Event *eventHandler; // Manejador de eventos
SDL_Renderer *renderer; // El renderizador de la ventana
Text *text; // Objeto para escribir texto en pantalla
Texture *texture; // Textura para la fuente para el texto
// Variables
int counter; // 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
// Actualiza las variables
void update();
// Dibuja en pantalla
void render();
// Comprueba el manejador de eventos
void checkEventHandler();
public:
// Constructor
EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options);
// Destructor
~EnterID();
// Bucle principal
section_t run();
};
#endif

View File

@@ -87,7 +87,6 @@ void Logo::checkEventHandler()
switch (eventHandler->key.keysym.scancode) switch (eventHandler->key.keysym.scancode)
{ {
case SDL_SCANCODE_ESCAPE: case SDL_SCANCODE_ESCAPE:
// std::cout << "PULSADO ESCAPE" << std::endl;
section.name = SECTION_PROG_QUIT; section.name = SECTION_PROG_QUIT;
break; break;
@@ -270,7 +269,13 @@ void Logo::update()
// Comprueba si ha terminado el logo // Comprueba si ha terminado el logo
if (counter == endLogo + postLogo) if (counter == endLogo + postLogo)
{ {
if (section.subsection == SUBSECTION_LOGO_TO_INTRO) if (options->online.jailerID == "")
{
section.name = SECTION_PROG_ENTER_ID;
section.subsection = 0;
}
else if (section.subsection == SUBSECTION_LOGO_TO_INTRO)
{ {
section.name = SECTION_PROG_INTRO; section.name = SECTION_PROG_INTRO;
section.subsection = 0; section.subsection = 0;