Tratando de eliminar las variables globales
This commit is contained in:
@@ -32,9 +32,74 @@ GameDirector::GameDirector()
|
|||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
GameDirector::~GameDirector()
|
||||||
|
{
|
||||||
|
// Libera los efectos de sonido
|
||||||
|
Mix_FreeChunk(gPopBalloonFX);
|
||||||
|
Mix_FreeChunk(gBulletFX);
|
||||||
|
gPopBalloonFX = NULL;
|
||||||
|
gBulletFX = NULL;
|
||||||
|
|
||||||
|
// Libra la música
|
||||||
|
Mix_FreeMusic(gTitleMusic);
|
||||||
|
gTitleMusic = NULL;
|
||||||
|
Mix_FreeMusic(gPlayingMusic);
|
||||||
|
gPlayingMusic = NULL;
|
||||||
|
|
||||||
|
// Libera el mando
|
||||||
|
SDL_JoystickClose(gGameController);
|
||||||
|
gGameController = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// Iniciador
|
// Iniciador
|
||||||
void GameDirector::init()
|
void GameDirector::init()
|
||||||
{
|
{
|
||||||
|
// Carga la música del titulo
|
||||||
|
gTitleMusic = Mix_LoadMUS("media/music/title.ogg");
|
||||||
|
if (gTitleMusic == NULL)
|
||||||
|
{
|
||||||
|
printf("Failed to load title music! SDL_mixer Error: %s\n", Mix_GetError());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga la música del juego
|
||||||
|
gPlayingMusic = Mix_LoadMUS("media/music/playing.ogg");
|
||||||
|
if (gPlayingMusic == NULL)
|
||||||
|
{
|
||||||
|
printf("Failed to load playing music! SDL_mixer Error: %s\n", Mix_GetError());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga los efectos de sonido para la explosión de los globos
|
||||||
|
gPopBalloonFX = Mix_LoadWAV("media/sound/balloon.wav");
|
||||||
|
if (gPopBalloonFX == NULL)
|
||||||
|
{
|
||||||
|
printf("Failed to load balloon sound effect! SDL_mixer Error: %s\n", Mix_GetError());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga los efectos de sonido para los disparos del jugador
|
||||||
|
gBulletFX = Mix_LoadWAV("media/sound/bullet.wav");
|
||||||
|
if (gBulletFX == NULL)
|
||||||
|
{
|
||||||
|
printf("Failed to load bullet sound effect! SDL_mixer Error: %s\n", Mix_GetError());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba los mandos
|
||||||
|
if (SDL_NumJoysticks() < 1)
|
||||||
|
{
|
||||||
|
printf("Warning: No joysticks connected!\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Carga el mando
|
||||||
|
gGameController = SDL_JoystickOpen(0);
|
||||||
|
if (gGameController == NULL)
|
||||||
|
{
|
||||||
|
printf("Warning: Unable to open game controller! SDL Error: %s\n", SDL_GetError());
|
||||||
|
}
|
||||||
|
printf("%i joysticks were found.\n", SDL_NumJoysticks());
|
||||||
|
std::cout << SDL_JoystickNumButtons(gGameController) << " buttons\n";
|
||||||
|
}
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
mGameStatus = GAME_STATE_TITLE;
|
mGameStatus = GAME_STATE_TITLE;
|
||||||
mOldTicks = 0;
|
mOldTicks = 0;
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ public:
|
|||||||
// Constructor
|
// Constructor
|
||||||
GameDirector();
|
GameDirector();
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~GameDirector();
|
||||||
|
|
||||||
// Iniciador
|
// Iniciador
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
@@ -126,6 +129,17 @@ public:
|
|||||||
void runPausedGame();
|
void runPausedGame();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Objetos con la música del juego
|
||||||
|
Mix_Music *gTitleMusic = NULL;
|
||||||
|
Mix_Music *gPlayingMusic = NULL;
|
||||||
|
|
||||||
|
// Objetos con los efectos de sonido del juego
|
||||||
|
Mix_Chunk *gPopBalloonFX = NULL;
|
||||||
|
Mix_Chunk *gBulletFX = NULL;
|
||||||
|
|
||||||
|
// Manejador para el mando 1
|
||||||
|
SDL_Joystick *gGameController = NULL;
|
||||||
|
|
||||||
// Manejador de eventos
|
// Manejador de eventos
|
||||||
SDL_Event eventHandler;
|
SDL_Event eventHandler;
|
||||||
|
|
||||||
|
|||||||
@@ -15,21 +15,9 @@ struct Circle
|
|||||||
Uint8 r;
|
Uint8 r;
|
||||||
};
|
};
|
||||||
|
|
||||||
//La ventana donde dibujamos
|
|
||||||
SDL_Window *gWindow = NULL;
|
|
||||||
|
|
||||||
//El renderizador de la ventana
|
//El renderizador de la ventana
|
||||||
SDL_Renderer *gRenderer = NULL;
|
SDL_Renderer *gRenderer = NULL;
|
||||||
|
|
||||||
//Manejador para el mando 1
|
|
||||||
SDL_Joystick* gGameController = NULL;
|
|
||||||
|
|
||||||
//Objetos con la música del juego
|
|
||||||
Mix_Music *gTitleMusic = NULL;
|
|
||||||
Mix_Music *gPlayingMusic = NULL;
|
|
||||||
|
|
||||||
//Objetos con los efectos de sonido del juego
|
|
||||||
Mix_Chunk *gPopBalloonFX = NULL;
|
|
||||||
Mix_Chunk *gBulletFX = NULL;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -54,6 +54,9 @@ un tipo asociado diferente a NO_KIND
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
//La ventana donde dibujamos
|
||||||
|
SDL_Window *gWindow = NULL;
|
||||||
|
|
||||||
//Arranca SDL y crea la ventana
|
//Arranca SDL y crea la ventana
|
||||||
bool init();
|
bool init();
|
||||||
|
|
||||||
@@ -90,23 +93,6 @@ bool init()
|
|||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Comprueba los mandos
|
|
||||||
if (SDL_NumJoysticks() < 1)
|
|
||||||
{
|
|
||||||
printf("Warning: No joysticks connected!\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//Carga el mando
|
|
||||||
gGameController = SDL_JoystickOpen(0);
|
|
||||||
if (gGameController == NULL)
|
|
||||||
{
|
|
||||||
printf("Warning: Unable to open game controller! SDL Error: %s\n", SDL_GetError());
|
|
||||||
}
|
|
||||||
printf("%i joysticks were found.\n", SDL_NumJoysticks());
|
|
||||||
std::cout << SDL_JoystickNumButtons(gGameController) << " buttons\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
//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);
|
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)
|
if (gWindow == NULL)
|
||||||
@@ -214,38 +200,6 @@ bool loadMedia()
|
|||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Carga la música del titulo
|
|
||||||
gTitleMusic = Mix_LoadMUS("media/music/title.ogg");
|
|
||||||
if (gTitleMusic == NULL)
|
|
||||||
{
|
|
||||||
printf("Failed to load title music! SDL_mixer Error: %s\n", Mix_GetError());
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Carga la música del juego
|
|
||||||
gPlayingMusic = Mix_LoadMUS("media/music/playing.ogg");
|
|
||||||
if (gPlayingMusic == NULL)
|
|
||||||
{
|
|
||||||
printf("Failed to load playing music! SDL_mixer Error: %s\n", Mix_GetError());
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Carga los efectos de sonido para la explosión de los globos
|
|
||||||
gPopBalloonFX = Mix_LoadWAV("media/sound/balloon.wav");
|
|
||||||
if (gPopBalloonFX == NULL)
|
|
||||||
{
|
|
||||||
printf("Failed to load balloon sound effect! SDL_mixer Error: %s\n", Mix_GetError());
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Carga los efectos de sonido para los disparos del jugador
|
|
||||||
gBulletFX = Mix_LoadWAV("media/sound/bullet.wav");
|
|
||||||
if (gBulletFX == NULL)
|
|
||||||
{
|
|
||||||
printf("Failed to load bullet sound effect! SDL_mixer Error: %s\n", Mix_GetError());
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,22 +216,6 @@ void close()
|
|||||||
gBalloonTexture.free();
|
gBalloonTexture.free();
|
||||||
gMiscTexture.free();
|
gMiscTexture.free();
|
||||||
|
|
||||||
//Libera los efectos de sonido
|
|
||||||
Mix_FreeChunk(gPopBalloonFX);
|
|
||||||
Mix_FreeChunk(gBulletFX);
|
|
||||||
gPopBalloonFX = NULL;
|
|
||||||
gBulletFX = NULL;
|
|
||||||
|
|
||||||
//Libra la música
|
|
||||||
Mix_FreeMusic(gTitleMusic);
|
|
||||||
gTitleMusic = NULL;
|
|
||||||
Mix_FreeMusic(gPlayingMusic);
|
|
||||||
gPlayingMusic = NULL;
|
|
||||||
|
|
||||||
//Libera el mando
|
|
||||||
SDL_JoystickClose(gGameController);
|
|
||||||
gGameController = NULL;
|
|
||||||
|
|
||||||
//Destruye la ventana
|
//Destruye la ventana
|
||||||
SDL_DestroyRenderer(gRenderer);
|
SDL_DestroyRenderer(gRenderer);
|
||||||
SDL_DestroyWindow(gWindow);
|
SDL_DestroyWindow(gWindow);
|
||||||
|
|||||||
Reference in New Issue
Block a user