diff --git a/source/.gitignore b/source/.gitignore new file mode 100644 index 0000000..44ead2d --- /dev/null +++ b/source/.gitignore @@ -0,0 +1,2 @@ +.vscode +volcano diff --git a/source/volcano.cpp b/source/volcano.cpp index e90bcd3..2b8783d 100644 --- a/source/volcano.cpp +++ b/source/volcano.cpp @@ -21,13 +21,13 @@ void allocatePointers() prog.sprite = new LTexture(); // Sounds - game.sound_drop_enemy = new Mix_Chunk(); - game.sound_drop_splat = new Mix_Chunk(); - menu.sound_logo = new Mix_Chunk(); - menu.sound_start = new Mix_Chunk(); - player.sound_coin = new Mix_Chunk(); - player.sound_death = new Mix_Chunk(); - player.sound_jump = new Mix_Chunk(); + //game.sound_drop_enemy = new Mix_Chunk(); + //game.sound_drop_splat = new Mix_Chunk(); + //menu.sound_logo = new Mix_Chunk(); + //menu.sound_start = new Mix_Chunk(); + //player.sound_coin = new Mix_Chunk(); + //player.sound_death = new Mix_Chunk(); + //player.sound_jump = new Mix_Chunk(); // Music //game.music = new Mix_Music(); @@ -47,13 +47,13 @@ void deletePointers() delete prog.sprite; // Sounds - delete game.sound_drop_enemy; - delete game.sound_drop_splat; - delete menu.sound_logo; - delete menu.sound_start; - delete player.sound_coin; - delete player.sound_death; - delete player.sound_jump; + JA_DeleteSound(game.sound_drop_enemy); + JA_DeleteSound(game.sound_drop_splat); + JA_DeleteSound(menu.sound_logo); + JA_DeleteSound(menu.sound_start); + JA_DeleteSound(player.sound_coin); + JA_DeleteSound(player.sound_death); + JA_DeleteSound(player.sound_jump); // Music //game.music = new Mix_Music(); @@ -75,17 +75,17 @@ bool loadTextureFromFile(LTexture *texture, std::string path, SDL_Renderer *rend return success; } -void CloseSound(Mix_Chunk *sound) +void CloseSound(JA_Sound sound) { if (sound != nullptr) - Mix_FreeChunk(sound); + JA_DeleteSound(sound); sound = nullptr; } -void CloseMusic(Mix_Music *music) +void CloseMusic(JA_Music music) { if (music != nullptr) - Mix_FreeMusic(music); + JA_DeleteMusic(music); music = nullptr; } @@ -154,11 +154,11 @@ void SetMapMusic(Uint8 zone) switch (zone) { case ZONE_SURFACE: - game.music = Mix_LoadMUS(FILE_MUSIC_SURFACE.c_str()); + game.music = JA_LoadMusic(FILE_MUSIC_SURFACE.c_str()); break; case ZONE_VOLCANO: - game.music = Mix_LoadMUS(FILE_MUSIC_VOLCANO.c_str()); + game.music = JA_LoadMusic(FILE_MUSIC_VOLCANO.c_str()); break; } } @@ -187,7 +187,7 @@ void SetZone(int room) SetMapGFX(game.zone); SetMapMusic(game.zone); - Mix_PlayMusic(game.music, -1); + JA_PlayMusic(game.music, -1); } void SetPlayerAnimation(Uint8 anim) @@ -473,9 +473,9 @@ void IniMenu() menu.enabled = true; menu.section = MENU_SECTION_ANIMATION; - menu.music = Mix_LoadMUS(FILE_MUSIC_MENU.c_str()); - menu.sound_logo = Mix_LoadWAV(FILE_SOUND_MENU_LOGO.c_str()); - menu.sound_start = Mix_LoadWAV(FILE_SOUND_MENU_START.c_str()); + menu.music = JA_LoadMusic(FILE_MUSIC_MENU.c_str()); + menu.sound_logo = JA_LoadSound(FILE_SOUND_MENU_LOGO.c_str()); + menu.sound_start = JA_LoadSound(FILE_SOUND_MENU_START.c_str()); loadTextureFromFile(menu.sprite, FILE_MENU.c_str(), renderer); menu.frame = 0; @@ -685,9 +685,9 @@ void IniPlayer() player.coins = 0; for (Uint8 i = 0; i < 6; i++) player.key[i] = false; - player.sound_jump = Mix_LoadWAV(FILE_SOUND_JUMP.c_str()); - player.sound_death = Mix_LoadWAV(FILE_SOUND_DEATH.c_str()); - player.sound_coin = Mix_LoadWAV(FILE_SOUND_COIN.c_str()); + player.sound_jump = JA_LoadSound(FILE_SOUND_JUMP.c_str()); + player.sound_death = JA_LoadSound(FILE_SOUND_DEATH.c_str()); + player.sound_coin = JA_LoadSound(FILE_SOUND_COIN.c_str()); player.animation[0].num_frames = 33; player.animation[0].index = 0; @@ -826,8 +826,8 @@ void EndHud() void IniGame(Uint8 zone) { - game.sound_drop_enemy = Mix_LoadWAV(FILE_SOUND_DROP_ENEMY.c_str()); - game.sound_drop_splat = Mix_LoadWAV(FILE_SOUND_DROP_SPLAT.c_str()); + game.sound_drop_enemy = JA_LoadSound(FILE_SOUND_DROP_ENEMY.c_str()); + game.sound_drop_splat = JA_LoadSound(FILE_SOUND_DROP_SPLAT.c_str()); game.enabled = true; game.zone = zone; @@ -859,8 +859,8 @@ void EndGame() EndMap(); CloseSound(game.sound_drop_enemy); CloseSound(game.sound_drop_splat); - if (Mix_PlayingMusic() == 1) - Mix_HaltMusic(); + if (JA_GetMusicState() == JA_MUSIC_PLAYING) + JA_StopMusic(); CloseMusic(game.music); game.enabled = false; } @@ -876,7 +876,7 @@ void KillPlayer() else SetPlayerAnimation(PLAYER_ANIMATION_DYING_RIGHT); - Mix_PlayChannel(-1, player.sound_death, 0); + JA_PlaySound(player.sound_death, 0); } bool OnFloor() @@ -1195,7 +1195,7 @@ void MoveActors() while (actor[k].enabled) k++; CreateActor(actor[k], KIND_DROP_ENEMY, 0, actor[i].dst_rect.x, actor[i].dst_rect.y, 16, 16, 0, 8 * 16, 0, 2, 0, 0, DOWN, i); - Mix_PlayChannel(-1, game.sound_drop_enemy, 0); + JA_PlaySound(game.sound_drop_enemy, 0); } // Animacio @@ -1226,7 +1226,7 @@ void MoveActors() actor[i].frame = 0; actor[i].timer = 30; actor[i].src_rect.y = 11 * 16; - Mix_PlayChannel(-1, game.sound_drop_splat, 0); + JA_PlaySound(game.sound_drop_splat, 0); } // Animacio @@ -1302,7 +1302,7 @@ void MovePlayer(int direction) player.dst_rect.y = player.dst_rect.y + player.speed_y; // Soroll de saltar - Mix_PlayChannel(-1, player.sound_jump, 0); + JA_PlaySound(player.sound_jump, 0); } // Nou frame d'animaci� @@ -1629,7 +1629,7 @@ void CheckPlayerCollisionWithActors() player.coins++; actor[i].enabled = false; SetActor((actor[i].dst_rect.x / 16), (actor[i].dst_rect.y / 16), 0); - Mix_PlayChannel(-1, player.sound_coin, 0); + JA_PlaySound(player.sound_coin, 0); } break; @@ -1647,7 +1647,7 @@ void CheckPlayerCollisionWithActors() player.lifes++; actor[i].enabled = false; SetActor((actor[i].dst_rect.x / 16), (actor[i].dst_rect.y / 16), 0); - Mix_PlayChannel(-1, player.sound_coin, 0); + JA_PlaySound(player.sound_coin, 0); } break; @@ -1664,7 +1664,7 @@ void CheckPlayerCollisionWithActors() player.key[actor[i].id] = true; actor[i].enabled = false; SetActor((actor[i].dst_rect.x / 16), (actor[i].dst_rect.y / 16), 0); - Mix_PlayChannel(-1, player.sound_coin, 0); + JA_PlaySound(player.sound_coin, 0); } break; @@ -1739,10 +1739,10 @@ void IniProgram() SetProgSection(SECTION_MENU); prog.debug = false; - if (prog.music_enabled) + /*if (prog.music_enabled) // [TODO] Jail_Audio encara no permet canviar el volum Mix_VolumeMusic(100); else - Mix_VolumeMusic(0); + Mix_VolumeMusic(0); */ loadTextureFromFile(prog.sprite, FILE_FILTER.c_str(), renderer); @@ -1777,8 +1777,9 @@ int main(int argc, char *args[]) SDL_RenderSetLogicalSize(renderer, 320, 240); // Inicializa el audio - Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 2048); - + //Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 2048); + JA_Init(22050, AUDIO_S16SYS, 2); + allocatePointers(); // Inicializa el programa IniProgram(); @@ -1801,7 +1802,7 @@ int main(int argc, char *args[]) LoadRoom(STARTING_ROOM); // Conecta la musica - Mix_PlayMusic(game.music, -1); + JA_PlayMusic(game.music, -1); // Bucle de joc while (game.enabled) @@ -1859,10 +1860,10 @@ int main(int argc, char *args[]) case SDL_SCANCODE_M: prog.music_enabled = !prog.music_enabled; - if (prog.music_enabled) + /*if (prog.music_enabled) // [TODO] Jail_Audio encara no permet canviar el volum Mix_VolumeMusic(100); else - Mix_VolumeMusic(0); + Mix_VolumeMusic(0);*/ break; case SDL_SCANCODE_T: @@ -2021,7 +2022,7 @@ int main(int argc, char *args[]) SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); // Apaga la musica - Mix_HaltMusic(); + JA_StopMusic(); while (menu.enabled) { @@ -2063,10 +2064,10 @@ int main(int argc, char *args[]) // (Des)Activa la musica case SDL_SCANCODE_M: prog.music_enabled = !prog.music_enabled; - if (prog.music_enabled) + /*if (prog.music_enabled) // [TODO] Jail_Audio encara no permet canviar el volum Mix_VolumeMusic(100); else - Mix_VolumeMusic(0); + Mix_VolumeMusic(0);*/ break; // (Des)Activa les scanlines @@ -2079,9 +2080,9 @@ int main(int argc, char *args[]) if (menu.timer > 99) { menu.timer = 99; - Mix_HaltMusic(); - Mix_HaltChannel(-1); - Mix_PlayChannel(-1, menu.sound_start, 0); + JA_StopMusic(); + JA_StopChannel(-1); + JA_PlaySound(menu.sound_start, 0); menu.frame = 0; } break; @@ -2118,10 +2119,10 @@ int main(int argc, char *args[]) DrawSprite(menu.sprite, menu.src_rect_logo, menu.dst_rect_logo_zoom); if (menu.frame == (154 / 4)) - Mix_PlayChannel(-1, menu.sound_logo, 0); + JA_PlaySound(menu.sound_logo, 0); if (menu.frame == (300 / 4)) // Conecta la musica - Mix_PlayMusic(menu.music, -1); + JA_PlayMusic(menu.music, -1); if (menu.frame > (300 / 4)) { @@ -2210,8 +2211,8 @@ int main(int argc, char *args[]) else // Animaci� segona en loop { - if (Mix_PlayingMusic() == 0) - Mix_PlayMusic(menu.music, -1); + if (JA_GetMusicState() != JA_MUSIC_PLAYING) + JA_PlayMusic(menu.music, -1); // Borrem pantalla SDL_RenderSetLogicalSize(renderer, 320, 240); @@ -2244,7 +2245,7 @@ int main(int argc, char *args[]) else // Hem pulsat el bot� d'start { - Mix_HaltMusic(); + JA_StopMusic(); // Borrem pantalla SDL_RenderSetLogicalSize(renderer, 320, 240); @@ -2299,12 +2300,12 @@ int main(int argc, char *args[]) CloseSound(game.sound_drop_enemy); CloseSound(game.sound_drop_splat); - Mix_HaltMusic(); + JA_StopMusic(); CloseMusic(game.music); CloseMusic(menu.music); - Mix_CloseAudio(); + //Mix_CloseAudio(); EndProgram(); diff --git a/source/volcano.h b/source/volcano.h index 961fd10..d638279 100644 --- a/source/volcano.h +++ b/source/volcano.h @@ -32,9 +32,9 @@ struct Tprogram struct Tgame { bool enabled; - Mix_Chunk *sound_drop_enemy; - Mix_Chunk *sound_drop_splat; - Mix_Music *music; + JA_Sound sound_drop_enemy; + JA_Sound sound_drop_splat; + JA_Music music; Uint8 zone; // Zona en la que estamos }; @@ -45,9 +45,9 @@ struct Tmenu int timer; LTexture *sprite_animation; LTexture *sprite; - Mix_Chunk *sound_logo; - Mix_Chunk *sound_start; - Mix_Music *music; + JA_Sound sound_logo; + JA_Sound sound_start; + JA_Music music; SDL_Rect dst_rect_animation; SDL_Rect dst_rect_fondo; SDL_Rect dst_rect_logo_zoom; @@ -80,9 +80,9 @@ struct Tplayer int speed_x; // Cantidad de pixeles a desplazarse int speed_y; // Cantidad de pixels a desplazarse LTexture *sprite; // Textura con los graficos del jugador - Mix_Chunk *sound_coin; // Sonido al coger monedas - Mix_Chunk *sound_death; // Sonido al morir - Mix_Chunk *sound_jump; // Sonido al saltar + JA_Sound sound_coin; // Sonido al coger monedas + JA_Sound sound_death; // Sonido al morir + JA_Sound sound_jump; // Sonido al saltar SDL_Rect dst_rect; // Rectangulo donde dibujar el sprite del jugador. Es la posición del jugador SDL_Rect src_rect; // Rectangulo con el dibujo del jugador a pintar Tanimation animation[8]; // Vector con las animaciones del jugador @@ -171,9 +171,9 @@ void ApplyGravity(); void CheckPlayerCollisionWithActors(); void CheckPlayerCollisionWithActors(); void CheckPlayerCollisionWithMap(); -void CloseMusic(Mix_Music *music); +void CloseMusic(JA_Music music); void ClosePicture(LTexture *picture); -void CloseSound(Mix_Chunk *sound); +void CloseSound(JA_Sound sound); void CreateActor(Tactor &a, Uint8 kind, Uint8 id, Sint16 dstx, Sint16 dsty, Sint16 dstw, Sint16 dsth, Sint16 srcx, Sint16 srcy, Sint16 sx, Sint16 sy, Sint16 timer, Sint16 frame, Uint8 direction, Uint8 parent); void DrawHud(); void DrawMap();