14 Commits

Author SHA1 Message Date
ba19dcb904 Actualizar 'README.md' 2022-11-23 22:37:02 +01:00
b035b92ff4 Retocada ROAD TO THE JAIL 2022-11-23 22:32:57 +01:00
8c425f5698 Fix: De enter_id iba siempre a intro 2022-11-23 22:22:32 +01:00
d382bb6403 Optimizado el calculo del tamaño de las notificaciones 2022-11-23 20:53:01 +01:00
da64a5e082 Oculta el ratón en el modo a pantalla completa 2022-11-23 20:38:21 +01:00
7070dac482 Arreglado tamaño de las notificaciones en pantalla completa 2022-11-23 20:33:54 +01:00
ea5360ea74 Trabajando en las notificaciones 2022-11-23 20:14:53 +01:00
3aa4440390 Trabajando en las notificaciones 2022-11-23 20:05:07 +01:00
ce105e252e Trabajando en el tamaño de las notificaciones 2022-11-23 19:52:10 +01:00
1aac5b7719 Trabajando en las notificaciones 2022-11-23 18:20:29 +01:00
a8b467290f Completado el ciclo para pedir el ID online. Añadido sonido a las notificaciones. Agregado control de versión del fichero de configuración 2022-11-23 16:59:40 +01:00
706ad6f9c0 Trabajando en el escalado de las notificaciones 2022-11-23 14:11:47 +01:00
54d428ed96 Ya permite establecer el online ID desde el propio juego 2022-11-23 13:29:35 +01:00
c71adfbac4 Trabajando en la sección EnterID 2022-11-23 09:54:08 +01:00
24 changed files with 630 additions and 144 deletions

View File

@@ -2,7 +2,7 @@ executable = jaildoctors_dilemma
source = source/*.cpp source/common/*.cpp
appName = JailDoctor's Dilemma
releaseFolder = jdd_release
version = v1.06
version = v1.06.1
# Release names
windowsRelease = $(executable)-$(version)-win32-x64.zip

View File

@@ -1,4 +1,4 @@
# JailDoctor's Dilemma
# JailDoctor's Dilemma (v1.06.1)
JailDoc es un Jailer. A los Jailers les gusta empezar proyectos. A nadie le gusta terminarlos. Los Jailers viven en la Jail. A la Jail va uno a empezar proyectos. A la Jail va uno a enseñar sus proyectos. A la Jail va uno a aprender como empezar nuevos proyectos. A la Jail va uno a ayudar a sus compañeros a que empiecen nuevos proyectos.
@@ -70,6 +70,8 @@ En **MacOS** se encuentra en:
En **Linux** se encuentra en:
`~/.jaildoctors_dilemma`
La primera vez, el juego te pregunta por tu identificador online. Esta información se guarda para futuras partidas.
En la carpeta está el fichero de configuración `config.txt` donde se puede modificar la configuración para conectarse al servicio online y los ficheros `stats.csv` y `stats_buffer.csv` con información de las estadisticas de juego.
## Agradecimientos

View File

@@ -17,7 +17,7 @@
34,34,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25,25,
34,34,389,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,387,25,25,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,513,190,189,190,537,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,513,189,190,537,0,0,0,0,
34,34,189,190,189,190,189,190,189,190,189,190,189,190,189,190,189,190,189,191,0,0,189,190,189,190,189,190,189,190,25,25
</data>
</layer>

BIN
data/sound/notify.wav Normal file

Binary file not shown.

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

@@ -4,7 +4,7 @@
#include <iostream>
// Constructor
Notify::Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textFile)
Notify::Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textFile, std::string soundFile)
{
// Inicializa variables
this->renderer = renderer;
@@ -14,6 +14,7 @@ Notify::Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textF
// Crea objetos
texture = new Texture(renderer, bitmapFile);
text = new Text(textFile, texture, renderer);
sound = JA_LoadSound(soundFile.c_str());
}
// Destructor
@@ -22,6 +23,7 @@ Notify::~Notify()
// Libera la memoria de los objetos
delete texture;
delete text;
JA_DeleteSound(sound);
for (auto notification : notifications)
{
@@ -143,6 +145,9 @@ void Notify::showText(std::string text)
// Añade la notificación a la lista
notifications.push_back(n);
// Reproduce el sonido de la notificación
JA_PlaySound(sound);
}
// Indica si hay notificaciones activas

View File

@@ -1,9 +1,10 @@
#pragma once
#include <SDL2/SDL.h>
#include "jail_audio.h"
#include "sprite.h"
#include "text.h"
#include "texture.h"
#include "sprite.h"
#include "utils.h"
#include <vector>
@@ -55,6 +56,7 @@ private:
color_t bgColor; // Color de fondo de las notificaciones
int waitTime; // Tiempo que se ve la notificación
std::vector<notification_t> notifications; // La lista de notificaciones activas
JA_Sound sound; // Sonido a reproducir cuando suena la notificación
// Elimina las notificaciones finalizadas
void clearFinishedNotifications();
@@ -67,7 +69,7 @@ public:
void update();
// Constructor
Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textFile);
Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textFile, std::string soundFile);
// Destructor
~Notify();

View File

@@ -12,12 +12,14 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
this->asset = asset;
// Crea los objetos
notify = new Notify(renderer, asset->get("smb2.png"), asset->get("smb2.txt"));
notify = new Notify(renderer, asset->get("smb2.png"), asset->get("smb2.txt"), asset->get("notify.wav"));
gameCanvasWidth = options->gameWidth;
gameCanvasHeight = options->gameHeight;
borderWidth = options->gameWidth * options->borderSize;
borderHeight = options->gameHeight * options->borderSize;
notificationLogicalWidth = gameCanvasWidth;
notificationLogicalHeight = gameCanvasHeight;
iniFade();
iniSpectrumFade();
@@ -28,9 +30,12 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
// Crea la textura donde se dibujan los graficos del juego
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight);
if (gameCanvas == nullptr)
{
if (options->console)
{
std::cout << "TitleSurface could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
// Establece el modo de video
setVideoMode(options->videoMode);
@@ -81,6 +86,9 @@ void Screen::blit()
// Establece el modo de video
void Screen::setVideoMode(int videoMode)
{
// Muestra el puntero
SDL_ShowCursor(SDL_ENABLE);
// Aplica el modo de video
SDL_SetWindowFullscreen(window, videoMode);
@@ -109,6 +117,9 @@ void Screen::setVideoMode(int videoMode)
// Si está activo el modo de pantalla completa añade el borde
else if (videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
{
// Oculta el puntero
SDL_ShowCursor(SDL_DISABLE);
// Obten el alto y el ancho de la ventana
SDL_GetWindowSize(window, &windowWidth, &windowHeight);
@@ -158,6 +169,9 @@ void Screen::setVideoMode(int videoMode)
// Actualiza el valor de la variable
options->videoMode = videoMode;
// Establece el tamaño de las notificaciones
setNotificationSize();
}
// Camibia entre pantalla completa y ventana
@@ -348,7 +362,7 @@ void Screen::updateNotifier()
}
// Muestra una notificación de texto por pantalla;
void Screen::showText(std::string text)
void Screen::showNotification(std::string text)
{
notify->showText(text);
}
@@ -361,7 +375,31 @@ void Screen::renderNotifications()
return;
}
SDL_RenderSetLogicalSize(renderer, windowWidth * 2, windowHeight * 2);
SDL_RenderSetLogicalSize(renderer, notificationLogicalWidth, notificationLogicalHeight);
notify->render();
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
}
// Establece el tamaño de las notificaciones
void Screen::setNotificationSize()
{
if (options->videoMode == 0)
{
if (options->windowSize == 3)
{
notificationLogicalWidth = (windowWidth * 3) / 2;
notificationLogicalHeight = (windowHeight * 3) / 2;
}
else
{
notificationLogicalWidth = windowWidth * 2;
notificationLogicalHeight = windowHeight * 2;
}
}
if (options->videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
{
notificationLogicalWidth = windowWidth / 3;
notificationLogicalHeight = windowHeight / 3;
}
}

View File

@@ -33,6 +33,8 @@ private:
SDL_Rect dest; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
bool notifyActive; // Indica si hay notificaciones activas
int notificationLogicalWidth; // Ancho lógico de las notificaciones en relación al tamaño de pantalla
int notificationLogicalHeight; // Alto lógico de las notificaciones en relación al tamaño de pantalla
// Variables - Efectos
bool fade; // Indica si esta activo el efecto de fade
@@ -64,6 +66,9 @@ private:
// Dibuja las notificaciones
void renderNotifications();
// Establece el tamaño de las notificaciones
void setNotificationSize();
public:
// Constructor
Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options);
@@ -126,7 +131,7 @@ public:
void updateNotifier();
// Muestra una notificación de texto por pantalla;
void showText(std::string text);
void showNotification(std::string text);
};
#endif

View File

@@ -94,6 +94,9 @@ Text::Text(std::string textFile, Texture *texture, SDL_Renderer *renderer)
// Crea los objetos
sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture, renderer);
// Inicializa variables
fixedWidth = false;
}
// Constructor
@@ -111,6 +114,9 @@ Text::Text(textFile_t *textFile, Texture *texture, SDL_Renderer *renderer)
// Crea los objetos
sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture, renderer);
// Inicializa variables
fixedWidth = false;
}
// Destructor
@@ -133,7 +139,8 @@ void Text::write(int x, int y, std::string text, int kerning, int lenght)
sprite->setPosX(x + shift);
sprite->setPosY(y);
sprite->render();
shift += (offset[int(text[i])].w + kerning);
// shift += (offset[int(text[i])].w + kerning);
shift += fixedWidth ? boxWidth : (offset[int(text[i])].w + kerning);
}
}
@@ -226,3 +233,9 @@ void Text::reLoadTexture()
{
sprite->getTexture()->reLoad();
}
// Establece si se usa un tamaño fijo de letra
void Text::setFixedWidth(bool value)
{
fixedWidth = value;
}

View File

@@ -38,6 +38,7 @@ private:
// Variables
int boxWidth; // Anchura de la caja de cada caracter en el png
int boxHeight; // Altura de la caja de cada caracter en el png
bool fixedWidth; // Indica si el texto se ha de escribir con longitud fija en todas las letras
offset_t offset[128]; // Vector con las posiciones y ancho de cada letra
public:
@@ -71,6 +72,9 @@ public:
// Recarga la textura
void reLoadTexture();
// Establece si se usa un tamaño fijo de letra
void setFixedWidth(bool value);
};
#endif

View File

@@ -294,28 +294,6 @@ SDL_Point checkCollision(d_line_t &l1, v_line_t &l2)
return {-1, -1};
}
// Detector de colisiones entre una linea diagonal y una vertical
/*bool checkCollision(d_line_t &l1, v_line_t &l2)
{
// Normaliza la linea diagonal
normalizeLine(l1);
// Comprueba si la linea vertical esta a la izquierda de la linea diagonal
if (l2.x < l1.x1)
{
return false;
}
// Comprueba si la linea vertical esta a la derecha de la linea diagonal
if (l2.x > l1.x2)
{
return false;
}
// Inacabada
return true;
}*/
// Normaliza una linea diagonal
void normalizeLine(d_line_t &l)
{
@@ -367,16 +345,6 @@ bool checkCollision(SDL_Point &p, d_line_t &l)
// En caso contrario, el punto está en la linea
return true;
/*const int m = (l.y2 - l.y1) / (l.x2 - l.x1);
const int c = 0;
// Comprueba si p cumple la ecuación de la linea
if (p.y == ((m * p.x) + c))
return true;
return false;*/
}
// Devuelve un color_t a partir de un string

View File

@@ -92,6 +92,7 @@ struct op_stats_t
// Estructura con todas las opciones de configuración del programa
struct options_t
{
std::string configVersion; // Versión del programa. Sirve para saber si las opciones son compatibles
Uint32 videoMode; // Contiene el valor del modo de pantalla completa
int windowSize; // Contiene el valor por el que se multiplica el tamaño de la ventana
Uint32 filter; // Filtro usado para el escalado de la imagen

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_ENDING 7
#define SECTION_PROG_ENDING2 8
#define SECTION_PROG_QUIT 9
#define SECTION_PROG_ENTER_ID 9
#define SECTION_PROG_QUIT 10
// Subsecciones
#define SUBSECTION_LOGO_TO_INTRO 0

View File

@@ -318,14 +318,6 @@ section_t Credits::run()
// Cambia la paleta
void Credits::switchPalette()
{
if (options->palette == p_zxspectrum)
{
options->palette = p_zxarne;
}
else
{
options->palette = p_zxspectrum;
}
options->palette = options->palette == p_zxspectrum ? p_zxarne : p_zxspectrum;
fillTexture();
}

View File

@@ -59,7 +59,7 @@ Director::Director(int argc, char *argv[])
music = JA_LoadMusic(asset->get("title.ogg").c_str());
// Inicializa los servicios online
initOnline();
//initOnline();
}
Director::~Director()
@@ -84,37 +84,24 @@ Director::~Director()
// Inicializa los servicios online
void Director::initOnline()
{
if (!options->online.enabled)
{
return;
}
// Obten el Jailer ID
if (options->online.jailerID == "")
{ // Jailer ID no definido
screen->showText("No ha especificado ningun Jailer ID");
std::cout << "No ha especificado ningun Jailer ID" << std::endl;
options->online.enabled = false;
}
else
{ // Jailer ID iniciado
// Establece el servidor y el puerto
if (options->online.enabled)
{ // Establece el servidor y el puerto
jscore::init(options->online.server, options->online.port);
// Obtiene la información online
if (jscore::initOnlineScore(options->online.gameID))
const std::string caption = options->online.jailerID + " IS LOGGED IN";
screen->showNotification(caption);
if (options->console)
{
screen->showText(options->online.jailerID + " ha iniciado sesion");
std::cout << options->online.jailerID << " ha iniciado sesion" << std::endl;
std::cout << caption << std::endl;
}
else
{
screen->showText("Fallo al conectar a " + options->online.server);
std::cout << "Fallo al conectar a " << options->online.server << std::endl;
options->online.enabled = false;
return;
}
}
}
@@ -125,7 +112,10 @@ void Director::initOptions()
// Crea el puntero a la estructura de opciones
options = new options_t;
// Inicializa valores
// Version
options->configVersion = "v1.06.1";
// Opciones dee video
options->gameWidth = GAMECANVAS_WIDTH;
options->gameHeight = GAMECANVAS_HEIGHT;
options->videoMode = 0;
@@ -147,8 +137,8 @@ void Director::initOptions()
options->stats.rooms = 0;
options->stats.items = 0;
// Online
options->online.enabled = false;
// Opciones online
options->online.enabled = true;
options->online.server = "jaildoctor.duckdns.org";
options->online.port = 9911;
#ifdef DEBUG
@@ -201,6 +191,10 @@ bool Director::loadConfig()
// Indicador de éxito en la carga
bool success = true;
// Versión actual del fichero
const std::string configVersion = options->configVersion;
options->configVersion = "";
// Variables para manejar el fichero
std::string line;
std::ifstream file(asset->get("config.txt"));
@@ -247,6 +241,13 @@ bool Director::loadConfig()
saveConfig();
}
// Si la versión de fichero no coincide, crea un fichero nuevo con los valores por defecto
if (configVersion != options->configVersion)
{
initOptions();
saveConfig();
}
// Normaliza los valores
const bool a = options->videoMode == 0;
const bool b = options->videoMode == SDL_WINDOW_FULLSCREEN;
@@ -302,7 +303,10 @@ bool Director::saveConfig()
}
// Escribe en el fichero
file << "## VISUAL OPTIONS\n";
file << "## VERSION\n";
file << "configVersion=" + options->configVersion + "\n";
file << "\n## VISUAL OPTIONS\n";
if (options->videoMode == 0)
{
file << "videoMode=0\n";
@@ -967,7 +971,12 @@ bool Director::setOptions(options_t *options, std::string var, std::string value
// Indicador de éxito en la asignación
bool success = true;
if (var == "videoMode")
if (var == "configVersion")
{
options->configVersion = value;
}
else if (var == "videoMode")
{
if (value == "SDL_WINDOW_FULLSCREEN_DESKTOP")
{
@@ -1525,6 +1534,7 @@ bool Director::setFileList()
asset->add(prefix + "/data/sound/jump22.wav", t_sound);
asset->add(prefix + "/data/sound/jump23.wav", t_sound);
asset->add(prefix + "/data/sound/jump24.wav", t_sound);
asset->add(prefix + "/data/sound/notify.wav", t_sound);
// Logo
asset->add(prefix + "/data/logo/jailgames.png", t_bitmap);
@@ -1647,6 +1657,20 @@ void Director::runDemo()
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, section);
setSection(enterID->run());
delete enterID;
resource->free();
}
// Ejecuta la seccion del final del juego
void Director::runEnding()
{
@@ -1731,6 +1755,10 @@ void Director::run()
runDemo();
break;
case SECTION_PROG_ENTER_ID:
runEnterID();
break;
case SECTION_PROG_GAME:
runGame();
break;

View File

@@ -12,13 +12,14 @@
#include "const.h"
#include "credits.h"
#include "demo.h"
#include "ending.h"
#include "ending2.h"
#include "enter_id.h"
#include "game_over.h"
#include "game.h"
#include "intro.h"
#include "logo.h"
#include "title.h"
#include "game_over.h"
#include "ending.h"
#include "ending2.h"
#ifndef DIRECTOR_H
#define DIRECTOR_H
@@ -39,6 +40,7 @@ private:
Intro *intro; // Objeto para gestionar la introducción 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
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
Ending2 *ending2; // Objeto para gestionar el final del juego
GameOver *gameOver; // Objeto para gestionar el final de la partida
@@ -46,9 +48,9 @@ private:
struct options_t *options; // Variable con todas las opciones del programa
// Variables
section_t section; // Sección y subsección actual del programa;
JA_Music music; // Musica del titulo
std::string executablePath; // Path del ejecutable
section_t section; // Sección y subsección actual del programa;
std::string systemFolder; // Carpeta del sistema donde guardar datos
// Crea e inicializa las opciones del programa
@@ -111,6 +113,9 @@ private:
// Ejecuta la seccion de la demo, donde se ven pantallas del juego
void runDemo();
// Ejecuta la seccion en la que se solicita al usuario su ID online
void runEnterID();
// Ejecuta la seccion del final del juego
void runEnding();

310
source/enter_id.cpp Normal file
View File

@@ -0,0 +1,310 @@
#include "common/jail_audio.h"
#include "common/jscore.h"
#include "const.h"
#include "enter_id.h"
#include <iostream>
// Constructor
EnterID::EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options, section_t section)
{
// 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);
// Crea la textura para el texto que se escribe en pantalla
textTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
if (textTexture == nullptr)
{
if (options->console)
{
std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
SDL_SetTextureBlendMode(textTexture, SDL_BLENDMODE_BLEND);
// Inicializa variables
counter = 0;
ticks = 0;
ticksSpeed = 15;
pos = 0;
name[pos] = 0;
maxLenght = 15;
this->section.subsection = section.subsection;
if (options->online.enabled && options->online.jailerID == "")
{
this->section.name = SECTION_PROG_ENTER_ID;
}
else
{
endSection();
}
// Escribe el texto en la textura
fillTexture();
}
// 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;
}
// El ENTER solo se comprueba cuando se suelta, para no saltarse la siguiente sección
if ((eventHandler->type == SDL_KEYUP && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONUP))
{
if (eventHandler->key.keysym.scancode == SDL_SCANCODE_RETURN)
{
options->online.jailerID = (std::string)name;
endSection();
break;
}
}
// Comprueba las teclas que se han pulsado
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
{
if (eventHandler->key.keysym.scancode >= SDL_SCANCODE_A && eventHandler->key.keysym.scancode <= SDL_SCANCODE_Z)
{ // Si pulsa una letra
if (pos < maxLenght)
{
name[pos++] = eventHandler->key.keysym.scancode + 61;
name[pos] = 0;
}
}
else if (eventHandler->key.keysym.scancode >= SDL_SCANCODE_1 && eventHandler->key.keysym.scancode <= SDL_SCANCODE_9)
{ // Si pulsa un número
if (pos < maxLenght)
{ // En ascii el '0' va antes del '1', pero en scancode el '0' va despues de '9'
name[pos++] = eventHandler->key.keysym.scancode + 19;
name[pos] = 0;
}
}
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_0)
{
if (pos < maxLenght)
{
name[pos++] = 48;
name[pos] = 0;
}
}
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_BACKSPACE)
{
if (pos > 0)
{
name[--pos] = 0;
}
}
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_ESCAPE)
{
section.name = SECTION_PROG_QUIT;
break;
}
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_F1)
{
screen->setWindowSize(1);
break;
}
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_F2)
{
screen->setWindowSize(2);
break;
}
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_F3)
{
screen->setWindowSize(3);
break;
}
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_F4)
{
screen->setWindowSize(4);
break;
}
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_F5)
{
switchPalette();
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++;
// Actualiza el cursor
cursor = (counter % 20 >= 10) ? " " : "_";
}
}
// Dibuja en pantalla
void EnterID::render()
{
// Prepara para empezar a dibujar en la textura de juego
screen->start();
// Limpia la pantalla
screen->clean();
// Dibuja la textura con el texto en pantalla
SDL_RenderCopy(renderer, textTexture, nullptr, nullptr);
// Escribe el jailerID
const std::string jailerID = (std::string)name + cursor;
const color_t color = stringToColor(options->palette, "white");
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, (16 * 8 + 1), jailerID, 1, color);
// Vuelca el contenido del renderizador en pantalla
screen->blit();
}
// Inicializa los textos
void EnterID::iniTexts()
{
texts.clear();
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"ONLINE CONFIGURATION:", stringToColor(options->palette, "red")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"YOU HAVE NOT SPECIFIED ANY ID", stringToColor(options->palette, "white")});
texts.push_back({"FOR THE ONLINE SERVICE", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"PLEASE ENTER AN ID OR", stringToColor(options->palette, "white")});
texts.push_back({"LEAVE BLANK FOR OFFLINE MODE", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"JAILER_ID:", stringToColor(options->palette, "red")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
}
// Escribe el texto en la textura
void EnterID::fillTexture()
{
// Inicializa los textos
iniTexts();
// Rellena la textura de texto
SDL_SetRenderTarget(renderer, textTexture);
color_t c = stringToColor(options->palette, "black");
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
SDL_RenderClear(renderer);
// Escribe el texto en la textura
const int size = text->getCharacterSize();
int i = 0;
for (auto t : texts)
{
text->writeDX(TXT_CENTER | TXT_COLOR, PLAY_AREA_CENTER_X, i * size, t.label, 1, t.color);
i++;
}
SDL_SetRenderTarget(renderer, nullptr);
}
// Cambia la paleta
void EnterID::switchPalette()
{
options->palette = options->palette == p_zxspectrum ? p_zxarne : p_zxspectrum;
fillTexture();
}
// Inicializa los servicios online
void EnterID::initOnline()
{
if (options->online.jailerID == "")
{ // Jailer ID no definido
options->online.enabled = false;
}
else
{ // Jailer ID iniciado
options->online.enabled = true;
jscore::init(options->online.server, options->online.port);
const std::string caption = options->online.jailerID + " IS LOGGED IN";
screen->showNotification(caption);
if (options->console)
{
std::cout << caption << std::endl;
}
}
}
// Termina la sección
void EnterID::endSection()
{
initOnline();
section.name = (section.subsection == SUBSECTION_LOGO_TO_INTRO) ? SECTION_PROG_INTRO : SECTION_PROG_TITLE;
section.subsection = 0;
}

80
source/enter_id.h Normal file
View File

@@ -0,0 +1,80 @@
#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:
struct captions_t
{
std::string label; // Texto a escribir
color_t color; // Color del texto
};
// 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
SDL_Texture *textTexture; // Textura para dibujar el texto
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
std::vector<captions_t> texts; // Vector con los textos
std::string cursor; // Contiene el caracter que se muestra como cursor
char name[15];
int pos;
int maxLenght; // Tamaño máximo del jailerID
// Actualiza las variables
void update();
// Dibuja en pantalla
void render();
// Comprueba el manejador de eventos
void checkEventHandler();
// Inicializa los textos
void iniTexts();
// Escribe el texto en la textura
void fillTexture();
// Cambia la paleta
void switchPalette();
// Inicializa los servicios online
void initOnline();
// Termina la sección
void endSection();
public:
// Constructor
EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options, section_t section);
// Destructor
~EnterID();
// Bucle principal
section_t run();
};
#endif

View File

@@ -137,7 +137,7 @@ void Game::checkEventHandler()
break;
case SDL_SCANCODE_F6:
screen->showText("MAMA MIRA! SIN MANOS!");
screen->showNotification("MAMA MIRA! SIN MANOS!");
break;
#endif

View File

@@ -82,12 +82,11 @@ void Logo::checkEventHandler()
}
// Comprueba las teclas que se han pulsado
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
if ((eventHandler->type == SDL_KEYUP && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONUP))
{
switch (eventHandler->key.keysym.scancode)
{
case SDL_SCANCODE_ESCAPE:
// std::cout << "PULSADO ESCAPE" << std::endl;
section.name = SECTION_PROG_QUIT;
break;
@@ -126,8 +125,8 @@ void Logo::checkEventHandler()
break;
default:
section.name = SECTION_PROG_TITLE;
section.subsection = 0;
section.subsection = SUBSECTION_LOGO_TO_TITLE;
endSection();
break;
}
}
@@ -270,16 +269,7 @@ void Logo::update()
// Comprueba si ha terminado el logo
if (counter == endLogo + postLogo)
{
if (section.subsection == SUBSECTION_LOGO_TO_INTRO)
{
section.name = SECTION_PROG_INTRO;
section.subsection = 0;
}
else
{
section.name = SECTION_PROG_TITLE;
section.subsection = 0;
}
endSection();
}
}
}
@@ -322,12 +312,11 @@ section_t Logo::run()
// Cambia la paleta
void Logo::switchPalette()
{
if (options->palette == p_zxspectrum)
{
options->palette = p_zxarne;
}
else
{
options->palette = p_zxspectrum;
}
options->palette = options->palette == p_zxspectrum ? p_zxarne : p_zxspectrum;
}
// Termina la sección
void Logo::endSection()
{
section.name = SECTION_PROG_ENTER_ID;
}

View File

@@ -56,6 +56,9 @@ private:
// Cambia la paleta
void switchPalette();
// Termina la sección
void endSection();
public:
// Constructor
Logo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, int subsection);

View File

@@ -117,7 +117,7 @@ void Title::checkEventHandler()
#ifdef DEBUG
case SDL_SCANCODE_F6:
screen->showText("MAMA MIRA! SIN MANOS!");
screen->showNotification("MAMA MIRA! SIN MANOS!");
break;
#endif