Death sound added

This commit is contained in:
Michael Chen 2018-01-27 11:37:39 +01:00
parent 33e69b0bb4
commit e67f684fa7
4 changed files with 14 additions and 3 deletions

BIN
bin/assets/sounds/death.wav Normal file

Binary file not shown.

View File

@ -1,11 +1,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
#include <math.h>
#include <time.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_mixer.h>
#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);

View File

@ -6,6 +6,8 @@
#include <math.h>
#include <time.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_mixer.h>
#include "vector.h"

6
main.c
View File

@ -6,6 +6,7 @@
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_mixer.h>
#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");