diff --git a/bin/assets/sounds/death.wav b/bin/assets/sounds/death.wav new file mode 100644 index 0000000..2d16917 Binary files /dev/null and b/bin/assets/sounds/death.wav differ diff --git a/breakout.c b/breakout.c index 9b03b30..d14200e 100644 --- a/breakout.c +++ b/breakout.c @@ -1,11 +1,11 @@ #include #include -#include #include #include +#include #include #include -#include +#include #include "breakout.h" #include "vector.h" @@ -21,6 +21,7 @@ extern int width, height; #define BLOCK_TexturePath "assets/images/spritesheet.png" #define BRAEKOUT_CountdownTexturePath "assets/images/text.png" #define BRAEKOUT_PausedTexturePath "assets/images/paused.png" +#define BRAEKOUT_DeathSoundPath "assets/sounds/death.wav" #define BALL_MinSpeed 8.0f #define BALL_MaxSpeed 25.0f #define BALL_AccelerationTime 10000 @@ -56,6 +57,7 @@ bool BREAKOUT_IsInit = false; bool BALL_IsInit = false; bool PADDLE_IsInit = false; bool BLOCK_IsInit = false; +Mix_Chunk * deathSound; void BREAKOUT_INITIALIZE(SDL_Renderer * renderer){ if (!BREAKOUT_IsInit) { @@ -75,6 +77,7 @@ void BREAKOUT_INITIALIZE(SDL_Renderer * renderer){ BREAKOUT_CountdownSourceRects[1] = (SDL_Rect) {.x = 1, .y = 1, .w = 242, .h = 665 }; BREAKOUT_CountdownSourceRects[2] = (SDL_Rect) {.x = 245, .y = 1, .w = 443, .h = 665 }; BREAKOUT_CountdownSourceRects[3] = (SDL_Rect) {.x = 690, .y = 1, .w = 443, .h = 665 }; + deathSound = Mix_LoadWAV(BRAEKOUT_DeathSoundPath); printf("Game initialized!\n"); BREAKOUT_IsInit = true; } else printf("Game is already initialized!\n"); @@ -231,6 +234,7 @@ void BREAKOUT_DrawLivesHUD(SDL_Renderer * renderer, Scenery * scenery){ void BREAKOUT_DEINITIALIZE(){ if (BREAKOUT_IsInit) { printf("De-initializing Game...\n"); + Mix_FreeChunk(deathSound); SDL_DestroyTexture(BREAKOUT_CountdownTexture); SDL_DestroyTexture(BREAKOUT_PausedTexture); free(PADDLE_MoveLeftKeys); @@ -462,6 +466,7 @@ void BALL_Update(Ball * obj, Scenery * scenery){ } } if ((obj->Location).y > height) { // Collide with box boundaries + Mix_PlayChannel(-1, deathSound, 0); scenery->IsGameOver = true; printf("Ball called game_over!\n"); } else BALL_CollideWithBorders(obj); diff --git a/breakout.h b/breakout.h index 7240da0..e299fca 100644 --- a/breakout.h +++ b/breakout.h @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include "vector.h" diff --git a/main.c b/main.c index 8f841d2..aac8627 100644 --- a/main.c +++ b/main.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "breakout.h" #include "vector.h" @@ -188,6 +189,8 @@ void INITIALIZE() { else printf("IMG was successfully initialized!\n"); if (TTF_Init() == -1) printf("TTF could not initialize! Error: %s\n", TTF_GetError()); else printf("TTF was successfully initialized!\n"); + if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0) printf("Mixer could not initialize! Error %s\n", Mix_GetError()); + else printf("Mixer was successfully initialized!\n"); window = SDL_CreateWindow("BreakING", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL); SDL_SetWindowResizable(window, true); @@ -200,7 +203,7 @@ void INITIALIZE() { Load_Textures(renderer); HIGHSCORES_Initialize(); BACKGROUND_Initialize(renderer, width, height); - Settings_Initialize(renderer,&scenery); + Settings_Initialize(renderer, &scenery); GAMEOVER_Initialize(renderer); printf("Initializing finished!\n"); } /* INITIALIZE */ @@ -213,6 +216,7 @@ void QUIT(){ HIGHSCORES_Deinitialize(); BREAKOUT_DestroyObject(&scenery); BREAKOUT_DEINITIALIZE(); + Mix_CloseAudio(); TTF_Quit(); IMG_Quit(); printf("Quitting SDL_IMG finished!\n");