Sanejar codi

This commit is contained in:
2025-02-21 14:45:41 +01:00
parent ec73c5fa30
commit 6bb877b510
10 changed files with 98 additions and 107 deletions

View File

@@ -4,69 +4,64 @@
#include <string>
#include "utils.h"
#ifndef CONST_H
#define CONST_H
// Textos
#define WINDOW_CAPTION "JailDoctor's Dilemma"
#define TEXT_COPYRIGHT "@2022 JailDesigner"
#define VERSION "0.7"
constexpr const char* WINDOW_CAPTION = "JailDoctor's Dilemma";
constexpr const char* TEXT_COPYRIGHT = "@2022 JailDesigner";
constexpr const char* VERSION = "0.7";
// Tamaño de bloque
#define BLOCK 8
#define HALF_BLOCK 4
constexpr int BLOCK = 8;
constexpr int HALF_BLOCK = 4;
// Tamaño de la pantalla virtual
#define GAMECANVAS_WIDTH 256
#define GAMECANVAS_HEIGHT 192
constexpr int GAMECANVAS_WIDTH = 256;
constexpr int GAMECANVAS_HEIGHT = 192;
// Zona de juego
const int PLAY_AREA_TOP = (0 * BLOCK);
const int PLAY_AREA_BOTTOM = (16 * BLOCK);
const int PLAY_AREA_LEFT = (0 * BLOCK);
const int PLAY_AREA_RIGHT = (32 * BLOCK);
const int PLAY_AREA_WIDTH = PLAY_AREA_RIGHT - PLAY_AREA_LEFT;
const int PLAY_AREA_HEIGHT = PLAY_AREA_BOTTOM - PLAY_AREA_TOP;
const int PLAY_AREA_CENTER_X = PLAY_AREA_LEFT + (PLAY_AREA_WIDTH / 2);
const int PLAY_AREA_CENTER_FIRST_QUARTER_X = (PLAY_AREA_WIDTH / 4);
const int PLAY_AREA_CENTER_THIRD_QUARTER_X = (PLAY_AREA_WIDTH / 4) * 3;
const int PLAY_AREA_CENTER_Y = PLAY_AREA_TOP + (PLAY_AREA_HEIGHT / 2);
const int PLAY_AREA_FIRST_QUARTER_Y = PLAY_AREA_HEIGHT / 4;
const int PLAY_AREA_THIRD_QUARTER_Y = (PLAY_AREA_HEIGHT / 4) * 3;
constexpr int PLAY_AREA_TOP = (0 * BLOCK);
constexpr int PLAY_AREA_BOTTOM = (16 * BLOCK);
constexpr int PLAY_AREA_LEFT = (0 * BLOCK);
constexpr int PLAY_AREA_RIGHT = (32 * BLOCK);
constexpr int PLAY_AREA_WIDTH = PLAY_AREA_RIGHT - PLAY_AREA_LEFT;
constexpr int PLAY_AREA_HEIGHT = PLAY_AREA_BOTTOM - PLAY_AREA_TOP;
constexpr int PLAY_AREA_CENTER_X = PLAY_AREA_LEFT + (PLAY_AREA_WIDTH / 2);
constexpr int PLAY_AREA_CENTER_FIRST_QUARTER_X = (PLAY_AREA_WIDTH / 4);
constexpr int PLAY_AREA_CENTER_THIRD_QUARTER_X = (PLAY_AREA_WIDTH / 4) * 3;
constexpr int PLAY_AREA_CENTER_Y = PLAY_AREA_TOP + (PLAY_AREA_HEIGHT / 2);
constexpr int PLAY_AREA_FIRST_QUARTER_Y = PLAY_AREA_HEIGHT / 4;
constexpr int PLAY_AREA_THIRD_QUARTER_Y = (PLAY_AREA_HEIGHT / 4) * 3;
#define BORDER_TOP 0
#define BORDER_RIGHT 1
#define BORDER_BOTTOM 2
#define BORDER_LEFT 3
constexpr int BORDER_TOP = 0;
constexpr int BORDER_RIGHT = 1;
constexpr int BORDER_BOTTOM = 2;
constexpr int BORDER_LEFT = 3;
// Anclajes de pantalla
const int GAMECANVAS_CENTER_X = GAMECANVAS_WIDTH / 2;
const int GAMECANVAS_FIRST_QUARTER_X = GAMECANVAS_WIDTH / 4;
const int GAMECANVAS_THIRD_QUARTER_X = (GAMECANVAS_WIDTH / 4) * 3;
const int GAMECANVAS_CENTER_Y = GAMECANVAS_HEIGHT / 2;
const int GAMECANVAS_FIRST_QUARTER_Y = GAMECANVAS_HEIGHT / 4;
const int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3;
constexpr int GAMECANVAS_CENTER_X = GAMECANVAS_WIDTH / 2;
constexpr int GAMECANVAS_FIRST_QUARTER_X = GAMECANVAS_WIDTH / 4;
constexpr int GAMECANVAS_THIRD_QUARTER_X = (GAMECANVAS_WIDTH / 4) * 3;
constexpr int GAMECANVAS_CENTER_Y = GAMECANVAS_HEIGHT / 2;
constexpr int GAMECANVAS_FIRST_QUARTER_Y = GAMECANVAS_HEIGHT / 4;
constexpr int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3;
// Secciones del programa
#define SECTION_LOGO 0
#define SECTION_LOADING_SCREEN 1
#define SECTION_TITLE 2
#define SECTION_CREDITS 3
#define SECTION_GAME 4
#define SECTION_DEMO 5
#define SECTION_GAME_OVER 6
#define SECTION_ENDING 7
#define SECTION_ENDING2 8
#define SECTION_QUIT 9
constexpr int SECTION_LOGO = 0;
constexpr int SECTION_LOADING_SCREEN = 1;
constexpr int SECTION_TITLE = 2;
constexpr int SECTION_CREDITS = 3;
constexpr int SECTION_GAME = 4;
constexpr int SECTION_DEMO = 5;
constexpr int SECTION_GAME_OVER = 6;
constexpr int SECTION_ENDING = 7;
constexpr int SECTION_ENDING2 = 8;
constexpr int SECTION_QUIT = 9;
// Subsecciones
#define SUBSECTION_LOGO_TO_INTRO 0
#define SUBSECTION_LOGO_TO_TITLE 1
#define SUBSECTION_TITLE_WITH_LOADING_SCREEN 2
#define SUBSECTION_TITLE_WITHOUT_LOADING_SCREEN 3
constexpr int SUBSECTION_LOGO_TO_INTRO = 0;
constexpr int SUBSECTION_LOGO_TO_TITLE = 1;
constexpr int SUBSECTION_TITLE_WITH_LOADING_SCREEN = 2;
constexpr int SUBSECTION_TITLE_WITHOUT_LOADING_SCREEN = 3;
// Colores
const color_t borderColor = {0x27, 0x27, 0x36};
const color_t black = {0xFF, 0xFF, 0xFF};
#endif

View File

@@ -41,8 +41,10 @@
#endif
// Constructor
Director::Director(int argc, char *argv[])
Director::Director(int argc, const char *argv[])
{
std::cout << "Game start" << std::endl;
section = new section_t();
section->name = SECTION_LOGO;
section->subsection = SUBSECTION_LOGO_TO_INTRO;
@@ -112,6 +114,8 @@ Director::~Director()
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
std::cout << "\nBye!" << std::endl;
}
// Crea e inicializa las opciones del programa
@@ -165,7 +169,7 @@ void Director::initOptions()
}
// Comprueba los parametros del programa
void Director::checkProgramArguments(int argc, char *argv[])
void Director::checkProgramArguments(int argc, const char *argv[])
{
// Establece la ruta del programa
executablePath = argv[0];
@@ -360,7 +364,7 @@ bool Director::saveConfig()
}
else
{
file << "filter=FILTER_LINEAL\n";
file << "filter=FILTER_LINEAR\n";
}
file << "shaders=" + boolToString(options->shaders) + "\n";
@@ -1081,9 +1085,9 @@ bool Director::setOptions(options_t *options, std::string var, std::string value
else if (var == "filter")
{
if (value == "FILTER_LINEAL")
if (value == "FILTER_LINEAR")
{
options->filter = FILTER_LINEAL;
options->filter = FILTER_LINEAR;
}
else
{
@@ -1843,7 +1847,7 @@ void Director::runGame()
resource->free();
}
void Director::run()
int Director::run()
{
// Bucle principal
while (section->name != SECTION_QUIT)
@@ -1887,4 +1891,6 @@ void Director::run()
break;
}
}
return 0;
}

View File

@@ -53,7 +53,7 @@ private:
void initOptions();
// Comprueba los parametros del programa
void checkProgramArguments(int argc, char *argv[]);
void checkProgramArguments(int argc, const char *argv[]);
// Carga el fichero de configuración
bool loadConfig();
@@ -111,11 +111,11 @@ private:
public:
// Constructor
Director(int argc, char *argv[]);
Director(int argc, const char *argv[]);
// Destructor
~Director();
// Bucle principal
void run();
int run();
};

View File

@@ -6,6 +6,15 @@
#include <string> // Para string, basic_string
#include <vector> // Para vector
// Definiciones de repetición
constexpr bool REPEAT_TRUE = true;
constexpr bool REPEAT_FALSE = false;
// Tipos de entrada
constexpr int INPUT_USE_KEYBOARD = 0;
constexpr int INPUT_USE_GAMECONTROLLER = 1;
constexpr int INPUT_USE_ANY = 2;
enum inputs_e
{
// Inputs obligatorios
@@ -33,13 +42,6 @@ enum inputs_e
input_number_of_inputs
};
#define REPEAT_TRUE true
#define REPEAT_FALSE false
#define INPUT_USE_KEYBOARD 0
#define INPUT_USE_GAMECONTROLLER 1
#define INPUT_USE_ANY 2
enum i_disable_e
{
d_notDisabled,

View File

@@ -1,5 +1,3 @@
#ifndef NO_SHADERS
#pragma once
#include <SDL2/SDL_render.h> // para SDL_Texture
@@ -44,5 +42,4 @@ namespace shader
const char *vertexShader, const char *fragmentShader = nullptr);
void render();
}
#endif
}

View File

@@ -5,26 +5,14 @@ Empezado en Castalla el 01/07/2022.
*/
#include <memory>
#include "director.h"
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
cout << "Starting the game..." << endl;
// Crea el objeto Director
Director *director = new Director(argc, argv);
auto director = std::make_unique<Director>(argc, const_cast<const char **>(argv));
// Bucle principal
director->run();
// Destruye el objeto Director
delete director;
director = nullptr;
cout << "\nShutting down the game..." << endl;
return 0;
return director->run();
}

View File

@@ -11,17 +11,17 @@ class Resource;
class Text;
struct JA_Sound_t;
// Tipos de fondos para el menu
#define MENU_BACKGROUND_TRANSPARENT 0
#define MENU_BACKGROUND_SOLID 1
// Tipos de fondos para el menú
constexpr int MENU_BACKGROUND_TRANSPARENT = 0;
constexpr int MENU_BACKGROUND_SOLID = 1;
// Tipos de archivos de audio
#define SOUND_ACCEPT 0
#define SOUND_MOVE 1
#define SOUND_CANCEL 2
constexpr int SOUND_ACCEPT = 0;
constexpr int SOUND_MOVE = 1;
constexpr int SOUND_CANCEL = 2;
// Opciones de menu
#define MENU_NO_OPTION -1
// Opciones de menú
constexpr int MENU_NO_OPTION = -1;
// Clase Menu
class Menu

View File

@@ -10,8 +10,8 @@
class Asset;
class Notify;
#define FILTER_NEAREST 0
#define FILTER_LINEAL 1
constexpr int FILTER_NEAREST = 0;
constexpr int FILTER_LINEAR = 1;
class Screen
{

View File

@@ -7,10 +7,10 @@ class Sprite;
class Texture;
#include "utils.h"
#define TXT_COLOR 1
#define TXT_SHADOW 2
#define TXT_CENTER 4
#define TXT_STROKE 8
constexpr int TXT_COLOR = 1;
constexpr int TXT_SHADOW = 2;
constexpr int TXT_CENTER = 4;
constexpr int TXT_STROKE = 8;
struct offset_t
{