Commit para seguir en otro ordenador
This commit is contained in:
@@ -11,16 +11,16 @@
|
|||||||
#define HALF_BLOCK BLOCK / 2
|
#define HALF_BLOCK BLOCK / 2
|
||||||
|
|
||||||
// Tamaño de la pantalla que contendrá la pantalla de juego
|
// Tamaño de la pantalla que contendrá la pantalla de juego
|
||||||
#define REAL_SCREEN_WIDTH 320
|
//#define REAL_SCREEN_WIDTH 256
|
||||||
#define REAL_SCREEN_HEIGHT 240
|
//#define REAL_SCREEN_HEIGHT 192
|
||||||
|
|
||||||
// Tamaño de la pantalla de juego
|
// Tamaño de la pantalla de juego
|
||||||
#define SCREEN_WIDTH 256
|
#define SCREEN_WIDTH 256
|
||||||
#define SCREEN_HEIGHT 192
|
#define SCREEN_HEIGHT 192
|
||||||
|
|
||||||
// Tamaño de la pantalla que se muestra
|
// Tamaño de la pantalla que se muestra
|
||||||
const int VIEW_WIDTH = REAL_SCREEN_WIDTH * 3;
|
//const int VIEW_WIDTH = REAL_SCREEN_WIDTH * 3;
|
||||||
const int VIEW_HEIGHT = REAL_SCREEN_HEIGHT * 3;
|
//const int VIEW_HEIGHT = REAL_SCREEN_HEIGHT * 3;
|
||||||
|
|
||||||
// Zona de juego
|
// Zona de juego
|
||||||
const int PLAY_AREA_TOP = (0 * BLOCK);
|
const int PLAY_AREA_TOP = (0 * BLOCK);
|
||||||
|
|||||||
@@ -27,20 +27,21 @@ Director::Director(std::string path)
|
|||||||
|
|
||||||
// Crea el puntero a la estructura y carga el fichero de configuración
|
// Crea el puntero a la estructura y carga el fichero de configuración
|
||||||
mOptions = new options_t;
|
mOptions = new options_t;
|
||||||
if (!loadConfigFile())
|
loadConfigFile();
|
||||||
{
|
//if (!loadConfigFile())
|
||||||
mOptions->fullScreenMode = 0;
|
//{
|
||||||
mOptions->windowSize = 3;
|
// mOptions->fullScreenMode = 0;
|
||||||
mOptions->language = en_UK;
|
// mOptions->windowSize = 3;
|
||||||
mOptions->difficulty = DIFFICULTY_NORMAL;
|
// mOptions->language = en_UK;
|
||||||
mOptions->input[0].deviceType = INPUT_USE_KEYBOARD;
|
// mOptions->difficulty = DIFFICULTY_NORMAL;
|
||||||
mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
|
// mOptions->input[0].deviceType = INPUT_USE_KEYBOARD;
|
||||||
mOptions->filter = FILTER_NEAREST;
|
// mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
|
||||||
mOptions->vSync = true;
|
// mOptions->filter = FILTER_NEAREST;
|
||||||
mOptions->screenHeight = SCREEN_HEIGHT;
|
// mOptions->vSync = true;
|
||||||
mOptions->screenWidth = SCREEN_WIDTH;
|
// mOptions->screenHeight = SCREEN_HEIGHT;
|
||||||
mOptions->integerScale = true;
|
// mOptions->screenWidth = SCREEN_WIDTH;
|
||||||
}
|
// mOptions->integerScale = true;
|
||||||
|
//}
|
||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
mInput = new Input(mFileList[53]);
|
mInput = new Input(mFileList[53]);
|
||||||
@@ -171,7 +172,7 @@ bool Director::initSDL()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crea la ventana
|
// Crea la ventana
|
||||||
mWindow = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, VIEW_WIDTH, VIEW_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
|
mWindow = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, mOptions->screenWidth * mOptions->windowSize, mOptions->screenHeight * mOptions->windowSize, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
|
||||||
if (mWindow == NULL)
|
if (mWindow == NULL)
|
||||||
{
|
{
|
||||||
printf("Window could not be created!\nSDL Error: %s\n", SDL_GetError());
|
printf("Window could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||||
@@ -367,9 +368,9 @@ bool Director::loadConfigFile()
|
|||||||
mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
|
mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
|
||||||
mOptions->filter = FILTER_NEAREST;
|
mOptions->filter = FILTER_NEAREST;
|
||||||
mOptions->vSync = true;
|
mOptions->vSync = true;
|
||||||
mOptions->screenHeight = 480;
|
mOptions->screenWidth = 544;
|
||||||
mOptions->screenWidth = 640;
|
mOptions->screenHeight = 834;
|
||||||
mOptions->integerScale = true;
|
mOptions->integerScale = false;
|
||||||
|
|
||||||
// Indicador de éxito en la carga
|
// Indicador de éxito en la carga
|
||||||
bool success = true;
|
bool success = true;
|
||||||
@@ -398,8 +399,8 @@ bool Director::loadConfigFile()
|
|||||||
SDL_RWwrite(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
|
SDL_RWwrite(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
|
||||||
SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
||||||
SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
||||||
SDL_RWwrite(file, &mOptions->screenHeight, sizeof(mOptions->screenHeight), 1);
|
|
||||||
SDL_RWwrite(file, &mOptions->screenWidth, sizeof(mOptions->screenWidth), 1);
|
SDL_RWwrite(file, &mOptions->screenWidth, sizeof(mOptions->screenWidth), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->screenHeight, sizeof(mOptions->screenHeight), 1);
|
||||||
SDL_RWwrite(file, &mOptions->integerScale, sizeof(mOptions->integerScale), 1);
|
SDL_RWwrite(file, &mOptions->integerScale, sizeof(mOptions->integerScale), 1);
|
||||||
|
|
||||||
// Cierra el fichero
|
// Cierra el fichero
|
||||||
@@ -424,8 +425,8 @@ bool Director::loadConfigFile()
|
|||||||
SDL_RWread(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
|
SDL_RWread(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
|
||||||
SDL_RWread(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
SDL_RWread(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
||||||
SDL_RWread(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
SDL_RWread(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
||||||
SDL_RWread(file, &mOptions->screenHeight, sizeof(mOptions->screenHeight), 1);
|
|
||||||
SDL_RWread(file, &mOptions->screenWidth, sizeof(mOptions->screenWidth), 1);
|
SDL_RWread(file, &mOptions->screenWidth, sizeof(mOptions->screenWidth), 1);
|
||||||
|
SDL_RWread(file, &mOptions->screenHeight, sizeof(mOptions->screenHeight), 1);
|
||||||
SDL_RWread(file, &mOptions->integerScale, sizeof(mOptions->integerScale), 1);
|
SDL_RWread(file, &mOptions->integerScale, sizeof(mOptions->integerScale), 1);
|
||||||
|
|
||||||
// Normaliza los valores
|
// Normaliza los valores
|
||||||
@@ -463,8 +464,8 @@ bool Director::saveConfigFile()
|
|||||||
SDL_RWwrite(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
|
SDL_RWwrite(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
|
||||||
SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
||||||
SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
||||||
SDL_RWwrite(file, &mOptions->screenHeight, sizeof(mOptions->screenHeight), 1);
|
|
||||||
SDL_RWwrite(file, &mOptions->screenWidth, sizeof(mOptions->screenWidth), 1);
|
SDL_RWwrite(file, &mOptions->screenWidth, sizeof(mOptions->screenWidth), 1);
|
||||||
|
SDL_RWwrite(file, &mOptions->screenHeight, sizeof(mOptions->screenHeight), 1);
|
||||||
SDL_RWwrite(file, &mOptions->integerScale, sizeof(mOptions->integerScale), 1);
|
SDL_RWwrite(file, &mOptions->integerScale, sizeof(mOptions->integerScale), 1);
|
||||||
|
|
||||||
printf("Writing file %s\n", filename.c_str());
|
printf("Writing file %s\n", filename.c_str());
|
||||||
|
|||||||
@@ -10,25 +10,34 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, int screenWidth, int
|
|||||||
|
|
||||||
mScreenWidth = screenWidth;
|
mScreenWidth = screenWidth;
|
||||||
mScreenHeight = screenHeight;
|
mScreenHeight = screenHeight;
|
||||||
mGameCanvasWidth = SCREEN_WIDTH;
|
mGameCanvasWidth = SCREEN_WIDTH;
|
||||||
mGameCanvasHeight = SCREEN_HEIGHT;
|
mGameCanvasHeight = SCREEN_HEIGHT;
|
||||||
mGameCanvasPosX = (mScreenWidth - mGameCanvasWidth) / 2;
|
|
||||||
mGameCanvasPosY = (mScreenHeight - mGameCanvasHeight) / 2;
|
mDest.x = (mScreenWidth - mGameCanvasWidth) / 2;
|
||||||
|
mDest.y = (mScreenHeight - mGameCanvasHeight) / 2;
|
||||||
mIntegerScale = integerScale;
|
mIntegerScale = integerScale;
|
||||||
|
//mIntegerScale = true;
|
||||||
|
|
||||||
// Calcula el tamaño de la escala máxima
|
// Calcula el tamaño de la escala máxima
|
||||||
mScale = 0;
|
int scale = 0;
|
||||||
int width = mGameCanvasWidth;
|
while (((mGameCanvasWidth * (scale + 1)) <= mScreenWidth) && ((mGameCanvasHeight * (scale + 1)) <= mScreenHeight))
|
||||||
int height = mGameCanvasHeight;
|
|
||||||
while (((width * (mScale + 1)) < mScreenWidth) && ((height * (mScale + 1)) < mScreenHeight))
|
|
||||||
{
|
{
|
||||||
mScale++;
|
scale++;
|
||||||
}
|
}
|
||||||
|
|
||||||
width = width * mScale;
|
if (mIntegerScale)
|
||||||
height = height * mScale;
|
{
|
||||||
mGameCanvasPosX = (mScreenWidth - width) / 2;
|
mDest.w = mGameCanvasWidth * scale;
|
||||||
mGameCanvasPosY = (mScreenHeight - height) / 2;
|
mDest.h = mGameCanvasHeight * scale;
|
||||||
|
mDest.x = (mScreenWidth - mGameCanvasWidth) / 2;
|
||||||
|
mDest.y = (mScreenHeight - mGameCanvasHeight) / 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mDest.w = mScreenWidth;
|
||||||
|
mDest.h = mScreenHeight;
|
||||||
|
mDest.x = mDest.y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
mBorderColor = {0x27, 0x27, 0x36};
|
mBorderColor = {0x27, 0x27, 0x36};
|
||||||
mBorderColor = {0x00, 0x00, 0x00};
|
mBorderColor = {0x00, 0x00, 0x00};
|
||||||
@@ -68,11 +77,8 @@ void Screen::blit()
|
|||||||
SDL_SetRenderDrawColor(mRenderer, mBorderColor.r, mBorderColor.g, mBorderColor.b, 0xFF);
|
SDL_SetRenderDrawColor(mRenderer, mBorderColor.r, mBorderColor.g, mBorderColor.b, 0xFF);
|
||||||
SDL_RenderClear(mRenderer);
|
SDL_RenderClear(mRenderer);
|
||||||
|
|
||||||
// Rectangulo de destino donde se dibujarà la textura con el juego
|
|
||||||
SDL_Rect dest = {mGameCanvasPosX, mGameCanvasPosY, mGameCanvasWidth*mScale, mGameCanvasHeight*mScale};
|
|
||||||
|
|
||||||
// Copia la textura de juego en el renderizador en la posición adecuada
|
// Copia la textura de juego en el renderizador en la posición adecuada
|
||||||
SDL_RenderCopy(mRenderer, mGameCanvas, NULL, &dest);
|
SDL_RenderCopy(mRenderer, mGameCanvas, NULL, &mDest);
|
||||||
|
|
||||||
// Muestra por pantalla el renderizador
|
// Muestra por pantalla el renderizador
|
||||||
SDL_RenderPresent(mRenderer);
|
SDL_RenderPresent(mRenderer);
|
||||||
|
|||||||
@@ -17,12 +17,9 @@ private:
|
|||||||
int mScreenHeight; // Alto de la pantalla
|
int mScreenHeight; // Alto de la pantalla
|
||||||
int mGameCanvasWidth; // Ancho de la textura donde se dibuja el juego
|
int mGameCanvasWidth; // Ancho de la textura donde se dibuja el juego
|
||||||
int mGameCanvasHeight; // Alto de la textura donde se dibuja el juego
|
int mGameCanvasHeight; // Alto de la textura donde se dibuja el juego
|
||||||
int mGameCanvasPosX; // Posicion en el eje X donde se dibujará la textura del juego dentro de la pantalla
|
|
||||||
int mGameCanvasPosY; // Posicion en el eje Y donde se dibujará la textura del juego dentro de la pantalla
|
|
||||||
bool mIntegerScale; // Indica si la textura se escala en multiplos enteros
|
bool mIntegerScale; // Indica si la textura se escala en multiplos enteros
|
||||||
Uint8 mScale; // Contiene el valor por el cual se multiplica el GameCanvas para aprovechar el maximo de pantalla
|
SDL_Rect mDest; // Coordenadas donde se va a dibujar la textura del juego
|
||||||
|
color_t mBorderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
||||||
color_t mBorderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
|
|||||||
Reference in New Issue
Block a user