diff --git a/.gitignore b/.gitignore
index 55e763b..75dc5d6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,4 +10,4 @@ thumbs.db
*.tar.gz
*.zip
*.app
-*_debug
\ No newline at end of file
+*_debug*
\ No newline at end of file
diff --git a/jaildoctors_dilemma_debug.dSYM/Contents/Info.plist b/jaildoctors_dilemma_debug.dSYM/Contents/Info.plist
deleted file mode 100644
index a15c338..0000000
--- a/jaildoctors_dilemma_debug.dSYM/Contents/Info.plist
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
- CFBundleDevelopmentRegion
- English
- CFBundleIdentifier
- com.apple.xcode.dsym.jaildoctors_dilemma_debug
- CFBundleInfoDictionaryVersion
- 6.0
- CFBundlePackageType
- dSYM
- CFBundleSignature
- ????
- CFBundleShortVersionString
- 1.0
- CFBundleVersion
- 1
-
-
diff --git a/source/common/jscore.cpp b/source/common/jscore.cpp
new file mode 100644
index 0000000..bb9e7cd
--- /dev/null
+++ b/source/common/jscore.cpp
@@ -0,0 +1,154 @@
+#include "jscore.h"
+#include
+#include
+#include
+#include
+#ifdef _WIN32
+ #include
+#else
+ #include
+ #include
+ #include
+#endif
+#include
+#include
+#include
+
+namespace jscore {
+
+ using namespace std;
+ struct user {
+ string name;
+ int points;
+ };
+ vector score;
+
+ #define bzero(b,len) (memset((b), '\0', (len)), (void) 0)
+ int sock;
+ struct sockaddr_in client;
+
+ int PORT = 9911;
+ string HOST = "jaildoctor.duckdns.org";
+
+#ifdef WIN32
+ WSADATA WsaData;
+#endif
+
+ bool jscore_error = false;
+ string error_message;
+
+ void init(std::string host, const int port) {
+ PORT = port;
+ HOST = host;
+ }
+
+ void setErrorMessage(string message) {
+ jscore_error = true;
+ error_message = message;
+ }
+
+ string sendRequest(const string request) {
+#ifdef WIN32
+ int ret = WSAStartup(0x101,&WsaData);
+ if (ret != 0) return 0;
+#endif
+ struct hostent * host = gethostbyname(HOST.c_str());
+
+ if ( (host == NULL) || (host->h_addr == NULL) ) {
+ setErrorMessage("Error retrieving DNS information.\n");
+ return "";
+ }
+
+ bzero(&client, sizeof(client));
+ client.sin_family = AF_INET;
+ client.sin_port = htons( PORT );
+ memcpy(&client.sin_addr, host->h_addr, host->h_length);
+
+ sock = socket(AF_INET, SOCK_STREAM, 0);
+
+ if (sock < 0) {
+ setErrorMessage("Error creating socket.\n");
+ return "";
+ }
+
+ if ( connect(sock, (struct sockaddr *)&client, sizeof(client)) < 0 ) {
+ close(sock);
+ setErrorMessage("Could not connect\n");
+ return "";
+ }
+
+ string r = request + " HTTP/1.1\r\nHost: "+HOST+"\r\nConnection: close\r\n\r\n\r\n";
+ if (send(sock, r.c_str(), r.length(), 0) != (int)r.length()) {
+ setErrorMessage("Error sending request.\n");
+ return "";
+ }
+
+ char cur;
+ char start[5]="\r\n\r\n";
+ int pos = 0;
+ while ( recv(sock, &cur, 1,0) > 0 ) {
+ if (cur==start[pos]) { pos++; if (pos == 4) break; } else { pos = 0; }
+ }
+
+ char buffer[1024]; buffer[0]=0; pos=0;
+ while ( recv(sock, &cur, 1,0) > 0 ) {
+ buffer[pos] = cur;
+ pos++;
+ }
+#ifdef WIN32
+ WSACleanup();
+#endif
+ buffer[pos]=0;
+ return buffer;
+ }
+
+ const bool initOnlineScore(string game) {
+ string strbuff = sendRequest("GET /score-list.php?game=" + game);
+ if (jscore_error) return not jscore_error;
+
+ user u;
+ char buffer[1024];
+ strcpy(buffer, strbuff.c_str());
+ char *str = buffer;
+ char *p = str;
+ score.clear();
+ while (*p!=0) {
+ while (*p!=',') {p++;}
+ *p=0; u.name = str; p++; str=p;
+ while (*p!='\n') {p++;}
+ *p=0; u.points = atoi(str); p++; str=p;
+ score.push_back(u);
+ }
+ return not jscore_error;
+ }
+
+ const int getNumUsers() {
+ return score.size();
+ }
+ string getUserName(const int index) {
+ return score[index].name;
+ }
+ const int getPoints(const int index) {
+ return score[index].points;
+ }
+
+ const bool updateUserPoints(string game, string user, const int points) {
+ string strbuff = sendRequest("GET /score-update.php?game=" + game + "&user=" + user + "&points=" + to_string(points));
+ initOnlineScore(game);
+ return not jscore_error;
+ }
+
+ const int getUserPoints(string game, std::string user) {
+ return atoi(sendRequest("GET /getuserpoints.php?game=" + game + "&user=" + user).c_str());
+ }
+
+ string getUserData(string game, string user) {
+ return sendRequest("GET /getuserdata.php?game=" + game + "&user=" + user);
+ }
+
+ void setUserData(string game, string user, string data) {
+ sendRequest("GET /setuserdata.php?game=" + game + "&user=" + user + "&data=" + data);
+ }
+
+};
+
diff --git a/source/common/jscore.h b/source/common/jscore.h
new file mode 100644
index 0000000..8378a4a
--- /dev/null
+++ b/source/common/jscore.h
@@ -0,0 +1,16 @@
+#pragma once
+#include
+
+namespace jscore {
+ void init(std::string host, const int port);
+ const bool initOnlineScore(std::string game);
+ const int getNumUsers();
+ std::string getUserName(const int index);
+ const int getPoints(const int index);
+ const int getUserPoints(std::string game, std::string user);
+
+ const bool updateUserPoints(std::string game, std::string user, const int points);
+ std::string getUserData(std::string game, std::string user);
+ void setUserData(std::string game, std::string user, std::string data);
+};
+
diff --git a/source/common/notify.cpp b/source/common/notify.cpp
new file mode 100644
index 0000000..65b6d67
--- /dev/null
+++ b/source/common/notify.cpp
@@ -0,0 +1,156 @@
+#include "notify.h"
+#include
+#include
+
+// Constructor
+Notify::Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textFile)
+{
+ // Inicializa variables
+ this->renderer = renderer;
+ bgColor = {64, 64, 64};
+ waitTime = 300;
+
+ // Crea objetos
+ texture = new Texture(renderer, bitmapFile);
+ text = new Text(textFile, texture, renderer);
+}
+
+// Destructor
+Notify::~Notify()
+{
+ // Libera la memoria de los objetos
+ delete texture;
+ delete text;
+
+ for (auto notification : notifications)
+ {
+ delete notification.sprite;
+ delete notification.texture;
+ }
+}
+
+// Dibuja las notificaciones por pantalla
+void Notify::render()
+{
+ for (int i = (int)notifications.size() - 1; i >= 0; --i)
+ {
+ notifications.at(i).sprite->render();
+ }
+}
+
+// Actualiza el estado de las notificaiones
+void Notify::update()
+{
+ for (int i = 0; i < (int)notifications.size(); ++i)
+ {
+ notifications.at(i).counter++;
+
+ // Comprueba los estados
+ if (notifications.at(i).state == ns_rising)
+ {
+ const float step = ((float)notifications.at(i).counter / notifications.at(i).travelDist);
+ const int alpha = 255 * step;
+
+ notifications.at(i).rect.y++;
+ notifications.at(i).texture->setAlpha(alpha);
+
+ if (notifications.at(i).rect.y == notifications.at(i).y)
+ {
+ notifications.at(i).state = ns_stay;
+ notifications.at(i).texture->setAlpha(255);
+ notifications.at(i).counter = 0;
+ }
+ }
+
+ else if (notifications.at(i).state == ns_stay)
+ {
+ if (notifications.at(i).counter == waitTime)
+ {
+ notifications.at(i).state = ns_vanishing;
+ notifications.at(i).counter = 0;
+ }
+ }
+ else if (notifications.at(i).state == ns_vanishing)
+ {
+
+ const float step = (notifications.at(i).counter / (float)notifications.at(i).travelDist);
+ const int alpha = 255 * (1 - step);
+
+ notifications.at(i).rect.y--;
+ notifications.at(i).texture->setAlpha(alpha);
+
+ if (notifications.at(i).rect.y == notifications.at(i).y - notifications.at(i).travelDist)
+ {
+ notifications.at(i).state = ns_finished;
+ }
+ }
+
+ notifications.at(i).sprite->setRect(notifications.at(i).rect);
+ }
+
+ clearFinishedNotifications();
+}
+
+// Elimina las notificaciones finalizadas
+void Notify::clearFinishedNotifications()
+{
+ for (int i = (int)notifications.size() - 1; i >= 0; --i)
+ {
+ if (notifications.at(i).state == ns_finished)
+ {
+ delete notifications.at(i).sprite;
+ delete notifications.at(i).texture;
+ notifications.erase(notifications.begin() + i);
+ }
+ }
+}
+
+// Muestra una notificación de texto por pantalla;
+void Notify::showText(std::string text)
+{
+ // Crea constantes
+ const int width = this->text->lenght(text) + (this->text->getCharacterSize() * 2);
+ const int height = this->text->getCharacterSize() * 2;
+ const int despH = this->text->getCharacterSize() / 2;
+ const int despV = despH;
+ const int travelDist = height + despV;
+ // const int offset = (int)notifications.size() * (travelDist) + despV;
+ const int offset = (int)notifications.size() > 0 ? notifications.back().y + travelDist : despV;
+
+ // Crea la notificacion
+ notification_t n;
+
+ // inicializa variables
+ n.y = offset;
+ n.travelDist = travelDist;
+ n.counter = 0;
+ n.state = ns_rising;
+ n.text = text;
+ n.rect = {despH, offset - travelDist, width, height};
+
+ // Crea la textura
+ n.texture = new Texture(renderer);
+ n.texture->createBlank(renderer, width, height, SDL_TEXTUREACCESS_TARGET);
+ n.texture->setAsRenderTarget(renderer);
+ SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
+ SDL_RenderClear(renderer);
+ 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});
+
+ // Crea el sprite
+ n.sprite = new Sprite(n.rect, n.texture, renderer);
+
+ // Añade la notificación a la lista
+ notifications.push_back(n);
+}
+
+// Indica si hay notificaciones activas
+bool Notify::active()
+{
+ if ((int)notifications.size() > 0)
+ {
+ return true;
+ }
+
+ return false;
+}
\ No newline at end of file
diff --git a/source/common/notify.h b/source/common/notify.h
new file mode 100644
index 0000000..dbc6b67
--- /dev/null
+++ b/source/common/notify.h
@@ -0,0 +1,82 @@
+#pragma once
+
+#include
+#include "text.h"
+#include "texture.h"
+#include "sprite.h"
+#include "utils.h"
+#include
+
+#ifndef NOTIFY_H
+#define NOTIFY_H
+
+class Notify
+{
+private:
+ enum notification_state_e
+ {
+ ns_rising,
+ ns_stay,
+ ns_vanishing,
+ ns_finished
+ };
+
+ enum notification_position_e
+ {
+ upperLeft,
+ upperCenter,
+ upperRight,
+ middleLeft,
+ middleRight,
+ bottomLeft,
+ bottomCenter,
+ bottomRight
+ };
+
+ struct notification_t
+ {
+ std::string text;
+ int counter;
+ notification_state_e state;
+ notification_position_e position;
+ Texture *texture;
+ Sprite *sprite;
+ SDL_Rect rect;
+ int y;
+ int travelDist;
+ };
+
+ // Objetos y punteros
+ SDL_Renderer *renderer; // El renderizador de la ventana
+ Texture *texture; // Textura para la fuente de las notificaciones
+ Text *text; // Objeto para dibujar texto
+
+ // Variables
+ color_t bgColor; // Color de fondo de las notificaciones
+ int waitTime; // Tiempo que se ve la notificación
+ std::vector notifications; // La lista de notificaciones activas
+
+ // Elimina las notificaciones finalizadas
+ void clearFinishedNotifications();
+
+public:
+ // Dibuja las notificaciones por pantalla
+ void render();
+
+ // Actualiza el estado de las notificaiones
+ void update();
+
+ // Constructor
+ Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textFile);
+
+ // Destructor
+ ~Notify();
+
+ // Muestra una notificación de texto por pantalla;
+ void showText(std::string text);
+
+ // Indica si hay notificaciones activas
+ bool active();
+};
+
+#endif
diff --git a/source/common/screen.cpp b/source/common/screen.cpp
index 1d26692..0bd660a 100644
--- a/source/common/screen.cpp
+++ b/source/common/screen.cpp
@@ -3,15 +3,19 @@
#include
// Constructor
-Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options, int gameInternalResX, int gameInternalResY)
+Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options)
{
// Inicializa variables
this->window = window;
this->renderer = renderer;
this->options = options;
+ this->asset = asset;
- gameCanvasWidth = gameInternalResX;
- gameCanvasHeight = gameInternalResY;
+ // Crea los objetos
+ notify = new Notify(renderer, asset->get("smb2.png"), asset->get("smb2.txt"));
+
+ gameCanvasWidth = options->gameWidth;
+ gameCanvasHeight = options->gameHeight;
iniFade();
iniSpectrumFade();
@@ -27,15 +31,16 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options, i
}
// Establece el modo de video
- setVideoMode(options->fullScreenMode);
+ setVideoMode(options->videoMode);
- // Calcula los anclajes
- anchor.left = 0;
- anchor.right = gameCanvasWidth;
- anchor.center = gameCanvasWidth / 2;
- anchor.top = 0;
- anchor.bottom = gameCanvasHeight;
- anchor.middle = gameCanvasHeight / 2;
+ // Inicializa variables
+ notifyActive = false;
+}
+
+// Destructor
+Screen::~Screen()
+{
+ delete notify;
}
// Limpia la pantalla
@@ -64,42 +69,49 @@ void Screen::blit()
// Copia la textura de juego en el renderizador en la posición adecuada
SDL_RenderCopy(renderer, gameCanvas, nullptr, &dest);
+ // Dibuja las notificaciones
+ // renderNotifications();
+
// Muestra por pantalla el renderizador
SDL_RenderPresent(renderer);
}
// Establece el modo de video
-void Screen::setVideoMode(int fullScreenMode)
+void Screen::setVideoMode(int videoMode)
{
// Aplica el modo de video
- SDL_SetWindowFullscreen(window, fullScreenMode);
+ SDL_SetWindowFullscreen(window, videoMode);
// Si está activo el modo ventana quita el borde
- if (fullScreenMode == 0)
+ if (videoMode == 0)
{
if (options->borderEnabled)
{
- const int incWidth = gameCanvasWidth * options->borderSize;
- const int incHeight = gameCanvasHeight * options->borderSize;
- screenWidth = gameCanvasWidth + incWidth;
- screenHeight = gameCanvasHeight + incHeight;
- dest = {0 + (incWidth / 2), 0 + (incHeight / 2), gameCanvasWidth, gameCanvasHeight};
+ const int incWidth = options->gameWidth * options->borderSize;
+ const int incHeight = options->gameHeight * options->borderSize;
+ gameCanvasWidth = options->gameWidth + incWidth;
+ gameCanvasHeight = options->gameHeight + incHeight;
+ screenWidth = gameCanvasWidth * options->windowSize;
+ screenHeight = gameCanvasHeight * options->windowSize;
+ dest = {0 + (incWidth / 2), 0 + (incHeight / 2), options->gameWidth, options->gameHeight};
}
else
{
- screenWidth = gameCanvasWidth;
- screenHeight = gameCanvasHeight;
+ gameCanvasWidth = options->gameWidth;
+ gameCanvasHeight = options->gameHeight;
+ screenWidth = gameCanvasWidth * options->windowSize;
+ screenHeight = gameCanvasHeight * options->windowSize;
dest = {0, 0, gameCanvasWidth, gameCanvasHeight};
}
// Modifica el tamaño del renderizador y de la ventana
- SDL_RenderSetLogicalSize(renderer, screenWidth, screenHeight);
- SDL_SetWindowSize(window, screenWidth * options->windowSize, screenHeight * options->windowSize);
+ SDL_RenderSetLogicalSize(renderer, gameCanvasWidth, gameCanvasHeight);
+ SDL_SetWindowSize(window, screenWidth, screenHeight);
}
// Si está activo el modo de pantalla completa añade el borde
- else if (fullScreenMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
+ else if (videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
{
// Obten el alto y el ancho de la ventana
SDL_GetWindowSize(window, &screenWidth, &screenHeight);
@@ -149,22 +161,14 @@ void Screen::setVideoMode(int fullScreenMode)
}
// Actualiza el valor de la variable
- options->fullScreenMode = fullScreenMode;
+ options->videoMode = videoMode;
}
// Camibia entre pantalla completa y ventana
void Screen::switchVideoMode()
{
- if (options->fullScreenMode == 0)
- {
- options->fullScreenMode = SDL_WINDOW_FULLSCREEN_DESKTOP;
- }
- else
- {
- options->fullScreenMode = 0;
- }
-
- setVideoMode(options->fullScreenMode);
+ options->videoMode = (options->videoMode == 0) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
+ setVideoMode(options->videoMode);
}
// Cambia el tamaño de la ventana
@@ -338,4 +342,30 @@ void Screen::renderFX()
{
renderFade();
renderSpectrumFade();
+}
+
+// Actualiza el notificador
+void Screen::updateNotifier()
+{
+ notify->update();
+ notifyActive = notify->active();
+}
+
+// Muestra una notificación de texto por pantalla;
+void Screen::showText(std::string text)
+{
+ notify->showText(text);
+}
+
+// Dibuja las notificaciones
+void Screen::renderNotifications()
+{
+ if (!notifyActive)
+ {
+ return;
+ }
+
+ SDL_RenderSetLogicalSize(renderer, screenWidth, screenHeight);
+ notify->render();
+ SDL_RenderSetLogicalSize(renderer, gameCanvasWidth, gameCanvasHeight);
}
\ No newline at end of file
diff --git a/source/common/screen.h b/source/common/screen.h
index c40e64c..b3282a4 100644
--- a/source/common/screen.h
+++ b/source/common/screen.h
@@ -1,6 +1,8 @@
#pragma once
#include
+#include "asset.h"
+#include "notify.h"
#include "utils.h"
#include
@@ -10,42 +12,33 @@
#define FILTER_NEAREST 0
#define FILTER_LINEAL 1
-struct anchor_t
-{
- int left; // Parte izquierda de la pantalla de juego
- int right; // Parte drecha de la pantalla de juego
- int center; // Parte central horizontal de la pantalla de juego
- int top; // Parte superior de la pantalla de juego
- int bottom; // Parte infoerior de la pantalla de juego
- int middle; // Parte central vertical de la pantalla de juego
-};
-
-// Clase Screen
class Screen
{
private:
// Objetos y punteros
SDL_Window *window; // Ventana de la aplicación
SDL_Renderer *renderer; // El renderizador de la ventana
+ Asset *asset; // Objeto con el listado de recursos
SDL_Texture *gameCanvas; // Textura para completar la ventana de juego hasta la pantalla completa
options_t *options; // Variable con todas las opciones del programa
+ Notify *notify; // Dibuja notificaciones por pantalla
// Variables
int screenWidth; // Ancho de la pantalla o ventana
int screenHeight; // Alto de la pantalla o ventana
int gameCanvasWidth; // Resolución interna del juego. Es el ancho de la textura donde se dibuja el juego
int gameCanvasHeight; // Resolución interna del juego. Es el alto de la textura donde se dibuja el juego
- anchor_t anchor; // Variable con los anclajes de la pantalla
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
// Variables - Efectos
- bool fade; // Indica si esta activo el efecto de fade
- int fadeCounter; // Temporizador para el efecto de fade
- int fadeLenght; // Duración del fade
- bool spectrumFade; // Indica si esta activo el efecto de fade spectrum
- int spectrumFadeCounter; // Temporizador para el efecto de fade spectrum
- int spectrumFadeLenght; // Duración del fade spectrum
+ bool fade; // Indica si esta activo el efecto de fade
+ int fadeCounter; // Temporizador para el efecto de fade
+ int fadeLenght; // Duración del fade
+ bool spectrumFade; // Indica si esta activo el efecto de fade spectrum
+ int spectrumFadeCounter; // Temporizador para el efecto de fade spectrum
+ int spectrumFadeLenght; // Duración del fade spectrum
std::vector spectrumColor; // Colores para el fade spectrum
// Inicializa las variables para el fade
@@ -66,9 +59,15 @@ private:
// Dibuja el spectrum fade
void renderSpectrumFade();
+ // Dibuja las notificaciones
+ void renderNotifications();
+
public:
// Constructor
- Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options, int gameInternalResX, int gameInternalResY);
+ Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options);
+
+ // Destructor
+ ~Screen();
// Limpia la pantalla
void clean(color_t color = {0x00, 0x00, 0x00});
@@ -80,7 +79,7 @@ public:
void blit();
// Establece el modo de video
- void setVideoMode(int fullScreenMode);
+ void setVideoMode(int videoMode);
// Camibia entre pantalla completa y ventana
void switchVideoMode();
@@ -120,6 +119,12 @@ public:
// Dibuja los efectos
void renderFX();
+
+ // Actualiza el notificador
+ void updateNotifier();
+
+ // Muestra una notificación de texto por pantalla;
+ void showText(std::string text);
};
#endif
diff --git a/source/common/utils.h b/source/common/utils.h
index be3c927..f9d7aea 100644
--- a/source/common/utils.h
+++ b/source/common/utils.h
@@ -70,24 +70,36 @@ struct cheat_t
bool altSkin; // Indicxa si se usa una skin diferente para el jugador
};
+// Estructura para el servicio online
+struct online_t
+{
+ bool enabled; // Indica si se quiere usar el modo online o no
+ std::string server; // Servidor para los servicios online
+ int port; // Puerto del servidor
+ std::string gameID; // Identificador del juego para los servicios online
+ std::string jailerID; // Identificador del jugador para los servicios online
+ int score; // Puntuación almacenada online
+};
+
// Estructura con todas las opciones de configuración del programa
struct options_t
{
- Uint32 fullScreenMode; // 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
- bool vSync; // Indica si se quiere usar vsync o no
- int screenWidth; // Ancho de la pantalla o ventana
- int screenHeight; // Alto de la pantalla o ventana
- bool integerScale; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa
- bool keepAspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa
- bool borderEnabled; // Indica si ha de mostrar el borde en el modo de ventana
- float borderSize; // Porcentaje de borde que se añade a lo ventana
- palette_e palette; // Paleta de colores a usar en el juego
- bool console; // Indica si ha de mostrar información por la consola de texto
- cheat_t cheat; // Contiene trucos y ventajas para el juego
- int rooms; // Cantidad de habitaciones visitadas
- int items; // Cantidad de items obtenidos
+ 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
+ bool vSync; // Indica si se quiere usar vsync o no
+ int gameWidth; // Ancho de la resolucion nativa del juego
+ int gameHeight; // Alto de la resolucion nativa del juego
+ bool integerScale; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa
+ bool keepAspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa
+ bool borderEnabled; // Indica si ha de mostrar el borde en el modo de ventana
+ float borderSize; // Porcentaje de borde que se añade a lo ventana
+ palette_e palette; // Paleta de colores a usar en el juego
+ bool console; // Indica si ha de mostrar información por la consola de texto
+ cheat_t cheat; // Contiene trucos y ventajas para el juego
+ int rooms; // Cantidad de habitaciones visitadas
+ int items; // Cantidad de items obtenidos
+ online_t online; // Datos del servicio online
};
// Calcula el cuadrado de la distancia entre dos puntos
diff --git a/source/credits.cpp b/source/credits.cpp
index b8514a7..69a4d4f 100644
--- a/source/credits.cpp
+++ b/source/credits.cpp
@@ -168,7 +168,7 @@ void Credits::fillTexture()
{
// Inicializa los textos
iniTexts();
-
+
// Rellena la textura de texto
SDL_SetRenderTarget(renderer, textTexture);
color_t c = stringToColor(options->palette, "black");
@@ -264,6 +264,9 @@ void Credits::update()
// Actualiza el contador
updateCounter();
+ // Actualiza las notificaciones
+ screen->updateNotifier();
+
// Actualiza el sprite con el brillo
if (counter > 770)
{
diff --git a/source/demo.cpp b/source/demo.cpp
index 31dd7f6..a46aafd 100644
--- a/source/demo.cpp
+++ b/source/demo.cpp
@@ -153,6 +153,9 @@ void Demo::update()
scoreboard->update();
screen->updateFX();
checkRoomChange();
+
+ // Actualiza las notificaciones
+ screen->updateNotifier();
}
}
@@ -189,7 +192,7 @@ void Demo::renderRoomName()
// Recarga todas las texturas
void Demo::reLoadTextures()
{
- if (options->console)
+ if (options->console)
{
std::cout << "** RELOAD REQUESTED" << std::endl;
}
diff --git a/source/director.cpp b/source/director.cpp
index 5806d53..5be96bc 100644
--- a/source/director.cpp
+++ b/source/director.cpp
@@ -1,3 +1,4 @@
+#include "common/jscore.h"
#include "common/utils.h"
#include "director.h"
#include
@@ -52,11 +53,14 @@ Director::Director(int argc, char *argv[])
resource = new Resource(renderer, asset, options);
input = new Input(asset->get("gamecontrollerdb.txt"));
initInput();
- screen = new Screen(window, renderer, options, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
+ screen = new Screen(window, renderer, asset, options);
screen->setBorderColor(borderColor);
- screen->setVideoMode(options->fullScreenMode);
+ // screen->setVideoMode(options->videoMode);
debug = new Debug(renderer, screen, asset);
music = JA_LoadMusic(asset->get("title.ogg").c_str());
+
+ // Inicializa los servicios online
+ // initOnline();
}
Director::~Director()
@@ -78,6 +82,56 @@ Director::~Director()
SDL_Quit();
}
+// 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;
+ }
+ else
+ { // Jailer ID iniciado
+
+ // 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))
+ {
+ screen->showText(options->online.jailerID + " ha iniciado sesion");
+ std::cout << options->online.jailerID << " ha iniciado sesion" << 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;
+ }
+
+ // Obten las estadisticas online
+ const int points = jscore::getUserPoints(options->online.gameID, options->online.jailerID);
+ if (points == 0)
+ { // Fallo de conexión o no hay registros
+ screen->showText("No se ha podido obtener la puntuacion online");
+ std::cout << "No se ha podido obtener la puntuacion online" << std::endl;
+ }
+ else
+ {
+ options->online.score = points;
+ }
+ }
+}
+
// Crea e inicializa las opciones del programa
void Director::iniOptions()
{
@@ -85,7 +139,9 @@ void Director::iniOptions()
options = new options_t;
// Inicializa valores
- options->fullScreenMode = 0;
+ options->gameWidth = GAMECANVAS_WIDTH;
+ options->gameHeight = GAMECANVAS_HEIGHT;
+ options->videoMode = 0;
options->windowSize = 3;
options->filter = FILTER_NEAREST;
options->vSync = true;
@@ -103,6 +159,13 @@ void Director::iniOptions()
options->cheat.altSkin = false;
options->rooms = 0;
options->items = 0;
+
+ // Online
+ options->online.enabled = false;
+ options->online.server = "";
+ options->online.port = 0;
+ options->online.gameID = "jaildoctors_dilemma_test";
+ options->online.jailerID = "";
}
// Comprueba los parametros del programa
@@ -193,19 +256,33 @@ bool Director::loadConfig()
saveConfig();
}
+ // Normaliza los valores
+ const bool a = options->videoMode == 0;
+ const bool b = options->videoMode == SDL_WINDOW_FULLSCREEN;
+ const bool c = options->videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP;
+ if (!(a || b || c))
+ {
+ options->videoMode = 0;
+ }
+
+ if (options->windowSize < 1 || options->windowSize > 4)
+ {
+ options->windowSize = 3;
+ }
+
// Aplica opciones
- if (options->borderEnabled)
- {
- const int incWidth = GAMECANVAS_WIDTH * options->borderSize;
- const int incHeight = GAMECANVAS_HEIGHT * options->borderSize;
- options->screenWidth = (GAMECANVAS_WIDTH + incWidth) * options->windowSize;
- options->screenHeight = (GAMECANVAS_HEIGHT + incHeight) * options->windowSize;
- }
- else
- {
- options->screenWidth = GAMECANVAS_WIDTH * options->windowSize;
- options->screenHeight = GAMECANVAS_HEIGHT * options->windowSize;
- }
+ // if (options->borderEnabled)
+ //{
+ // const int incWidth = GAMECANVAS_WIDTH * options->borderSize;
+ // const int incHeight = GAMECANVAS_HEIGHT * options->borderSize;
+ // options->gameWidth = GAMECANVAS_WIDTH + incWidth;
+ // options->gameHeight = GAMECANVAS_HEIGHT + incHeight;
+ //}
+ // else
+ //{
+ // options->gameWidth = GAMECANVAS_WIDTH;
+ // options->gameHeight = GAMECANVAS_HEIGHT;
+ //}
return success;
}
@@ -234,19 +311,20 @@ bool Director::saveConfig()
}
// Escribe en el fichero
- if (options->fullScreenMode == 0)
+ file << "## VISUAL OPTIONS\n";
+ if (options->videoMode == 0)
{
- file << "fullScreenMode=0\n";
+ file << "videoMode=0\n";
}
- else if (options->fullScreenMode == SDL_WINDOW_FULLSCREEN)
+ else if (options->videoMode == SDL_WINDOW_FULLSCREEN)
{
- file << "fullScreenMode=SDL_WINDOW_FULLSCREEN\n";
+ file << "videoMode=SDL_WINDOW_FULLSCREEN\n";
}
- else if (options->fullScreenMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
+ else if (options->videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
{
- file << "fullScreenMode=SDL_WINDOW_FULLSCREEN_DESKTOP\n";
+ file << "videoMode=SDL_WINDOW_FULLSCREEN_DESKTOP\n";
}
file << "windowSize=" + std::to_string(options->windowSize) + "\n";
@@ -267,6 +345,12 @@ bool Director::saveConfig()
file << "borderSize=" + std::to_string(options->borderSize) + "\n";
file << "palette=" + std::to_string(options->palette) + "\n";
+ file << "\n## ONLINE OPTIONS\n";
+ file << "enabled=" + boolToString(options->online.enabled) + "\n";
+ file << "server=" + options->online.server + "\n";
+ file << "port=" + std::to_string(options->online.port) + "\n";
+ file << "jailerID=" + options->online.jailerID + "\n";
+
// Cierra el fichero
file.close();
@@ -277,15 +361,15 @@ bool Director::saveConfig()
void Director::createSystemFolder()
{
#ifdef _WIN32
- systemFolder = std::string(getenv("APPDATA")) + "/jailgames/jaildoctors_dilemma";
+ systemFolder = std::string(getenv("APPDATA")) + "/jaildoctors_dilemma";
#elif __APPLE__
struct passwd *pw = getpwuid(getuid());
const char *homedir = pw->pw_dir;
- systemFolder = std::string(homedir) + "/Library/Application Support/jailgames/jaildoctors_dilemma";
+ systemFolder = std::string(homedir) + "/Library/Application Support/jaildoctors_dilemma";
#elif __linux__
struct passwd *pw = getpwuid(getuid());
const char *homedir = pw->pw_dir;
- systemFolder = std::string(homedir) + "/.jailgames/jaildoctors_dilemma";
+ systemFolder = std::string(homedir) + "/.jaildoctors_dilemma";
#endif
struct stat st = {0};
@@ -883,19 +967,19 @@ bool Director::setOptions(options_t *options, std::string var, std::string value
// Indicador de éxito en la asignación
bool success = true;
- if (var == "fullScreenMode")
+ if (var == "videoMode")
{
if (value == "SDL_WINDOW_FULLSCREEN_DESKTOP")
{
- options->fullScreenMode = SDL_WINDOW_FULLSCREEN_DESKTOP;
+ options->videoMode = SDL_WINDOW_FULLSCREEN_DESKTOP;
}
else if (value == "SDL_WINDOW_FULLSCREEN")
{
- options->fullScreenMode = SDL_WINDOW_FULLSCREEN;
+ options->videoMode = SDL_WINDOW_FULLSCREEN;
}
else
{
- options->fullScreenMode = 0;
+ options->videoMode = 0;
}
}
@@ -964,7 +1048,31 @@ bool Director::setOptions(options_t *options, std::string var, std::string value
}
}
- else if (var == "")
+ else if (var == "enabled")
+ {
+ options->online.enabled = stringToBool(value);
+ }
+
+ else if (var == "server")
+ {
+ options->online.server = value;
+ }
+
+ else if (var == "port")
+ {
+ if (value == "")
+ {
+ value = "0";
+ }
+ options->online.port = std::stoi(value);
+ }
+
+ else if (var == "jailerID")
+ {
+ options->online.jailerID = value;
+ }
+
+ else if (var == "" || var.substr(0, 1) == "#")
{
}
@@ -1044,7 +1152,15 @@ bool Director::initSDL()
}
// Crea la ventana
- window = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, options->screenWidth, options->screenHeight, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
+ int incW = 0;
+ int incH = 0;
+ if (options->borderEnabled)
+ {
+ incW = options->gameWidth * options->borderSize;
+ incH = options->gameHeight * options->borderSize;
+ }
+
+ window = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, (options->gameWidth + incW) * options->windowSize, (options->gameHeight + incH) * options->windowSize, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
if (window == nullptr)
{
if (options->console)
@@ -1079,7 +1195,7 @@ bool Director::initSDL()
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
// Establece el tamaño del buffer de renderizado
- SDL_RenderSetLogicalSize(renderer, options->screenWidth, options->screenHeight);
+ SDL_RenderSetLogicalSize(renderer, options->gameWidth, options->gameHeight);
// Establece el modo de mezcla
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
diff --git a/source/director.h b/source/director.h
index d458282..75293e9 100644
--- a/source/director.h
+++ b/source/director.h
@@ -51,6 +51,9 @@ private:
section_t section; // Sección y subsección actual del programa;
std::string systemFolder; // Carpeta del sistema donde guardar datos
+ // Inicializa los servicios online
+ void initOnline();
+
// Crea e inicializa las opciones del programa
void iniOptions();
diff --git a/source/ending.cpp b/source/ending.cpp
index 6fe65b6..da0fc65 100644
--- a/source/ending.cpp
+++ b/source/ending.cpp
@@ -103,6 +103,9 @@ void Ending::update()
// Actualiza el volumen de la musica
updateMusicVolume();
+
+ // Actualiza las notificaciones
+ screen->updateNotifier();
}
}
diff --git a/source/ending2.cpp b/source/ending2.cpp
index 893697a..f0640cb 100644
--- a/source/ending2.cpp
+++ b/source/ending2.cpp
@@ -102,6 +102,9 @@ void Ending2::update()
// Actualiza el volumen de la musica
updateMusicVolume();
+
+ // Actualiza las notificaciones
+ screen->updateNotifier();
}
}
diff --git a/source/game.cpp b/source/game.cpp
index c5b4adc..b8434ba 100644
--- a/source/game.cpp
+++ b/source/game.cpp
@@ -233,6 +233,9 @@ void Game::update()
updateBlackScreen();
+ // Actualiza las notificaciones
+ screen->updateNotifier();
+
#ifdef DEBUG
updateDebugInfo();
#endif
diff --git a/source/game_over.cpp b/source/game_over.cpp
index ebd9afd..8d47bf8 100644
--- a/source/game_over.cpp
+++ b/source/game_over.cpp
@@ -73,6 +73,9 @@ void GameOver::update()
// Actualiza los dos sprites
playerSprite->update();
tvSprite->update();
+
+ // Actualiza las notificaciones
+ screen->updateNotifier();
}
}
@@ -97,7 +100,6 @@ void GameOver::render()
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y + 40, "ITEMS: " + itemsTxt, 1, color);
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y + 55, "ROOMS: " + roomsTxt, 1, color);
-
// Vuelca el contenido del renderizador en pantalla
screen->blit();
}
diff --git a/source/intro.cpp b/source/intro.cpp
index 34a462b..d3d6cbb 100644
--- a/source/intro.cpp
+++ b/source/intro.cpp
@@ -251,6 +251,9 @@ void Intro::update()
// Gestiona el contador de carga
updateLoad();
+ // Actualiza las notificaciones
+ screen->updateNotifier();
+
// Comprueba si ha terminado la intro
if (loadCounter >= 768)
{
@@ -281,7 +284,7 @@ void Intro::render()
section_t Intro::run()
{
// Inicia el sonido de carga
- JA_SetVolume(64);
+ JA_SetVolume(64);
JA_PlayMusic(loadingSound1);
while (section.name == SECTION_PROG_INTRO)
@@ -290,7 +293,7 @@ section_t Intro::run()
render();
}
- JA_SetVolume(128);
+ JA_SetVolume(128);
return section;
}
diff --git a/source/logo.cpp b/source/logo.cpp
index e603153..28db2b9 100644
--- a/source/logo.cpp
+++ b/source/logo.cpp
@@ -85,7 +85,7 @@ void Logo::checkEventHandler()
switch (eventHandler->key.keysym.scancode)
{
case SDL_SCANCODE_ESCAPE:
- //std::cout << "PULSADO ESCAPE" << std::endl;
+ // std::cout << "PULSADO ESCAPE" << std::endl;
section.name = SECTION_PROG_QUIT;
break;
@@ -262,6 +262,9 @@ void Logo::update()
// Gestiona el color de las texturas
updateTextureColors();
+ // Actualiza las notificaciones
+ screen->updateNotifier();
+
// Comprueba si ha terminado el logo
if (counter == endLogo + postLogo)
{
diff --git a/source/title.cpp b/source/title.cpp
index c74368a..45ce59c 100644
--- a/source/title.cpp
+++ b/source/title.cpp
@@ -176,6 +176,9 @@ void Title::update()
// Actualiza la marquesina
updateMarquee();
+ // Actualiza las notificaciones
+ screen->updateNotifier();
+
// Comprueba si ha terminado la marquesina y acaba con el titulo
if (letters.at(letters.size() - 1).x < -10)
{