Actualizada la clase screen con nuevos procedimientos. Incluído el fichero const.h. Cambio de tamaño de ventana y pantalla completa
This commit is contained in:
@@ -1,18 +1,47 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#ifndef CONST_H
|
#ifndef CONST_H
|
||||||
#define CONST_H
|
#define CONST_H
|
||||||
|
|
||||||
// Tamaño de bloque
|
// Textos
|
||||||
#define BLOCK 16
|
#define WINDOW_CAPTION "Volcano"
|
||||||
#define HALF_BLOCK 8
|
#define TEXT_COPYRIGHT "2016,2022 JAILDESIGNER & JAILBROTHER"
|
||||||
|
#define VERSION "0.5"
|
||||||
|
|
||||||
// Tamaño de la pantalla real
|
// Tamaño de bloque
|
||||||
#define SCREEN_WIDTH 320
|
#define BLOCK 8
|
||||||
#define SCREEN_HEIGHT 240
|
#define HALF_BLOCK 4
|
||||||
|
|
||||||
// Tamaño de la pantalla virtual
|
// Tamaño de la pantalla virtual
|
||||||
#define GAMECANVAS_WIDTH 320
|
#define GAMECANVAS_WIDTH 320
|
||||||
#define GAMECANVAS_HEIGHT 240
|
#define GAMECANVAS_HEIGHT 240
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
// Colores
|
||||||
|
const color_t borderColor = {0x27, 0x27, 0x36};
|
||||||
|
const color_t black = {0xFF, 0xFF, 0xFF};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -83,6 +83,55 @@ void Game::update()
|
|||||||
section.name = SECTION_PROG_QUIT;
|
section.name = SECTION_PROG_QUIT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
else if ((eventHandler->type == SDL_KEYDOWN) and (eventHandler->key.repeat == 0))
|
||||||
|
{
|
||||||
|
switch (eventHandler->key.keysym.scancode)
|
||||||
|
{
|
||||||
|
case SDL_SCANCODE_ESCAPE:
|
||||||
|
section.name = SECTION_PROG_QUIT;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_SCANCODE_D:
|
||||||
|
debug = !debug;
|
||||||
|
musicEnabled = !debug;
|
||||||
|
if (musicEnabled)
|
||||||
|
{
|
||||||
|
JA_PlayMusic(music);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
JA_StopMusic();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_SCANCODE_R:
|
||||||
|
delete map;
|
||||||
|
map = new Map(asset->get("01.map"), renderer, asset, itemTracker);
|
||||||
|
delete player;
|
||||||
|
player = new Player(renderer, asset, input, map);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_SCANCODE_F:
|
||||||
|
screen->switchVideoMode();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_SCANCODE_F1:
|
||||||
|
screen->setWindowSize(1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_SCANCODE_F2:
|
||||||
|
screen->setWindowSize(2);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_SCANCODE_F3:
|
||||||
|
screen->setWindowSize(3);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_SCANCODE_F4:
|
||||||
|
screen->setWindowSize(4);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
map->update();
|
map->update();
|
||||||
@@ -113,32 +162,6 @@ void Game::render()
|
|||||||
// Comprueba la entrada
|
// Comprueba la entrada
|
||||||
void Game::checkInput()
|
void Game::checkInput()
|
||||||
{
|
{
|
||||||
if (input->checkInput(INPUT_BUTTON_2, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
debug = !debug;
|
|
||||||
musicEnabled = !debug;
|
|
||||||
if (musicEnabled)
|
|
||||||
{
|
|
||||||
JA_PlayMusic(music);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
JA_StopMusic();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input->checkInput(INPUT_BUTTON_3, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
delete map;
|
|
||||||
map = new Map(asset->get("01.map"), renderer, asset, itemTracker);
|
|
||||||
delete player;
|
|
||||||
player = new Player(renderer, asset, input, map);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input->checkInput(INPUT_BUTTON_ESCAPE, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
section.name = SECTION_PROG_QUIT;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Muestra información de depuración
|
// Muestra información de depuración
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset)
|
|||||||
eventHandler = new SDL_Event();
|
eventHandler = new SDL_Event();
|
||||||
texture = new LTexture();
|
texture = new LTexture();
|
||||||
loadTextureFromFile(texture, asset->get("logo.png"), renderer);
|
loadTextureFromFile(texture, asset->get("logo.png"), renderer);
|
||||||
sprite = new Sprite(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, texture, renderer);
|
sprite = new Sprite(0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT, texture, renderer);
|
||||||
|
|
||||||
// Crea un backbuffer para el renderizador
|
// Crea un backbuffer para el renderizador
|
||||||
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, SCREEN_WIDTH, SCREEN_HEIGHT);
|
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
|
||||||
if (backbuffer == NULL)
|
if (backbuffer == NULL)
|
||||||
printf("Backbuffer could not be created!\nSDL Error: %s\n", SDL_GetError());
|
printf("Backbuffer could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ void Logo::render()
|
|||||||
// Dibuja el fade
|
// Dibuja el fade
|
||||||
if (counter >= initFade)
|
if (counter >= initFade)
|
||||||
{
|
{
|
||||||
const SDL_Rect rect = {0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
|
const SDL_Rect rect = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT};
|
||||||
const color_t color = {0xFF, 0xFF, 0xFF};
|
const color_t color = {0xFF, 0xFF, 0xFF};
|
||||||
const int fadeLenght = endLogo - initFade;
|
const int fadeLenght = endLogo - initFade;
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "asset.h"
|
#include "asset.h"
|
||||||
#include "jail_audio.h"
|
#include "jail_audio.h"
|
||||||
|
#include "const.h"
|
||||||
|
|
||||||
#ifndef LOGO_H
|
#ifndef LOGO_H
|
||||||
#define LOGO_H
|
#define LOGO_H
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ Prog::Prog(std::string executablePath)
|
|||||||
options->windowSize = 2;
|
options->windowSize = 2;
|
||||||
options->filter = FILTER_NEAREST;
|
options->filter = FILTER_NEAREST;
|
||||||
options->vSync = true;
|
options->vSync = true;
|
||||||
options->screenWidth = GAME_WIDTH * options->windowSize;
|
options->screenWidth = GAMECANVAS_WIDTH * options->windowSize;
|
||||||
options->screenHeight = GAME_HEIGHT * options->windowSize;
|
options->screenHeight = GAMECANVAS_HEIGHT * options->windowSize;
|
||||||
options->integerScale = true;
|
options->integerScale = true;
|
||||||
options->keepAspect = true;
|
options->keepAspect = true;
|
||||||
|
|
||||||
@@ -29,7 +29,8 @@ Prog::Prog(std::string executablePath)
|
|||||||
section.name = SECTION_PROG_GAME;
|
section.name = SECTION_PROG_GAME;
|
||||||
}
|
}
|
||||||
input = new Input(asset->get("gamecontrollerdb.txt"));
|
input = new Input(asset->get("gamecontrollerdb.txt"));
|
||||||
screen = new Screen(window, renderer, options);
|
screen = new Screen(window, renderer, options, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
|
||||||
|
screen->setBorderColor(borderColor);
|
||||||
|
|
||||||
// Controles
|
// Controles
|
||||||
input->bindKey(INPUT_UP, SDL_SCANCODE_UP);
|
input->bindKey(INPUT_UP, SDL_SCANCODE_UP);
|
||||||
|
|||||||
@@ -12,14 +12,11 @@
|
|||||||
#include "intro.h"
|
#include "intro.h"
|
||||||
#include "title.h"
|
#include "title.h"
|
||||||
#include "prog.h"
|
#include "prog.h"
|
||||||
|
#include "const.h"
|
||||||
|
|
||||||
#ifndef PROG_H
|
#ifndef PROG_H
|
||||||
#define PROG_H
|
#define PROG_H
|
||||||
|
|
||||||
#define WINDOW_CAPTION "Volcano"
|
|
||||||
#define GAME_WIDTH 320
|
|
||||||
#define GAME_HEIGHT 240
|
|
||||||
|
|
||||||
class Prog
|
class Prog
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "const.h"
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
// Constructor
|
// 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
|
// Inicializa variables
|
||||||
this->window = window;
|
this->window = window;
|
||||||
this->renderer = renderer;
|
this->renderer = renderer;
|
||||||
this->options = options;
|
this->options = options;
|
||||||
|
|
||||||
gameCanvasWidth = SCREEN_WIDTH;
|
gameCanvasWidth = gameInternalResX;
|
||||||
gameCanvasHeight = SCREEN_HEIGHT;
|
gameCanvasHeight = gameInternalResY;
|
||||||
|
|
||||||
// Establece el modo de video
|
// Establece el modo de video
|
||||||
setVideoMode(options->fullScreenMode);
|
setVideoMode(options->fullScreenMode);
|
||||||
@@ -25,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);
|
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight);
|
||||||
if (gameCanvas == NULL)
|
if (gameCanvas == NULL)
|
||||||
printf("TitleSurface could not be created!\nSDL Error: %s\n", SDL_GetError());
|
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
|
// Destructor
|
||||||
@@ -82,7 +89,7 @@ void Screen::setVideoMode(int fullScreenMode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Si está activo el modo de pantalla completa añade el borde
|
// Si está activo el modo de pantalla completa añade el borde
|
||||||
if (fullScreenMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
|
else if (fullScreenMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
|
||||||
{
|
{
|
||||||
// Obten el alto y el ancho de la ventana
|
// Obten el alto y el ancho de la ventana
|
||||||
SDL_GetWindowSize(window, &screenWidth, &screenHeight);
|
SDL_GetWindowSize(window, &screenWidth, &screenHeight);
|
||||||
@@ -130,4 +137,33 @@ void Screen::setVideoMode(int fullScreenMode)
|
|||||||
// Modifica el tamaño del renderizador
|
// Modifica el tamaño del renderizador
|
||||||
SDL_RenderSetLogicalSize(renderer, screenWidth, screenHeight);
|
SDL_RenderSetLogicalSize(renderer, screenWidth, screenHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actualiza el valor de la variable
|
||||||
|
options->fullScreenMode = fullScreenMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Camibia entre pantalla completa y ventana
|
||||||
|
void Screen::switchVideoMode()
|
||||||
|
{
|
||||||
|
if (options->fullScreenMode == 0)
|
||||||
|
{
|
||||||
|
setVideoMode(SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setVideoMode(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cambia el tamaño de la ventana
|
||||||
|
void Screen::setWindowSize(int size)
|
||||||
|
{
|
||||||
|
options->windowSize = size;
|
||||||
|
setVideoMode(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cambia el color del borde
|
||||||
|
void Screen::setBorderColor(color_t color)
|
||||||
|
{
|
||||||
|
borderColor = color;
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,16 @@
|
|||||||
#ifndef SCREEN_H
|
#ifndef SCREEN_H
|
||||||
#define 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
|
// Clase Screen
|
||||||
class Screen
|
class Screen
|
||||||
{
|
{
|
||||||
@@ -15,16 +25,17 @@ private:
|
|||||||
SDL_Texture *gameCanvas; // Textura para completar la ventana de juego hasta la pantalla completa
|
SDL_Texture *gameCanvas; // Textura para completar la ventana de juego hasta la pantalla completa
|
||||||
options_t *options; // Variable con todas las opciones del programa
|
options_t *options; // Variable con todas las opciones del programa
|
||||||
|
|
||||||
int screenWidth; // Ancho de la pantalla
|
int screenWidth; // Ancho de la pantalla o ventana
|
||||||
int screenHeight; // Alto de la pantalla
|
int screenHeight; // Alto de la pantalla o ventana
|
||||||
int gameCanvasWidth; // Ancho de la textura donde se dibuja el juego
|
int gameCanvasWidth; // Resolución interna del juego. Es el ancho de la textura donde se dibuja el juego
|
||||||
int gameCanvasHeight; // Alto de la textura donde se dibuja el juego
|
int gameCanvasHeight; // Resolución interna del juego. Es el alto de la textura donde se dibuja el juego
|
||||||
SDL_Rect dest; // Coordenadas donde se va a dibujar la textura del 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
|
color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// 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
|
// Destructor
|
||||||
~Screen();
|
~Screen();
|
||||||
@@ -40,6 +51,15 @@ public:
|
|||||||
|
|
||||||
// Establece el modo de video
|
// Establece el modo de video
|
||||||
void setVideoMode(int fullScreenMode);
|
void setVideoMode(int fullScreenMode);
|
||||||
|
|
||||||
|
// Camibia entre pantalla completa y ventana
|
||||||
|
void switchVideoMode();
|
||||||
|
|
||||||
|
// Cambia el tamaño de la ventana
|
||||||
|
void setWindowSize(int size);
|
||||||
|
|
||||||
|
// Cambia el color del borde
|
||||||
|
void setBorderColor(color_t color);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -94,7 +94,8 @@ void Title::render()
|
|||||||
|
|
||||||
// Dibuja los objetos
|
// Dibuja los objetos
|
||||||
sprite->render();
|
sprite->render();
|
||||||
text->writeDX(TXT_CENTER | TXT_COLOR, 160, 205, "@2016,2022 JAILDESIGNER & JAILBROTHER (v0.4)", 0, {255, 93, 4});
|
//const std::string text = TEXT_COPYRIGHT + " (" + VERSION + ")";
|
||||||
|
this->text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, 205, TEXT_COPYRIGHT, 0, {255, 93, 4});
|
||||||
menu->render();
|
menu->render();
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
|
|||||||
Reference in New Issue
Block a user