Intentando hacer que suene jail_audio

This commit is contained in:
2022-10-21 17:52:50 +02:00
parent f63ff07397
commit 5098ed1638
3 changed files with 70 additions and 279 deletions

View File

@@ -43,6 +43,70 @@ GameDirector::GameDirector(SDL_Renderer *gRenderer)
bullet[i] = new Bullet(gRenderer); bullet[i] = new Bullet(gRenderer);
} }
// Carga la música del titulo
gTitleMusic = JA_LoadMusic("media/music/title.ogg");
// Carga la música del juego
gPlayingMusic = JA_LoadMusic("media/music/playing.ogg");
// Carga los efectos de sonido para la explosión de los globos
gPopBalloonFX = JA_LoadSound("media/sound/balloon.wav");
// Carga los efectos de sonido para los disparos del jugador
gBulletFX = JA_LoadSound("media/sound/bullet.wav");
// Carga los gráficos del fondo del juego
gGameBackgroundTexture = new LTexture(gRenderer);
if (!gGameBackgroundTexture->loadFromFile("media/gfx/background.png"))
{
printf("Failed to load game background texture!\n");
}
// Carga los gráficos del fondo de la pantalla de titulo
gTitleBackgroundTexture = new LTexture(gRenderer);
if (!gTitleBackgroundTexture->loadFromFile("media/gfx/title.png"))
{
printf("Failed to load title texture!\n");
}
// Carga varios gráficos para varios propósitos
gMiscTexture = new LTexture(gRenderer);
if (!gMiscTexture->loadFromFile("media/gfx/misc.png"))
{
printf("Failed to load misc texture!\n");
}
// Carga los gráficos para el texto blanco
gWhiteFontTexture = new LTexture(gRenderer);
if (!gWhiteFontTexture->loadFromFile("media/gfx/white_font.png"))
{
printf("Failed to load white font texture!\n");
}
// Carga los gráficos para el texto negro
gBlackFontTexture = new LTexture(gRenderer);
if (!gBlackFontTexture->loadFromFile("media/gfx/black_font.png"))
{
printf("Failed to load black font texture!\n");
}
// 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";
}
init(); init();
} }
@@ -50,18 +114,10 @@ GameDirector::GameDirector(SDL_Renderer *gRenderer)
GameDirector::~GameDirector() GameDirector::~GameDirector()
{ {
// Libera los efectos de sonido // Libera los efectos de sonido
// Mix_FreeChunk(gPopBalloonFX);
// Mix_FreeChunk(gBulletFX);
// gPopBalloonFX = NULL;
// gBulletFX = NULL;
JA_DeleteSound(gPopBalloonFX); JA_DeleteSound(gPopBalloonFX);
JA_DeleteSound(gBulletFX); JA_DeleteSound(gBulletFX);
// Libra la música // Libra la música
// Mix_FreeMusic(gTitleMusic);
// gTitleMusic = NULL;
// Mix_FreeMusic(gPlayingMusic);
// gPlayingMusic = NULL;
JA_DeleteMusic(gTitleMusic); JA_DeleteMusic(gTitleMusic);
JA_DeleteMusic(gPlayingMusic); JA_DeleteMusic(gPlayingMusic);
@@ -95,91 +151,6 @@ GameDirector::~GameDirector()
// 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());
//}
gTitleMusic = JA_LoadMusic("media/music/title.ogg");
gPlayingMusic = JA_LoadMusic("media/music/playing.ogg");
gPopBalloonFX = JA_LoadSound("media/sound/balloon.wav");
gBulletFX = JA_LoadSound("media/sound/bullet.wav");
gGameBackgroundTexture = new LTexture(gRenderer);
// Carga los gráficos del fondo del juego
if (!gGameBackgroundTexture->loadFromFile("media/gfx/background.png"))
{
printf("Failed to load game background texture!\n");
}
gTitleBackgroundTexture = new LTexture(gRenderer);
// 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");
}
gMiscTexture = new LTexture(gRenderer);
// Carga varios gráficos para varios propósitos
if (!gMiscTexture->loadFromFile("media/gfx/misc.png"))
{
printf("Failed to load misc texture!\n");
}
gWhiteFontTexture = new LTexture(gRenderer);
// Carga los gráficos para el texto blanco
if (!gWhiteFontTexture->loadFromFile("media/gfx/white_font.png"))
{
printf("Failed to load white font texture!\n");
}
gBlackFontTexture = new LTexture(gRenderer);
// Carga los gráficos para el texto negro
if (!gBlackFontTexture->loadFromFile("media/gfx/black_font.png"))
{
printf("Failed to load black font texture!\n");
}
// 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;
@@ -199,24 +170,12 @@ void GameDirector::init()
// Establece a cero todos los valores del vector de objetos globo // Establece a cero todos los valores del vector de objetos globo
resetBalloons(); resetBalloons();
// Crea dos objetos globo y los centra en el area de juego
// balloon[0].init(0, BLOCK, BALLOON_4, BALLON_VELX_POSITIVE, 0);
// balloon[0].allignTo(PLAY_AREA_WIDTH / 2);
// balloon[1].init(0, BLOCK, BALLOON_4, BALLON_VELX_NEGATIVE, 0);
// balloon[1].allignTo(PLAY_AREA_WIDTH / 2);
// Con los globos creados, calcula el nivel de amenaza // Con los globos creados, calcula el nivel de amenaza
calculateMenaceLevel(); calculateMenaceLevel();
// Establece a cero todos los valores del vector de objetos bala // Establece a cero todos los valores del vector de objetos bala
resetBullets(); resetBullets();
#ifdef TEST
balloonTest.init(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, BALLOON_4, 0);
balloonTest.stop();
bulletTest.init(SCREEN_WIDTH / 4, SCREEN_HEIGHT / 2, BULLET_UP);
#endif
// Los fondos // Los fondos
gameBackground.init(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - (0 * BLOCK), gGameBackgroundTexture); gameBackground.init(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - (0 * BLOCK), gGameBackgroundTexture);
titleBackground.init(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, gTitleBackgroundTexture); titleBackground.init(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, gTitleBackgroundTexture);
@@ -242,16 +201,6 @@ void GameDirector::init()
menuPause->centerMenuOnScreen(); menuPause->centerMenuOnScreen();
} }
// Hace una pausa de milisegundos
void GameDirector::sleep(Uint16 time)
{
Uint32 ticks = SDL_GetTicks();
while (SDL_GetTicks() - ticks < time)
{
/* code */
}
}
// Establece el valor de la variable // Establece el valor de la variable
void GameDirector::setScore(Uint32 score) void GameDirector::setScore(Uint32 score)
{ {
@@ -301,6 +250,7 @@ std::string GameDirector::updateScoreText(Uint32 num)
case 100000 ... 999999: case 100000 ... 999999:
return (std::to_string(num)); return (std::to_string(num));
break; break;
default: default:
return (std::to_string(num)); return (std::to_string(num));
break; break;
@@ -681,7 +631,6 @@ void GameDirector::checkGameInput()
setGameStatus(GAME_STATE_PAUSED); setGameStatus(GAME_STATE_PAUSED);
// Detiene la música // Detiene la música
//Mix_HaltMusic();
JA_StopMusic(); JA_StopMusic();
} }
} }
@@ -707,88 +656,6 @@ void GameDirector::checkMenuInput(Menu *menu)
{ {
menu->checkInput(INPUT_FIRE); menu->checkInput(INPUT_FIRE);
} }
#ifdef TEST
if (SDL_JoystickGetButton(gGameController, 1))
{
std::cout << "button1\n";
}
if (SDL_JoystickGetButton(gGameController, 1))
{
std::cout << "button1\n";
}
if (SDL_JoystickGetButton(gGameController, 2))
{
std::cout << "button2\n";
}
if (SDL_JoystickGetButton(gGameController, 3))
{
std::cout << "button3\n";
}
if (SDL_JoystickGetButton(gGameController, 4))
{
std::cout << "button4\n";
}
if (SDL_JoystickGetButton(gGameController, 5))
{
std::cout << "button5\n";
}
if (SDL_JoystickGetButton(gGameController, 6))
{
std::cout << "button6\n";
}
if (SDL_JoystickGetButton(gGameController, 7))
{
std::cout << "button7\n";
}
if (SDL_JoystickGetButton(gGameController, 8))
{
std::cout << "button8\n";
}
if (SDL_JoystickGetButton(gGameController, 9))
{
std::cout << "button9\n";
}
if (SDL_JoystickGetButton(gGameController, 10))
{
std::cout << "button10\n";
}
if (SDL_JoystickGetButton(gGameController, 11))
{
std::cout << "button11\n";
}
if (SDL_JoystickGetButton(gGameController, 12))
{
std::cout << "button12\n";
}
if (SDL_JoystickGetButton(gGameController, 13))
{
std::cout << "button13\n";
}
if (SDL_JoystickGetButton(gGameController, 14))
{
std::cout << "button14\n";
}
if (SDL_JoystickGetButton(gGameController, 15))
{
std::cout << "button15\n";
}
#endif
} }
// Obtiene el valor de la variable // Obtiene el valor de la variable
@@ -898,11 +765,9 @@ void GameDirector::renderGetReady()
void GameDirector::runTitle() void GameDirector::runTitle()
{ {
// Si la música no está sonando // Si la música no está sonando
//if (Mix_PlayingMusic() == 0)
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
{ {
// Reproduce la música // Reproduce la música
//Mix_PlayMusic(gTitleMusic, -1);
JA_PlayMusic(gTitleMusic); JA_PlayMusic(gTitleMusic);
} }
@@ -937,17 +802,17 @@ void GameDirector::runTitle()
setGameStatus(GAME_STATE_PLAYING); setGameStatus(GAME_STATE_PLAYING);
menuTitle->resetMenu(); menuTitle->resetMenu();
renderTransition(1); renderTransition(1);
//Mix_HaltMusic();
JA_StopMusic(); JA_StopMusic();
SDL_Delay(1200); SDL_Delay(1200);
break; break;
case 1: case 1:
setGameStatus(GAME_STATE_QUIT); setGameStatus(GAME_STATE_QUIT);
menuTitle->resetMenu(); menuTitle->resetMenu();
renderTransition(1); renderTransition(1);
//Mix_HaltMusic();
JA_StopMusic(); JA_StopMusic();
break; break;
default: default:
break; break;
} }
@@ -957,11 +822,9 @@ void GameDirector::runTitle()
void GameDirector::runGame() void GameDirector::runGame()
{ {
// Si la música no está sonando // Si la música no está sonando
//if (Mix_PlayingMusic() == 0)
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
{ {
// Reproduce la música // Reproduce la música
//Mix_PlayMusic(gPlayingMusic, -1);
JA_PlayMusic(gPlayingMusic); JA_PlayMusic(gPlayingMusic);
} }
@@ -991,39 +854,6 @@ void GameDirector::runGame()
popBalloon(0); popBalloon(0);
break; break;
} }
#ifdef TEST
// W key pressed
if (eventHandler.key.keysym.sym == SDLK_w)
{
bulletTest.setPosY(bulletTest.getPosY() - 1);
bulletTest.testMove();
break;
}
// S key pressed
if (eventHandler.key.keysym.sym == SDLK_s)
{
bulletTest.setPosY(bulletTest.getPosY() + 1);
bulletTest.testMove();
break;
}
// A key pressed
if (eventHandler.key.keysym.sym == SDLK_a)
{
bulletTest.setPosX(bulletTest.getPosX() - 1);
bulletTest.testMove();
break;
}
// D key pressed
if (eventHandler.key.keysym.sym == SDLK_d)
{
bulletTest.setPosX(bulletTest.getPosX() + 1);
bulletTest.testMove();
break;
}
#endif
} }
// Actualiza el jugador // Actualiza el jugador
@@ -1032,10 +862,6 @@ void GameDirector::runGame()
// Mueve los globos // Mueve los globos
moveBalloons(); moveBalloons();
#ifdef TEST
balloonTest.move();
#endif
// Mueve las balas // Mueve las balas
moveBullets(); moveBullets();
@@ -1059,16 +885,6 @@ void GameDirector::runGame()
// Dibuja los objetos // Dibuja los objetos
gameBackground.render(); gameBackground.render();
renderBalloons(); renderBalloons();
#ifdef TEST
balloonTest.render();
bulletTest.render();
if (checkCollision(balloonTest.getCollider(), bulletTest.getCollider()))
{
whiteText.write(0, 0, "X");
}
#endif
// whiteText.write(0, 0, std::to_string(mMenaceLevelThreshold));
// whiteText.write(0, BLOCK, std::to_string(player->getPosX() + player->getWidth()));
renderBullets(); renderBullets();
player->render(); player->render();
renderScoreBoard(whiteText); renderScoreBoard(whiteText);
@@ -1112,12 +928,14 @@ void GameDirector::runPausedGame()
setGameStatus(GAME_STATE_PLAYING); setGameStatus(GAME_STATE_PLAYING);
menuPause->resetMenu(); menuPause->resetMenu();
break; break;
case 1: case 1:
setGameStatus(GAME_STATE_TITLE); setGameStatus(GAME_STATE_TITLE);
menuPause->resetMenu(); menuPause->resetMenu();
renderTransition(1); renderTransition(1);
init(); init();
break; break;
default: default:
break; break;
} }

View File

@@ -27,9 +27,6 @@ public:
// Iniciador // Iniciador
void init(); void init();
// Hace una pausa de milisegundos
void sleep(Uint16 time);
// Establece el valor de la variable // Establece el valor de la variable
void setScore(Uint32 score); void setScore(Uint32 score);

View File

@@ -35,7 +35,6 @@ Los objetos globo tienen varios contadores para alternar de un estado a otro.
En los vectores que contienen objetos, se considera activos los objetos que tienen En los vectores que contienen objetos, se considera activos los objetos que tienen
un tipo asociado diferente a NO_KIND un tipo asociado diferente a NO_KIND
*/ */
#define TEST_
#include "background.h" #include "background.h"
#include "balloon.h" #include "balloon.h"
@@ -78,7 +77,7 @@ bool init()
JA_Init(44100, AUDIO_S16, 2); JA_Init(44100, AUDIO_S16, 2);
// Inicializa SDL // Inicializa SDL
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) < 0) if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0)
{ {
printf("SDL could not initialize! SDL Error: %s\n", SDL_GetError()); printf("SDL could not initialize! SDL Error: %s\n", SDL_GetError());
success = false; success = false;
@@ -91,13 +90,6 @@ bool init()
printf("Warning: Nearest texture filtering not enabled!"); printf("Warning: Nearest texture filtering not enabled!");
} }
// 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); 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)
@@ -121,14 +113,6 @@ bool init()
// Establece el tamaño del buffer de renderizado // Establece el tamaño del buffer de renderizado
SDL_RenderSetLogicalSize(gRenderer, SCREEN_WIDTH, SCREEN_HEIGHT); SDL_RenderSetLogicalSize(gRenderer, SCREEN_WIDTH, SCREEN_HEIGHT);
// Inicializa el cargador de PNG
/*int imgFlags = IMG_INIT_PNG;
if (!(IMG_Init(imgFlags) & imgFlags))
{
printf("SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError());
success = false;
}*/
} }
} }
} }
@@ -146,7 +130,6 @@ void close()
gRenderer = NULL; gRenderer = NULL;
// Sal del subsistema SDL // Sal del subsistema SDL
//IMG_Quit();
SDL_Quit(); SDL_Quit();
} }
@@ -164,13 +147,6 @@ int main(int argc, char *args[])
// Crea el objeto gameDirector // Crea el objeto gameDirector
GameDirector gameDirector(gRenderer); GameDirector gameDirector(gRenderer);
// 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)) while (!(gameDirector.getGameStatus() == GAME_STATE_QUIT))
{ {