forked from jaildesigner-jailgames/jaildoctors_dilemma
Completado el ciclo para pedir el ID online. Añadido sonido a las notificaciones. Agregado control de versión del fichero de configuración
This commit is contained in:
2
Makefile
2
Makefile
@@ -2,7 +2,7 @@ executable = jaildoctors_dilemma
|
|||||||
source = source/*.cpp source/common/*.cpp
|
source = source/*.cpp source/common/*.cpp
|
||||||
appName = JailDoctor's Dilemma
|
appName = JailDoctor's Dilemma
|
||||||
releaseFolder = jdd_release
|
releaseFolder = jdd_release
|
||||||
version = v1.06
|
version = v1.06.1
|
||||||
|
|
||||||
# Release names
|
# Release names
|
||||||
windowsRelease = $(executable)-$(version)-win32-x64.zip
|
windowsRelease = $(executable)-$(version)-win32-x64.zip
|
||||||
|
|||||||
BIN
data/sound/notify.wav
Normal file
BIN
data/sound/notify.wav
Normal file
Binary file not shown.
@@ -1,13 +0,0 @@
|
|||||||
#include "ask_me.h"
|
|
||||||
|
|
||||||
// Constructor
|
|
||||||
AskMe::AskMe(options_t *options)
|
|
||||||
{
|
|
||||||
this->options = options;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
AskMe::~AskMe()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
#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
|
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
// Constructor
|
// 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
|
// Inicializa variables
|
||||||
this->renderer = renderer;
|
this->renderer = renderer;
|
||||||
@@ -14,6 +14,7 @@ Notify::Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textF
|
|||||||
// Crea objetos
|
// Crea objetos
|
||||||
texture = new Texture(renderer, bitmapFile);
|
texture = new Texture(renderer, bitmapFile);
|
||||||
text = new Text(textFile, texture, renderer);
|
text = new Text(textFile, texture, renderer);
|
||||||
|
sound = JA_LoadSound(soundFile.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -22,6 +23,7 @@ Notify::~Notify()
|
|||||||
// Libera la memoria de los objetos
|
// Libera la memoria de los objetos
|
||||||
delete texture;
|
delete texture;
|
||||||
delete text;
|
delete text;
|
||||||
|
JA_DeleteSound(sound);
|
||||||
|
|
||||||
for (auto notification : notifications)
|
for (auto notification : notifications)
|
||||||
{
|
{
|
||||||
@@ -143,6 +145,9 @@ void Notify::showText(std::string text)
|
|||||||
|
|
||||||
// Añade la notificación a la lista
|
// Añade la notificación a la lista
|
||||||
notifications.push_back(n);
|
notifications.push_back(n);
|
||||||
|
|
||||||
|
// Reproduce el sonido de la notificación
|
||||||
|
JA_PlaySound(sound);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Indica si hay notificaciones activas
|
// Indica si hay notificaciones activas
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
#include "jail_audio.h"
|
||||||
|
#include "sprite.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
#include "sprite.h"
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -55,6 +56,7 @@ private:
|
|||||||
color_t bgColor; // Color de fondo de las notificaciones
|
color_t bgColor; // Color de fondo de las notificaciones
|
||||||
int waitTime; // Tiempo que se ve la notificación
|
int waitTime; // Tiempo que se ve la notificación
|
||||||
std::vector<notification_t> notifications; // La lista de notificaciones activas
|
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
|
// Elimina las notificaciones finalizadas
|
||||||
void clearFinishedNotifications();
|
void clearFinishedNotifications();
|
||||||
@@ -67,7 +69,7 @@ public:
|
|||||||
void update();
|
void update();
|
||||||
|
|
||||||
// Constructor
|
// 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
|
// Destructor
|
||||||
~Notify();
|
~Notify();
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
|
|||||||
this->asset = asset;
|
this->asset = asset;
|
||||||
|
|
||||||
// Crea los objetos
|
// 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;
|
gameCanvasWidth = options->gameWidth;
|
||||||
gameCanvasHeight = options->gameHeight;
|
gameCanvasHeight = options->gameHeight;
|
||||||
|
|||||||
@@ -294,28 +294,6 @@ SDL_Point checkCollision(d_line_t &l1, v_line_t &l2)
|
|||||||
return {-1, -1};
|
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
|
// Normaliza una linea diagonal
|
||||||
void normalizeLine(d_line_t &l)
|
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
|
// En caso contrario, el punto está en la linea
|
||||||
return true;
|
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
|
// Devuelve un color_t a partir de un string
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ struct op_stats_t
|
|||||||
// Estructura con todas las opciones de configuración del programa
|
// Estructura con todas las opciones de configuración del programa
|
||||||
struct options_t
|
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
|
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
|
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
|
Uint32 filter; // Filtro usado para el escalado de la imagen
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ Director::Director(int argc, char *argv[])
|
|||||||
section.subsection = SUBSECTION_LOGO_TO_INTRO;
|
section.subsection = SUBSECTION_LOGO_TO_INTRO;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
section.name = SECTION_PROG_GAME;
|
section.name = SECTION_PROG_LOGO;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Crea e inicializa las opciones del programa
|
// Crea e inicializa las opciones del programa
|
||||||
@@ -59,7 +59,7 @@ Director::Director(int argc, char *argv[])
|
|||||||
music = JA_LoadMusic(asset->get("title.ogg").c_str());
|
music = JA_LoadMusic(asset->get("title.ogg").c_str());
|
||||||
|
|
||||||
// Inicializa los servicios online
|
// Inicializa los servicios online
|
||||||
initOnline();
|
//initOnline();
|
||||||
}
|
}
|
||||||
|
|
||||||
Director::~Director()
|
Director::~Director()
|
||||||
@@ -112,7 +112,10 @@ void Director::initOptions()
|
|||||||
// Crea el puntero a la estructura de opciones
|
// Crea el puntero a la estructura de opciones
|
||||||
options = new options_t;
|
options = new options_t;
|
||||||
|
|
||||||
// Inicializa valores
|
// Version
|
||||||
|
options->configVersion = "v1.06.1";
|
||||||
|
|
||||||
|
// Opciones dee video
|
||||||
options->gameWidth = GAMECANVAS_WIDTH;
|
options->gameWidth = GAMECANVAS_WIDTH;
|
||||||
options->gameHeight = GAMECANVAS_HEIGHT;
|
options->gameHeight = GAMECANVAS_HEIGHT;
|
||||||
options->videoMode = 0;
|
options->videoMode = 0;
|
||||||
@@ -134,8 +137,8 @@ void Director::initOptions()
|
|||||||
options->stats.rooms = 0;
|
options->stats.rooms = 0;
|
||||||
options->stats.items = 0;
|
options->stats.items = 0;
|
||||||
|
|
||||||
// Online
|
// Opciones online
|
||||||
options->online.enabled = false;
|
options->online.enabled = true;
|
||||||
options->online.server = "jaildoctor.duckdns.org";
|
options->online.server = "jaildoctor.duckdns.org";
|
||||||
options->online.port = 9911;
|
options->online.port = 9911;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@@ -188,6 +191,10 @@ bool Director::loadConfig()
|
|||||||
// Indicador de éxito en la carga
|
// Indicador de éxito en la carga
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
|
// Versión actual del fichero
|
||||||
|
const std::string configVersion = options->configVersion;
|
||||||
|
options->configVersion = "";
|
||||||
|
|
||||||
// Variables para manejar el fichero
|
// Variables para manejar el fichero
|
||||||
std::string line;
|
std::string line;
|
||||||
std::ifstream file(asset->get("config.txt"));
|
std::ifstream file(asset->get("config.txt"));
|
||||||
@@ -234,6 +241,13 @@ bool Director::loadConfig()
|
|||||||
saveConfig();
|
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
|
// Normaliza los valores
|
||||||
const bool a = options->videoMode == 0;
|
const bool a = options->videoMode == 0;
|
||||||
const bool b = options->videoMode == SDL_WINDOW_FULLSCREEN;
|
const bool b = options->videoMode == SDL_WINDOW_FULLSCREEN;
|
||||||
@@ -289,7 +303,10 @@ bool Director::saveConfig()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Escribe en el fichero
|
// Escribe en el fichero
|
||||||
file << "## VISUAL OPTIONS\n";
|
file << "## VERSION\n";
|
||||||
|
file << "version=" + options->configVersion + "\n";
|
||||||
|
|
||||||
|
file << "\n## VISUAL OPTIONS\n";
|
||||||
if (options->videoMode == 0)
|
if (options->videoMode == 0)
|
||||||
{
|
{
|
||||||
file << "videoMode=0\n";
|
file << "videoMode=0\n";
|
||||||
@@ -954,7 +971,12 @@ bool Director::setOptions(options_t *options, std::string var, std::string value
|
|||||||
// Indicador de éxito en la asignación
|
// Indicador de éxito en la asignación
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
if (var == "videoMode")
|
if (var == "configVersion")
|
||||||
|
{
|
||||||
|
options->configVersion = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "videoMode")
|
||||||
{
|
{
|
||||||
if (value == "SDL_WINDOW_FULLSCREEN_DESKTOP")
|
if (value == "SDL_WINDOW_FULLSCREEN_DESKTOP")
|
||||||
{
|
{
|
||||||
@@ -1512,6 +1534,7 @@ bool Director::setFileList()
|
|||||||
asset->add(prefix + "/data/sound/jump22.wav", t_sound);
|
asset->add(prefix + "/data/sound/jump22.wav", t_sound);
|
||||||
asset->add(prefix + "/data/sound/jump23.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/jump24.wav", t_sound);
|
||||||
|
asset->add(prefix + "/data/sound/notify.wav", t_sound);
|
||||||
|
|
||||||
// Logo
|
// Logo
|
||||||
asset->add(prefix + "/data/logo/jailgames.png", t_bitmap);
|
asset->add(prefix + "/data/logo/jailgames.png", t_bitmap);
|
||||||
|
|||||||
@@ -40,9 +40,6 @@ EnterID::EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t
|
|||||||
|
|
||||||
// Escribe el texto en la textura
|
// Escribe el texto en la textura
|
||||||
fillTexture();
|
fillTexture();
|
||||||
|
|
||||||
// Deja el texto a tamaño fijo
|
|
||||||
// text->setFixedWidth(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -81,6 +78,17 @@ void EnterID::checkEventHandler()
|
|||||||
break;
|
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
|
// Comprueba las teclas que se han pulsado
|
||||||
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
||||||
{
|
{
|
||||||
@@ -116,13 +124,7 @@ void EnterID::checkEventHandler()
|
|||||||
name[--pos] = 0;
|
name[--pos] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_RETURN)
|
|
||||||
{
|
|
||||||
options->online.jailerID = (std::string)name;
|
|
||||||
initOnline();
|
|
||||||
section.name = SECTION_PROG_INTRO;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_ESCAPE)
|
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_ESCAPE)
|
||||||
{
|
{
|
||||||
section.name = SECTION_PROG_QUIT;
|
section.name = SECTION_PROG_QUIT;
|
||||||
@@ -287,3 +289,11 @@ void EnterID::initOnline()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
@@ -63,6 +63,9 @@ private:
|
|||||||
// Inicializa los servicios online
|
// Inicializa los servicios online
|
||||||
void initOnline();
|
void initOnline();
|
||||||
|
|
||||||
|
// Termina la sección
|
||||||
|
void endSection();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options);
|
EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options);
|
||||||
|
|||||||
@@ -125,8 +125,7 @@ void Logo::checkEventHandler()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
section.name = SECTION_PROG_TITLE;
|
endSection();
|
||||||
section.subsection = 0;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -269,22 +268,7 @@ void Logo::update()
|
|||||||
// Comprueba si ha terminado el logo
|
// Comprueba si ha terminado el logo
|
||||||
if (counter == endLogo + postLogo)
|
if (counter == endLogo + postLogo)
|
||||||
{
|
{
|
||||||
if (options->online.jailerID == "")
|
endSection();
|
||||||
{
|
|
||||||
section.name = SECTION_PROG_ENTER_ID;
|
|
||||||
section.subsection = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (section.subsection == SUBSECTION_LOGO_TO_INTRO)
|
|
||||||
{
|
|
||||||
section.name = SECTION_PROG_INTRO;
|
|
||||||
section.subsection = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
section.name = SECTION_PROG_TITLE;
|
|
||||||
section.subsection = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -327,12 +311,18 @@ section_t Logo::run()
|
|||||||
// Cambia la paleta
|
// Cambia la paleta
|
||||||
void Logo::switchPalette()
|
void Logo::switchPalette()
|
||||||
{
|
{
|
||||||
if (options->palette == p_zxspectrum)
|
options->palette = options->palette == p_zxspectrum ? p_zxarne : p_zxspectrum;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Termina la sección
|
||||||
|
void Logo::endSection()
|
||||||
|
{
|
||||||
|
if (options->online.enabled && options->online.jailerID == "")
|
||||||
{
|
{
|
||||||
options->palette = p_zxarne;
|
section.name = SECTION_PROG_ENTER_ID;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
options->palette = p_zxspectrum;
|
section.name = (section.subsection == SUBSECTION_LOGO_TO_INTRO) ? SECTION_PROG_INTRO : SECTION_PROG_TITLE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,6 +56,9 @@ private:
|
|||||||
// Cambia la paleta
|
// Cambia la paleta
|
||||||
void switchPalette();
|
void switchPalette();
|
||||||
|
|
||||||
|
// Termina la sección
|
||||||
|
void endSection();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Logo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, int subsection);
|
Logo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, int subsection);
|
||||||
|
|||||||
Reference in New Issue
Block a user