Modificado el bucle principal

This commit is contained in:
2022-08-08 20:12:51 +02:00
parent 1801c23957
commit 4439f8477a
4 changed files with 75 additions and 48 deletions

View File

@@ -8,6 +8,18 @@
// Textos // Textos
#define WINDOW_CAPTION "Volcano (©2016,2022 JailDesigner v0.6)" #define WINDOW_CAPTION "Volcano (©2016,2022 JailDesigner v0.6)"
// Tamaño de bloque
#define BLOCK 8
#define HALF_BLOCK 4
// Tamaño de la pantalla real
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240
// Tamaño de la pantalla virtual
#define GAMECANVAS_WIDTH 320
#define GAMECANVAS_HEIGHT 240
const Uint8 GAME_SPEED = 24; //16 = normal-rapido, 24 = normal. Cuanto mas pequeño, más rápido const Uint8 GAME_SPEED = 24; //16 = normal-rapido, 24 = normal. Cuanto mas pequeño, más rápido
const Uint8 UP = 0; const Uint8 UP = 0;
@@ -161,16 +173,6 @@ const Uint8 TOTAL_MUSIC = 3;
///////////////////////////////COFFEE CRISIS////////////////////////////////////////////// ///////////////////////////////COFFEE CRISIS//////////////////////////////////////////////
// Tamaño de bloque
const Uint8 BLOCK = 8;
const Uint8 HALF_BLOCK = BLOCK / 2;
// Tamaño de la pantalla real
const int SCREEN_WIDTH = 320;
const int SCREEN_HEIGHT = SCREEN_WIDTH * 3 / 4; // 240
// Tamaño de la pantalla que se muestra // Tamaño de la pantalla que se muestra
const int VIEW_WIDTH = SCREEN_WIDTH * 3; // 960 const int VIEW_WIDTH = SCREEN_WIDTH * 3; // 960
const int VIEW_HEIGHT = SCREEN_HEIGHT * 3; // 720 const int VIEW_HEIGHT = SCREEN_HEIGHT * 3; // 720

View File

@@ -347,18 +347,6 @@ bool Director::initResourceList()
return checkResourceList(); return checkResourceList();
} }
// Carga un archivo de imagen en una textura
bool Director::loadTextureFromFile(LTexture *texture, std::string path, SDL_Renderer *renderer)
{
bool success = true;
if (!texture->loadFromFile(path, renderer))
{
printf("Failed to load %s texture!\n", path.c_str());
success = false;
}
return success;
}
// Carga los recursos necesarios // Carga los recursos necesarios
bool Director::loadMedia(Uint8 section) bool Director::loadMedia(Uint8 section)
{ {
@@ -682,3 +670,37 @@ void Director::renderGame()
// Muestra el backbuffer en pantalla // Muestra el backbuffer en pantalla
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);
} }
// Bucle principal
void Director::run()
{
bool quit = false;
// Comprueba si existen todos los ficheros de recursos
if (!initResourceList())
{
quit = true;
}
// Arranca SDL y crea la ventana
if ((!quit) && (!initSDL()))
{
quit = true;
}
// Inicializa las variables del juego
if (!quit)
{
initGame();
}
// Bucle del juego
if (!quit)
{
while (isRunning())
{
runGame();
}
}
quitGame();
}

View File

@@ -100,13 +100,6 @@ private:
_section section; // Seccion actual del programa _section section; // Seccion actual del programa
bool quit; // Indica si hay que terminar el programa bool quit; // Indica si hay que terminar el programa
public:
// Constructor
Director(std::string _path);
// Destructor
~Director();
// Inicializa todas las variables // Inicializa todas las variables
void init(std::string _path); void init(std::string _path);
@@ -140,9 +133,6 @@ public:
// Inicializa la variable con los ficheros de recursos // Inicializa la variable con los ficheros de recursos
bool initResourceList(); bool initResourceList();
// Carga un archivo de imagen en una textura
bool loadTextureFromFile(LTexture *texture, std::string path, SDL_Renderer *renderer);
// Carga los recursos necesarios // Carga los recursos necesarios
bool loadMedia(Uint8 section); bool loadMedia(Uint8 section);
@@ -178,6 +168,16 @@ public:
// Actualiza la lógica del juego // Actualiza la lógica del juego
void updateGame(); void updateGame();
public:
// Constructor
Director(std::string _path);
// Destructor
~Director();
// Bucle principal
void run();
}; };
#endif #endif

View File

@@ -27,7 +27,7 @@ int main(int argc, char *args[])
// Crea el objeto director // Crea el objeto director
Director *director = new Director(args[0]); Director *director = new Director(args[0]);
// Comprueba si existen todos los ficheros de recursos /* // Comprueba si existen todos los ficheros de recursos
if (!director->initResourceList()) if (!director->initResourceList())
return -1; return -1;
@@ -40,7 +40,10 @@ int main(int argc, char *args[])
{ {
director->runGame(); director->runGame();
} }
director->quitGame(); director->quitGame(); */
// Bucle principal
director->run();
// Libera todos los recursos y cierra SDL // Libera todos los recursos y cierra SDL
delete director; delete director;