Quitadas todas las variables globales y transformadas en punteros

This commit is contained in:
2022-10-20 18:24:12 +02:00
parent 596bf2c4a5
commit b4e76a4c7d
25 changed files with 848 additions and 781 deletions

View File

@@ -43,7 +43,6 @@ un tipo asociado diferente a NO_KIND
#include "const.h"
#include "gamedirector.h"
#include "globals.h"
#include "globals2.h"
#include "ltexture.h"
#include "menu.h"
#include "player.h"
@@ -54,25 +53,28 @@ un tipo asociado diferente a NO_KIND
#include <stdio.h>
#include <string>
//La ventana donde dibujamos
// La ventana donde dibujamos
SDL_Window *gWindow = NULL;
//Arranca SDL y crea la ventana
// El renderizador de la ventana
SDL_Renderer *gRenderer = NULL;
// Arranca SDL y crea la ventana
bool init();
//Carga todos los recursos
// Carga todos los recursos
bool loadMedia();
//Libera todos los recursos y cierra SDL
// Libera todos los recursos y cierra SDL
void close();
//Arranca SDL y crea la ventana
// Arranca SDL y crea la ventana
bool init()
{
//Indicador de inicialización
// Indicador de inicialización
bool success = true;
//Inicializa SDL
// Inicializa SDL
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) < 0)
{
printf("SDL could not initialize! SDL Error: %s\n", SDL_GetError());
@@ -80,20 +82,20 @@ bool init()
}
else
{
//Establece el filtro de la textura a nearest
// Establece el filtro de la textura a nearest
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0"))
{
printf("Warning: Nearest texture filtering not enabled!");
}
//Inicializa SDL_mixer
// Inicializa SDL_mixer
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0)
{
printf("SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError());
success = false;
}
//Crea la ventana
// Crea la ventana
gWindow = SDL_CreateWindow("Super Popping (Like Loc) in Jailers World", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, VIEW_WIDTH, VIEW_HEIGHT, SDL_WINDOW_SHOWN);
if (gWindow == NULL)
{
@@ -102,7 +104,7 @@ bool init()
}
else
{
//Crea un renderizador para la ventana con vsync
// Crea un renderizador para la ventana con vsync
gRenderer = SDL_CreateRenderer(gWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (gRenderer == NULL)
{
@@ -111,13 +113,13 @@ bool init()
}
else
{
//Inicializa el color de renderizado
// Inicializa el color de renderizado
SDL_SetRenderDrawColor(gRenderer, 0x00, 0x00, 0x00, 0xFF);
//Establece el tamaño del buffer de renderizado
// Establece el tamaño del buffer de renderizado
SDL_RenderSetLogicalSize(gRenderer, SCREEN_WIDTH, SCREEN_HEIGHT);
//Inicializa el cargador de PNG
// Inicializa el cargador de PNG
int imgFlags = IMG_INIT_PNG;
if (!(IMG_Init(imgFlags) & imgFlags))
{
@@ -131,105 +133,23 @@ bool init()
return success;
}
//Carga todos los recursos
bool loadMedia()
{
//Indicador de éxito en la carga
bool success = true;
//Carga los gráficos del jugador
if (!gPlayerTexture.loadFromFile("media/gfx/player.png"))
{
printf("Failed to load player texture!\n");
success = false;
}
//Carga los gráficos de los globos
if (!gBalloonTexture.loadFromFile("media/gfx/balloon.png"))
{
printf("Failed to load balloon texture!\n");
success = false;
}
//Carga los gráficos de las balas
if (!gBulletTexture.loadFromFile("media/gfx/bullet.png"))
{
printf("Failed to load bullet texture!\n");
success = false;
}
//Carga los gráficos del fondo del juego
if (!gGameBackgroundTexture.loadFromFile("media/gfx/background.png"))
{
printf("Failed to load game background texture!\n");
success = false;
}
//Carga los gráficos del fondo de la pantalla de titulo
if (!gTitleBackgroundTexture.loadFromFile("media/gfx/title.png"))
{
printf("Failed to load title texture!\n");
success = false;
}
//Carga varios gráficos para varios propósitos
if (!gMiscTexture.loadFromFile("media/gfx/misc.png"))
{
printf("Failed to load misc texture!\n");
success = false;
}
//Carga los gráficos para el menu
if (!gMenuTexture.loadFromFile("media/gfx/menu.png"))
{
printf("Failed to load menu texture!\n");
success = false;
}
//Carga los gráficos para el texto blanco
if (!gWhiteFontTexture.loadFromFile("media/gfx/white_font.png"))
{
printf("Failed to load white font texture!\n");
success = false;
}
//Carga los gráficos para el texto negro
if (!gBlackFontTexture.loadFromFile("media/gfx/black_font.png"))
{
printf("Failed to load black font texture!\n");
success = false;
}
return success;
}
//Libera todos los recursos y cierra SDL
// Libera todos los recursos y cierra SDL
void close()
{
//Libera todas las imagenes
gPlayerTexture.free();
gGameBackgroundTexture.free();
gTitleBackgroundTexture.free();
gWhiteFontTexture.free();
gBlackFontTexture.free();
gMenuTexture.free();
gBalloonTexture.free();
gMiscTexture.free();
//Destruye la ventana
// Destruye la ventana
SDL_DestroyRenderer(gRenderer);
SDL_DestroyWindow(gWindow);
gWindow = NULL;
gRenderer = NULL;
//Sal del subsistema SDL
// Sal del subsistema SDL
IMG_Quit();
SDL_Quit();
}
int main(int argc, char *args[])
{
//Arranca SDL y crea la ventana
// Arranca SDL y crea la ventana
if (!init())
{
printf("Failed to initialize!\n");
@@ -237,24 +157,18 @@ int main(int argc, char *args[])
}
else
{
//Carga los recursos
if (!loadMedia())
{
printf("Failed to load media!\n");
}
else
{
//Crea el objeto gameDirector
GameDirector gameDirector;
// Crea el objeto gameDirector
GameDirector gameDirector(gRenderer);
//Inicializa el objeto gameDirector
// Inicializa el objeto gameDirector
gameDirector.init();
#ifdef TEST
gameDirector.resetBalloons();
#endif
//Mientras no se quiera salir del juego
// Mientras no se quiera salir del juego
while (!(gameDirector.getGameStatus() == GAME_STATE_QUIT))
{
switch (gameDirector.getGameStatus())
@@ -274,7 +188,7 @@ int main(int argc, char *args[])
}
}
//Libera todos los recursos y cierra SDL
// Libera todos los recursos y cierra SDL
close();
return 0;