Retocando las constantes

This commit is contained in:
2022-08-30 14:01:44 +02:00
parent add7e5201a
commit c5728d0849
11 changed files with 124 additions and 533 deletions

61
source/const.h Normal file
View File

@@ -0,0 +1,61 @@
#pragma once
#include <SDL2/SDL.h>
#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.1"
// Tamaño de bloque
#define BLOCK 8
#define HALF_BLOCK 4
// Tamaño de la pantalla virtual
#define GAMECANVAS_WIDTH 256
#define 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;
#define BORDER_TOP 0
#define BORDER_RIGHT 1
#define BORDER_BOTTOM 2
#define 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;
// Secciones del programa
#define SECTION_PROG_LOGO 0
#define SECTION_PROG_INTRO 1
#define SECTION_PROG_TITLE 2
#define SECTION_PROG_GAME 3
#define SECTION_PROG_QUIT 4
// Colores
const color_t borderColor = {0x27, 0x27, 0x36};
const color_t black = {0xFF, 0xFF, 0xFF};
#endif

View File

@@ -7,19 +7,19 @@
// Constructor
Director::Director(std::string path)
{
// Inicializa la ruta
setExecutablePath(path);
// Crea el objeto que controla los ficheros de recursos
asset = new Asset(executablePath);
// Establece la lista de ficheros
setFileList();
asset = new Asset(path.substr(0, path.find_last_of("\\/")));
// Si falta algún fichero no inicia el programa
Uint8 section = SECTION_PROG_GAME;
if (!asset->check())
section = SECTION_PROG_QUIT;
if (!setFileList())
{
section.name = SECTION_PROG_QUIT;
}
else
{
section.name = SECTION_PROG_GAME;
section.subsection = 0;
}
// Crea el puntero a la estructura y carga el fichero de configuración
options = new options_t;
@@ -27,22 +27,21 @@ Director::Director(std::string path)
options->windowSize = 2;
options->filter = FILTER_NEAREST;
options->vSync = true;
options->screenWidth = GAME_WIDTH * options->windowSize;
options->screenHeight = GAME_HEIGHT * options->windowSize;
options->screenWidth = GAMECANVAS_WIDTH * options->windowSize;
options->screenHeight = GAMECANVAS_HEIGHT * options->windowSize;
options->integerScale = true;
options->keepAspect = true;
// Crea los objetos
input = new Input(asset->get("gamecontrollerdb.txt"));
// Inicializa SDL
initSDL();
// Inicializa JailAudio
initJailAudio();
// Inicializa el resto de variables
init(section);
// Crea los objetos
input = new Input(asset->get("gamecontrollerdb.txt"));
initInput();
screen = new Screen(window, renderer, options, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
}
Director::~Director()
@@ -58,13 +57,8 @@ Director::~Director()
}
// Inicia las variables necesarias para arrancar el programa
void Director::init(Uint8 name)
void Director::initInput()
{
// Sección
section.name = name;
section.subsection = 0;
// Controles
input->bindKey(INPUT_UP, SDL_SCANCODE_UP);
input->bindKey(INPUT_DOWN, SDL_SCANCODE_DOWN);
input->bindKey(INPUT_LEFT, SDL_SCANCODE_LEFT);
@@ -101,7 +95,6 @@ bool Director::initSDL()
// Inicializa SDL
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_AUDIO) < 0)
//if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
{
printf("SDL could not initialize!\nSDL Error: %s\n", SDL_GetError());
success = false;
@@ -156,13 +149,15 @@ bool Director::initSDL()
}
// Crea el indice de ficheros
void Director::setFileList()
bool Director::setFileList()
{
asset->add("/media/font/smb2.png", font);
asset->add("/media/font/smb2.txt", font);
asset->add("/media/font/debug.png", font);
asset->add("/media/font/debug.txt", font);
asset->add("/data/gamecontrollerdb.txt", data);
asset->add("/data/room/01.room", room);
asset->add("/data/room/02.room", room);
asset->add("/data/room/03.room", room);
@@ -173,22 +168,22 @@ void Director::setFileList()
asset->add("/data/room/03.tmx", room);
asset->add("/data/room/04.tmx", room);
asset->add("/data/room/05.tmx", room);
asset->add("/media/tilesets/standard.png", bitmap);
asset->add("/media/enemies/paco.png", bitmap);
asset->add("/media/enemies/paco.ani", data);
asset->add("/media/enemies/chip.png", bitmap);
asset->add("/media/enemies/chip.ani", data);
asset->add("/media/enemies/wave.png", bitmap);
asset->add("/media/enemies/wave.ani", data);
asset->add("/media/player/player01.png", bitmap);
asset->add("/media/player/player01.ani", data);
asset->add("/media/items/items.png", bitmap);
}
// Establece el valor de la variable
void Director::setExecutablePath(std::string path)
{
executablePath = path.substr(0, path.find_last_of("\\/"));
return asset->check();
}
// Obtiene el valor de la variable

View File

@@ -10,14 +10,11 @@
#include "input.h"
#include "game.h"
#include "asset.h"
#include "const.h"
#ifndef DIRECTOR_H
#define DIRECTOR_H
#define WINDOW_CAPTION "JailDoctor's Dilemma"
#define GAME_WIDTH 256
#define GAME_HEIGHT 192
// Director
class Director
{
@@ -34,23 +31,17 @@ private:
std::string executablePath; // Path del ejecutable
section_t section; // Sección y subsección actual del programa;
// Inicia las variables necesarias para arrancar el programa
void init(Uint8 name);
// Inicializa jail_audio
void initJailAudio();
// Arranca SDL y crea la ventana
bool initSDL();
// Inicializa el objeto Input
void initInput();
// Crea el indice de ficheros
void setFileList();
// Comprueba que todos los ficheros existen
bool checkFileList();
// Establece el valor de la variable
void setExecutablePath(std::string path);
bool setFileList();
// Obtiene el valor de la variable
Uint8 getSubsection();
@@ -73,9 +64,6 @@ private:
// Ejecuta la seccion de juego donde se juega
void runGame();
// Comprueba los ficheros del vector de ficheros que coinciden con una ruta dada
bool checkFolder(std::string name, std::string path);
public:
// Constructor
Director(std::string path);

View File

@@ -6,6 +6,7 @@
#include "room.h"
#include "animatedsprite.h"
#include "input.h"
#include "const.h"
#include <string>
#ifndef PLAYER_H

View File

@@ -6,6 +6,7 @@
#include "enemy.h"
#include "item.h"
#include "item_tracker.h"
#include "const.h"
#include <string>
#include <vector>

View File

@@ -3,15 +3,15 @@
#include <stdio.h>
// Constructor
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options, int gameInternalResX, int gameInternalResY)
{
// Inicializa variables
this->window = window;
this->renderer = renderer;
this->options = options;
gameCanvasWidth = 256;
gameCanvasHeight = 192;
gameCanvasWidth = gameInternalResX;
gameCanvasHeight = gameInternalResY;
// Establece el modo de video
setVideoMode(options->fullScreenMode);
@@ -24,6 +24,14 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight);
if (gameCanvas == NULL)
printf("TitleSurface could not be created!\nSDL Error: %s\n", SDL_GetError());
// Calcula los anclajes
anchor.left = 0;
anchor.right = gameCanvasWidth;
anchor.center = gameCanvasWidth / 2;
anchor.top = 0;
anchor.bottom = gameCanvasHeight;
anchor.middle = gameCanvasHeight / 2;
}
// Destructor

View File

@@ -6,6 +6,16 @@
#ifndef SCREEN_H
#define SCREEN_H
struct anchor_t
{
int left; // Parte izquierda de la pantalla de juego
int right; // Parte drecha de la pantalla de juego
int center; // Parte central horizontal de la pantalla de juego
int top; // Parte superior de la pantalla de juego
int bottom; // Parte infoerior de la pantalla de juego
int middle; // Parte central vertical de la pantalla de juego
};
// Clase Screen
class Screen
{
@@ -15,16 +25,17 @@ private:
SDL_Texture *gameCanvas; // Textura para completar la ventana de juego hasta la pantalla completa
options_t *options; // Variable con todas las opciones del programa
int screenWidth; // Ancho de la pantalla
int screenHeight; // Alto de la pantalla
int gameCanvasWidth; // Ancho de la textura donde se dibuja el juego
int gameCanvasHeight; // Alto de la textura donde se dibuja el juego
SDL_Rect dest; // Coordenadas donde se va a dibujar la textura del juego
int screenWidth; // Ancho de la pantalla o ventana
int screenHeight; // Alto de la pantalla o ventana
int gameCanvasWidth; // Resolución interna del juego. Es el ancho de la textura donde se dibuja el juego
int gameCanvasHeight; // Resolución interna del juego. Es el alto de la textura donde se dibuja el juego
anchor_t anchor; // Variable con los anclajes de la pantalla
SDL_Rect dest; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
public:
// Constructor
Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options);
Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options, int gameInternalResX, int gameInternalResY);
// Destructor
~Screen();

View File

@@ -56,8 +56,8 @@ struct options_t
int windowSize; // Contiene el valor por el que se multiplica el tamaño de la ventana
Uint32 filter; // Filtro usado para el escalado de la imagen
bool vSync; // Indica si se quiere usar vsync o no
int screenWidth; // Ancho de la pantalla/ventana
int screenHeight; // Alto de la pantalla/ventana
int screenWidth; // Ancho de la pantalla o ventana
int screenHeight; // Alto de la pantalla o ventana
bool integerScale; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa
bool keepAspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa
};