forked from jaildesigner-jailgames/jaildoctors_dilemma
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ba19dcb904 | |||
| b035b92ff4 | |||
| 8c425f5698 | |||
| d382bb6403 | |||
| da64a5e082 | |||
| 7070dac482 | |||
| ea5360ea74 | |||
| 3aa4440390 | |||
| ce105e252e | |||
| 1aac5b7719 | |||
| a8b467290f | |||
| 706ad6f9c0 | |||
| 54d428ed96 | |||
| c71adfbac4 |
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
|
||||||
|
|||||||
@@ -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.
|
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:
|
En **Linux** se encuentra en:
|
||||||
`~/.jaildoctors_dilemma`
|
`~/.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.
|
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
|
## Agradecimientos
|
||||||
|
|||||||
@@ -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,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,
|
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,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
|
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>
|
</data>
|
||||||
</layer>
|
</layer>
|
||||||
|
|||||||
BIN
data/sound/notify.wav
Normal file
BIN
data/sound/notify.wav
Normal file
Binary file not shown.
13
source/cheevos.cpp
Normal file
13
source/cheevos.cpp
Normal 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
27
source/cheevos.h
Normal 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
|
||||||
@@ -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,12 +12,14 @@ 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;
|
||||||
borderWidth = options->gameWidth * options->borderSize;
|
borderWidth = options->gameWidth * options->borderSize;
|
||||||
borderHeight = options->gameHeight * options->borderSize;
|
borderHeight = options->gameHeight * options->borderSize;
|
||||||
|
notificationLogicalWidth = gameCanvasWidth;
|
||||||
|
notificationLogicalHeight = gameCanvasHeight;
|
||||||
|
|
||||||
iniFade();
|
iniFade();
|
||||||
iniSpectrumFade();
|
iniSpectrumFade();
|
||||||
@@ -29,7 +31,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
|
||||||
@@ -81,6 +86,9 @@ void Screen::blit()
|
|||||||
// Establece el modo de video
|
// Establece el modo de video
|
||||||
void Screen::setVideoMode(int videoMode)
|
void Screen::setVideoMode(int videoMode)
|
||||||
{
|
{
|
||||||
|
// Muestra el puntero
|
||||||
|
SDL_ShowCursor(SDL_ENABLE);
|
||||||
|
|
||||||
// Aplica el modo de video
|
// Aplica el modo de video
|
||||||
SDL_SetWindowFullscreen(window, videoMode);
|
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
|
// Si está activo el modo de pantalla completa añade el borde
|
||||||
else if (videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
|
else if (videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
|
||||||
{
|
{
|
||||||
|
// Oculta el puntero
|
||||||
|
SDL_ShowCursor(SDL_DISABLE);
|
||||||
|
|
||||||
// Obten el alto y el ancho de la ventana
|
// Obten el alto y el ancho de la ventana
|
||||||
SDL_GetWindowSize(window, &windowWidth, &windowHeight);
|
SDL_GetWindowSize(window, &windowWidth, &windowHeight);
|
||||||
|
|
||||||
@@ -158,6 +169,9 @@ void Screen::setVideoMode(int videoMode)
|
|||||||
|
|
||||||
// Actualiza el valor de la variable
|
// Actualiza el valor de la variable
|
||||||
options->videoMode = videoMode;
|
options->videoMode = videoMode;
|
||||||
|
|
||||||
|
// Establece el tamaño de las notificaciones
|
||||||
|
setNotificationSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Camibia entre pantalla completa y ventana
|
// Camibia entre pantalla completa y ventana
|
||||||
@@ -348,7 +362,7 @@ void Screen::updateNotifier()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Muestra una notificación de texto por pantalla;
|
// Muestra una notificación de texto por pantalla;
|
||||||
void Screen::showText(std::string text)
|
void Screen::showNotification(std::string text)
|
||||||
{
|
{
|
||||||
notify->showText(text);
|
notify->showText(text);
|
||||||
}
|
}
|
||||||
@@ -361,7 +375,31 @@ void Screen::renderNotifications()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_RenderSetLogicalSize(renderer, windowWidth * 2, windowHeight * 2);
|
SDL_RenderSetLogicalSize(renderer, notificationLogicalWidth, notificationLogicalHeight);
|
||||||
notify->render();
|
notify->render();
|
||||||
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -24,15 +24,17 @@ private:
|
|||||||
Notify *notify; // Dibuja notificaciones por pantalla
|
Notify *notify; // Dibuja notificaciones por pantalla
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int windowWidth; // Ancho de la pantalla o ventana
|
int windowWidth; // Ancho de la pantalla o ventana
|
||||||
int windowHeight; // Alto de la pantalla o ventana
|
int windowHeight; // 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 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
|
int gameCanvasHeight; // Resolución interna del juego. Es el alto de la textura donde se dibuja el juego
|
||||||
int borderWidth; // Anchura del borde
|
int borderWidth; // Anchura del borde
|
||||||
int borderHeight; // Anltura del borde
|
int borderHeight; // Anltura del borde
|
||||||
SDL_Rect dest; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
|
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
|
color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
||||||
bool notifyActive; // Indica si hay notificaciones activas
|
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
|
// Variables - Efectos
|
||||||
bool fade; // Indica si esta activo el efecto de fade
|
bool fade; // Indica si esta activo el efecto de fade
|
||||||
@@ -64,6 +66,9 @@ private:
|
|||||||
// Dibuja las notificaciones
|
// Dibuja las notificaciones
|
||||||
void renderNotifications();
|
void renderNotifications();
|
||||||
|
|
||||||
|
// Establece el tamaño de las notificaciones
|
||||||
|
void setNotificationSize();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options);
|
Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options);
|
||||||
@@ -126,7 +131,7 @@ public:
|
|||||||
void updateNotifier();
|
void updateNotifier();
|
||||||
|
|
||||||
// Muestra una notificación de texto por pantalla;
|
// Muestra una notificación de texto por pantalla;
|
||||||
void showText(std::string text);
|
void showNotification(std::string text);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -94,6 +94,9 @@ Text::Text(std::string textFile, Texture *texture, SDL_Renderer *renderer)
|
|||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture, renderer);
|
sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture, renderer);
|
||||||
|
|
||||||
|
// Inicializa variables
|
||||||
|
fixedWidth = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
@@ -111,6 +114,9 @@ Text::Text(textFile_t *textFile, Texture *texture, SDL_Renderer *renderer)
|
|||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture, renderer);
|
sprite = new Sprite({0, 0, boxWidth, boxHeight}, texture, renderer);
|
||||||
|
|
||||||
|
// Inicializa variables
|
||||||
|
fixedWidth = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -133,7 +139,8 @@ void Text::write(int x, int y, std::string text, int kerning, int lenght)
|
|||||||
sprite->setPosX(x + shift);
|
sprite->setPosX(x + shift);
|
||||||
sprite->setPosY(y);
|
sprite->setPosY(y);
|
||||||
sprite->render();
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,4 +232,10 @@ int Text::getCharacterSize()
|
|||||||
void Text::reLoadTexture()
|
void Text::reLoadTexture()
|
||||||
{
|
{
|
||||||
sprite->getTexture()->reLoad();
|
sprite->getTexture()->reLoad();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece si se usa un tamaño fijo de letra
|
||||||
|
void Text::setFixedWidth(bool value)
|
||||||
|
{
|
||||||
|
fixedWidth = value;
|
||||||
}
|
}
|
||||||
@@ -33,11 +33,12 @@ class Text
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
Sprite *sprite; // Objeto con los graficos para el texto
|
Sprite *sprite; // Objeto con los graficos para el texto
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int boxWidth; // Anchura de la caja de cada caracter en el png
|
int boxWidth; // Anchura de la caja de cada caracter en el png
|
||||||
int boxHeight; // Altura 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
|
offset_t offset[128]; // Vector con las posiciones y ancho de cada letra
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -71,6 +72,9 @@ public:
|
|||||||
|
|
||||||
// Recarga la textura
|
// Recarga la textura
|
||||||
void reLoadTexture();
|
void reLoadTexture();
|
||||||
|
|
||||||
|
// Establece si se usa un tamaño fijo de letra
|
||||||
|
void setFixedWidth(bool value);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -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,21 +92,22 @@ 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
|
||||||
{
|
{
|
||||||
Uint32 videoMode; // Contiene el valor del modo de pantalla completa
|
std::string configVersion; // Versión del programa. Sirve para saber si las opciones son compatibles
|
||||||
int windowSize; // Contiene el valor por el que se multiplica el tamaño de la ventana
|
Uint32 videoMode; // Contiene el valor del modo de pantalla completa
|
||||||
Uint32 filter; // Filtro usado para el escalado de la imagen
|
int windowSize; // Contiene el valor por el que se multiplica el tamaño de la ventana
|
||||||
bool vSync; // Indica si se quiere usar vsync o no
|
Uint32 filter; // Filtro usado para el escalado de la imagen
|
||||||
int gameWidth; // Ancho de la resolucion nativa del juego
|
bool vSync; // Indica si se quiere usar vsync o no
|
||||||
int gameHeight; // Alto de la resolucion nativa del juego
|
int gameWidth; // Ancho 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
|
int gameHeight; // Alto de la resolucion nativa del juego
|
||||||
bool keepAspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa
|
bool integerScale; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa
|
||||||
bool borderEnabled; // Indica si ha de mostrar el borde en el modo de ventana
|
bool keepAspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa
|
||||||
float borderSize; // Porcentaje de borde que se añade a lo ventana
|
bool borderEnabled; // Indica si ha de mostrar el borde en el modo de ventana
|
||||||
palette_e palette; // Paleta de colores a usar en el juego
|
float borderSize; // Porcentaje de borde que se añade a lo ventana
|
||||||
bool console; // Indica si ha de mostrar información por la consola de texto
|
palette_e palette; // Paleta de colores a usar en el juego
|
||||||
cheat_t cheat; // Contiene trucos y ventajas para el juego
|
bool console; // Indica si ha de mostrar información por la consola de texto
|
||||||
op_stats_t stats; // Datos con las estadisticas de juego
|
cheat_t cheat; // Contiene trucos y ventajas para el juego
|
||||||
online_t online; // Datos del servicio online
|
op_stats_t stats; // Datos con las estadisticas de juego
|
||||||
|
online_t online; // Datos del servicio online
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calcula el cuadrado de la distancia entre dos puntos
|
// Calcula el cuadrado de la distancia entre dos puntos
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -318,14 +318,6 @@ section_t Credits::run()
|
|||||||
// Cambia la paleta
|
// Cambia la paleta
|
||||||
void Credits::switchPalette()
|
void Credits::switchPalette()
|
||||||
{
|
{
|
||||||
if (options->palette == p_zxspectrum)
|
options->palette = options->palette == p_zxspectrum ? p_zxarne : p_zxspectrum;
|
||||||
{
|
fillTexture();
|
||||||
options->palette = p_zxarne;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
options->palette = p_zxspectrum;
|
|
||||||
}
|
|
||||||
|
|
||||||
fillTexture();
|
|
||||||
}
|
}
|
||||||
@@ -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()
|
||||||
@@ -84,37 +84,24 @@ Director::~Director()
|
|||||||
// Inicializa los servicios online
|
// Inicializa los servicios online
|
||||||
void Director::initOnline()
|
void Director::initOnline()
|
||||||
{
|
{
|
||||||
if (!options->online.enabled)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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");
|
|
||||||
std::cout << "No ha especificado ningun Jailer ID" << std::endl;
|
options->online.enabled = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // Jailer ID iniciado
|
{ // Jailer ID iniciado
|
||||||
|
|
||||||
// Establece el servidor y el puerto
|
if (options->online.enabled)
|
||||||
jscore::init(options->online.server, options->online.port);
|
{ // Establece el servidor y el puerto
|
||||||
|
jscore::init(options->online.server, options->online.port);
|
||||||
|
|
||||||
// Obtiene la información online
|
const std::string caption = options->online.jailerID + " IS LOGGED IN";
|
||||||
if (jscore::initOnlineScore(options->online.gameID))
|
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
|
// 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;
|
||||||
@@ -147,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
|
||||||
@@ -201,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"));
|
||||||
@@ -247,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;
|
||||||
@@ -302,7 +303,10 @@ bool Director::saveConfig()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Escribe en el fichero
|
// 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)
|
if (options->videoMode == 0)
|
||||||
{
|
{
|
||||||
file << "videoMode=0\n";
|
file << "videoMode=0\n";
|
||||||
@@ -358,9 +362,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 +390,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);
|
||||||
@@ -967,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")
|
||||||
{
|
{
|
||||||
@@ -1525,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);
|
||||||
@@ -1647,6 +1657,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, section);
|
||||||
|
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 +1755,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;
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -46,14 +48,14 @@ private:
|
|||||||
struct options_t *options; // Variable con todas las opciones del programa
|
struct options_t *options; // Variable con todas las opciones del programa
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
|
section_t section; // Sección y subsección actual del programa;
|
||||||
JA_Music music; // Musica del titulo
|
JA_Music music; // Musica del titulo
|
||||||
std::string executablePath; // Path del ejecutable
|
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
|
std::string systemFolder; // Carpeta del sistema donde guardar datos
|
||||||
|
|
||||||
// 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();
|
||||||
|
|
||||||
|
|||||||
310
source/enter_id.cpp
Normal file
310
source/enter_id.cpp
Normal 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
80
source/enter_id.h
Normal 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
|
||||||
@@ -137,7 +137,7 @@ void Game::checkEventHandler()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_SCANCODE_F6:
|
case SDL_SCANCODE_F6:
|
||||||
screen->showText("MAMA MIRA! SIN MANOS!");
|
screen->showNotification("MAMA MIRA! SIN MANOS!");
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -82,12 +82,11 @@ void Logo::checkEventHandler()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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_KEYUP && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONUP))
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
|
||||||
@@ -126,8 +125,8 @@ void Logo::checkEventHandler()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
section.name = SECTION_PROG_TITLE;
|
section.subsection = SUBSECTION_LOGO_TO_TITLE;
|
||||||
section.subsection = 0;
|
endSection();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -270,16 +269,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 (section.subsection == SUBSECTION_LOGO_TO_INTRO)
|
endSection();
|
||||||
{
|
|
||||||
section.name = SECTION_PROG_INTRO;
|
|
||||||
section.subsection = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
section.name = SECTION_PROG_TITLE;
|
|
||||||
section.subsection = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -322,12 +312,11 @@ 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;
|
||||||
{
|
}
|
||||||
options->palette = p_zxarne;
|
|
||||||
}
|
// Termina la sección
|
||||||
else
|
void Logo::endSection()
|
||||||
{
|
{
|
||||||
options->palette = p_zxspectrum;
|
section.name = SECTION_PROG_ENTER_ID;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -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);
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ void Title::checkEventHandler()
|
|||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
case SDL_SCANCODE_F6:
|
case SDL_SCANCODE_F6:
|
||||||
screen->showText("MAMA MIRA! SIN MANOS!");
|
screen->showNotification("MAMA MIRA! SIN MANOS!");
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user