24 Commits

Author SHA1 Message Date
adab0b420c - Modificada la carpeta de guardar datos al estandar de jailgames 2023-02-12 18:05:53 +01:00
4f9d8bec42 - Cambiados los textos de los creditos/instrucciones para reflejar las nuevas teclas
- Cambiados los textos de los creditos/instrucciones para la versión de consola
2023-02-12 17:44:00 +01:00
31e657d138 - Cambiadas las teclas de cambiar el tamaño de ventana para adecuarse al estandar de jailgames 2023-02-12 17:28:48 +01:00
8b3d257baf - La ventana ya no se destruye al cambiar de tamaño de ventana
- La ventana aparece centrada al cambiar de tamaño
2023-02-12 17:05:16 +01:00
d1143b9dfe - Trabajando en la creación y destrucción de la ventana
- FIX: la clase screen no liberaba la textura gameCanvas al finalizar
2023-02-10 22:55:36 +01:00
68ebff722e - FIX: cambiado el boton de guía por el de select (o back)
- Añadido flag para intercambiar los botones de start y select en consola
- Añadido botón para activar o desactivar el borde con el mando (botón X)
2023-02-10 20:31:37 +01:00
3be9d4459c - Ya se puede usar el mando en todas las secciones del juego
- Definido flag para compilar para consola de juegos (GAME_CONSOLE)
2023-02-10 20:08:06 +01:00
76e928e21d Commit para seguir programando en WSL 2023-02-10 19:07:19 +01:00
9c6924d7bb - La clase input ya admite inputs personalizados
- El juego ya utiliza el objeto input para comprobar las teclas de cambio de tamaño de ventana, pausa, etc.
2023-02-10 18:28:53 +01:00
5007bea835 Se había quedado una linea comentada 2023-01-09 09:21:22 +01:00
5e7be1c2fb Ya se guardan los logros en un fichero 2023-01-02 09:46:09 +01:00
faf2e69b63 Creando iconos para las notificaciones 2022-12-30 13:18:43 +01:00
4c3c844ccf Fix: En la secuencia del final, al pulsar ESC se cerraba el juego. Ahora vuelve al logo 2022-12-29 15:26:02 +01:00
48b8ae049a Testeados todos los logros. Los logros no funcionan con los trucos activados 2022-12-29 14:59:48 +01:00
c0d4eddde7 Colocados los disparadores de los logros en su sitio 2022-12-29 14:08:42 +01:00
f590101047 Definidos los logros 2022-12-29 13:03:10 +01:00
c7fcbd0258 Añadidos nuevos iconos para las notificaciones. Rediseñada la notificación de login. Arreglado bug: No se podia elegir un icono para las notificaciones que no fuera de la primera fila 2022-12-29 11:58:32 +01:00
b2061c86d2 Cambiado el tamaño de las notificaciones. Posibilidad de añadir un icono 2022-12-29 11:36:44 +01:00
510a6ca718 Añadido bisel a las notificaciones 2022-12-29 11:00:26 +01:00
ec8209265a Añadidos iconos a las notificaciones 2022-12-29 10:19:11 +01:00
e963251fd9 Modificadas las notificaciones a dos lineas de texto 2022-12-29 09:42:57 +01:00
a2f1efd2a6 Empezando a trabajar con los logros 2022-12-29 09:09:36 +01:00
8959b7bcce Arreglado el cambio de paleta durante la pantalla de carga optimizada 2022-12-16 11:15:13 +01:00
4d8bb46a52 Cambiada la variable section por un puntero 2022-12-16 09:32:33 +01:00
38 changed files with 1305 additions and 777 deletions

View File

@@ -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.07 version = v1.08
# Release names # Release names
windowsRelease = $(executable)-$(version)-win32-x64.zip windowsRelease = $(executable)-$(version)-win32-x64.zip

View File

@@ -1,4 +1,4 @@
# JailDoctor's Dilemma (v1.07) # JailDoctor's Dilemma (v1.08)
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.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -23,11 +23,11 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>APPL</string> <string>APPL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.0.7</string> <string>1.0.8</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1.0.7</string> <string>1.0.8</string>
<key>CSResourcesFileMapped</key> <key>CSResourcesFileMapped</key>
<true/> <true/>
<key>LSMinimumSystemVersion</key> <key>LSMinimumSystemVersion</key>

View File

@@ -1,13 +1,242 @@
#include "cheevos.h" #include "cheevos.h"
#include <iostream>
// Constructor // Constructor
Cheevos::Cheevos(options_t *options) Cheevos::Cheevos(Screen *screen, options_t *options, std::string file)
{ {
// Copia la dirección de los objetos
this->options = options; this->options = options;
this->screen = screen;
this->file = file;
// Inicializa los logros
init();
// Inicializa variables
enabled = true;
// Carga el estado de los logros desde un fichero
loadFromFile();
} }
// Destructor // Destructor
Cheevos::~Cheevos() Cheevos::~Cheevos()
{ {
// Guarda el estado de los logros en un fichero
saveToFile();
cheevos.clear();
}
// Inicializa los logros
void Cheevos::init()
{
cheevos_t c;
c.completed = false;
c.valid = true;
c.icon = 2;
c.id = 1;
c.caption = "SHINY THINGS";
c.description = "Get 25\% of the items";
cheevos.push_back(c);
c.id = 2;
c.caption = "HALF THE WORK";
c.description = "Get 50\% of the items";
cheevos.push_back(c);
c.id = 3;
c.caption = "GETTING THERE";
c.description = "Get 75\% of the items";
cheevos.push_back(c);
c.id = 4;
c.caption = "THE COLLECTOR";
c.description = "Get 100\% of the items";
cheevos.push_back(c);
c.id = 5;
c.caption = "WANDERING AROUND";
c.description = "Visit 20 rooms";
cheevos.push_back(c);
c.id = 6;
c.caption = "I GOT LOST";
c.description = "Visit 40 rooms";
cheevos.push_back(c);
c.id = 7;
c.caption = "I LIKE TO EXPLORE";
c.description = "Visit all rooms";
cheevos.push_back(c);
c.id = 8;
c.caption = "FINISH THE GAME";
c.description = "Complete the game";
cheevos.push_back(c);
c.id = 9;
c.caption = "I WAS SUCKED BY A HOLE";
c.description = "Complete the game without entering the jail";
cheevos.push_back(c);
c.id = 10;
c.caption = "MY LITTLE PROJECTS";
c.description = "Complete the game with all items";
cheevos.push_back(c);
c.id = 11;
c.caption = "I LIKE MY MULTICOLOURED FRIENDS";
c.description = "Complete the game without dying";
cheevos.push_back(c);
c.id = 12;
c.caption = "SHIT PROJECTS DONE FAST";
c.description = "Complete the game in under 30 minutes";
cheevos.push_back(c);
}
// Busca un logro por id y devuelve el indice
int Cheevos::find(int id)
{
for (int i = 0; i < (int)cheevos.size(); ++i)
{
if (cheevos[i].id == id)
{
return i;
}
}
return -1;
}
// Desbloquea un logro
void Cheevos::unlock(int id)
{
const int index = find(id);
if (index == -1)
{
return;
}
if (!cheevos[index].valid)
{
return;
}
if (cheevos[index].completed)
{
return;
}
if (!enabled)
{
return;
}
cheevos[index].completed = true;
screen->showNotification("ACHIEVEMENT UNLOCKED!", cheevos[index].caption, cheevos[index].icon);
}
// Invalida un logro
void Cheevos::invalidate(int id)
{
const int index = find(id);
if (index == -1)
{
return;
}
cheevos[index].valid = false;
}
// Habilita o deshabilita los logros
void Cheevos::enable(bool value)
{
enabled = value;
}
// Carga el estado de los logros desde un fichero
void Cheevos::loadFromFile()
{
// Open file for reading in binary
SDL_RWops *file = SDL_RWFromFile(this->file.c_str(), "r+b");
// El fichero no existe
if (file == NULL)
{
if (options->console)
{
std::cout << "Warning: Unable to open file! SDL Error: " << SDL_GetError() << std::endl;
}
// Crea el fichero en modo escritura
file = SDL_RWFromFile(this->file.c_str(), "w+b");
if (file != NULL)
{
if (options->console)
{
std::cout << "New file created!" << std::endl;
}
// Guarda la información
for (int i = 0; i < (int)cheevos.size(); ++i)
{
SDL_RWwrite(file, &cheevos[i].completed, sizeof(bool), 1);
}
// Cierra el fichero
SDL_RWclose(file);
}
else
{
if (options->console)
{
std::cout << "Error: Unable to create file! SDL Error: " << SDL_GetError() << std::endl;
}
}
}
// El fichero existe
else
{
// Carga los datos
if (options->console)
{
std::cout << "Reading file...!" << std::endl;
}
for (int i = 0; i < (int)cheevos.size(); ++i)
{
SDL_RWread(file, &cheevos[i].completed, sizeof(bool), 1);
}
// Cierra el fichero
SDL_RWclose(file);
}
}
// Guarda el estado de los logros en un fichero
void Cheevos::saveToFile()
{
// Abre el fichero en modo escritura
SDL_RWops *file = SDL_RWFromFile(this->file.c_str(), "w+b");
if (file != NULL)
{
// Guarda la información
for (int i = 0; i < (int)cheevos.size(); ++i)
{
SDL_RWwrite(file, &cheevos[i].completed, sizeof(bool), 1);
}
// Cierra el fichero
SDL_RWclose(file);
}
else
{
if (options->console)
{
std::cout << "Error: Unable to save file! " << SDL_GetError() << std::endl;
}
}
} }

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include "common/screen.h"
#include "common/utils.h" #include "common/utils.h"
#include <string> #include <string>
#include <vector> #include <vector>
@@ -7,21 +8,55 @@
#ifndef CHEEVOS_H #ifndef CHEEVOS_H
#define CHEEVOS_H #define CHEEVOS_H
struct cheevos_t
{
int id; // Identificador del logro
std::string caption; // Texto con el nombre del logro
std::string description; // Texto que describe el logro
int icon; // Indice del icono a utilizar en la notificación
bool completed; // Indica si se ha obtenido el logro
bool valid; // Indica si se puede obtener el logro
};
class Cheevos class Cheevos
{ {
private: private:
// Punteros y objetos // Punteros y objetos
options_t *options; Screen *screen; // Objeto encargado de dibujar en pantalla
options_t *options; // Puntero a las opciones del juego
// Variables // Variables
std::vector<cheevos_t> cheevos; // Listado de logros
bool enabled; // Indica si los logros se pueden obtener
std::string file; // Fichero done leer/almacenar el estado de los logros
// Inicializa los logros
void init();
// Busca un logro por id y devuelve el indice
int find(int id);
// Carga el estado de los logros desde un fichero
void loadFromFile();
// Guarda el estado de los logros en un fichero
void saveToFile();
public: public:
// Constructor // Constructor
Cheevos(options_t *options); Cheevos(Screen *screen, options_t *options, std::string file);
// Destructor // Destructor
~Cheevos(); ~Cheevos();
// Desbloquea un logro
void unlock(int id);
// Invalida un logro
void invalidate(int id);
// Habilita o deshabilita los logros
void enable(bool value);
}; };
#endif #endif

View File

@@ -11,12 +11,12 @@ Input::Input(std::string file)
keyBindings_t kb; keyBindings_t kb;
kb.scancode = 0; kb.scancode = 0;
kb.active = false; kb.active = false;
keyBindings.resize(17, kb); keyBindings.resize(input_number_of_inputs, kb);
GameControllerBindings_t gcb; GameControllerBindings_t gcb;
gcb.button = SDL_CONTROLLER_BUTTON_INVALID; gcb.button = SDL_CONTROLLER_BUTTON_INVALID;
gcb.active = false; gcb.active = false;
gameControllerBindings.resize(17, gcb); gameControllerBindings.resize(input_number_of_inputs, gcb);
verbose = true; verbose = true;
enabled = true; enabled = true;

View File

@@ -7,23 +7,31 @@
#ifndef INPUT_H #ifndef INPUT_H
#define INPUT_H #define INPUT_H
#define INPUT_NULL 0 enum inputs_e
#define INPUT_UP 1 {
#define INPUT_DOWN 2 // Inputs obligatorios
#define INPUT_LEFT 3 input_null,
#define INPUT_RIGHT 4 input_up,
#define INPUT_ACCEPT 5 input_down,
#define INPUT_CANCEL 6 input_left,
#define INPUT_BUTTON_1 7 input_right,
#define INPUT_BUTTON_2 8 input_pause,
#define INPUT_BUTTON_3 9 input_exit,
#define INPUT_BUTTON_4 10 input_accept,
#define INPUT_BUTTON_5 11 input_cancel,
#define INPUT_BUTTON_6 12
#define INPUT_BUTTON_7 13 // Inputs personalizados
#define INPUT_BUTTON_8 14 input_jump,
#define INPUT_BUTTON_PAUSE 15 input_window_fullscreen,
#define INPUT_BUTTON_ESCAPE 16 input_window_inc_size,
input_window_dec_size,
input_toggle_border,
input_switch_music,
input_swap_palette,
// Input obligatorio
input_number_of_inputs
};
#define REPEAT_TRUE true #define REPEAT_TRUE true
#define REPEAT_FALSE false #define REPEAT_FALSE false
@@ -81,7 +89,7 @@ public:
void bindGameControllerButton(Uint8 input, SDL_GameControllerButton button); void bindGameControllerButton(Uint8 input, SDL_GameControllerButton button);
// Comprueba si un input esta activo // Comprueba si un input esta activo
bool checkInput(Uint8 input, bool repeat, int device = INPUT_USE_ANY, int index = 0); bool checkInput(Uint8 input, bool repeat = true, int device = INPUT_USE_ANY, int index = 0);
// Comprueba si hay almenos un input activo // Comprueba si hay almenos un input activo
bool checkAnyInput(int device = INPUT_USE_ANY, int index = 0); bool checkAnyInput(int device = INPUT_USE_ANY, int index = 0);

View File

@@ -850,7 +850,7 @@ void Menu::setDefaultActionWhenCancel(int item)
// Gestiona la entrada de teclado y mando durante el menu // Gestiona la entrada de teclado y mando durante el menu
void Menu::checkInput() void Menu::checkInput()
{ {
if (input->checkInput(INPUT_UP, REPEAT_FALSE)) if (input->checkInput(input_up, REPEAT_FALSE))
{ {
if (decreaseSelectorIndex()) if (decreaseSelectorIndex())
{ {
@@ -861,7 +861,7 @@ void Menu::checkInput()
} }
} }
if (input->checkInput(INPUT_DOWN, REPEAT_FALSE)) if (input->checkInput(input_down, REPEAT_FALSE))
{ {
if (increaseSelectorIndex()) if (increaseSelectorIndex())
{ {
@@ -872,7 +872,7 @@ void Menu::checkInput()
} }
} }
if (input->checkInput(INPUT_ACCEPT, REPEAT_FALSE)) if (input->checkInput(input_accept, REPEAT_FALSE))
{ {
itemSelected = selector.index; itemSelected = selector.index;
if (soundAccept) if (soundAccept)
@@ -881,7 +881,7 @@ void Menu::checkInput()
} }
} }
if (input->checkInput(INPUT_CANCEL, REPEAT_FALSE)) if (input->checkInput(input_cancel, REPEAT_FALSE))
{ {
itemSelected = defaultActionWhenCancel; itemSelected = defaultActionWhenCancel;
if (soundCancel) if (soundCancel)

View File

@@ -4,7 +4,7 @@
#include <iostream> #include <iostream>
// Constructor // Constructor
Notify::Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textFile, std::string soundFile, options_t *options) Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile, options_t *options)
{ {
// Inicializa variables // Inicializa variables
this->renderer = renderer; this->renderer = renderer;
@@ -13,8 +13,9 @@ Notify::Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textF
waitTime = 300; waitTime = 300;
// Crea objetos // Crea objetos
texture = new Texture(renderer, bitmapFile); iconTexture = new Texture(renderer, iconFile);
text = new Text(textFile, texture, renderer); textTexture = new Texture(renderer, bitmapFile);
text = new Text(textFile, textTexture, renderer);
sound = JA_LoadSound(soundFile.c_str()); sound = JA_LoadSound(soundFile.c_str());
} }
@@ -22,7 +23,8 @@ Notify::Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textF
Notify::~Notify() Notify::~Notify()
{ {
// Libera la memoria de los objetos // Libera la memoria de los objetos
delete texture; delete textTexture;
delete iconTexture;
delete text; delete text;
JA_DeleteSound(sound); JA_DeleteSound(sound);
@@ -124,12 +126,15 @@ void Notify::clearFinishedNotifications()
} }
// Muestra una notificación de texto por pantalla; // Muestra una notificación de texto por pantalla;
void Notify::showText(std::string text) void Notify::showText(std::string text1, std::string text2, int icon)
{ {
// Inicializa variables // Inicializa variables
const int width = this->text->lenght(text) + (this->text->getCharacterSize() * 2); const int iconSize = 16;
const int height = this->text->getCharacterSize() * 2; const int padding = text->getCharacterSize();
const int padding = (this->text->getCharacterSize() / 2); const int iconSpace = icon >= 0 ? iconSize + padding : 0;
const std::string txt = text1.length() > text2.length() ? text1 : text2;
const int width = text->lenght(txt) + (padding * 2) + iconSpace;
const int height = (text->getCharacterSize() * 2) + (padding * 2);
// Posición horizontal // Posición horizontal
int despH = 0; int despH = 0;
@@ -178,7 +183,8 @@ void Notify::showText(std::string text)
n.travelDist = travelDist; n.travelDist = travelDist;
n.counter = 0; n.counter = 0;
n.state = ns_rising; n.state = ns_rising;
n.text = text; n.text1 = text1;
n.text2 = text2;
if (options->notifications.posV == pos_top) if (options->notifications.posV == pos_top)
{ {
n.rect = {despH, offset - travelDist, width, height}; n.rect = {despH, offset - travelDist, width, height};
@@ -191,14 +197,52 @@ void Notify::showText(std::string text)
// Crea la textura // Crea la textura
n.texture = new Texture(renderer); n.texture = new Texture(renderer);
n.texture->createBlank(renderer, width, height, SDL_TEXTUREACCESS_TARGET); 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); n.texture->setBlendMode(SDL_BLENDMODE_BLEND);
this->text->writeDX(TXT_CENTER | TXT_STROKE, width / 2, padding, text, 1, {255, 255, 255}, 1, {0, 0, 0});
// Prepara para dibujar en la textura
n.texture->setAsRenderTarget(renderer);
// Dibuja el fondo de la notificación
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
SDL_Rect rect;
rect = {4, 0, width - (4 * 2), height};
SDL_RenderFillRect(renderer, &rect);
rect = {4 / 2, 1, width - 4, height - 2};
SDL_RenderFillRect(renderer, &rect);
rect = {1, 4 / 2, width - 2, height - 4};
SDL_RenderFillRect(renderer, &rect);
rect = {0, 4, width, height - (4 * 2)};
SDL_RenderFillRect(renderer, &rect);
// Dibuja el icono de la notificación
if (icon >= 0)
{
Sprite *sp = new Sprite({0, 0, iconSize, iconSize}, iconTexture, renderer);
sp->setPos({padding, padding, iconSize, iconSize});
sp->setSpriteClip({iconSize * (icon % 10), iconSize * (icon / 10), iconSize, iconSize});
sp->render();
delete sp;
}
// Escribe el texto de la notificación
color_t color = {255, 255, 255};
if (text2 != "")
{ // Dos lineas de texto
text->writeColored(padding + iconSpace, padding, text1, color);
text->writeColored(padding + iconSpace, padding + text->getCharacterSize() + 1, text2, color);
}
else
{ // Una linea de texto
text->writeColored(padding + iconSpace, (height / 2) - (text->getCharacterSize() / 2), text1, color);
}
// Deja de dibujar en la textura
SDL_SetRenderTarget(renderer, nullptr); SDL_SetRenderTarget(renderer, nullptr);
// Crea el sprite // Crea el sprite de la notificación
n.sprite = new Sprite(n.rect, n.texture, renderer); n.sprite = new Sprite(n.rect, n.texture, renderer);
// Añade la notificación a la lista // Añade la notificación a la lista

View File

@@ -36,7 +36,8 @@ private:
struct notification_t struct notification_t
{ {
std::string text; std::string text1;
std::string text2;
int counter; int counter;
notification_state_e state; notification_state_e state;
notification_position_e position; notification_position_e position;
@@ -49,7 +50,8 @@ private:
// Objetos y punteros // Objetos y punteros
SDL_Renderer *renderer; // El renderizador de la ventana SDL_Renderer *renderer; // El renderizador de la ventana
Texture *texture; // Textura para la fuente de las notificaciones Texture *textTexture; // Textura para la fuente de las notificaciones
Texture *iconTexture; // Textura para los iconos de las notificaciones
Text *text; // Objeto para dibujar texto Text *text; // Objeto para dibujar texto
options_t *options; // Variable con todas las opciones del programa options_t *options; // Variable con todas las opciones del programa
@@ -57,7 +59,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_t* sound; // Sonido a reproducir cuando suena la notificación JA_Sound_t *sound; // Sonido a reproducir cuando suena la notificación
// Elimina las notificaciones finalizadas // Elimina las notificaciones finalizadas
void clearFinishedNotifications(); void clearFinishedNotifications();
@@ -70,13 +72,13 @@ public:
void update(); void update();
// Constructor // Constructor
Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textFile, std::string soundFile, options_t *options); Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile, options_t *options);
// Destructor // Destructor
~Notify(); ~Notify();
// Muestra una notificación de texto por pantalla; // Muestra una notificación de texto por pantalla;
void showText(std::string text); void showText(std::string text1 = "", std::string text2 = "", int icon = -1);
// Indica si hay notificaciones activas // Indica si hay notificaciones activas
bool active(); bool active();

View File

@@ -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"), asset->get("notify.wav"), options); notify = new Notify(renderer, asset->get("notify.png"), asset->get("smb2.png"), asset->get("smb2.txt"), asset->get("notify.wav"), options);
gameCanvasWidth = options->gameWidth; gameCanvasWidth = options->gameWidth;
gameCanvasHeight = options->gameHeight; gameCanvasHeight = options->gameHeight;
@@ -48,6 +48,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
Screen::~Screen() Screen::~Screen()
{ {
delete notify; delete notify;
SDL_DestroyTexture(gameCanvas);
} }
// Limpia la pantalla // Limpia la pantalla
@@ -86,15 +87,18 @@ 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);
// Si está activo el modo ventana quita el borde // Si está activo el modo ventana quita el borde
if (videoMode == 0) if (videoMode == 0)
{ {
// Muestra el puntero
SDL_ShowCursor(SDL_ENABLE);
// Esconde la ventana
//SDL_HideWindow(window);
if (options->borderEnabled) if (options->borderEnabled)
{ {
windowWidth = gameCanvasWidth + borderWidth; windowWidth = gameCanvasWidth + borderWidth;
@@ -109,9 +113,12 @@ void Screen::setVideoMode(int videoMode)
dest = {0, 0, gameCanvasWidth, gameCanvasHeight}; dest = {0, 0, gameCanvasWidth, gameCanvasHeight};
} }
// Modifica el tamaño del renderizador y de la ventana // Modifica el tamaño de la ventana
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
SDL_SetWindowSize(window, windowWidth * options->windowSize, windowHeight * options->windowSize); SDL_SetWindowSize(window, windowWidth * options->windowSize, windowHeight * options->windowSize);
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
// Muestra la ventana
//SDL_ShowWindow(window);
} }
// Si está activo el modo de pantalla completa añade el borde // Si está activo el modo de pantalla completa añade el borde
@@ -162,11 +169,11 @@ void Screen::setVideoMode(int videoMode)
dest.h = windowHeight; dest.h = windowHeight;
dest.x = dest.y = 0; dest.x = dest.y = 0;
} }
// Modifica el tamaño del renderizador
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
} }
// Modifica el tamaño del renderizador
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
// Actualiza las opciones // Actualiza las opciones
options->videoMode = videoMode; options->videoMode = videoMode;
options->screen.windowWidth = windowWidth; options->screen.windowWidth = windowWidth;
@@ -190,6 +197,22 @@ void Screen::setWindowSize(int size)
setVideoMode(0); setVideoMode(0);
} }
// Reduce el tamaño de la ventana
void Screen::decWindowSize()
{
--options->windowSize;
options->windowSize = std::max(options->windowSize, 1);
setVideoMode(0);
}
// Aumenta el tamaño de la ventana
void Screen::incWindowSize()
{
++options->windowSize;
options->windowSize = std::min(options->windowSize, 4);
setVideoMode(0);
}
// Cambia el color del borde // Cambia el color del borde
void Screen::setBorderColor(color_t color) void Screen::setBorderColor(color_t color)
{ {
@@ -370,9 +393,9 @@ void Screen::updateNotifier()
} }
// Muestra una notificación de texto por pantalla; // Muestra una notificación de texto por pantalla;
void Screen::showNotification(std::string text) void Screen::showNotification(std::string text1, std::string text2, int icon)
{ {
notify->showText(text); notify->showText(text1, text2, icon);
} }
// Dibuja las notificaciones // Dibuja las notificaciones
@@ -383,9 +406,9 @@ void Screen::renderNotifications()
return; return;
} }
//SDL_RenderSetLogicalSize(renderer, notificationLogicalWidth, notificationLogicalHeight); 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 // Establece el tamaño de las notificaciones

View File

@@ -4,6 +4,7 @@
#include "asset.h" #include "asset.h"
#include "notify.h" #include "notify.h"
#include "utils.h" #include "utils.h"
#include "../const.h"
#include <vector> #include <vector>
#ifndef SCREEN_H #ifndef SCREEN_H
@@ -94,6 +95,12 @@ public:
// Cambia el tamaño de la ventana // Cambia el tamaño de la ventana
void setWindowSize(int size); void setWindowSize(int size);
// Reduce el tamaño de la ventana
void decWindowSize();
// Aumenta el tamaño de la ventana
void incWindowSize();
// Cambia el color del borde // Cambia el color del borde
void setBorderColor(color_t color); void setBorderColor(color_t color);
@@ -132,7 +139,7 @@ public:
void updateNotifier(); void updateNotifier();
// Muestra una notificación de texto por pantalla; // Muestra una notificación de texto por pantalla;
void showNotification(std::string text); void showNotification(std::string text1 = "", std::string text2 = "", int icon = -1);
}; };
#endif #endif

View File

@@ -2,14 +2,16 @@
#include <iostream> #include <iostream>
// Constructor // Constructor
Credits::Credits(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options) Credits::Credits(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section)
{ {
// Copia la dirección de los objetos // Copia la dirección de los objetos
this->resource = resource;
this->renderer = renderer; this->renderer = renderer;
this->screen = screen; this->screen = screen;
this->resource = resource;
this->asset = asset; this->asset = asset;
this->input = input;
this->options = options; this->options = options;
this->section = section;
// Reserva memoria para los punteros // Reserva memoria para los punteros
eventHandler = new SDL_Event(); eventHandler = new SDL_Event();
@@ -20,8 +22,8 @@ Credits::Credits(SDL_Renderer *renderer, Screen *screen, Resource *resource, Ass
counter = 0; counter = 0;
counterEnabled = true; counterEnabled = true;
subCounter = 0; subCounter = 0;
section.name = SECTION_PROG_CREDITS; section->name = SECTION_PROG_CREDITS;
section.subsection = 0; section->subsection = 0;
ticks = 0; ticks = 0;
ticksSpeed = 15; ticksSpeed = 15;
sprite->setRect({194, 174, 8, 8}); sprite->setRect({194, 174, 8, 8});
@@ -74,59 +76,50 @@ void Credits::checkEventHandler()
// Evento de salida de la aplicación // Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT) if (eventHandler->type == SDL_QUIT)
{ {
section.name = SECTION_PROG_QUIT; section->name = SECTION_PROG_QUIT;
break; break;
} }
}
}
// Comprueba las teclas que se han pulsado // Comprueba las entradas
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN)) void Credits::checkInput()
{ {
switch (eventHandler->key.keysym.scancode)
{
case SDL_SCANCODE_ESCAPE:
section.name = SECTION_PROG_QUIT;
break;
case SDL_SCANCODE_B: if (input->checkInput(input_exit, REPEAT_FALSE))
screen->switchBorder(); {
resource->reLoadTextures(); section->name = SECTION_PROG_QUIT;
break; }
case SDL_SCANCODE_F: else if (input->checkInput(input_toggle_border, REPEAT_FALSE))
screen->switchVideoMode(); {
resource->reLoadTextures(); screen->switchBorder();
break; }
case SDL_SCANCODE_F1: else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
screen->setWindowSize(1); {
resource->reLoadTextures(); screen->switchVideoMode();
break; }
case SDL_SCANCODE_F2: else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
screen->setWindowSize(2); {
resource->reLoadTextures(); screen->decWindowSize();
break; }
case SDL_SCANCODE_F3: else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
screen->setWindowSize(3); {
resource->reLoadTextures(); screen->incWindowSize();
break; }
case SDL_SCANCODE_F4: else if (input->checkInput(input_swap_palette, REPEAT_FALSE))
screen->setWindowSize(4); {
resource->reLoadTextures(); switchPalette();
break; }
case SDL_SCANCODE_F5: else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_jump, REPEAT_FALSE))
switchPalette(); {
break; section->name = SECTION_PROG_TITLE;
section->subsection = 0;
default:
section.name = SECTION_PROG_TITLE;
section.subsection = 0;
break;
}
}
} }
} }
@@ -147,6 +140,7 @@ void Credits::iniTexts()
keys = "A,D AND W"; keys = "A,D AND W";
} }
#ifndef GAME_CONSOLE
texts.clear(); texts.clear();
texts.push_back({"", stringToColor(options->palette, "white")}); texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"INSTRUCTIONS:", stringToColor(options->palette, "yellow")}); texts.push_back({"INSTRUCTIONS:", stringToColor(options->palette, "yellow")});
@@ -160,11 +154,11 @@ void Credits::iniTexts()
texts.push_back({"KEYS:", stringToColor(options->palette, "yellow")}); texts.push_back({"KEYS:", stringToColor(options->palette, "yellow")});
texts.push_back({"", stringToColor(options->palette, "white")}); texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({keys + " TO MOVE AND JUMP", stringToColor(options->palette, "white")}); texts.push_back({keys + " TO MOVE AND JUMP", stringToColor(options->palette, "white")});
texts.push_back({"M TO TURN ON/OFF THE MUSIC", stringToColor(options->palette, "white")}); texts.push_back({"M TO SWITCH THE MUSIC", stringToColor(options->palette, "white")});
texts.push_back({"H TO HOLD/PAUSE THE GAME", stringToColor(options->palette, "white")}); texts.push_back({"H TO PAUSE THE GAME", stringToColor(options->palette, "white")});
texts.push_back({"F1-F4 TO CHANGE WINDOWS SIZE", stringToColor(options->palette, "white")}); texts.push_back({"F1-F2 TO CHANGE WINDOWS SIZE", stringToColor(options->palette, "white")});
texts.push_back({"F TO SWITCH TO FULLSCREEN", stringToColor(options->palette, "white")}); texts.push_back({"F3 TO SWITCH TO FULLSCREEN", stringToColor(options->palette, "white")});
texts.push_back({"B TO SWITCH THE BORDER SCREEN", stringToColor(options->palette, "white")}); texts.push_back({"B TO TOOGLE THE BORDER SCREEN", 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")});
@@ -175,6 +169,36 @@ void Credits::iniTexts()
texts.push_back({"I LOVE JAILGAMES! ", stringToColor(options->palette, "white")}); texts.push_back({"I LOVE JAILGAMES! ", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")}); texts.push_back({"", stringToColor(options->palette, "white")});
#else
texts.clear();
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"INSTRUCTIONS:", stringToColor(options->palette, "yellow")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"HELP JAILDOC TO GET BACK ALL", stringToColor(options->palette, "white")});
texts.push_back({"HIS PROJECTS AND GO TO THE", stringToColor(options->palette, "white")});
texts.push_back({"JAIL TO FINISH THEM", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"KEYS:", stringToColor(options->palette, "yellow")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"B TO JUMP", stringToColor(options->palette, "white")});
texts.push_back({"R TO SWITCH THE MUSIC", stringToColor(options->palette, "white")});
texts.push_back({"L TO SWAP THE COLOR PALETTE", stringToColor(options->palette, "white")});
texts.push_back({"START TO PAUSE", stringToColor(options->palette, "white")});
texts.push_back({"SELECT TO EXIT", 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({"A GAME BY JAILDESIGNER", stringToColor(options->palette, "yellow")});
texts.push_back({"MADE ON SUMMER/FALL 2022", stringToColor(options->palette, "yellow")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
texts.push_back({"I LOVE JAILGAMES! ", stringToColor(options->palette, "white")});
texts.push_back({"", stringToColor(options->palette, "white")});
#endif
} }
// Escribe el texto en la textura // Escribe el texto en la textura
@@ -259,21 +283,24 @@ void Credits::updateCounter()
// Comprueba si ha terminado la sección // Comprueba si ha terminado la sección
if (counter > 1200) if (counter > 1200)
{ {
section.name = SECTION_PROG_DEMO; section->name = SECTION_PROG_DEMO;
} }
} }
// Actualiza las variables // Actualiza las variables
void Credits::update() void Credits::update()
{ {
// Comprueba el manejador de eventos
checkEventHandler();
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego // Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
if (SDL_GetTicks() - ticks > ticksSpeed) if (SDL_GetTicks() - ticks > ticksSpeed)
{ {
// Actualiza el contador de ticks // Actualiza el contador de ticks
ticks = SDL_GetTicks(); ticks = SDL_GetTicks();
// Comprueba el manejador de eventos // Comprueba las entradas
checkEventHandler(); checkInput();
// Actualiza el contador // Actualiza el contador
updateCounter(); updateCounter();
@@ -318,15 +345,13 @@ void Credits::render()
} }
// Bucle para el logo del juego // Bucle para el logo del juego
section_t Credits::run() void Credits::run()
{ {
while (section.name == SECTION_PROG_CREDITS) while (section->name == SECTION_PROG_CREDITS)
{ {
update(); update();
render(); render();
} }
return section;
} }
// Cambia la paleta // Cambia la paleta

View File

@@ -3,6 +3,7 @@
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include "common/animatedsprite.h" #include "common/animatedsprite.h"
#include "common/asset.h" #include "common/asset.h"
#include "common/input.h"
#include "common/jail_audio.h" #include "common/jail_audio.h"
#include "common/resource.h" #include "common/resource.h"
#include "common/screen.h" #include "common/screen.h"
@@ -30,18 +31,19 @@ private:
Screen *screen; // Objeto encargado de dibujar en pantalla Screen *screen; // Objeto encargado de dibujar en pantalla
Resource *resource; // Objeto con los recursos Resource *resource; // Objeto con los recursos
Asset *asset; // Objeto con los ficheros de recursos Asset *asset; // Objeto con los ficheros de recursos
Input *input; // Objeto pata gestionar la entrada
SDL_Event *eventHandler; // Manejador de eventos SDL_Event *eventHandler; // Manejador de eventos
Text *text; // Objeto para escribir texto en pantalla Text *text; // Objeto para escribir texto en pantalla
SDL_Texture *textTexture; // Textura para dibujar el texto SDL_Texture *textTexture; // Textura para dibujar el texto
SDL_Texture *coverTexture; // Textura para cubrir el texto SDL_Texture *coverTexture; // Textura para cubrir el texto
AnimatedSprite *sprite; // Sprite para el brillo del corazón AnimatedSprite *sprite; // Sprite para el brillo del corazón
options_t *options; // Puntero a las opciones del juego options_t *options; // Puntero a las opciones del juego
section_t *section; // Estado del bucle principal para saber si continua o se sale
// Variables // Variables
int counter; // Contador int counter; // Contador
bool counterEnabled; // Indica si esta activo el contador bool counterEnabled; // Indica si esta activo el contador
int subCounter; // Contador secundario int subCounter; // Contador secundario
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 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
std::vector<captions_t> texts; // Vector con los textos std::vector<captions_t> texts; // Vector con los textos
@@ -55,6 +57,9 @@ private:
// Comprueba el manejador de eventos // Comprueba el manejador de eventos
void checkEventHandler(); void checkEventHandler();
// Comprueba las entradas
void checkInput();
// Actualiza el contador // Actualiza el contador
void updateCounter(); void updateCounter();
@@ -69,13 +74,13 @@ private:
public: public:
// Constructor // Constructor
Credits(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options); Credits(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section);
// Destructor // Destructor
~Credits(); ~Credits();
// Bucle principal // Bucle principal
section_t run(); void run();
}; };
#endif #endif

View File

@@ -1,7 +1,7 @@
#include "demo.h" #include "demo.h"
// Constructor // Constructor
Demo::Demo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Debug *debug) Demo::Demo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section, Debug *debug)
{ {
// Inicia algunas variables // Inicia algunas variables
board.iniClock = SDL_GetTicks(); board.iniClock = SDL_GetTicks();
@@ -18,12 +18,14 @@ Demo::Demo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
currentRoom = rooms[roomIndex]; currentRoom = rooms[roomIndex];
// Copia los punteros // Copia los punteros
this->resource = resource;
this->renderer = renderer; this->renderer = renderer;
this->asset = asset;
this->screen = screen; this->screen = screen;
this->debug = debug; this->resource = resource;
this->asset = asset;
this->input = input;
this->options = options; this->options = options;
this->section = section;
this->debug = debug;
// Crea los objetos // Crea los objetos
itemTracker = new ItemTracker(); itemTracker = new ItemTracker();
@@ -44,8 +46,8 @@ Demo::Demo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
board.music = true; board.music = true;
setScoreBoardColor(); setScoreBoardColor();
section.name = SECTION_PROG_DEMO; section->name = SECTION_PROG_DEMO;
section.subsection = 0; section->subsection = 0;
} }
Demo::~Demo() Demo::~Demo()
@@ -67,86 +69,82 @@ void Demo::checkEventHandler()
// Evento de salida de la aplicación // Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT) if (eventHandler->type == SDL_QUIT)
{ {
section.name = SECTION_PROG_QUIT; section->name = SECTION_PROG_QUIT;
screen->setBorderColor(stringToColor(options->palette, "black")); screen->setBorderColor(stringToColor(options->palette, "black"));
break; break;
} }
// Comprueba las teclas que se han pulsado
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
{
switch (eventHandler->key.keysym.scancode)
{
case SDL_SCANCODE_ESCAPE:
section.name = SECTION_PROG_QUIT;
break;
case SDL_SCANCODE_B:
screen->switchBorder();
reLoadTextures();
break;
case SDL_SCANCODE_F:
screen->switchVideoMode();
reLoadTextures();
break;
case SDL_SCANCODE_F1:
screen->setWindowSize(1);
reLoadTextures();
break;
case SDL_SCANCODE_F2:
screen->setWindowSize(2);
reLoadTextures();
break;
case SDL_SCANCODE_F3:
screen->setWindowSize(3);
reLoadTextures();
break;
case SDL_SCANCODE_F4:
screen->setWindowSize(4);
reLoadTextures();
break;
case SDL_SCANCODE_F5:
switchPalette();
break;
default:
section.name = SECTION_PROG_TITLE;
section.subsection = 0;
break;
}
}
} }
} }
// Bucle para el juego // Comprueba las entradas
section_t Demo::run() void Demo::checkInput()
{ {
while (section.name == SECTION_PROG_DEMO)
if (input->checkInput(input_exit, REPEAT_FALSE))
{
section->name = SECTION_PROG_QUIT;
}
else if (input->checkInput(input_toggle_border, REPEAT_FALSE))
{
screen->switchBorder();
reLoadTextures();
}
else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
{
screen->switchVideoMode();
reLoadTextures();
}
else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
{
screen->decWindowSize();
reLoadTextures();
}
else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
{
screen->incWindowSize();
reLoadTextures();
}
else if (input->checkInput(input_swap_palette, REPEAT_FALSE))
{
switchPalette();
}
else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_jump, REPEAT_FALSE))
{
section->name = SECTION_PROG_TITLE;
section->subsection = 0;
}
}
// Bucle para el juego
void Demo::run()
{
while (section->name == SECTION_PROG_DEMO)
{ {
update(); update();
render(); render();
} }
return section;
} }
// Actualiza el juego, las variables, comprueba la entrada, etc. // Actualiza el juego, las variables, comprueba la entrada, etc.
void Demo::update() void Demo::update()
{ {
// Comprueba los eventos de la cola
checkEventHandler();
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego // Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
if (SDL_GetTicks() - ticks > ticksSpeed) if (SDL_GetTicks() - ticks > ticksSpeed)
{ {
// Actualiza el contador de ticks // Actualiza el contador de ticks
ticks = SDL_GetTicks(); ticks = SDL_GetTicks();
// Comprueba los eventos de la cola // Comprueba las entradas
checkEventHandler(); checkInput();
// Actualiza los objetos // Actualiza los objetos
room->update(); room->update();
@@ -255,8 +253,8 @@ void Demo::checkRoomChange()
roomIndex++; roomIndex++;
if (roomIndex == (int)rooms.size()) if (roomIndex == (int)rooms.size())
{ {
section.name = SECTION_PROG_LOGO; section->name = SECTION_PROG_LOGO;
section.subsection = SUBSECTION_LOGO_TO_TITLE; section->subsection = SUBSECTION_LOGO_TO_TITLE;
} }
else else
{ {

View File

@@ -3,6 +3,7 @@
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include "common/animatedsprite.h" #include "common/animatedsprite.h"
#include "common/asset.h" #include "common/asset.h"
#include "common/input.h"
#include "common/debug.h" #include "common/debug.h"
#include "common/input.h" #include "common/input.h"
#include "common/resource.h" #include "common/resource.h"
@@ -29,16 +30,17 @@ private:
Room *room; // Objeto encargado de gestionar cada habitación del juego Room *room; // Objeto encargado de gestionar cada habitación del juego
Resource *resource; // Objeto con los recursos Resource *resource; // Objeto con los recursos
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
Input *input; // Objeto pata gestionar la entrada
Text *text; // Objeto para los textos del juego Text *text; // Objeto para los textos del juego
ScoreBoard *scoreboard; // Objeto encargado de gestionar el marcador ScoreBoard *scoreboard; // Objeto encargado de gestionar el marcador
ItemTracker *itemTracker; // Lleva el control de los objetos recogidos ItemTracker *itemTracker; // Lleva el control de los objetos recogidos
Debug *debug; // Objeto para gestionar la información de debug Debug *debug; // Objeto para gestionar la información de debug
options_t *options; // Puntero a las opciones del juego options_t *options; // Puntero a las opciones del juego
section_t *section; // Seccion actual dentro del juego
// Variables // Variables
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
section_t section; // Seccion actual dentro del juego
std::string currentRoom; // Fichero de la habitación actual std::string currentRoom; // Fichero de la habitación actual
board_t board; // Estructura con los datos del marcador board_t board; // Estructura con los datos del marcador
int counter; // Contador para el modo demo int counter; // Contador para el modo demo
@@ -55,6 +57,9 @@ private:
// Comprueba los eventos de la cola // Comprueba los eventos de la cola
void checkEventHandler(); void checkEventHandler();
// Comprueba las entradas
void checkInput();
// Escribe el nombre de la pantalla // Escribe el nombre de la pantalla
void renderRoomName(); void renderRoomName();
@@ -75,13 +80,13 @@ private:
public: public:
// Constructor // Constructor
Demo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Debug *debug); Demo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section, Debug *debug);
// Destructor // Destructor
~Demo(); ~Demo();
// Bucle para el juego // Bucle para el juego
section_t run(); void run();
}; };
#endif #endif

View File

@@ -14,11 +14,12 @@
// Constructor // Constructor
Director::Director(int argc, char *argv[]) Director::Director(int argc, char *argv[])
{ {
section.name = SECTION_PROG_LOGO; section = new section_t();
section.subsection = SUBSECTION_LOGO_TO_INTRO; section->name = SECTION_PROG_LOGO;
section->subsection = SUBSECTION_LOGO_TO_INTRO;
#ifdef DEBUG #ifdef DEBUG
section.name = SECTION_PROG_LOGO; section->name = SECTION_PROG_GAME;
#endif #endif
// Crea e inicializa las opciones del programa // Crea e inicializa las opciones del programa
@@ -28,7 +29,12 @@ Director::Director(int argc, char *argv[])
checkProgramArguments(argc, argv); checkProgramArguments(argc, argv);
// Crea la carpeta del sistema donde guardar datos // Crea la carpeta del sistema donde guardar datos
createSystemFolder(); createSystemFolder("jailgames");
#ifndef DEBUG
createSystemFolder("jailgames/jaildoctors_dilemma");
#else
createSystemFolder("jailgames/jaildoctors_dilemma_debug");
#endif
// Crea el objeto que controla los ficheros de recursos // Crea el objeto que controla los ficheros de recursos
asset = new Asset(executablePath); asset = new Asset(executablePath);
@@ -65,6 +71,7 @@ Director::~Director()
saveConfig(); saveConfig();
// Libera la memoria // Libera la memoria
delete section;
delete options; delete options;
delete asset; delete asset;
delete input; delete input;
@@ -158,7 +165,7 @@ void Director::initOptions()
options->notifications.posV = pos_top; options->notifications.posV = pos_top;
options->notifications.posH = pos_left; options->notifications.posH = pos_left;
options->notifications.sound = true; options->notifications.sound = true;
options->notifications.color = {64, 64, 64}; options->notifications.color = {48, 48, 48};
} }
// Comprueba los parametros del programa // Comprueba los parametros del programa
@@ -408,24 +415,18 @@ bool Director::saveConfig()
} }
// Crea la carpeta del sistema donde guardar datos // Crea la carpeta del sistema donde guardar datos
void Director::createSystemFolder() void Director::createSystemFolder(std::string folder)
{ {
#ifdef DEBUG
const std::string folderName = "jaildoctors_dilemma_debug";
#else
const std::string folderName = "jaildoctors_dilemma";
#endif
#ifdef _WIN32 #ifdef _WIN32
systemFolder = std::string(getenv("APPDATA")) + "/" + folderName; systemFolder = std::string(getenv("APPDATA")) + "/" + folder;
#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" + "/" + folder;
#elif __linux__ #elif __linux__
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) + "/." + folderName; systemFolder = std::string(homedir) + "/." + folder;
#endif #endif
struct stat st = {0}; struct stat st = {0};
@@ -463,14 +464,14 @@ void Director::createSystemFolder()
} }
// Carga los recursos // Carga los recursos
void Director::loadResources(section_t section) void Director::loadResources(section_t *section)
{ {
if (options->console) if (options->console)
{ {
std::cout << "** LOAD RESOURCES" << std::endl; std::cout << "** LOAD RESOURCES" << std::endl;
} }
if (section.name == SECTION_PROG_LOGO) if (section->name == SECTION_PROG_LOGO)
{ {
std::vector<std::string> textureList; std::vector<std::string> textureList;
textureList.push_back("jailgames.png"); textureList.push_back("jailgames.png");
@@ -479,7 +480,7 @@ void Director::loadResources(section_t section)
resource->loadTextures(textureList); resource->loadTextures(textureList);
} }
else if (section.name == SECTION_PROG_INTRO) else if (section->name == SECTION_PROG_INTRO)
{ {
std::vector<std::string> textureList; std::vector<std::string> textureList;
textureList.push_back("loading_screen_bn.png"); textureList.push_back("loading_screen_bn.png");
@@ -490,7 +491,7 @@ void Director::loadResources(section_t section)
resource->loadTextures(textureList); resource->loadTextures(textureList);
} }
else if (section.name == SECTION_PROG_TITLE) else if (section->name == SECTION_PROG_TITLE)
{ {
std::vector<std::string> textureList; std::vector<std::string> textureList;
textureList.push_back("loading_screen_color.png"); textureList.push_back("loading_screen_color.png");
@@ -506,7 +507,7 @@ void Director::loadResources(section_t section)
resource->loadOffsets(offsetsList); resource->loadOffsets(offsetsList);
} }
else if (section.name == SECTION_PROG_CREDITS) else if (section->name == SECTION_PROG_CREDITS)
{ {
// Texturas // Texturas
std::vector<std::string> textureList; std::vector<std::string> textureList;
@@ -528,7 +529,7 @@ void Director::loadResources(section_t section)
resource->loadOffsets(offsetsList); resource->loadOffsets(offsetsList);
} }
else if (section.name == SECTION_PROG_ENDING) else if (section->name == SECTION_PROG_ENDING)
{ {
// Texturas // Texturas
std::vector<std::string> textureList; std::vector<std::string> textureList;
@@ -553,7 +554,7 @@ void Director::loadResources(section_t section)
resource->loadOffsets(offsetsList); resource->loadOffsets(offsetsList);
} }
else if (section.name == SECTION_PROG_ENDING2) else if (section->name == SECTION_PROG_ENDING2)
{ {
// Texturas // Texturas
std::vector<std::string> textureList; std::vector<std::string> textureList;
@@ -691,7 +692,7 @@ void Director::loadResources(section_t section)
resource->loadOffsets(offsetsList); resource->loadOffsets(offsetsList);
} }
else if (section.name == SECTION_PROG_GAME_OVER) else if (section->name == SECTION_PROG_GAME_OVER)
{ {
// Texturas // Texturas
std::vector<std::string> textureList; std::vector<std::string> textureList;
@@ -715,7 +716,7 @@ void Director::loadResources(section_t section)
resource->loadOffsets(offsetsList); resource->loadOffsets(offsetsList);
} }
else if (section.name == SECTION_PROG_GAME || section.name == SECTION_PROG_DEMO) else if (section->name == SECTION_PROG_GAME || section->name == SECTION_PROG_DEMO)
{ {
// Texturas // Texturas
std::vector<std::string> textureList; std::vector<std::string> textureList;
@@ -1207,43 +1208,56 @@ void Director::initInput()
// Busca si hay un mando conectado // Busca si hay un mando conectado
input->discoverGameController(); input->discoverGameController();
// Asigna inputs a teclas // Teclado - Movimiento
if (options->keys == ctrl_cursor) if (options->keys == ctrl_cursor)
{ {
input->bindKey(INPUT_UP, SDL_SCANCODE_UP); input->bindKey(input_jump, SDL_SCANCODE_UP);
input->bindKey(INPUT_LEFT, SDL_SCANCODE_LEFT); input->bindKey(input_left, SDL_SCANCODE_LEFT);
input->bindKey(INPUT_RIGHT, SDL_SCANCODE_RIGHT); input->bindKey(input_right, SDL_SCANCODE_RIGHT);
} }
else if (options->keys == ctrl_opqa) else if (options->keys == ctrl_opqa)
{ {
input->bindKey(INPUT_UP, SDL_SCANCODE_Q); input->bindKey(input_jump, SDL_SCANCODE_Q);
input->bindKey(INPUT_LEFT, SDL_SCANCODE_O); input->bindKey(input_left, SDL_SCANCODE_O);
input->bindKey(INPUT_RIGHT, SDL_SCANCODE_P); input->bindKey(input_right, SDL_SCANCODE_P);
} }
else if (options->keys == ctrl_wasd) else if (options->keys == ctrl_wasd)
{ {
input->bindKey(INPUT_UP, SDL_SCANCODE_W); input->bindKey(input_jump, SDL_SCANCODE_W);
input->bindKey(INPUT_LEFT, SDL_SCANCODE_A); input->bindKey(input_left, SDL_SCANCODE_A);
input->bindKey(INPUT_RIGHT, SDL_SCANCODE_D); input->bindKey(input_right, SDL_SCANCODE_D);
} }
input->bindKey(INPUT_DOWN, SDL_SCANCODE_DOWN); // Teclado - Otros
input->bindKey(INPUT_ACCEPT, SDL_SCANCODE_RETURN); input->bindKey(input_accept, SDL_SCANCODE_RETURN);
input->bindKey(INPUT_CANCEL, SDL_SCANCODE_ESCAPE); input->bindKey(input_cancel, SDL_SCANCODE_ESCAPE);
input->bindKey(INPUT_BUTTON_1, SDL_SCANCODE_SPACE); input->bindKey(input_pause, SDL_SCANCODE_H);
input->bindKey(INPUT_BUTTON_2, SDL_SCANCODE_D); input->bindKey(input_exit, SDL_SCANCODE_ESCAPE);
input->bindKey(INPUT_BUTTON_PAUSE, SDL_SCANCODE_ESCAPE); input->bindKey(input_window_dec_size, SDL_SCANCODE_F1);
input->bindKey(INPUT_BUTTON_ESCAPE, SDL_SCANCODE_ESCAPE); input->bindKey(input_window_inc_size, SDL_SCANCODE_F2);
input->bindKey(input_window_fullscreen, SDL_SCANCODE_F3);
input->bindKey(input_swap_palette, SDL_SCANCODE_F5);
input->bindKey(input_switch_music, SDL_SCANCODE_M);
input->bindKey(input_toggle_border, SDL_SCANCODE_B);
input->bindGameControllerButton(INPUT_UP, SDL_CONTROLLER_BUTTON_B); // Mando - Movimiento
input->bindGameControllerButton(INPUT_DOWN, SDL_CONTROLLER_BUTTON_DPAD_DOWN); input->bindGameControllerButton(input_jump, SDL_CONTROLLER_BUTTON_B);
input->bindGameControllerButton(INPUT_LEFT, SDL_CONTROLLER_BUTTON_DPAD_LEFT); input->bindGameControllerButton(input_left, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
input->bindGameControllerButton(INPUT_RIGHT, SDL_CONTROLLER_BUTTON_DPAD_RIGHT); input->bindGameControllerButton(input_right, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
input->bindGameControllerButton(INPUT_ACCEPT, SDL_CONTROLLER_BUTTON_B);
input->bindGameControllerButton(INPUT_CANCEL, SDL_CONTROLLER_BUTTON_A); // Mando - Otros
input->bindGameControllerButton(INPUT_BUTTON_1, SDL_CONTROLLER_BUTTON_B); input->bindGameControllerButton(input_accept, SDL_CONTROLLER_BUTTON_B);
input->bindGameControllerButton(INPUT_BUTTON_PAUSE, SDL_CONTROLLER_BUTTON_START); input->bindGameControllerButton(input_cancel, SDL_CONTROLLER_BUTTON_A);
input->bindGameControllerButton(INPUT_BUTTON_ESCAPE, SDL_CONTROLLER_BUTTON_GUIDE); #ifdef GAME_CONSOLE
input->bindGameControllerButton(input_pause, SDL_CONTROLLER_BUTTON_BACK);
input->bindGameControllerButton(input_exit, SDL_CONTROLLER_BUTTON_START);
#else
input->bindGameControllerButton(input_pause, SDL_CONTROLLER_BUTTON_START);
input->bindGameControllerButton(input_exit, SDL_CONTROLLER_BUTTON_BACK);
#endif
input->bindGameControllerButton(input_swap_palette, SDL_CONTROLLER_BUTTON_LEFTSHOULDER);
input->bindGameControllerButton(input_switch_music, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER);
input->bindGameControllerButton(input_toggle_border, SDL_CONTROLLER_BUTTON_X);
} }
// Inicializa JailAudio // Inicializa JailAudio
@@ -1362,6 +1376,10 @@ bool Director::setFileList()
asset->add(systemFolder + "/config.txt", t_data, false, true); asset->add(systemFolder + "/config.txt", t_data, false, true);
asset->add(systemFolder + "/stats_buffer.csv", t_data, false, true); asset->add(systemFolder + "/stats_buffer.csv", t_data, false, true);
asset->add(systemFolder + "/stats.csv", t_data, false, true); asset->add(systemFolder + "/stats.csv", t_data, false, true);
asset->add(systemFolder + "/cheevos.bin", t_data, false, true);
// Notificaciones
asset->add(prefix + "/data/notifications/notify.png", t_bitmap);
// Habitaciones // Habitaciones
asset->add(prefix + "/data/room/01.room", t_room); asset->add(prefix + "/data/room/01.room", t_room);
@@ -1686,24 +1704,6 @@ bool Director::setFileList()
return asset->check(); return asset->check();
} }
// Obtiene el valor de la variable
Uint8 Director::getSubsection()
{
return section.subsection;
}
// Obtiene el valor de la variable
Uint8 Director::getSection()
{
return section.name;
}
// Establece el valor de la variable
void Director::setSection(section_t section)
{
this->section = section;
}
// Ejecuta la seccion de juego con el logo // Ejecuta la seccion de juego con el logo
void Director::runLogo() void Director::runLogo()
{ {
@@ -1712,8 +1712,8 @@ void Director::runLogo()
std::cout << "\n* SECTION: LOGO" << std::endl; std::cout << "\n* SECTION: LOGO" << std::endl;
} }
loadResources(section); loadResources(section);
logo = new Logo(renderer, screen, resource, asset, options, section.subsection); logo = new Logo(renderer, screen, resource, asset, input, options, section);
setSection(logo->run()); logo->run();
delete logo; delete logo;
resource->free(); resource->free();
} }
@@ -1726,8 +1726,8 @@ void Director::runIntro()
std::cout << "\n* SECTION: INTRO" << std::endl; std::cout << "\n* SECTION: INTRO" << std::endl;
} }
loadResources(section); loadResources(section);
intro = new Intro(renderer, screen, resource, asset, options); intro = new Intro(renderer, screen, resource, asset, input, options, section);
setSection(intro->run()); intro->run();
delete intro; delete intro;
resource->free(); resource->free();
} }
@@ -1744,8 +1744,8 @@ void Director::runTitle()
JA_PlayMusic(music); JA_PlayMusic(music);
} }
loadResources(section); loadResources(section);
title = new Title(renderer, screen, resource, asset, options); title = new Title(renderer, screen, resource, asset, input, options, section);
setSection(title->run()); title->run();
delete title; delete title;
resource->free(); resource->free();
} }
@@ -1758,8 +1758,8 @@ void Director::runCredits()
std::cout << "\n* SECTION: CREDITS" << std::endl; std::cout << "\n* SECTION: CREDITS" << std::endl;
} }
loadResources(section); loadResources(section);
credits = new Credits(renderer, screen, resource, asset, options); credits = new Credits(renderer, screen, resource, asset, input, options, section);
setSection(credits->run()); credits->run();
delete credits; delete credits;
resource->free(); resource->free();
} }
@@ -1772,8 +1772,8 @@ void Director::runDemo()
std::cout << "\n* SECTION: DEMO" << std::endl; std::cout << "\n* SECTION: DEMO" << std::endl;
} }
loadResources(section); loadResources(section);
demo = new Demo(renderer, screen, resource, asset, options, debug); demo = new Demo(renderer, screen, resource, asset, input, options, section, debug);
setSection(demo->run()); demo->run();
delete demo; delete demo;
resource->free(); resource->free();
} }
@@ -1787,7 +1787,7 @@ void Director::runEnterID()
} }
// loadResources(section); // loadResources(section);
enterID = new EnterID(renderer, screen, asset, options, section); enterID = new EnterID(renderer, screen, asset, options, section);
setSection(enterID->run()); enterID->run();
delete enterID; delete enterID;
resource->free(); resource->free();
} }
@@ -1800,8 +1800,8 @@ void Director::runEnding()
std::cout << "\n* SECTION: ENDING" << std::endl; std::cout << "\n* SECTION: ENDING" << std::endl;
} }
loadResources(section); loadResources(section);
ending = new Ending(renderer, screen, resource, asset, options); ending = new Ending(renderer, screen, resource, asset, input, options, section);
setSection(ending->run()); ending->run();
delete ending; delete ending;
resource->free(); resource->free();
} }
@@ -1814,8 +1814,8 @@ void Director::runEnding2()
std::cout << "\n* SECTION: ENDING2" << std::endl; std::cout << "\n* SECTION: ENDING2" << std::endl;
} }
loadResources(section); loadResources(section);
ending2 = new Ending2(renderer, screen, resource, asset, options); ending2 = new Ending2(renderer, screen, resource, asset, input, options, section);
setSection(ending2->run()); ending2->run();
delete ending2; delete ending2;
resource->free(); resource->free();
} }
@@ -1828,8 +1828,8 @@ void Director::runGameOver()
std::cout << "\n* SECTION: GAME OVER" << std::endl; std::cout << "\n* SECTION: GAME OVER" << std::endl;
} }
loadResources(section); loadResources(section);
gameOver = new GameOver(renderer, screen, resource, asset, options); gameOver = new GameOver(renderer, screen, resource, asset, input, options, section);
setSection(gameOver->run()); gameOver->run();
delete gameOver; delete gameOver;
resource->free(); resource->free();
} }
@@ -1843,8 +1843,8 @@ void Director::runGame()
} }
JA_StopMusic(); JA_StopMusic();
loadResources(section); loadResources(section);
game = new Game(renderer, screen, resource, asset, options, input, debug); game = new Game(renderer, screen, resource, asset, options, input, section, debug);
setSection(game->run()); game->run();
delete game; delete game;
resource->free(); resource->free();
} }
@@ -1852,9 +1852,9 @@ void Director::runGame()
void Director::run() void Director::run()
{ {
// Bucle principal // Bucle principal
while (getSection() != SECTION_PROG_QUIT) while (section->name != SECTION_PROG_QUIT)
{ {
switch (getSection()) switch (section->name)
{ {
case SECTION_PROG_LOGO: case SECTION_PROG_LOGO:
runLogo(); runLogo();

View File

@@ -46,10 +46,10 @@ private:
GameOver *gameOver; // Objeto para gestionar el final de la partida GameOver *gameOver; // Objeto para gestionar el final de la partida
Debug *debug; // Objeto para getsionar la información de debug Debug *debug; // Objeto para getsionar la información de debug
struct options_t *options; // Variable con todas las opciones del programa struct options_t *options; // Variable con todas las opciones del programa
section_t *section; // Sección y subsección actual del programa;
// Variables // Variables
section_t section; // Sección y subsección actual del programa; JA_Music_t *music; // Musica del titulo
JA_Music_t* music; // Musica del titulo
std::string executablePath; // Path del ejecutable std::string executablePath; // Path del ejecutable
std::string systemFolder; // Carpeta del sistema donde guardar datos std::string systemFolder; // Carpeta del sistema donde guardar datos
@@ -69,10 +69,10 @@ private:
bool saveConfig(); bool saveConfig();
// Crea la carpeta del sistema donde guardar datos // Crea la carpeta del sistema donde guardar datos
void createSystemFolder(); void createSystemFolder(std::string folder);
// Carga los recursos // Carga los recursos
void loadResources(section_t section); void loadResources(section_t *section);
// Asigna variables a partir de dos cadenas // Asigna variables a partir de dos cadenas
bool setOptions(options_t *options, std::string var, std::string value); bool setOptions(options_t *options, std::string var, std::string value);
@@ -89,15 +89,6 @@ private:
// Crea el indice de ficheros // Crea el indice de ficheros
bool setFileList(); bool setFileList();
// Obtiene el valor de la variable
Uint8 getSubsection();
// Obtiene el valor de la variable
Uint8 getSection();
// Establece el valor de la variable
void setSection(section_t section);
// Ejecuta la seccion de juego con el logo // Ejecuta la seccion de juego con el logo
void runLogo(); void runLogo();

View File

@@ -1,14 +1,16 @@
#include "ending.h" #include "ending.h"
// Constructor // Constructor
Ending::Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options) Ending::Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section)
{ {
// Copia los punteros // Copia los punteros
this->renderer = renderer; this->renderer = renderer;
this->screen = screen; this->screen = screen;
this->resource = resource; this->resource = resource;
this->asset = asset; this->asset = asset;
this->input = input;
this->options = options; this->options = options;
this->section = section;
// Reserva memoria para los punteros a objetos // Reserva memoria para los punteros a objetos
eventHandler = new SDL_Event(); eventHandler = new SDL_Event();
@@ -19,8 +21,8 @@ Ending::Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset
counter = -1; counter = -1;
preCounter = 0; preCounter = 0;
coverCounter = 0; coverCounter = 0;
section.name = SECTION_PROG_ENDING; section->name = SECTION_PROG_ENDING;
section.subsection = 0; section->subsection = 0;
ticks = 0; ticks = 0;
ticksSpeed = 15; ticksSpeed = 15;
scene = 0; scene = 0;
@@ -83,14 +85,17 @@ Ending::~Ending()
// Actualiza el objeto // Actualiza el objeto
void Ending::update() void Ending::update()
{ {
// Comprueba el manejador de eventos
checkEventHandler();
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego // Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
if (SDL_GetTicks() - ticks > ticksSpeed) if (SDL_GetTicks() - ticks > ticksSpeed)
{ {
// Actualiza el contador de ticks // Actualiza el contador de ticks
ticks = SDL_GetTicks(); ticks = SDL_GetTicks();
// Comprueba el manejador de eventos // Comprueba las entradas
checkEventHandler(); checkInput();
// Actualiza el contador // Actualiza el contador
updateCounters(); updateCounters();
@@ -150,57 +155,45 @@ void Ending::checkEventHandler()
// Evento de salida de la aplicación // Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT) if (eventHandler->type == SDL_QUIT)
{ {
section.name = SECTION_PROG_QUIT; section->name = SECTION_PROG_QUIT;
break; break;
} }
}
}
// Comprueba las teclas que se han pulsado // Comprueba las entradas
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN)) void Ending::checkInput()
{ {
switch (eventHandler->key.keysym.scancode)
{
case SDL_SCANCODE_ESCAPE:
section.name = SECTION_PROG_QUIT;
break;
case SDL_SCANCODE_B: if (input->checkInput(input_exit, REPEAT_FALSE))
screen->switchBorder(); {
resource->reLoadTextures(); section->name = SECTION_PROG_LOGO;
break; section->subsection = SUBSECTION_LOGO_TO_INTRO;
}
case SDL_SCANCODE_F: else if (input->checkInput(input_toggle_border, REPEAT_FALSE))
screen->switchVideoMode(); {
resource->reLoadTextures(); screen->switchBorder();
break; }
case SDL_SCANCODE_F1: else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
screen->setWindowSize(1); {
resource->reLoadTextures(); screen->switchVideoMode();
break; }
case SDL_SCANCODE_F2: else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
screen->setWindowSize(2); {
resource->reLoadTextures(); screen->decWindowSize();
break; }
case SDL_SCANCODE_F3: else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
screen->setWindowSize(3); {
resource->reLoadTextures(); screen->incWindowSize();
break; }
case SDL_SCANCODE_F4: else if (input->checkInput(input_swap_palette, REPEAT_FALSE))
screen->setWindowSize(4); {
resource->reLoadTextures(); switchPalette();
break;
case SDL_SCANCODE_F5:
switchPalette();
break;
default:
break;
}
}
} }
} }
@@ -482,11 +475,11 @@ void Ending::iniScenes()
} }
// Bucle principal // Bucle principal
section_t Ending::run() void Ending::run()
{ {
JA_PlayMusic(music); JA_PlayMusic(music);
while (section.name == SECTION_PROG_ENDING) while (section->name == SECTION_PROG_ENDING)
{ {
update(); update();
render(); render();
@@ -494,8 +487,6 @@ section_t Ending::run()
JA_StopMusic(); JA_StopMusic();
JA_SetVolume(128); JA_SetVolume(128);
return section;
} }
// Actualiza los contadores // Actualiza los contadores
@@ -571,7 +562,7 @@ void Ending::checkChangeScene()
if (scene == 5) if (scene == 5)
{ {
// Termina el bucle // Termina el bucle
section.name = SECTION_PROG_ENDING2; section->name = SECTION_PROG_ENDING2;
// Mantiene los valores anteriores // Mantiene los valores anteriores
scene = 4; scene = 4;

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include "common/asset.h" #include "common/asset.h"
#include "common/input.h"
#include "common/jail_audio.h" #include "common/jail_audio.h"
#include "common/resource.h" #include "common/resource.h"
#include "common/screen.h" #include "common/screen.h"
@@ -54,23 +55,24 @@ private:
Screen *screen; // Objeto encargado de dibujar en pantalla Screen *screen; // Objeto encargado de dibujar en pantalla
Resource *resource; // Objeto con los recursos Resource *resource; // Objeto con los recursos
Asset *asset; // Objeto con los ficheros de recursos Asset *asset; // Objeto con los ficheros de recursos
Input *input; // Objeto pata gestionar la entrada
options_t *options; // Puntero a las opciones del juego options_t *options; // Puntero a las opciones del juego
SDL_Event *eventHandler; // Manejador de eventos SDL_Event *eventHandler; // Manejador de eventos
Text *text; // Objeto para escribir texto en pantalla Text *text; // Objeto para escribir texto en pantalla
SDL_Texture *coverTexture; // Textura para cubrir el texto SDL_Texture *coverTexture; // Textura para cubrir el texto
section_t *section; // Estado del bucle principal para saber si continua o se sale
// Variables // Variables
int counter; // Contador int counter; // Contador
int preCounter; // Contador previo int preCounter; // Contador previo
int coverCounter; // Contador para la cortinilla int coverCounter; // Contador para la cortinilla
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 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
std::vector<endingTexture_t> spriteTexts; // Vector con los sprites de texto con su cortinilla std::vector<endingTexture_t> spriteTexts; // Vector con los sprites de texto con su cortinilla
std::vector<endingTexture_t> spritePics; // Vector con los sprites de texto con su cortinilla std::vector<endingTexture_t> spritePics; // Vector con los sprites de texto con su cortinilla
int scene; // Escena actual int scene; // Escena actual
std::vector<scene_t> scenes; // Vector con los textos e imagenes de cada escena std::vector<scene_t> scenes; // Vector con los textos e imagenes de cada escena
JA_Music_t* music; // Musica que suena durante el final JA_Music_t *music; // Musica que suena durante el final
// Actualiza el objeto // Actualiza el objeto
void update(); void update();
@@ -81,6 +83,9 @@ private:
// Comprueba el manejador de eventos // Comprueba el manejador de eventos
void checkEventHandler(); void checkEventHandler();
// Comprueba las entradas
void checkInput();
// Inicializa los textos // Inicializa los textos
void iniTexts(); void iniTexts();
@@ -113,13 +118,13 @@ private:
public: public:
// Constructor // Constructor
Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options); Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section);
// Destructor // Destructor
~Ending(); ~Ending();
// Bucle principal // Bucle principal
section_t run(); void run();
}; };
#endif #endif

View File

@@ -2,14 +2,16 @@
#include <algorithm> #include <algorithm>
// Constructor // Constructor
Ending2::Ending2(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options) Ending2::Ending2(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section)
{ {
// Copia los punteros // Copia los punteros
this->renderer = renderer; this->renderer = renderer;
this->screen = screen; this->screen = screen;
this->resource = resource; this->resource = resource;
this->asset = asset; this->asset = asset;
this->input = input;
this->options = options; this->options = options;
this->section = section;
// Reserva memoria para los punteros a objetos // Reserva memoria para los punteros a objetos
eventHandler = new SDL_Event(); eventHandler = new SDL_Event();
@@ -21,8 +23,8 @@ Ending2::Ending2(SDL_Renderer *renderer, Screen *screen, Resource *resource, Ass
preCounter = 0; preCounter = 0;
postCounter = 0; postCounter = 0;
postCounterEnabled = false; postCounterEnabled = false;
section.name = SECTION_PROG_ENDING2; section->name = SECTION_PROG_ENDING2;
section.subsection = 0; section->subsection = 0;
ticks = 0; ticks = 0;
ticksSpeed = 15; ticksSpeed = 15;
distSpriteText = 8; distSpriteText = 8;
@@ -73,14 +75,17 @@ Ending2::~Ending2()
// Actualiza el objeto // Actualiza el objeto
void Ending2::update() void Ending2::update()
{ {
// Comprueba el manejador de eventos
checkEventHandler();
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego // Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
if (SDL_GetTicks() - ticks > ticksSpeed) if (SDL_GetTicks() - ticks > ticksSpeed)
{ {
// Actualiza el contador de ticks // Actualiza el contador de ticks
ticks = SDL_GetTicks(); ticks = SDL_GetTicks();
// Comprueba el manejador de eventos // Comprueba las entradas
checkEventHandler(); checkInput();
// Actualiza los contadores // Actualiza los contadores
updateCounters(); updateCounters();
@@ -184,66 +189,54 @@ void Ending2::checkEventHandler()
// Evento de salida de la aplicación // Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT) if (eventHandler->type == SDL_QUIT)
{ {
section.name = SECTION_PROG_QUIT; section->name = SECTION_PROG_QUIT;
break; break;
} }
}
// Comprueba las teclas que se han pulsado }
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
{ // Comprueba las entradas
switch (eventHandler->key.keysym.scancode) void Ending2::checkInput()
{ {
case SDL_SCANCODE_ESCAPE:
section.name = SECTION_PROG_QUIT; if (input->checkInput(input_exit, REPEAT_FALSE))
break; {
section->name = SECTION_PROG_LOGO;
case SDL_SCANCODE_B: section->subsection = SUBSECTION_LOGO_TO_INTRO;
screen->switchBorder(); }
resource->reLoadTextures();
break; else if (input->checkInput(input_toggle_border, REPEAT_FALSE))
{
case SDL_SCANCODE_F: screen->switchBorder();
screen->switchVideoMode(); }
resource->reLoadTextures();
break; else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
{
case SDL_SCANCODE_F1: screen->switchVideoMode();
screen->setWindowSize(1); }
resource->reLoadTextures();
break; else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
{
case SDL_SCANCODE_F2: screen->decWindowSize();
screen->setWindowSize(2); }
resource->reLoadTextures();
break; else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
{
case SDL_SCANCODE_F3: screen->incWindowSize();
screen->setWindowSize(3); }
resource->reLoadTextures();
break; else if (input->checkInput(input_swap_palette, REPEAT_FALSE))
{
case SDL_SCANCODE_F4: switchPalette();
screen->setWindowSize(4);
resource->reLoadTextures();
break;
case SDL_SCANCODE_F5:
switchPalette();
break;
default:
break;
}
}
} }
} }
// Bucle principal // Bucle principal
section_t Ending2::run() void Ending2::run()
{ {
JA_PlayMusic(music); JA_PlayMusic(music);
while (section.name == SECTION_PROG_ENDING2) while (section->name == SECTION_PROG_ENDING2)
{ {
update(); update();
render(); render();
@@ -251,8 +244,6 @@ section_t Ending2::run()
JA_StopMusic(); JA_StopMusic();
JA_SetVolume(128); JA_SetVolume(128);
return section;
} }
// Actualiza los contadores // Actualiza los contadores
@@ -275,8 +266,8 @@ void Ending2::updateCounters()
if (postCounter > 600) if (postCounter > 600)
{ {
section.name = SECTION_PROG_LOGO; section->name = SECTION_PROG_LOGO;
section.subsection = SUBSECTION_LOGO_TO_INTRO; section->subsection = SUBSECTION_LOGO_TO_INTRO;
} }
} }

View File

@@ -2,6 +2,7 @@
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include "common/animatedsprite.h" #include "common/animatedsprite.h"
#include "common/asset.h" #include "common/asset.h"
#include "common/input.h"
#include "common/jail_audio.h" #include "common/jail_audio.h"
#include "common/resource.h" #include "common/resource.h"
#include "common/screen.h" #include "common/screen.h"
@@ -25,21 +26,22 @@ private:
Screen *screen; // Objeto encargado de dibujar en pantalla Screen *screen; // Objeto encargado de dibujar en pantalla
SDL_Event *eventHandler; // Manejador de eventos SDL_Event *eventHandler; // Manejador de eventos
SDL_Renderer *renderer; // El renderizador de la ventana SDL_Renderer *renderer; // El renderizador de la ventana
Input *input; // Objeto pata gestionar la entrada
Text *text; // Objeto para escribir texto en pantalla Text *text; // Objeto para escribir texto en pantalla
options_t *options; // Puntero a las opciones del juego options_t *options; // Puntero a las opciones del juego
std::vector<AnimatedSprite *> sprites; // Vector con todos los sprites a dibujar std::vector<AnimatedSprite *> sprites; // Vector con todos los sprites a dibujar
std::vector<MovingSprite *> spriteTexts; // Vector con los sprites de texto de los sprites std::vector<MovingSprite *> spriteTexts; // Vector con los sprites de texto de los sprites
std::vector<MovingSprite *> texts; // Vector con los sprites de texto std::vector<MovingSprite *> texts; // Vector con los sprites de texto
section_t *section; // Estado del bucle principal para saber si continua o se sale
// Variables // Variables
bool counterEnabled; // Indica si está el contador habilitado bool counterEnabled; // Indica si está el contador habilitado
int preCounter; // Contador previo int preCounter; // Contador previo
int postCounter; // Contador posterior int postCounter; // Contador posterior
bool postCounterEnabled; // Indica si está habilitado el contador bool postCounterEnabled; // Indica si está habilitado el 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 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
JA_Music_t* music; // Musica que suena durante el final JA_Music_t *music; // Musica que suena durante el final
std::vector<std::string> spriteList; // Lista con todos los sprites a dibujar std::vector<std::string> spriteList; // Lista con todos los sprites a dibujar
std::vector<color_t> colors; // Vector con los colores para el fade std::vector<color_t> colors; // Vector con los colores para el fade
int maxSpriteWidth; // El valor de ancho del sprite mas ancho int maxSpriteWidth; // El valor de ancho del sprite mas ancho
@@ -59,6 +61,9 @@ private:
// Comprueba el manejador de eventos // Comprueba el manejador de eventos
void checkEventHandler(); void checkEventHandler();
// Comprueba las entradas
void checkInput();
// Actualiza los contadores // Actualiza los contadores
void updateCounters(); void updateCounters();
@@ -115,13 +120,13 @@ private:
public: public:
// Constructor // Constructor
Ending2(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options); Ending2(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section);
// Destructor // Destructor
~Ending2(); ~Ending2();
// Bucle principal // Bucle principal
section_t run(); void run();
}; };
#endif #endif

View File

@@ -5,13 +5,14 @@
#include <iostream> #include <iostream>
// Constructor // Constructor
EnterID::EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options, section_t section) EnterID::EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options, section_t *section)
{ {
// Copia la dirección de los objetos // Copia la dirección de los objetos
this->renderer = renderer; this->renderer = renderer;
this->screen = screen; this->screen = screen;
this->asset = asset; this->asset = asset;
this->options = options; this->options = options;
this->section = section;
// Reserva memoria para los punteros // Reserva memoria para los punteros
eventHandler = new SDL_Event(); eventHandler = new SDL_Event();
@@ -36,11 +37,10 @@ EnterID::EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t
pos = 0; pos = 0;
name[pos] = 0; name[pos] = 0;
maxLenght = 15; maxLenght = 15;
this->section.subsection = section.subsection;
if (options->online.enabled && options->online.jailerID == "") if (options->online.enabled && options->online.jailerID == "")
{ {
this->section.name = SECTION_PROG_ENTER_ID; this->section->name = SECTION_PROG_ENTER_ID;
} }
else else
{ {
@@ -60,18 +60,16 @@ EnterID::~EnterID()
} }
// Bucle para el logo del juego // Bucle para el logo del juego
section_t EnterID::run() void EnterID::run()
{ {
// Detiene la música // Detiene la música
JA_StopMusic(); JA_StopMusic();
while (section.name == SECTION_PROG_ENTER_ID) while (section->name == SECTION_PROG_ENTER_ID)
{ {
update(); update();
render(); render();
} }
return section;
} }
// Comprueba el manejador de eventos // Comprueba el manejador de eventos
@@ -83,7 +81,7 @@ void EnterID::checkEventHandler()
// Evento de salida de la aplicación // Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT) if (eventHandler->type == SDL_QUIT)
{ {
section.name = SECTION_PROG_QUIT; section->name = SECTION_PROG_QUIT;
break; break;
} }
@@ -138,7 +136,7 @@ void EnterID::checkEventHandler()
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;
break; break;
} }
@@ -298,11 +296,11 @@ void EnterID::initOnline()
jscore::init(options->online.server, options->online.port); jscore::init(options->online.server, options->online.port);
#ifdef DEBUG #ifdef DEBUG
const std::string caption = options->online.jailerID + " IS LOGGED IN (DEBUG)"; const std::string caption = "IS LOGGED IN (DEBUG)";
#else #else
const std::string caption = options->online.jailerID + " IS LOGGED IN"; const std::string caption = "IS LOGGED IN";
#endif #endif
screen->showNotification(caption); screen->showNotification(options->online.jailerID, caption, 12);
if (options->console) if (options->console)
{ {
std::cout << caption << std::endl; std::cout << caption << std::endl;
@@ -314,6 +312,6 @@ void EnterID::initOnline()
void EnterID::endSection() void EnterID::endSection()
{ {
initOnline(); initOnline();
section.name = (section.subsection == SUBSECTION_LOGO_TO_INTRO) ? SECTION_PROG_INTRO : SECTION_PROG_TITLE; section->name = (section->subsection == SUBSECTION_LOGO_TO_INTRO) ? SECTION_PROG_INTRO : SECTION_PROG_TITLE;
section.subsection = 0; section->subsection = 0;
} }

View File

@@ -29,10 +29,10 @@ private:
SDL_Texture *textTexture; // Textura para dibujar el texto SDL_Texture *textTexture; // Textura para dibujar el texto
Text *text; // Objeto para escribir texto en pantalla Text *text; // Objeto para escribir texto en pantalla
Texture *texture; // Textura para la fuente para el texto Texture *texture; // Textura para la fuente para el texto
section_t *section; // Estado del bucle principal para saber si continua o se sale
// Variables // Variables
int counter; // Contador 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 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
std::vector<captions_t> texts; // Vector con los textos std::vector<captions_t> texts; // Vector con los textos
@@ -68,13 +68,13 @@ private:
public: public:
// Constructor // Constructor
EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options, section_t section); EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options, section_t *section);
// Destructor // Destructor
~EnterID(); ~EnterID();
// Bucle principal // Bucle principal
section_t run(); void run();
}; };
#endif #endif

View File

@@ -2,15 +2,8 @@
#include <iostream> #include <iostream>
// Constructor // Constructor
Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Input *input, Debug *debug) Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Input *input, section_t *section, Debug *debug)
{ {
// Inicia algunas variables
board.iniClock = SDL_GetTicks();
currentRoom = "03.room";
const int x = 25;
const int y = 13;
spawnPoint = {x * 8, y * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
// Copia los punteros // Copia los punteros
this->resource = resource; this->resource = resource;
this->renderer = renderer; this->renderer = renderer;
@@ -19,15 +12,25 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
this->input = input; this->input = input;
this->debug = debug; this->debug = debug;
this->options = options; this->options = options;
this->section = section;
// Inicia algunas variables
board.iniClock = SDL_GetTicks();
#ifdef DEBUG #ifdef DEBUG
currentRoom = "01.room"; currentRoom = "03.room";
const int x1 = 25; const int x = 25;
const int y1 = 13; const int y = 13;
spawnPoint = {x1 * 8, y1 * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL}; spawnPoint = {x * 8, y * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
debug->setEnabled(false);
#else
currentRoom = "03.room";
const int x = 25;
const int y = 13;
spawnPoint = {x * 8, y * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
#endif #endif
// Crea los objetos // Crea los objetos
cheevos = new Cheevos(screen, options, asset->get("cheevos.bin"));
scoreboard = new ScoreBoard(renderer, resource, asset, options, &board); scoreboard = new ScoreBoard(renderer, resource, asset, options, &board);
itemTracker = new ItemTracker(); itemTracker = new ItemTracker();
roomTracker = new RoomTracker(); roomTracker = new RoomTracker();
@@ -80,14 +83,17 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
totalItems = getTotalItems(); totalItems = getTotalItems();
initStats(); initStats();
stats->addVisit(room->getName()); stats->addVisit(room->getName());
const bool cheats = options->cheat.infiniteLives || options->cheat.invincible || options->cheat.jailEnabled;
cheevos->enable(!cheats); // Deshabilita los logros si hay trucos activados
section.name = SECTION_PROG_GAME; section->name = SECTION_PROG_GAME;
section.subsection = 0; section->subsection = 0;
} }
Game::~Game() Game::~Game()
{ {
// Libera la memoria de los objetos // Libera la memoria de los objetos
delete cheevos;
delete scoreboard; delete scoreboard;
delete itemTracker; delete itemTracker;
delete roomTracker; delete roomTracker;
@@ -112,7 +118,7 @@ void Game::checkEventHandler()
// Evento de salida de la aplicación // Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT) if (eventHandler->type == SDL_QUIT)
{ {
section.name = SECTION_PROG_QUIT; section->name = SECTION_PROG_QUIT;
screen->setBorderColor(stringToColor(options->palette, "black")); screen->setBorderColor(stringToColor(options->palette, "black"));
break; break;
} }
@@ -122,13 +128,10 @@ void Game::checkEventHandler()
reLoadTextures(); reLoadTextures();
} }
if ((eventHandler->type == SDL_KEYDOWN) and (eventHandler->key.repeat == 0)) if (eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0)
{ {
switch (eventHandler->key.keysym.scancode) switch (eventHandler->key.keysym.scancode)
{ {
case SDL_SCANCODE_ESCAPE:
section.name = SECTION_PROG_TITLE;
break;
#ifdef DEBUG #ifdef DEBUG
case SDL_SCANCODE_G: case SDL_SCANCODE_G:
debug->switchEnabled(); debug->switchEnabled();
@@ -158,53 +161,21 @@ void Game::checkEventHandler()
break; break;
case SDL_SCANCODE_F6: case SDL_SCANCODE_F6:
screen->showNotification("MAMA MIRA! SIN MANOS!"); screen->showNotification("ACHIEVEMENT UNLOCKED!", "I LIKE MY MULTICOLOURED FRIENDS", 2);
break;
case SDL_SCANCODE_F7:
screen->showNotification("ACHIEVEMENT UNLOCKED!", "I LIKE MY MULTICOLOURED FRIENDS", 3);
break;
case SDL_SCANCODE_F8:
screen->showNotification("JAILDESIGNER IS LOGGED IN", "", 4);
break;
case SDL_SCANCODE_F9:
screen->showNotification("JAILDESIGNER IS LOGGED IN", "", 5);
break; break;
#endif #endif
case SDL_SCANCODE_M:
board.music = !board.music;
board.music ? JA_ResumeMusic() : JA_PauseMusic();
break;
case SDL_SCANCODE_H:
switchPause();
break;
case SDL_SCANCODE_B:
screen->switchBorder();
reLoadTextures();
break;
case SDL_SCANCODE_F:
screen->switchVideoMode();
reLoadTextures();
break;
case SDL_SCANCODE_F1:
screen->setWindowSize(1);
reLoadTextures();
break;
case SDL_SCANCODE_F2:
screen->setWindowSize(2);
reLoadTextures();
break;
case SDL_SCANCODE_F3:
screen->setWindowSize(3);
reLoadTextures();
break;
case SDL_SCANCODE_F4:
screen->setWindowSize(4);
reLoadTextures();
break;
case SDL_SCANCODE_F5:
switchPalette();
break;
default: default:
break; break;
} }
@@ -212,8 +183,57 @@ void Game::checkEventHandler()
} }
} }
// Comprueba el teclado
void Game::checkInput()
{
if (input->checkInput(input_exit, REPEAT_FALSE))
{
section->name = SECTION_PROG_TITLE;
}
else if (input->checkInput(input_switch_music, REPEAT_FALSE))
{
board.music = !board.music;
board.music ? JA_ResumeMusic() : JA_PauseMusic();
}
else if (input->checkInput(input_pause, REPEAT_FALSE))
{
switchPause();
}
else if (input->checkInput(input_toggle_border, REPEAT_FALSE))
{
screen->switchBorder();
reLoadTextures();
}
else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
{
screen->switchVideoMode();
reLoadTextures();
}
else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
{
screen->decWindowSize();
reLoadTextures();
}
else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
{
screen->incWindowSize();
reLoadTextures();
}
else if (input->checkInput(input_swap_palette, REPEAT_FALSE))
{
switchPalette();
}
}
// Bucle para el juego // Bucle para el juego
section_t Game::run() void Game::run()
{ {
JA_PlayMusic(music); JA_PlayMusic(music);
if (!board.music) if (!board.music)
@@ -221,28 +241,29 @@ section_t Game::run()
JA_PauseMusic(); JA_PauseMusic();
} }
while (section.name == SECTION_PROG_GAME) while (section->name == SECTION_PROG_GAME)
{ {
update(); update();
render(); render();
} }
JA_StopMusic(); JA_StopMusic();
return section;
} }
// Actualiza el juego, las variables, comprueba la entrada, etc. // Actualiza el juego, las variables, comprueba la entrada, etc.
void Game::update() void Game::update()
{ {
// Comprueba los eventos de la cola
checkEventHandler();
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego // Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
if (SDL_GetTicks() - ticks > ticksSpeed) if (SDL_GetTicks() - ticks > ticksSpeed)
{ {
// Actualiza el contador de ticks // Actualiza el contador de ticks
ticks = SDL_GetTicks(); ticks = SDL_GetTicks();
// Comprueba los eventos de la cola // Comprueba el teclado
checkEventHandler(); checkInput();
#ifdef DEBUG #ifdef DEBUG
debug->clear(); debug->clear();
@@ -258,6 +279,7 @@ void Game::update()
checkGameOver(); checkGameOver();
checkEndGame(); checkEndGame();
checkRestoringJail(); checkRestoringJail();
checkSomeCheevos();
scoreboard->update(); scoreboard->update();
input->update(); input->update();
@@ -432,7 +454,7 @@ void Game::checkGameOver()
{ {
if (board.lives < 0 && blackScreenCounter > 17) if (board.lives < 0 && blackScreenCounter > 17)
{ {
section.name = SECTION_PROG_GAME_OVER; section->name = SECTION_PROG_GAME_OVER;
} }
} }
@@ -453,6 +475,9 @@ void Game::killPlayer()
// Actualiza las estadisticas // Actualiza las estadisticas
stats->addDeath(room->getName()); stats->addDeath(room->getName());
// Invalida el logro de pasarse el juego sin morir
cheevos->invalidate(11);
// Destruye la habitacion y el jugador // Destruye la habitacion y el jugador
delete room; delete room;
delete this->player; delete this->player;
@@ -569,7 +594,10 @@ bool Game::checkEndGame()
if (haveTheItems && isOnTheRoom && isOnTheDoor) if (haveTheItems && isOnTheRoom && isOnTheDoor)
{ {
section.name = SECTION_PROG_ENDING; // Comprueba los logros de completar el juego
checkEndGameCheevos();
section->name = SECTION_PROG_ENDING;
return true; return true;
} }
@@ -635,11 +663,19 @@ void Game::checkRestoringJail()
counter++; counter++;
} }
// Incrementa el numero de vidas
if (counter == 100) if (counter == 100)
{ {
counter = 0; counter = 0;
board.lives++; board.lives++;
JA_PlaySound(deathSound); JA_PlaySound(deathSound);
// Invalida el logro de completar el juego sin entrar a la jail
const bool haveTheItems = board.items >= int(totalItems * 0.9f);
if (!haveTheItems)
{
cheevos->invalidate(9);
}
} }
} }
@@ -674,3 +710,73 @@ void Game::fillRoomNameTexture()
// Deja el renderizador por defecto // Deja el renderizador por defecto
SDL_SetRenderTarget(renderer, nullptr); SDL_SetRenderTarget(renderer, nullptr);
} }
// Comprueba algunos logros
void Game::checkSomeCheevos()
{
// Logros sobre la cantidad de items
if (board.items == totalItems)
{
cheevos->unlock(4);
cheevos->unlock(3);
cheevos->unlock(2);
cheevos->unlock(1);
}
else if (board.items >= totalItems * 0.75f)
{
cheevos->unlock(3);
cheevos->unlock(2);
cheevos->unlock(1);
}
else if (board.items >= totalItems * 0.5f)
{
cheevos->unlock(2);
cheevos->unlock(1);
}
else if (board.items >= totalItems * 0.25f)
{
cheevos->unlock(1);
}
// Logros sobre las habitaciones visitadas
if (board.rooms >= 60)
{
cheevos->unlock(7);
cheevos->unlock(6);
cheevos->unlock(5);
}
else if (board.rooms >= 40)
{
cheevos->unlock(6);
cheevos->unlock(5);
}
else if (board.rooms >= 20)
{
cheevos->unlock(5);
}
}
// Comprueba los logros de completar el juego
void Game::checkEndGameCheevos()
{
// "Complete the game"
cheevos->unlock(8);
// "Complete the game without entering the jail"
cheevos->unlock(9);
// "Complete the game with all items"
if (board.items == totalItems)
{
cheevos->unlock(10);
}
// "Complete the game without dying"
cheevos->unlock(11);
// "Complete the game in under 30 minutes"
if (scoreboard->getMinutes() < 30)
{
cheevos->unlock(12);
}
}

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include "cheevos.h"
#include "common/animatedsprite.h" #include "common/animatedsprite.h"
#include "common/asset.h" #include "common/asset.h"
#include "common/debug.h" #include "common/debug.h"
@@ -37,17 +38,18 @@ private:
Input *input; // Objeto pata gestionar la entrada Input *input; // Objeto pata gestionar la entrada
Text *text; // Objeto para los textos del juego Text *text; // Objeto para los textos del juego
ScoreBoard *scoreboard; // Objeto encargado de gestionar el marcador ScoreBoard *scoreboard; // Objeto encargado de gestionar el marcador
Cheevos *cheevos; // Objeto encargado de gestionar los logros del juego
Resource *resource; // Objeto con los recursos Resource *resource; // Objeto con los recursos
Debug *debug; // Objeto para gestionar la información de debug Debug *debug; // Objeto para gestionar la información de debug
options_t *options; // Puntero a las opciones del juego options_t *options; // Puntero a las opciones del juego
Stats *stats; // Objeto encargado de gestionar las estadísticas Stats *stats; // Objeto encargado de gestionar las estadísticas
SDL_Texture *roomNameTexture; // Textura para escribir el nombre de la habitación SDL_Texture *roomNameTexture; // Textura para escribir el nombre de la habitación
section_t *section; // Seccion actual dentro del juego
// Variables // Variables
JA_Music_t *music; // Musica que suena durante el juego JA_Music_t *music; // Musica que suena durante el juego
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
section_t section; // Seccion actual dentro del juego
std::string currentRoom; // Fichero de la habitación actual std::string currentRoom; // Fichero de la habitación actual
playerSpawn_t spawnPoint; // Lugar de la habitación donde aparece el jugador playerSpawn_t spawnPoint; // Lugar de la habitación donde aparece el jugador
JA_Sound_t *deathSound; // Sonido a reproducir cuando muere el jugador JA_Sound_t *deathSound; // Sonido a reproducir cuando muere el jugador
@@ -81,6 +83,9 @@ private:
// Cambia de habitación // Cambia de habitación
bool changeRoom(std::string file); bool changeRoom(std::string file);
// Comprueba el teclado
void checkInput();
// Comprueba si el jugador esta en el borde de la pantalla y actua // Comprueba si el jugador esta en el borde de la pantalla y actua
void checkPlayerOnBorder(); void checkPlayerOnBorder();
@@ -138,15 +143,21 @@ private:
// Pone el nombre de la habitación en la textura // Pone el nombre de la habitación en la textura
void fillRoomNameTexture(); void fillRoomNameTexture();
// Comprueba algunos logros
void checkSomeCheevos();
// Comprueba los logros de completar el juego
void checkEndGameCheevos();
public: public:
// Constructor // Constructor
Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Input *input, Debug *debug); Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Input *input, section_t *section, Debug *debug);
// Destructor // Destructor
~Game(); ~Game();
// Bucle para el juego // Bucle para el juego
section_t run(); void run();
}; };
#endif #endif

View File

@@ -1,14 +1,16 @@
#include "game_over.h" #include "game_over.h"
// Constructor // Constructor
GameOver::GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options) GameOver::GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section)
{ {
// Copia los punteros // Copia los punteros
this->renderer = renderer; this->renderer = renderer;
this->screen = screen; this->screen = screen;
this->resource = resource; this->resource = resource;
this->asset = asset; this->asset = asset;
this->input = input;
this->options = options; this->options = options;
this->section = section;
// Reserva memoria para los punteros a objetos // Reserva memoria para los punteros a objetos
eventHandler = new SDL_Event(); eventHandler = new SDL_Event();
@@ -20,8 +22,8 @@ GameOver::GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, A
// Inicializa variables // Inicializa variables
preCounter = 0; preCounter = 0;
counter = 0; counter = 0;
section.name = SECTION_PROG_GAME_OVER; section->name = SECTION_PROG_GAME_OVER;
section.subsection = 0; section->subsection = 0;
ticks = 0; ticks = 0;
ticksSpeed = 15; ticksSpeed = 15;
endSection = 400; endSection = 400;
@@ -55,14 +57,17 @@ GameOver::~GameOver()
// Actualiza el objeto // Actualiza el objeto
void GameOver::update() void GameOver::update()
{ {
// Comprueba el manejador de eventos
checkEventHandler();
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego // Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
if (SDL_GetTicks() - ticks > ticksSpeed) if (SDL_GetTicks() - ticks > ticksSpeed)
{ {
// Actualiza el contador de ticks // Actualiza el contador de ticks
ticks = SDL_GetTicks(); ticks = SDL_GetTicks();
// Comprueba el manejador de eventos // Comprueba las entradas
checkEventHandler(); checkInput();
// Actualiza el color usado para renderizar los textos e imagenes // Actualiza el color usado para renderizar los textos e imagenes
updateColor(); updateColor();
@@ -121,71 +126,56 @@ void GameOver::checkEventHandler()
// Evento de salida de la aplicación // Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT) if (eventHandler->type == SDL_QUIT)
{ {
section.name = SECTION_PROG_QUIT; section->name = SECTION_PROG_QUIT;
section.subsection = 0; section->subsection = 0;
break; break;
} }
// Comprueba las teclas que se han pulsado
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
{
switch (eventHandler->key.keysym.scancode)
{
case SDL_SCANCODE_ESCAPE:
section.name = SECTION_PROG_QUIT;
break;
case SDL_SCANCODE_B:
screen->switchBorder();
resource->reLoadTextures();
break;
case SDL_SCANCODE_F:
screen->switchVideoMode();
resource->reLoadTextures();
break;
case SDL_SCANCODE_F1:
screen->setWindowSize(1);
resource->reLoadTextures();
break;
case SDL_SCANCODE_F2:
screen->setWindowSize(2);
resource->reLoadTextures();
break;
case SDL_SCANCODE_F3:
screen->setWindowSize(3);
resource->reLoadTextures();
break;
case SDL_SCANCODE_F4:
screen->setWindowSize(4);
resource->reLoadTextures();
break;
case SDL_SCANCODE_F5:
switchPalette();
break;
default:
break;
}
}
} }
} }
// Bucle principal // Comprueba las entradas
section_t GameOver::run() void GameOver::checkInput()
{ {
while (section.name == SECTION_PROG_GAME_OVER)
if (input->checkInput(input_exit, REPEAT_FALSE))
{
section->name = SECTION_PROG_QUIT;
}
else if (input->checkInput(input_toggle_border, REPEAT_FALSE))
{
screen->switchBorder();
}
else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
{
screen->switchVideoMode();
}
else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
{
screen->decWindowSize();
}
else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
{
screen->incWindowSize();
}
else if (input->checkInput(input_swap_palette, REPEAT_FALSE))
{
switchPalette();
}
}
// Bucle principal
void GameOver::run()
{
while (section->name == SECTION_PROG_GAME_OVER)
{ {
update(); update();
render(); render();
} }
return section;
} }
// Actualiza el color usado para renderizar los textos e imagenes // Actualiza el color usado para renderizar los textos e imagenes
@@ -195,7 +185,6 @@ void GameOver::updateColor()
if (counter < half) if (counter < half)
{ {
// const float step = std::min(std::max(counter, iniFade) - iniFade, fadeLenght) / (float)fadeLenght;
const float step = std::min(counter, fadeLenght) / (float)fadeLenght; const float step = std::min(counter, fadeLenght) / (float)fadeLenght;
const int index = (colors.size() - 1) - int((colors.size() - 1) * step); const int index = (colors.size() - 1) - int((colors.size() - 1) * step);
color = colors[index]; color = colors[index];
@@ -240,8 +229,8 @@ void GameOver::updateCounters()
// Comprueba si ha terminado la sección // Comprueba si ha terminado la sección
else if (counter == endSection) else if (counter == endSection)
{ {
section.name = SECTION_PROG_LOGO; section->name = SECTION_PROG_LOGO;
section.subsection = SUBSECTION_LOGO_TO_TITLE; section->subsection = SUBSECTION_LOGO_TO_TITLE;
} }
} }

View File

@@ -2,6 +2,7 @@
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include "common/animatedsprite.h" #include "common/animatedsprite.h"
#include "common/asset.h" #include "common/asset.h"
#include "common/input.h"
#include "common/jail_audio.h" #include "common/jail_audio.h"
#include "common/resource.h" #include "common/resource.h"
#include "common/screen.h" #include "common/screen.h"
@@ -23,16 +24,17 @@ private:
Screen *screen; // Objeto encargado de dibujar en pantalla Screen *screen; // Objeto encargado de dibujar en pantalla
Resource *resource; // Objeto con los recursos Resource *resource; // Objeto con los recursos
Asset *asset; // Objeto con los ficheros de recursos Asset *asset; // Objeto con los ficheros de recursos
Input *input; // Objeto pata gestionar la entrada
options_t *options; // Puntero a las opciones del juego options_t *options; // Puntero a las opciones del juego
SDL_Event *eventHandler; // Manejador de eventos SDL_Event *eventHandler; // Manejador de eventos
Text *text; // Objeto para escribir texto en pantalla Text *text; // Objeto para escribir texto en pantalla
AnimatedSprite *playerSprite; // Sprite con el jugador AnimatedSprite *playerSprite; // Sprite con el jugador
AnimatedSprite *tvSprite; // Sprite con el televisor AnimatedSprite *tvSprite; // Sprite con el televisor
section_t *section; // Estado del bucle principal para saber si continua o se sale
// Variables // Variables
int preCounter; // Contador previo int preCounter; // Contador previo
int counter; // Contador 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 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
std::vector<color_t> colors; // Vector con los colores para el fade std::vector<color_t> colors; // Vector con los colores para el fade
@@ -40,7 +42,7 @@ private:
int endSection; // Contador: cuando acaba la sección int endSection; // Contador: cuando acaba la sección
int iniFade; // Contador: cuando emiepza el fade int iniFade; // Contador: cuando emiepza el fade
int fadeLenght; // Contador: duración del fade int fadeLenght; // Contador: duración del fade
JA_Music_t* music; // Musica que suena durante el juego JA_Music_t *music; // Musica que suena durante el juego
// Actualiza el objeto // Actualiza el objeto
void update(); void update();
@@ -51,6 +53,9 @@ private:
// Comprueba el manejador de eventos // Comprueba el manejador de eventos
void checkEventHandler(); void checkEventHandler();
// Comprueba las entradas
void checkInput();
// Actualiza el color usado para renderizar los textos e imagenes // Actualiza el color usado para renderizar los textos e imagenes
void updateColor(); void updateColor();
@@ -65,13 +70,13 @@ private:
public: public:
// Constructor // Constructor
GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options); GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section);
// Destructor // Destructor
~GameOver(); ~GameOver();
// Bucle principal // Bucle principal
section_t run(); void run();
}; };
#endif #endif

View File

@@ -1,14 +1,16 @@
#include "intro.h" #include "intro.h"
// Constructor // Constructor
Intro::Intro(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options) Intro::Intro(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section)
{ {
// Copia la dirección de los objetos // Copia la dirección de los objetos
this->resource = resource; this->resource = resource;
this->renderer = renderer; this->renderer = renderer;
this->screen = screen; this->screen = screen;
this->asset = asset; this->asset = asset;
this->input = input;
this->options = options; this->options = options;
this->section = section;
// Reserva memoria para los punteros // Reserva memoria para los punteros
eventHandler = new SDL_Event(); eventHandler = new SDL_Event();
@@ -31,8 +33,8 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *
// Inicializa variables // Inicializa variables
preCounter = 0; preCounter = 0;
counter = 0; counter = 0;
section.name = SECTION_PROG_INTRO; section->name = SECTION_PROG_INTRO;
section.subsection = 0; section->subsection = 0;
ticks = 0; ticks = 0;
ticksSpeed = 15; ticksSpeed = 15;
loadCounter = 0; loadCounter = 0;
@@ -82,66 +84,57 @@ void Intro::checkEventHandler()
// Evento de salida de la aplicación // Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT) if (eventHandler->type == SDL_QUIT)
{ {
section.name = SECTION_PROG_QUIT; section->name = SECTION_PROG_QUIT;
break; break;
} }
}
}
// Comprueba las teclas que se han pulsado // Comprueba las entradas
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN)) void Intro::checkInput()
{ {
switch (eventHandler->key.keysym.scancode)
{
case SDL_SCANCODE_ESCAPE:
section.name = SECTION_PROG_QUIT;
break;
case SDL_SCANCODE_B: if (input->checkInput(input_exit, REPEAT_FALSE))
screen->switchBorder(); {
resource->reLoadTextures(); section->name = SECTION_PROG_QUIT;
break; }
case SDL_SCANCODE_F: else if (input->checkInput(input_toggle_border, REPEAT_FALSE))
screen->switchVideoMode(); {
resource->reLoadTextures(); screen->switchBorder();
break; }
case SDL_SCANCODE_F1: else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
screen->setWindowSize(1); {
resource->reLoadTextures(); screen->switchVideoMode();
break; }
case SDL_SCANCODE_F2: else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
screen->setWindowSize(2); {
resource->reLoadTextures(); screen->decWindowSize();
break; }
case SDL_SCANCODE_F3: else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
screen->setWindowSize(3); {
resource->reLoadTextures(); screen->incWindowSize();
break; }
case SDL_SCANCODE_F4: else if (input->checkInput(input_swap_palette, REPEAT_FALSE))
screen->setWindowSize(4); {
resource->reLoadTextures(); switchPalette();
break; }
case SDL_SCANCODE_F5: else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_jump, REPEAT_FALSE))
//switchPalette(); {
break; section->name = SECTION_PROG_TITLE;
section->subsection = 0;
default:
section.name = SECTION_PROG_TITLE;
section.subsection = 0;
break;
}
}
} }
} }
// Gestiona el contador de carga // Gestiona el contador de carga
void Intro::updateLoad() void Intro::updateLoad()
{ {
// Primera parte de la carga, la parte en blanco ynegro // Primera parte de la carga, la parte en blanco y negro
if (loadingFirstPart) if (loadingFirstPart)
{ {
// Cada 5 pasos el loadCounter se incrementa en uno // Cada 5 pasos el loadCounter se incrementa en uno
@@ -179,8 +172,8 @@ void Intro::updateLoad()
// Comprueba si ha terminado la intro // Comprueba si ha terminado la intro
if (loadCounter >= 768) if (loadCounter >= 768)
{ {
section.name = SECTION_PROG_TITLE; section->name = SECTION_PROG_TITLE;
section.subsection = 0; section->subsection = 0;
JA_StopMusic(); JA_StopMusic();
} }
} }
@@ -206,14 +199,17 @@ void Intro::renderLoad()
// Actualiza las variables // Actualiza las variables
void Intro::update() void Intro::update()
{ {
// Comprueba el manejador de eventos
checkEventHandler();
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego // Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
if (SDL_GetTicks() - ticks > ticksSpeed) if (SDL_GetTicks() - ticks > ticksSpeed)
{ {
// Actualiza el contador de ticks // Actualiza el contador de ticks
ticks = SDL_GetTicks(); ticks = SDL_GetTicks();
// Comprueba el manejador de eventos // Comprueba las entradas
checkEventHandler(); checkInput();
// Gestiona el contador interno // Gestiona el contador interno
updateCounter(); updateCounter();
@@ -240,20 +236,19 @@ void Intro::render()
} }
// Bucle para el logo del juego // Bucle para el logo del juego
section_t Intro::run() void Intro::run()
{ {
// Inicia el sonido de carga // Inicia el sonido de carga
JA_SetVolume(64); JA_SetVolume(64);
JA_PlayMusic(loadingSound1); JA_PlayMusic(loadingSound1);
while (section.name == SECTION_PROG_INTRO) while (section->name == SECTION_PROG_INTRO)
{ {
update(); update();
render(); render();
} }
JA_SetVolume(128); JA_SetVolume(128);
return section;
} }
// Cambia la paleta // Cambia la paleta
@@ -271,4 +266,45 @@ void Intro::switchPalette()
sprite1->setTexture(resource->getTexture("loading_screen_bn.png")); sprite1->setTexture(resource->getTexture("loading_screen_bn.png"));
sprite2->setTexture(resource->getTexture("loading_screen_color.png")); sprite2->setTexture(resource->getTexture("loading_screen_color.png"));
} }
recreateLoadingScreen();
}
// Reconstruye la pantalla de carga
void Intro::recreateLoadingScreen()
{
// Prepara para empezar a dibujar en la textura de juego
screen->start();
// Primera parte de la carga, la parte en blanco y negro
if (loadingFirstPart)
{
const int numSteps = 5;
const int step = 51;
for (int i = 0; i <= counter; i++)
{
loadCounter = i / numSteps;
loadRect.x = step * (i % numSteps);
loadRect.y = lineIndex[loadCounter];
sprite1->setSpriteClip(loadRect);
sprite1->setRect(loadRect);
sprite1->render();
}
}
// Segunda parte de la carga, la parte de los bloques en color
else
{
for (int i = 0; i <= loadCounter; i++)
{
loadRect.x = (i * 8) % 256;
loadRect.y = (i / 32) * 8;
sprite2->setSpriteClip(loadRect);
sprite2->setRect(loadRect);
sprite2->render();
}
}
// Vuelca el contenido del renderizador en pantalla
screen->blit();
} }

View File

@@ -2,6 +2,7 @@
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include "common/asset.h" #include "common/asset.h"
#include "common/input.h"
#include "common/jail_audio.h" #include "common/jail_audio.h"
#include "common/resource.h" #include "common/resource.h"
#include "common/screen.h" #include "common/screen.h"
@@ -24,26 +25,27 @@ private:
Screen *screen; // Objeto encargado de dibujar en pantalla Screen *screen; // Objeto encargado de dibujar en pantalla
Resource *resource; // Objeto con los recursos Resource *resource; // Objeto con los recursos
Asset *asset; // Objeto con los ficheros de recursos Asset *asset; // Objeto con los ficheros de recursos
Input *input; // Objeto pata gestionar la entrada
Texture *loadingScreenTexture1; // Textura con la pantalla de carga en blanco y negro Texture *loadingScreenTexture1; // Textura con la pantalla de carga en blanco y negro
Texture *loadingScreenTexture2; // Textura con la pantalla de carga en color Texture *loadingScreenTexture2; // Textura con la pantalla de carga en color
SDL_Event *eventHandler; // Manejador de eventos SDL_Event *eventHandler; // Manejador de eventos
Sprite *sprite1; // Sprite para manejar la textura loadingScreenTexture1 Sprite *sprite1; // Sprite para manejar la textura loadingScreenTexture1
Sprite *sprite2; // Sprite para manejar la textura loadingScreenTexture2 Sprite *sprite2; // Sprite para manejar la textura loadingScreenTexture2
options_t *options; // Puntero a las opciones del juego options_t *options; // Puntero a las opciones del juego
section_t *section; // Estado del bucle principal para saber si continua o se sale
// Variables // Variables
int preCounter; // Contador previo para realizar una pausa inicial int preCounter; // Contador previo para realizar una pausa inicial
int counter; // Contador 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 ticks; // Contador de ticks para ajustar la velocidad del programa Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa int loadCounter; // Contador para controlar las cargas
int loadCounter; // Contador para controlar las cargas bool loadingFirstPart; // Para saber en que parte de la carga se encuentra
bool loadingFirstPart; // Para saber en que parte de la carga se encuentra JA_Music_t *loadingSound1; // Sonidos para imitar la carga tipo spectrum
JA_Music_t* loadingSound1; // Sonidos para imitar la carga tipo spectrum JA_Music_t *loadingSound2; // Sonidos para imitar la carga tipo spectrum
JA_Music_t* loadingSound2; // Sonidos para imitar la carga tipo spectrum JA_Music_t *loadingSound3; // Sonidos para imitar la carga tipo spectrum
JA_Music_t* loadingSound3; // Sonidos para imitar la carga tipo spectrum int lineIndex[192]; // El orden en el que se procesan las 192 lineas de la pantalla de carga
int lineIndex[192]; // El orden en el que se procesan las 192 lineas de la pantalla de carga SDL_Rect loadRect; // Rectangulo para dibujar la pantalla de carga
SDL_Rect loadRect; // Rectangulo para dibujar la pantalla de carga
// Actualiza las variables // Actualiza las variables
void update(); void update();
@@ -54,6 +56,9 @@ private:
// Comprueba el manejador de eventos // Comprueba el manejador de eventos
void checkEventHandler(); void checkEventHandler();
// Comprueba las entradas
void checkInput();
// Gestiona el contador interno // Gestiona el contador interno
void updateCounter(); void updateCounter();
@@ -66,15 +71,18 @@ private:
// Cambia la paleta // Cambia la paleta
void switchPalette(); void switchPalette();
// Reconstruye la pantalla de carga
void recreateLoadingScreen();
public: public:
// Constructor // Constructor
Intro(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options); Intro(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section);
// Destructor // Destructor
~Intro(); ~Intro();
// Bucle principal // Bucle principal
section_t run(); void run();
}; };
#endif #endif

View File

@@ -2,14 +2,16 @@
#include <iostream> #include <iostream>
// Constructor // Constructor
Logo::Logo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, int subsection) Logo::Logo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section)
{ {
// Copia la dirección de los objetos // Copia la dirección de los objetos
this->resource = resource; this->resource = resource;
this->renderer = renderer; this->renderer = renderer;
this->screen = screen; this->screen = screen;
this->asset = asset; this->asset = asset;
this->input = input;
this->options = options; this->options = options;
this->section = section;
// Reserva memoria para los punteros // Reserva memoria para los punteros
eventHandler = new SDL_Event(); eventHandler = new SDL_Event();
@@ -37,8 +39,7 @@ Logo::Logo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
// Inicializa variables // Inicializa variables
counter = 0; counter = 0;
section.name = SECTION_PROG_LOGO; section->name = SECTION_PROG_LOGO;
section.subsection = subsection;
ticks = 0; ticks = 0;
ticksSpeed = 15; ticksSpeed = 15;
initFade = 300; initFade = 300;
@@ -77,59 +78,50 @@ void Logo::checkEventHandler()
// Evento de salida de la aplicación // Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT) if (eventHandler->type == SDL_QUIT)
{ {
section.name = SECTION_PROG_QUIT; section->name = SECTION_PROG_QUIT;
break; break;
} }
}
}
// Comprueba las teclas que se han pulsado // Comprueba las entradas
if ((eventHandler->type == SDL_KEYUP && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONUP)) void Logo::checkInput()
{ {
switch (eventHandler->key.keysym.scancode)
{
case SDL_SCANCODE_ESCAPE:
section.name = SECTION_PROG_QUIT;
break;
case SDL_SCANCODE_B: if (input->checkInput(input_exit, REPEAT_FALSE))
screen->switchBorder(); {
resource->reLoadTextures(); section->name = SECTION_PROG_TITLE;
break; }
case SDL_SCANCODE_F: else if (input->checkInput(input_toggle_border, REPEAT_FALSE))
screen->switchVideoMode(); {
resource->reLoadTextures(); screen->switchBorder();
break; }
case SDL_SCANCODE_F1: else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
screen->setWindowSize(1); {
resource->reLoadTextures(); screen->switchVideoMode();
break; }
case SDL_SCANCODE_F2: else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
screen->setWindowSize(2); {
resource->reLoadTextures(); screen->decWindowSize();
break; }
case SDL_SCANCODE_F3: else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
screen->setWindowSize(3); {
resource->reLoadTextures(); screen->incWindowSize();
break; }
case SDL_SCANCODE_F4: else if (input->checkInput(input_swap_palette, REPEAT_FALSE))
screen->setWindowSize(4); {
resource->reLoadTextures(); switchPalette();
break; }
case SDL_SCANCODE_F5: else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_jump, REPEAT_FALSE))
switchPalette(); {
break; section->subsection = SUBSECTION_LOGO_TO_TITLE;
endSection();
default:
section.subsection = SUBSECTION_LOGO_TO_TITLE;
endSection();
break;
}
}
} }
} }
@@ -175,26 +167,32 @@ void Logo::updateTextureColors()
{ {
texture2->setColor(color[0].r, color[0].g, color[0].b); texture2->setColor(color[0].r, color[0].g, color[0].b);
} }
else if (counter == ini + inc * 1) else if (counter == ini + inc * 1)
{ {
texture2->setColor(color[1].r, color[1].g, color[1].b); texture2->setColor(color[1].r, color[1].g, color[1].b);
} }
else if (counter == ini + inc * 2) else if (counter == ini + inc * 2)
{ {
texture2->setColor(color[2].r, color[2].g, color[2].b); texture2->setColor(color[2].r, color[2].g, color[2].b);
} }
else if (counter == ini + inc * 3) else if (counter == ini + inc * 3)
{ {
texture2->setColor(color[3].r, color[3].g, color[3].b); texture2->setColor(color[3].r, color[3].g, color[3].b);
} }
else if (counter == ini + inc * 4) else if (counter == ini + inc * 4)
{ {
texture2->setColor(color[4].r, color[4].g, color[4].b); texture2->setColor(color[4].r, color[4].g, color[4].b);
} }
else if (counter == ini + inc * 5) else if (counter == ini + inc * 5)
{ {
texture2->setColor(color[5].r, color[5].g, color[5].b); texture2->setColor(color[5].r, color[5].g, color[5].b);
} }
else if (counter == ini + inc * 6) else if (counter == ini + inc * 6)
{ {
texture2->setColor(color[6].r, color[6].g, color[6].b); texture2->setColor(color[6].r, color[6].g, color[6].b);
@@ -210,31 +208,37 @@ void Logo::updateTextureColors()
texture->setColor(color[6].r, color[6].g, color[6].b); texture->setColor(color[6].r, color[6].g, color[6].b);
texture2->setColor(color[6].r, color[6].g, color[6].b); texture2->setColor(color[6].r, color[6].g, color[6].b);
} }
else if (counter == initFade + inc * 1) else if (counter == initFade + inc * 1)
{ {
texture->setColor(color[5].r, color[5].g, color[5].b); texture->setColor(color[5].r, color[5].g, color[5].b);
texture2->setColor(color[5].r, color[5].g, color[5].b); texture2->setColor(color[5].r, color[5].g, color[5].b);
} }
else if (counter == initFade + inc * 2) else if (counter == initFade + inc * 2)
{ {
texture->setColor(color[4].r, color[4].g, color[4].b); texture->setColor(color[4].r, color[4].g, color[4].b);
texture2->setColor(color[4].r, color[4].g, color[4].b); texture2->setColor(color[4].r, color[4].g, color[4].b);
} }
else if (counter == initFade + inc * 3) else if (counter == initFade + inc * 3)
{ {
texture->setColor(color[3].r, color[3].g, color[3].b); texture->setColor(color[3].r, color[3].g, color[3].b);
texture2->setColor(color[3].r, color[3].g, color[3].b); texture2->setColor(color[3].r, color[3].g, color[3].b);
} }
else if (counter == initFade + inc * 4) else if (counter == initFade + inc * 4)
{ {
texture->setColor(color[2].r, color[2].g, color[2].b); texture->setColor(color[2].r, color[2].g, color[2].b);
texture2->setColor(color[2].r, color[2].g, color[2].b); texture2->setColor(color[2].r, color[2].g, color[2].b);
} }
else if (counter == initFade + inc * 5) else if (counter == initFade + inc * 5)
{ {
texture->setColor(color[1].r, color[1].g, color[1].b); texture->setColor(color[1].r, color[1].g, color[1].b);
texture2->setColor(color[1].r, color[1].g, color[1].b); texture2->setColor(color[1].r, color[1].g, color[1].b);
} }
else if (counter == initFade + inc * 6) else if (counter == initFade + inc * 6)
{ {
texture->setColor(color[0].r, color[0].g, color[0].b); texture->setColor(color[0].r, color[0].g, color[0].b);
@@ -254,6 +258,9 @@ void Logo::update()
// Comprueba el manejador de eventos // Comprueba el manejador de eventos
checkEventHandler(); checkEventHandler();
// Comprueba las entradas
checkInput();
// Incrementa el contador // Incrementa el contador
counter++; counter++;
@@ -295,18 +302,16 @@ void Logo::render()
} }
// Bucle para el logo del juego // Bucle para el logo del juego
section_t Logo::run() void Logo::run()
{ {
// Detiene la música // Detiene la música
JA_StopMusic(); JA_StopMusic();
while (section.name == SECTION_PROG_LOGO) while (section->name == SECTION_PROG_LOGO)
{ {
update(); update();
render(); render();
} }
return section;
} }
// Cambia la paleta // Cambia la paleta
@@ -318,5 +323,5 @@ void Logo::switchPalette()
// Termina la sección // Termina la sección
void Logo::endSection() void Logo::endSection()
{ {
section.name = SECTION_PROG_ENTER_ID; section->name = SECTION_PROG_ENTER_ID;
} }

View File

@@ -2,6 +2,7 @@
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include "common/asset.h" #include "common/asset.h"
#include "common/input.h"
#include "common/jail_audio.h" #include "common/jail_audio.h"
#include "common/resource.h" #include "common/resource.h"
#include "common/screen.h" #include "common/screen.h"
@@ -21,17 +22,18 @@ private:
Screen *screen; // Objeto encargado de dibujar en pantalla Screen *screen; // Objeto encargado de dibujar en pantalla
Resource *resource; // Objeto con los recursos Resource *resource; // Objeto con los recursos
Asset *asset; // Objeto con los ficheros de recursos Asset *asset; // Objeto con los ficheros de recursos
Input *input; // Objeto pata gestionar la entrada
Texture *texture; // Textura con los graficos "JAILGAMES" Texture *texture; // Textura con los graficos "JAILGAMES"
Texture *texture2; // Textura con los graficos "Since 1998" Texture *texture2; // Textura con los graficos "Since 1998"
SDL_Event *eventHandler; // Manejador de eventos SDL_Event *eventHandler; // Manejador de eventos
std::vector<Sprite *> sprite; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES std::vector<Sprite *> sprite; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES
Sprite *sprite2; // Sprite para manejar la textura2 Sprite *sprite2; // Sprite para manejar la textura2
options_t *options; // Puntero a las opciones del juego options_t *options; // Puntero a las opciones del juego
section_t *section; // Estado del bucle principal para saber si continua o se sale
// Variables // Variables
std::vector<color_t> color; // Vector con los colores para el fade std::vector<color_t> color; // Vector con los colores para el fade
int counter; // Contador 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 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
int initFade; // Tiempo del contador cuando inicia el fade a negro int initFade; // Tiempo del contador cuando inicia el fade a negro
@@ -47,6 +49,9 @@ private:
// Comprueba el manejador de eventos // Comprueba el manejador de eventos
void checkEventHandler(); void checkEventHandler();
// Comprueba las entradas
void checkInput();
// Gestiona el logo de JAILGAME // Gestiona el logo de JAILGAME
void updateJAILGAMES(); void updateJAILGAMES();
@@ -61,13 +66,13 @@ private:
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, Input *input, options_t *options, section_t *section);
// Destructor // Destructor
~Logo(); ~Logo();
// Bucle principal // Bucle principal
section_t run(); void run();
}; };
#endif #endif

View File

@@ -181,13 +181,13 @@ void Player::checkInput()
if (!autoMovement) if (!autoMovement)
{ // Comprueba las entradas de desplazamiento lateral solo en el caso de no estar enganchado a una superficie automatica { // Comprueba las entradas de desplazamiento lateral solo en el caso de no estar enganchado a una superficie automatica
if (input->checkInput(INPUT_LEFT, REPEAT_TRUE)) if (input->checkInput(input_left))
{ {
vx = -0.6f; vx = -0.6f;
sprite->setFlipH(true); sprite->setFlipH(true);
} }
else if (input->checkInput(INPUT_RIGHT, REPEAT_TRUE)) else if (input->checkInput(input_right))
{ {
vx = 0.6f; vx = 0.6f;
sprite->setFlipH(false); sprite->setFlipH(false);
@@ -216,7 +216,7 @@ void Player::checkInput()
} }
} }
if (input->checkInput(INPUT_UP, REPEAT_TRUE)) if (input->checkInput(input_jump))
{ {
// Solo puede saltar si ademas de estar (state == s_standing) // Solo puede saltar si ademas de estar (state == s_standing)
// Esta sobre el suelo, rampa o suelo que se mueve // Esta sobre el suelo, rampa o suelo que se mueve

View File

@@ -6,11 +6,11 @@
ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Resource *resource, Asset *asset, options_t *options, board_t *board) ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Resource *resource, Asset *asset, options_t *options, board_t *board)
{ {
// Obten punteros a objetos // Obten punteros a objetos
this->renderer = renderer;
this->resource = resource; this->resource = resource;
this->asset = asset; this->asset = asset;
this->renderer = renderer;
this->board = board;
this->options = options; this->options = options;
this->board = board;
// Reserva memoria para los objetos // Reserva memoria para los objetos
itemTexture = resource->getTexture("items.png"); itemTexture = resource->getTexture("items.png");
@@ -170,3 +170,9 @@ void ScoreBoard::updateItemsColor()
itemsColor = stringToColor(options->palette, "magenta"); itemsColor = stringToColor(options->palette, "magenta");
} }
} }
// Devuelve la cantidad de minutos de juego transcurridos
int ScoreBoard::getMinutes()
{
return getTime().minutes;
}

View File

@@ -84,6 +84,9 @@ public:
// Quita el modo pausa del marcador // Quita el modo pausa del marcador
void resume(); void resume();
// Devuelve la cantidad de minutos de juego transcurridos
int getMinutes();
}; };
#endif #endif

View File

@@ -1,14 +1,16 @@
#include "title.h" #include "title.h"
// Constructor // Constructor
Title::Title(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options) Title::Title(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section)
{ {
// Copia la dirección de los objetos // Copia la dirección de los objetos
this->resource = resource; this->resource = resource;
this->renderer = renderer; this->renderer = renderer;
this->screen = screen; this->screen = screen;
this->asset = asset; this->asset = asset;
this->input = input;
this->options = options; this->options = options;
this->section = section;
// Reserva memoria para los punteros // Reserva memoria para los punteros
eventHandler = new SDL_Event(); eventHandler = new SDL_Event();
@@ -25,8 +27,8 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *
// Inicializa variables // Inicializa variables
counter = 0; counter = 0;
section.name = SECTION_PROG_TITLE; section->name = SECTION_PROG_TITLE;
section.subsection = 0; section->subsection = 0;
ticks = 0; ticks = 0;
ticksSpeed = 15; ticksSpeed = 15;
longText = "HEY JAILERS!! IT'S 2022 AND WE'RE STILL ROCKING LIKE IT'S 1998!!! HAVE YOU HEARD IT? JAILGAMES ARE BACK!! YEEESSS BACK!! MORE THAN 10 TITLES ON JAILDOC'S KITCHEN!! THATS A LOOOOOOT OF JAILGAMES, BUT WHICH ONE WILL STRIKE FIRST? THERE IS ALSO A NEW DEVICE TO COME THAT WILL BLOW YOUR MIND WITH JAILGAMES ON THE GO: P.A.C.O. BUT WAIT! WHAT'S THAT BEAUTY I'M SEEING RIGHT OVER THERE?? OOOH THAT TINY MINIASCII IS PURE LOVE!! I WANT TO LICK EVERY BYTE OF IT!! OH SHIT! AND DON'T FORGET TO BRING BACK THOSE OLD AND FAT MS-DOS JAILGAMES TO GITHUB TO KEEP THEM ALIVE!! WHAT WILL BE THE NEXT JAILDOC RELEASE? WHAT WILL BE THE NEXT PROJECT TO COME ALIVE?? OH BABY WE DON'T KNOW BUT HERE YOU CAN FIND THE ANSWER, YOU JUST HAVE TO COMPLETE JAILDOCTOR'S DILEMMA ... COULD YOU?"; longText = "HEY JAILERS!! IT'S 2022 AND WE'RE STILL ROCKING LIKE IT'S 1998!!! HAVE YOU HEARD IT? JAILGAMES ARE BACK!! YEEESSS BACK!! MORE THAN 10 TITLES ON JAILDOC'S KITCHEN!! THATS A LOOOOOOT OF JAILGAMES, BUT WHICH ONE WILL STRIKE FIRST? THERE IS ALSO A NEW DEVICE TO COME THAT WILL BLOW YOUR MIND WITH JAILGAMES ON THE GO: P.A.C.O. BUT WAIT! WHAT'S THAT BEAUTY I'M SEEING RIGHT OVER THERE?? OOOH THAT TINY MINIASCII IS PURE LOVE!! I WANT TO LICK EVERY BYTE OF IT!! OH SHIT! AND DON'T FORGET TO BRING BACK THOSE OLD AND FAT MS-DOS JAILGAMES TO GITHUB TO KEEP THEM ALIVE!! WHAT WILL BE THE NEXT JAILDOC RELEASE? WHAT WILL BE THE NEXT PROJECT TO COME ALIVE?? OH BABY WE DON'T KNOW BUT HERE YOU CAN FIND THE ANSWER, YOU JUST HAVE TO COMPLETE JAILDOCTOR'S DILEMMA ... COULD YOU?";
@@ -41,8 +43,12 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *
letters[0].enabled = true; letters[0].enabled = true;
marqueeSpeed = 3; marqueeSpeed = 3;
// Crea el cartel de PRESS ENTER // Crea el cartel de PRESS ENTER
#ifdef GAME_CONSOLE
const std::string caption = "PRESS START TO PLAY";
#else
const std::string caption = "PRESS ENTER TO PLAY"; const std::string caption = "PRESS ENTER TO PLAY";
#endif
const color_t textColor = stringToColor(options->palette, "white"); const color_t textColor = stringToColor(options->palette, "white");
const color_t strokeColor = stringToColor(options->palette, "bright_blue"); const color_t strokeColor = stringToColor(options->palette, "bright_blue");
@@ -79,74 +85,54 @@ void Title::checkEventHandler()
// Evento de salida de la aplicación // Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT) if (eventHandler->type == SDL_QUIT)
{ {
section.name = SECTION_PROG_QUIT; section->name = SECTION_PROG_QUIT;
break; break;
} }
}
}
// Comprueba las teclas que se han pulsado // Comprueba las entradas
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN)) void Title::checkInput()
{ {
if (eventHandler->type == SDL_JOYBUTTONDOWN)
{
section.name = SECTION_PROG_GAME;
section.subsection = 0;
}
switch (eventHandler->key.keysym.scancode) if (input->checkInput(input_exit, REPEAT_FALSE))
{ {
case SDL_SCANCODE_ESCAPE: section->name = SECTION_PROG_QUIT;
section.name = SECTION_PROG_QUIT; }
break;
case SDL_SCANCODE_RETURN: else if (input->checkInput(input_toggle_border, REPEAT_FALSE))
section.name = SECTION_PROG_GAME; {
section.subsection = 0; screen->switchBorder();
break; resource->reLoadTextures();
}
case SDL_SCANCODE_B: else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
screen->switchBorder(); {
resource->reLoadTextures(); screen->switchVideoMode();
break; resource->reLoadTextures();
}
case SDL_SCANCODE_F: else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
screen->switchVideoMode(); {
resource->reLoadTextures(); screen->decWindowSize();
break; resource->reLoadTextures();
}
case SDL_SCANCODE_F1: else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
screen->setWindowSize(1); {
resource->reLoadTextures(); screen->incWindowSize();
break; resource->reLoadTextures();
}
case SDL_SCANCODE_F2: else if (input->checkInput(input_swap_palette, REPEAT_FALSE))
screen->setWindowSize(2); {
resource->reLoadTextures(); switchPalette();
break; }
case SDL_SCANCODE_F3: else if (input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_pause, REPEAT_FALSE))
screen->setWindowSize(3); {
resource->reLoadTextures(); section->name = SECTION_PROG_GAME;
break; section->subsection = 0;
case SDL_SCANCODE_F4:
screen->setWindowSize(4);
resource->reLoadTextures();
break;
case SDL_SCANCODE_F5:
switchPalette();
break;
#ifdef DEBUG
case SDL_SCANCODE_F6:
screen->showNotification("MAMA MIRA! SIN MANOS!");
break;
#endif
default:
break;
}
}
} }
} }
@@ -189,14 +175,17 @@ void Title::renderMarquee()
// Actualiza las variables // Actualiza las variables
void Title::update() void Title::update()
{ {
// Comprueba el manejador de eventos
checkEventHandler();
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego // Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
if (SDL_GetTicks() - ticks > ticksSpeed) if (SDL_GetTicks() - ticks > ticksSpeed)
{ {
// Actualiza el contador de ticks // Actualiza el contador de ticks
ticks = SDL_GetTicks(); ticks = SDL_GetTicks();
// Comprueba el manejador de eventos // Comprueba las entradas
checkEventHandler(); checkInput();
// Incrementa el contador // Incrementa el contador
counter++; counter++;
@@ -210,8 +199,8 @@ void Title::update()
// Comprueba si ha terminado la marquesina y acaba con el titulo // Comprueba si ha terminado la marquesina y acaba con el titulo
if (letters[letters.size() - 1].x < -10) if (letters[letters.size() - 1].x < -10)
{ {
section.name = SECTION_PROG_CREDITS; section->name = SECTION_PROG_CREDITS;
section.subsection = 0; section->subsection = 0;
} }
} }
} }
@@ -239,15 +228,13 @@ void Title::render()
} }
// Bucle para el logo del juego // Bucle para el logo del juego
section_t Title::run() void Title::run()
{ {
while (section.name == SECTION_PROG_TITLE) while (section->name == SECTION_PROG_TITLE)
{ {
update(); update();
render(); render();
} }
return section;
} }
// Recarga las texturas // Recarga las texturas

View File

@@ -2,6 +2,7 @@
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include "common/asset.h" #include "common/asset.h"
#include "common/input.h"
#include "common/jail_audio.h" #include "common/jail_audio.h"
#include "common/resource.h" #include "common/resource.h"
#include "common/screen.h" #include "common/screen.h"
@@ -29,6 +30,7 @@ private:
Screen *screen; // Objeto encargado de dibujar en pantalla Screen *screen; // Objeto encargado de dibujar en pantalla
Resource *resource; // Objeto con los recursos Resource *resource; // Objeto con los recursos
Asset *asset; // Objeto con los ficheros de recursos Asset *asset; // Objeto con los ficheros de recursos
Input *input; // Objeto pata gestionar la entrada
SDL_Event *eventHandler; // Manejador de eventos SDL_Event *eventHandler; // Manejador de eventos
Texture *texture; // Textura con los graficos Texture *texture; // Textura con los graficos
Sprite *sprite; // Sprite para manejar la textura Sprite *sprite; // Sprite para manejar la textura
@@ -36,10 +38,10 @@ private:
options_t *options; // Puntero a las opciones del juego options_t *options; // Puntero a las opciones del juego
Texture *pressEnterTexture; // Textura con los graficos de PRESS ENTER Texture *pressEnterTexture; // Textura con los graficos de PRESS ENTER
Sprite *pressEnterSprite; // Sprite para manejar la textura de PRESS ENTER Sprite *pressEnterSprite; // Sprite para manejar la textura de PRESS ENTER
section_t *section; // Estado del bucle principal para saber si continua o se sale
// Variables // Variables
int counter; // Contador int counter; // Contador
section_t section; // Estado del bucle principal para saber si continua o se sale
std::string longText; // Texto que aparece en la parte inferior del titulo std::string longText; // Texto que aparece en la parte inferior del titulo
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
@@ -55,6 +57,9 @@ private:
// Comprueba el manejador de eventos // Comprueba el manejador de eventos
void checkEventHandler(); void checkEventHandler();
// Comprueba las entradas
void checkInput();
// Actualiza la marquesina // Actualiza la marquesina
void updateMarquee(); void updateMarquee();
@@ -69,13 +74,13 @@ private:
public: public:
// Constructor // Constructor
Title(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options); Title(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section);
// Destructor // Destructor
~Title(); ~Title();
// Bucle principal // Bucle principal
section_t run(); void run();
}; };
#endif #endif