Eliminado sdl_mixer

This commit is contained in:
2022-10-21 16:48:21 +02:00
parent fd1fc0b582
commit 58f9841f71
4 changed files with 73 additions and 49 deletions

View File

@@ -50,16 +50,20 @@ GameDirector::GameDirector(SDL_Renderer *gRenderer)
GameDirector::~GameDirector()
{
// Libera los efectos de sonido
Mix_FreeChunk(gPopBalloonFX);
Mix_FreeChunk(gBulletFX);
gPopBalloonFX = NULL;
gBulletFX = NULL;
// Mix_FreeChunk(gPopBalloonFX);
// Mix_FreeChunk(gBulletFX);
// gPopBalloonFX = NULL;
// gBulletFX = NULL;
JA_DeleteSound(gPopBalloonFX);
JA_DeleteSound(gBulletFX);
// Libra la música
Mix_FreeMusic(gTitleMusic);
gTitleMusic = NULL;
Mix_FreeMusic(gPlayingMusic);
gPlayingMusic = NULL;
// Mix_FreeMusic(gTitleMusic);
// gTitleMusic = NULL;
// Mix_FreeMusic(gPlayingMusic);
// gPlayingMusic = NULL;
JA_DeleteMusic(gTitleMusic);
JA_DeleteMusic(gPlayingMusic);
// Libera el mando
SDL_JoystickClose(gGameController);
@@ -92,32 +96,37 @@ GameDirector::~GameDirector()
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());
}
// 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());
}
// 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());
}
// 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());
}
// 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
@@ -471,7 +480,7 @@ void GameDirector::processBulletBallonCollision()
setScore(player->getScore());
updateHiScore();
popBalloon(i);
Mix_PlayChannel(-1, gPopBalloonFX, 0);
JA_PlaySound(gPopBalloonFX);
bullet[j]->erase();
calculateMenaceLevel();
break;
@@ -636,7 +645,7 @@ void GameDirector::checkGameInput()
player->setFireCooldown(10);
// Reproduce el sonido de disparo
Mix_PlayChannel(-1, gBulletFX, 0);
JA_PlaySound(gBulletFX);
}
}
@@ -649,7 +658,7 @@ void GameDirector::checkGameInput()
player->setFireCooldown(10);
// Reproduce el sonido de disparo
Mix_PlayChannel(-1, gBulletFX, 0);
JA_PlaySound(gBulletFX);
}
}
@@ -662,7 +671,7 @@ void GameDirector::checkGameInput()
player->setFireCooldown(10);
// Reproduce el sonido de disparo
Mix_PlayChannel(-1, gBulletFX, 0);
JA_PlaySound(gBulletFX);
}
}
@@ -672,7 +681,8 @@ void GameDirector::checkGameInput()
setGameStatus(GAME_STATE_PAUSED);
// Detiene la música
Mix_HaltMusic();
//Mix_HaltMusic();
JA_StopMusic();
}
}
@@ -888,10 +898,12 @@ void GameDirector::renderGetReady()
void GameDirector::runTitle()
{
// Si la música no está sonando
if (Mix_PlayingMusic() == 0)
//if (Mix_PlayingMusic() == 0)
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
{
// Reproduce la música
Mix_PlayMusic(gTitleMusic, -1);
//Mix_PlayMusic(gTitleMusic, -1);
JA_PlayMusic(gTitleMusic);
}
// Comprueba los eventos que hay en la cola
@@ -925,14 +937,16 @@ void GameDirector::runTitle()
setGameStatus(GAME_STATE_PLAYING);
menuTitle->resetMenu();
renderTransition(1);
Mix_HaltMusic();
//Mix_HaltMusic();
JA_StopMusic();
SDL_Delay(1200);
break;
case 1:
setGameStatus(GAME_STATE_QUIT);
menuTitle->resetMenu();
renderTransition(1);
Mix_HaltMusic();
//Mix_HaltMusic();
JA_StopMusic();
break;
default:
break;
@@ -943,10 +957,12 @@ void GameDirector::runTitle()
void GameDirector::runGame()
{
// Si la música no está sonando
if (Mix_PlayingMusic() == 0)
//if (Mix_PlayingMusic() == 0)
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
{
// Reproduce la música
Mix_PlayMusic(gPlayingMusic, -1);
//Mix_PlayMusic(gPlayingMusic, -1);
JA_PlayMusic(gPlayingMusic);
}
// Lógica del juego

View File

@@ -9,6 +9,7 @@
#include "menu.h"
#include "player.h"
#include "text.h"
#include "jail_audio.h"
#ifndef GAMEDIRECTOR_H
#define GAMEDIRECTOR_H
@@ -133,12 +134,16 @@ private:
SDL_Renderer *gRenderer = NULL;
// Objetos con la música del juego
Mix_Music *gTitleMusic = NULL;
Mix_Music *gPlayingMusic = NULL;
//Mix_Music *gTitleMusic = NULL;
//Mix_Music *gPlayingMusic = NULL;
JA_Music gTitleMusic;
JA_Music gPlayingMusic;
// Objetos con los efectos de sonido del juego
Mix_Chunk *gPopBalloonFX = NULL;
Mix_Chunk *gBulletFX = NULL;
//Mix_Chunk *gPopBalloonFX = NULL;
//Mix_Chunk *gBulletFX = NULL;
JA_Sound gPopBalloonFX;
JA_Sound gBulletFX;
// Manejador para el mando 1
SDL_Joystick *gGameController = NULL;

View File

@@ -2,7 +2,7 @@
#include <SDL2/SDL.h>
//#include <SDL2/SDL_image.h>
#include <SDL2/SDL_mixer.h>
//#include <SDL2/SDL_mixer.h>
#ifndef GLOBALS_H
#define GLOBALS_H

View File

@@ -74,6 +74,9 @@ bool init()
// Indicador de inicialización
bool success = true;
// Inicializa JailAudio
JA_Init(44100, AUDIO_S16, 2);
// Inicializa SDL
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) < 0)
{
@@ -89,11 +92,11 @@ bool init()
}
// 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;
}
//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
gWindow = SDL_CreateWindow("Super Popping (Like Loc) in Jailers World", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, VIEW_WIDTH, VIEW_HEIGHT, SDL_WINDOW_SHOWN);