Trabajando en integrar la clase screen

This commit is contained in:
2021-09-10 23:04:52 +02:00
parent b28d798545
commit 3fe0861e4f
15 changed files with 240 additions and 81 deletions

View File

@@ -10,13 +10,17 @@
#define BLOCK 8 #define BLOCK 8
#define HALF_BLOCK BLOCK / 2 #define HALF_BLOCK BLOCK / 2
// Tamaño de la pantalla real // Tamaño de la pantalla que contendrá la pantalla de juego
#define REAL_SCREEN_WIDTH 320
#define REAL_SCREEN_HEIGHT 240
// 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 = SCREEN_WIDTH * 3; const int VIEW_WIDTH = REAL_SCREEN_WIDTH * 3;
const int VIEW_HEIGHT = 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);

View File

@@ -22,7 +22,7 @@ Director::Director(std::string path)
if (!checkFileList()) if (!checkFileList())
section = PROG_SECTION_QUIT; section = PROG_SECTION_QUIT;
// Inicializa el objeto de idioma // Crea el objeto de idioma
mLang = new Lang(mFileList); mLang = new Lang(mFileList);
// 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
@@ -45,12 +45,15 @@ Director::Director(std::string path)
// Inicializa SDL // Inicializa SDL
initSDL(); initSDL();
// Crea el objeto para dibujar en pantalla (Requiere initSDL)
mScreen = new Screen(mWindow, mRenderer);
// Inicializa JailAudio // Inicializa JailAudio
initJailAudio(); initJailAudio();
// Aplica las opciones // Aplica las opciones
SDL_SetWindowFullscreen(mWindow, mOptions->fullScreenMode); SDL_SetWindowFullscreen(mWindow, mOptions->fullScreenMode);
SDL_SetWindowSize(mWindow, SCREEN_WIDTH * mOptions->windowSize, SCREEN_HEIGHT * mOptions->windowSize); //SDL_SetWindowSize(mWindow, REAL_SCREEN_WIDTH * mOptions->windowSize, REAL_SCREEN_HEIGHT * mOptions->windowSize);
mLang->setLang(mOptions->language); mLang->setLang(mOptions->language);
#ifdef __MIPSEL__ #ifdef __MIPSEL__
@@ -76,6 +79,9 @@ Director::~Director()
delete mInput; delete mInput;
mInput = nullptr; mInput = nullptr;
delete mScreen;
mScreen = nullptr;
delete mLang; delete mLang;
mLang = nullptr; mLang = nullptr;
@@ -484,21 +490,21 @@ void Director::setSection(section_t section)
void Director::runLogo() void Director::runLogo()
{ {
mLogo = new Logo(mRenderer, mFileList); mLogo = new Logo(mRenderer, mScreen, mFileList);
setSection(mLogo->run()); setSection(mLogo->run());
delete mLogo; delete mLogo;
} }
void Director::runIntro() void Director::runIntro()
{ {
mIntro = new Intro(mRenderer, mFileList, mLang); mIntro = new Intro(mRenderer, mScreen, mFileList, mLang);
setSection(mIntro->run()); setSection(mIntro->run());
delete mIntro; delete mIntro;
} }
void Director::runTitle() void Director::runTitle()
{ {
mTitle = new Title(mWindow, mRenderer, mInput, mFileList, mOptions, mLang); mTitle = new Title(mWindow, mRenderer, mScreen, mInput, mFileList, mOptions, mLang);
setSection(mTitle->run(mSection.subsection)); setSection(mTitle->run(mSection.subsection));
delete mTitle; delete mTitle;
} }
@@ -506,9 +512,9 @@ void Director::runTitle()
void Director::runGame() void Director::runGame()
{ {
if (mSection.subsection == GAME_SECTION_PLAY_1P) if (mSection.subsection == GAME_SECTION_PLAY_1P)
mGame = new Game(1, mRenderer, mFileList, mLang, mInput, false, mOptions); mGame = new Game(1, mRenderer, mScreen, mFileList, mLang, mInput, false, mOptions);
if (mSection.subsection == GAME_SECTION_PLAY_2P) if (mSection.subsection == GAME_SECTION_PLAY_2P)
mGame = new Game(2, mRenderer, mFileList, mLang, mInput, false, mOptions); mGame = new Game(2, mRenderer, mScreen, mFileList, mLang, mInput, false, mOptions);
setSection(mGame->run()); setSection(mGame->run());
delete mGame; delete mGame;
} }

View File

@@ -19,6 +19,7 @@
#include "title.h" #include "title.h"
#include "game.h" #include "game.h"
#include "input.h" #include "input.h"
#include "screen.h"
#include "fade.h" #include "fade.h"
#ifndef DIRECTOR_H #ifndef DIRECTOR_H
@@ -36,6 +37,7 @@ class Director
private: private:
SDL_Window *mWindow; // La ventana donde dibujamos SDL_Window *mWindow; // La ventana donde dibujamos
SDL_Renderer *mRenderer; // El renderizador de la ventana SDL_Renderer *mRenderer; // El renderizador de la ventana
Screen *mScreen; // Objeto encargado de dibujar en pantalla
Logo *mLogo; // Objeto para la sección del logo Logo *mLogo; // Objeto para la sección del logo
Intro *mIntro; // Objeto para la sección de la intro Intro *mIntro; // Objeto para la sección de la intro
Title *mTitle; // Objeto para la sección del titulo y el menu de opciones Title *mTitle; // Objeto para la sección del titulo y el menu de opciones

View File

@@ -5,10 +5,11 @@
#endif #endif
// Constructor // Constructor
Game::Game(int numPlayers, SDL_Renderer *renderer, std::string *filelist, Lang *lang, Input *input, bool demo, options_t *options) Game::Game(int numPlayers, SDL_Renderer *renderer, Screen *screen, std::string *filelist, Lang *lang, Input *input, bool demo, options_t *options)
{ {
// Copia los punteros // Copia los punteros
mRenderer = renderer; mRenderer = renderer;
mScreen = screen;
mFileList = filelist; mFileList = filelist;
mLang = lang; mLang = lang;
mInput = input; mInput = input;
@@ -100,6 +101,7 @@ Game::~Game()
mOptions->input[0].deviceType = mOnePlayerControl; mOptions->input[0].deviceType = mOnePlayerControl;
mRenderer = nullptr; mRenderer = nullptr;
mScreen = nullptr;
mFileList = nullptr; mFileList = nullptr;
mLang = nullptr; mLang = nullptr;
mInput = nullptr; mInput = nullptr;

View File

@@ -1,23 +1,21 @@
#pragma once #pragma once
#include "ifdefs.h"
#include "const.h"
#include "utils.h"
#include "sprite.h"
#include "movingsprite.h"
#include "smartsprite.h"
#include "player.h"
#include "balloon.h" #include "balloon.h"
#include "bullet.h" #include "bullet.h"
#include "item.h" #include "const.h"
#include "text.h"
#include "writer.h"
#include "menu.h"
#include "input.h"
#include "fade.h" #include "fade.h"
#include "ifdefs.h"
#include "input.h"
#include "item.h"
#include "jail_audio.h" #include "jail_audio.h"
#include "menu.h"
#include "movingsprite.h"
#include "player.h"
#include "screen.h"
#include "smartsprite.h"
#include "sprite.h"
#include "text.h"
#include "utils.h"
#include "writer.h"
#ifndef GAME_H #ifndef GAME_H
#define GAME_H #define GAME_H
@@ -116,6 +114,7 @@ private:
}; };
SDL_Renderer *mRenderer; // El renderizador de la ventana SDL_Renderer *mRenderer; // El renderizador de la ventana
Screen *mScreen; // Objeto encargado de dibujar en pantalla
std::string *mFileList; // Lista de ficheros con los recursos std::string *mFileList; // Lista de ficheros con los recursos
Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas
@@ -145,13 +144,13 @@ private:
LTexture *mTextureTextScoreBoard; // Textura para el texto del marcador LTexture *mTextureTextScoreBoard; // Textura para el texto del marcador
LTexture *mTextureTextBig; // Textura para el texto grande LTexture *mTextureTextBig; // Textura para el texto grande
LTexture *mTextureTextNokia2; // Textura para la fuente de texto Nokia LTexture *mTextureTextNokia2; // Textura para la fuente de texto Nokia
LTexture *mTextureTextNokiaBig2; // Textura para la fuente de texto Nokia grande LTexture *mTextureTextNokiaBig2; // Textura para la fuente de texto Nokia grande
Text *mText; // Fuente para los textos del juego Text *mText; // Fuente para los textos del juego
Text *mTextBig; // Fuente de texto grande Text *mTextBig; // Fuente de texto grande
Text *mTextScoreBoard; // Fuente para el marcador del juego Text *mTextScoreBoard; // Fuente para el marcador del juego
Text *mTextNokia2; // Otra fuente de texto para mesajes Text *mTextNokia2; // Otra fuente de texto para mesajes
Text *mTextNokiaBig2; // Y la versión en grande Text *mTextNokiaBig2; // Y la versión en grande
Menu *mMenuGameOver; // Menú de la pantalla de game over Menu *mMenuGameOver; // Menú de la pantalla de game over
Menu *mMenuPause; // Menú de la pantalla de pausa Menu *mMenuPause; // Menú de la pantalla de pausa
@@ -536,7 +535,7 @@ private:
public: public:
// Constructor // Constructor
Game(int numPlayers, SDL_Renderer *renderer, std::string *filelist, Lang *lang, Input *input, bool demo, options_t *options); Game(int numPlayers, SDL_Renderer *renderer, Screen *screen, std::string *filelist, Lang *lang, Input *input, bool demo, options_t *options);
// Destructor // Destructor
~Game(); ~Game();

View File

@@ -7,10 +7,11 @@
const Uint8 SELF = 0; const Uint8 SELF = 0;
// Constructor // Constructor
Instructions::Instructions(SDL_Renderer *renderer, std::string *fileList, Lang *lang) Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, std::string *fileList, Lang *lang)
{ {
// Copia los punteros // Copia los punteros
mRenderer = renderer; mRenderer = renderer;
mScreen = screen;
mFileList = fileList; mFileList = fileList;
mLang = lang; mLang = lang;
@@ -30,6 +31,11 @@ Instructions::Instructions(SDL_Renderer *renderer, std::string *fileList, Lang *
// Destructor // Destructor
Instructions::~Instructions() Instructions::~Instructions()
{ {
mRenderer = nullptr;
mScreen = nullptr;
mFileList = nullptr;
mLang = nullptr;
mItemTexture->unload(); mItemTexture->unload();
delete mItemTexture; delete mItemTexture;
mItemTexture = nullptr; mItemTexture = nullptr;

View File

@@ -1,11 +1,11 @@
#pragma once #pragma once
#include "ifdefs.h"
#include "utils.h"
#include "const.h" #include "const.h"
#include "ifdefs.h"
#include "jail_audio.h"
#include "screen.h"
#include "sprite.h" #include "sprite.h"
#include "text.h" #include "text.h"
#include "jail_audio.h" #include "utils.h"
#ifndef INSTRUCTIONS_H #ifndef INSTRUCTIONS_H
#define INSTRUCTIONS_H #define INSTRUCTIONS_H
@@ -21,10 +21,11 @@
class Instructions class Instructions
{ {
private: private:
SDL_Renderer *mRenderer; // El renderizador de la ventana
Screen *mScreen; // Objeto encargado de dibujar en pantalla
LTexture *mItemTexture; // Textura con los graficos LTexture *mItemTexture; // Textura con los graficos
LTexture *mTextTexture; // Textura con los graficos LTexture *mTextTexture; // Textura con los graficos
SDL_Event *mEventHandler; // Manejador de eventos SDL_Event *mEventHandler; // Manejador de eventos
SDL_Renderer *mRenderer; // El renderizador de la ventana
SDL_Texture *mBackbuffer; // Textura para usar como backbuffer SDL_Texture *mBackbuffer; // Textura para usar como backbuffer
Sprite *mSprite; // Sprite con la textura de las instrucciones Sprite *mSprite; // Sprite con la textura de las instrucciones
std::string *mFileList; // Lista de ficheros std::string *mFileList; // Lista de ficheros
@@ -50,7 +51,7 @@ private:
public: public:
// Constructor // Constructor
Instructions(SDL_Renderer *renderer, std::string *fileList, Lang *lang); Instructions(SDL_Renderer *renderer, Screen *screen, std::string *fileList, Lang *lang);
// Destructor // Destructor
~Instructions(); ~Instructions();

View File

@@ -5,10 +5,11 @@
#endif #endif
// Constructor // Constructor
Intro::Intro(SDL_Renderer *renderer, std::string *fileList, Lang *lang) Intro::Intro(SDL_Renderer *renderer, Screen *screen, std::string *fileList, Lang *lang)
{ {
// Copia los punteros // Copia los punteros
mRenderer = renderer; mRenderer = renderer;
mScreen = screen;
mFileList = fileList; mFileList = fileList;
mLang = lang; mLang = lang;
@@ -28,6 +29,11 @@ Intro::Intro(SDL_Renderer *renderer, std::string *fileList, Lang *lang)
// Destructor // Destructor
Intro::~Intro() Intro::~Intro()
{ {
mRenderer = nullptr;
mScreen = nullptr;
mFileList = nullptr;
mLang = nullptr;
delete mEventHandler; delete mEventHandler;
mEventHandler = nullptr; mEventHandler = nullptr;
@@ -210,28 +216,29 @@ section_t Intro::run()
while (mSection.name == PROG_SECTION_INTRO) while (mSection.name == PROG_SECTION_INTRO)
{ {
// Comprueba los eventos que hay en la cola
while (SDL_PollEvent(mEventHandler) != 0)
{
// Evento de salida de la aplicación
if (mEventHandler->type == SDL_QUIT)
{
mSection.name = PROG_SECTION_QUIT;
break;
}
if ((mEventHandler->type == SDL_KEYDOWN) || (mEventHandler->type == SDL_JOYBUTTONDOWN))
{
JA_StopMusic();
mSection = {PROG_SECTION_TITLE, TITLE_SECTION_1};
}
}
// Calcula la lógica del bucle
if (SDL_GetTicks() - mTicks > mTicksSpeed) if (SDL_GetTicks() - mTicks > mTicksSpeed)
{ {
// Actualiza el contador de ticks // Actualiza el contador de ticks
mTicks = SDL_GetTicks(); mTicks = SDL_GetTicks();
// Comprueba los eventos que hay en la cola
while (SDL_PollEvent(mEventHandler) != 0)
{
// Evento de salida de la aplicación
if (mEventHandler->type == SDL_QUIT)
{
mSection.name = PROG_SECTION_QUIT;
break;
}
if ((mEventHandler->type == SDL_KEYDOWN) || (mEventHandler->type == SDL_JOYBUTTONDOWN))
{
JA_StopMusic();
mSection = {PROG_SECTION_TITLE, TITLE_SECTION_1};
}
}
// Actualiza los objetos // Actualiza los objetos
for (int i = 0; i < INTRO_TOTAL_BITMAPS; i++) for (int i = 0; i < INTRO_TOTAL_BITMAPS; i++)
mBitmap[i]->update(); mBitmap[i]->update();
@@ -352,8 +359,14 @@ section_t Intro::run()
} }
// Limpia la pantalla // Limpia la pantalla
SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, 0xFF); //SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, 0xFF);
SDL_RenderClear(mRenderer); //SDL_RenderClear(mRenderer);
// Prepara para empezar a dibujar en la textura de juego
mScreen->start();
// Limpia la pantalla
mScreen->clean(bgColor);
// Dibuja los objetos // Dibuja los objetos
for (int i = 0; i < INTRO_TOTAL_BITMAPS; i++) for (int i = 0; i < INTRO_TOTAL_BITMAPS; i++)
@@ -362,7 +375,10 @@ section_t Intro::run()
mWriter[i]->render(); mWriter[i]->render();
// Actualiza la pantalla // Actualiza la pantalla
SDL_RenderPresent(mRenderer); //SDL_RenderPresent(mRenderer);
// Vuelca el contenido del renderizador en pantalla
mScreen->blit();
} }
return mSection; return mSection;

View File

@@ -2,7 +2,7 @@
#include "ifdefs.h" #include "ifdefs.h"
#include "const.h" #include "const.h"
#include "utils.h" #include "utils.h"
#include "screen.h"
#include "smartsprite.h" #include "smartsprite.h"
#include "writer.h" #include "writer.h"
#include "jail_audio.h" #include "jail_audio.h"
@@ -36,10 +36,11 @@ const int INTRO_TOTAL_EVENTS = INTRO_TOTAL_BITMAPS + INTRO_TOTAL_TEXTS;
class Intro class Intro
{ {
private: private:
SDL_Renderer *mRenderer; // El renderizador de la ventana
Screen *mScreen; // Objeto encargado de dibujar en pantalla
LTexture *mBitmapTexture; // Textura con los graficos LTexture *mBitmapTexture; // Textura con los graficos
LTexture *mTextTexture; // Textura con los caracteres de texto LTexture *mTextTexture; // Textura con los caracteres de texto
SDL_Event *mEventHandler; // Manejador de eventos SDL_Event *mEventHandler; // Manejador de eventos
SDL_Renderer *mRenderer; // El renderizador de la ventana
std::string *mFileList; // Lista de ficheros std::string *mFileList; // Lista de ficheros
Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas
section_t mSection; // Estado del bucle principal para saber si continua o se sale section_t mSection; // Estado del bucle principal para saber si continua o se sale
@@ -53,7 +54,7 @@ private:
public: public:
// Constructor // Constructor
Intro(SDL_Renderer *renderer, std::string *fileList, Lang *lang); Intro(SDL_Renderer *renderer, Screen *screen, std::string *fileList, Lang *lang);
// Destructor // Destructor
~Intro(); ~Intro();

View File

@@ -4,16 +4,15 @@
#include <dirent.h> #include <dirent.h>
#endif #endif
# define INIT_FADE 100 #define INIT_FADE 100
# define END_LOGO 200 #define END_LOGO 200
// Constructor // Constructor
Logo::Logo(SDL_Renderer *renderer, std::string *fileList) Logo::Logo(SDL_Renderer *renderer, Screen *screen, std::string *fileList)
{ {
// Copia la dirección del renderizador // Copia la dirección de los objetos
mRenderer = renderer; mRenderer = renderer;
mScreen = screen;
// Copia la dirección del la lista de ficheros
mFileList = fileList; mFileList = fileList;
// Reserva memoria para los punteros // Reserva memoria para los punteros
@@ -30,6 +29,10 @@ Logo::Logo(SDL_Renderer *renderer, std::string *fileList)
// Destructor // Destructor
Logo::~Logo() Logo::~Logo()
{ {
mRenderer = nullptr;
mScreen = nullptr;
mFileList = nullptr;
mTexture->unload(); mTexture->unload();
delete mTexture; delete mTexture;
mTexture = nullptr; mTexture = nullptr;
@@ -97,8 +100,14 @@ section_t Logo::run()
} }
// Limpia el destino // Limpia el destino
SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, 255); //SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, 255);
SDL_RenderClear(mRenderer); //SDL_RenderClear(mRenderer);
// Prepara para empezar a dibujar en la textura de juego
mScreen->start();
// Limpia la pantalla
mScreen->clean(bgColor);
// Dibuja los objetos // Dibuja los objetos
mSprite->render(); mSprite->render();
@@ -115,7 +124,10 @@ section_t Logo::run()
} }
// Actualiza la pantalla // Actualiza la pantalla
SDL_RenderPresent(mRenderer); //SDL_RenderPresent(mRenderer);
// Vuelca el contenido del renderizador en pantalla
mScreen->blit();
// Comprueba si ha terminado el logo // Comprueba si ha terminado el logo
if (SDL_GetTicks() - mTicks > mTicksSpeed) if (SDL_GetTicks() - mTicks > mTicksSpeed)

View File

@@ -2,8 +2,8 @@
#include "ifdefs.h" #include "ifdefs.h"
#include "const.h" #include "const.h"
#include "utils.h" #include "utils.h"
#include "sprite.h" #include "sprite.h"
#include "screen.h"
#include "jail_audio.h" #include "jail_audio.h"
#ifndef LOGO_H #ifndef LOGO_H
@@ -13,12 +13,13 @@
class Logo class Logo
{ {
private: private:
SDL_Renderer *mRenderer; // El renderizador de la ventana
Screen *mScreen; // Objeto encargado de dibujar en pantalla
std::string *mFileList; // Lista de ficheros
LTexture *mTexture; // Textura con los graficos LTexture *mTexture; // Textura con los graficos
SDL_Event *mEventHandler; // Manejador de eventos SDL_Event *mEventHandler; // Manejador de eventos
SDL_Renderer *mRenderer; // El renderizador de la ventana
SDL_Texture *mBackbuffer; // Textura para usar como backbuffer SDL_Texture *mBackbuffer; // Textura para usar como backbuffer
Sprite *mSprite; // Sprite con la textura del logo Sprite *mSprite; // Sprite con la textura del logo
std::string *mFileList; // Lista de ficheros
Uint16 mCounter; // Contador Uint16 mCounter; // Contador
section_t mSection; // Estado del bucle principal para saber si continua o se sale section_t mSection; // Estado del bucle principal para saber si continua o se sale
Uint32 mTicks; // Contador de ticks para ajustar la velocidad del programa Uint32 mTicks; // Contador de ticks para ajustar la velocidad del programa
@@ -26,7 +27,7 @@ private:
public: public:
// Constructor // Constructor
Logo(SDL_Renderer *renderer, std::string *fileList); Logo(SDL_Renderer *renderer, Screen *screen, std::string *fileList);
// Destructor // Destructor
~Logo(); ~Logo();

63
source/screen.cpp Normal file
View File

@@ -0,0 +1,63 @@
#include "screen.h"
#include "const.h"
// Constructor
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
{
// Inicializa variables
mWindow = window;
mRenderer = renderer;
mScreenWidth = 320;//REAL_SCREEN_WIDTH;
mScreenHeight = 240;//REAL_SCREEN_HEIGHT;
mGameCanvasWidth = 256;//SCREEN_WIDTH;
mGameCanvasHeight = 192;//SCREEN_HEIGHT;
mGameCanvasPosX = 0;//(REAL_SCREEN_WIDTH - SCREEN_WIDTH) / 2;
mGameCanvasPosY = 0;//(REAL_SCREEN_HEIGHT - SCREEN_HEIGHT) / 2;
mBorderColor = {0x27, 0x27, 0x36};
// Crea la textura donde se dibujan los graficos del juego
mGameCanvas = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, mGameCanvasWidth, mGameCanvasHeight);
if (mGameCanvas == NULL)
printf("TitleSurface could not be created!\nSDL Error: %s\n", SDL_GetError());
}
// Destructor
Screen::~Screen()
{
mRenderer = nullptr;
}
// Limpia la pantalla
void Screen::clean(color_t color)
{
SDL_SetRenderDrawColor(mRenderer, color.r, color.g, color.b, 0xFF);
SDL_RenderClear(mRenderer);
}
// Prepara para empezar a dibujar en la textura de juego
void Screen::start()
{
SDL_SetRenderTarget(mRenderer, mGameCanvas);
}
// Vuelca el contenido del renderizador en pantalla
void Screen::blit()
{
// Vuelve a dejar el renderizador en modo normal
SDL_SetRenderTarget(mRenderer, NULL);
// Borra el contenido previo
SDL_SetRenderDrawColor(mRenderer, mBorderColor.r, mBorderColor.g, mBorderColor.b, 0xFF);
SDL_RenderClear(mRenderer);
// Rectangulo de destino donde se dibujarà la textura con el juego
SDL_Rect dest = {mGameCanvasPosX, mGameCanvasPosY, mGameCanvasWidth, mGameCanvasHeight};
// Copia la textura de juego en el renderizador en la posición adecuada
SDL_RenderCopy(mRenderer, mGameCanvas, NULL, &dest);
// Muestra por pantalla el renderizador
SDL_RenderPresent(mRenderer);
}

42
source/screen.h Normal file
View File

@@ -0,0 +1,42 @@
#pragma once
#include "ifdefs.h"
#include "utils.h"
#ifndef SCREEN_H
#define SCREEN_H
// Clase Screen
class Screen
{
private:
SDL_Window *mWindow; // Ventana de la aplicación
SDL_Renderer *mRenderer; // El renderizador de la ventana
SDL_Texture *mGameCanvas; // Textura para completar la ventana de juego hasta la pantalla completa
int mScreenWidth; // Ancho de la pantalla
int mScreenHeight; // Alto de la pantalla
int mGameCanvasWidth; // Ancho 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
color_t mBorderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
public:
// Constructor
Screen(SDL_Window *windows, SDL_Renderer *renderer);
// Destructor
~Screen();
// Limpia la pantalla
void clean(color_t color);
// Prepara para empezar a dibujar en la textura de juego
void start();
// Vuelca el contenido del renderizador en pantalla
void blit();
};
#endif

View File

@@ -5,11 +5,12 @@
#endif #endif
// Constructor // Constructor
Title::Title(SDL_Window *window, SDL_Renderer *renderer, Input *input, std::string *fileList, options_t *options, Lang *lang) Title::Title(SDL_Window *window, SDL_Renderer *renderer, Screen *screen, Input *input, std::string *fileList, options_t *options, Lang *lang)
{ {
// Copia las direcciones de los punteros // Copia las direcciones de los punteros
mWindow = window; mWindow = window;
mRenderer = renderer; mRenderer = renderer;
mScreen = screen;
mInput = input; mInput = input;
mFileList = fileList; mFileList = fileList;
mOptions = options; mOptions = options;
@@ -44,6 +45,7 @@ Title::~Title()
{ {
mWindow = nullptr; mWindow = nullptr;
mRenderer = nullptr; mRenderer = nullptr;
mScreen = nullptr;
mInput = nullptr; mInput = nullptr;
mFileList = nullptr; mFileList = nullptr;
mOptions = nullptr; mOptions = nullptr;
@@ -910,7 +912,7 @@ section_t Title::run(Uint8 subsection)
// Ejecuta la parte donde se muestran las instrucciones // Ejecuta la parte donde se muestran las instrucciones
void Title::runInstructions(Uint8 mode) void Title::runInstructions(Uint8 mode)
{ {
mInstructions = new Instructions(mRenderer, mFileList, mLang); mInstructions = new Instructions(mRenderer, mScreen, mFileList, mLang);
mInstructions->run(mode); mInstructions->run(mode);
delete mInstructions; delete mInstructions;
} }
@@ -918,7 +920,7 @@ void Title::runInstructions(Uint8 mode)
// Ejecuta el juego en modo demo // Ejecuta el juego en modo demo
void Title::runDemoGame() void Title::runDemoGame()
{ {
mDemoGame = new Game(1, mRenderer, mFileList, mLang, mInput, true, mOptions); mDemoGame = new Game(1, mRenderer, mScreen, mFileList, mLang, mInput, true, mOptions);
mDemoGame->run(); mDemoGame->run();
delete mDemoGame; delete mDemoGame;
} }

View File

@@ -12,6 +12,7 @@
#include "input.h" #include "input.h"
#include "instructions.h" #include "instructions.h"
#include "game.h" #include "game.h"
#include "screen.h"
#include "jail_audio.h" #include "jail_audio.h"
#ifndef TITLE_H #ifndef TITLE_H
@@ -31,6 +32,8 @@ class Title
{ {
private: private:
SDL_Window *mWindow; // Ventana de la aplicación SDL_Window *mWindow; // Ventana de la aplicación
SDL_Renderer *mRenderer; // El renderizador de la ventana
Screen *mScreen; // Objeto encargado de dibujar en pantalla
AnimatedSprite *mDustBitmapL; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo AnimatedSprite *mDustBitmapL; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo
AnimatedSprite *mDustBitmapR; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo AnimatedSprite *mDustBitmapR; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo
bool mMenuVisible; // Indicador para saber si se muestra el menu del titulo o la frase intermitente bool mMenuVisible; // Indicador para saber si se muestra el menu del titulo o la frase intermitente
@@ -43,7 +46,6 @@ private:
LTexture *mTextTexture2; // Textura con los gráficos para el texto LTexture *mTextTexture2; // Textura con los gráficos para el texto
SDL_Event *mEventHandler; // Manejador de eventos SDL_Event *mEventHandler; // Manejador de eventos
SDL_Rect mBackgroundWindow; // Ventana visible para la textura de fondo del titulo SDL_Rect mBackgroundWindow; // Ventana visible para la textura de fondo del titulo
SDL_Renderer *mRenderer; // El renderizador de la ventana
SDL_Texture *mBackground; // Textura dibujar el fondo del titulo SDL_Texture *mBackground; // Textura dibujar el fondo del titulo
SmartSprite *mCoffeeBitmap; // Sprite con la palabra COFFEE para la pantalla de titulo SmartSprite *mCoffeeBitmap; // Sprite con la palabra COFFEE para la pantalla de titulo
SmartSprite *mCrisisBitmap; // Sprite con la palabra CRISIS para la pantalla de titulo SmartSprite *mCrisisBitmap; // Sprite con la palabra CRISIS para la pantalla de titulo
@@ -77,10 +79,10 @@ private:
}; };
menu_t mMenu; // Variable con todos los objetos menus y sus variables menu_t mMenu; // Variable con todos los objetos menus y sus variables
struct options_t *mOptions; // Variable con todas las variables de las opciones del programa struct options_t *mOptions; // Variable con todas las variables de las opciones del programa
options_t mOptionsPrevious; // Variable de respaldo para las opciones options_t mOptionsPrevious; // Variable de respaldo para las opciones
std::vector<input_t> mAvailableInputDevices; // Vector con todos los metodos de control disponibles std::vector<input_t> mAvailableInputDevices; // Vector con todos los metodos de control disponibles
int mDeviceIndex[2]; // Indice para el jugador [i] del vector de dispositivos de entrada disponibles int mDeviceIndex[2]; // Indice para el jugador [i] del vector de dispositivos de entrada disponibles
// Carga los recursos necesarios para la sección 'Title' // Carga los recursos necesarios para la sección 'Title'
bool loadMedia(); bool loadMedia();
@@ -111,7 +113,7 @@ private:
public: public:
// Constructor // Constructor
Title(SDL_Window *window, SDL_Renderer *renderer, Input *input, std::string *fileList, options_t *options, Lang *lang); Title(SDL_Window *window, SDL_Renderer *renderer, Screen *screen, Input *input, std::string *fileList, options_t *options, Lang *lang);
// Destructor // Destructor
~Title(); ~Title();