Death sound added
This commit is contained in:
parent
33e69b0bb4
commit
e67f684fa7
BIN
bin/assets/sounds/death.wav
Normal file
BIN
bin/assets/sounds/death.wav
Normal file
Binary file not shown.
@ -1,11 +1,11 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <time.h>
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL2/SDL_image.h>
|
#include <SDL2/SDL_image.h>
|
||||||
#include <SDL2/SDL_ttf.h>
|
#include <SDL2/SDL_mixer.h>
|
||||||
|
|
||||||
#include "breakout.h"
|
#include "breakout.h"
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
@ -21,6 +21,7 @@ extern int width, height;
|
|||||||
#define BLOCK_TexturePath "assets/images/spritesheet.png"
|
#define BLOCK_TexturePath "assets/images/spritesheet.png"
|
||||||
#define BRAEKOUT_CountdownTexturePath "assets/images/text.png"
|
#define BRAEKOUT_CountdownTexturePath "assets/images/text.png"
|
||||||
#define BRAEKOUT_PausedTexturePath "assets/images/paused.png"
|
#define BRAEKOUT_PausedTexturePath "assets/images/paused.png"
|
||||||
|
#define BRAEKOUT_DeathSoundPath "assets/sounds/death.wav"
|
||||||
#define BALL_MinSpeed 8.0f
|
#define BALL_MinSpeed 8.0f
|
||||||
#define BALL_MaxSpeed 25.0f
|
#define BALL_MaxSpeed 25.0f
|
||||||
#define BALL_AccelerationTime 10000
|
#define BALL_AccelerationTime 10000
|
||||||
@ -56,6 +57,7 @@ bool BREAKOUT_IsInit = false;
|
|||||||
bool BALL_IsInit = false;
|
bool BALL_IsInit = false;
|
||||||
bool PADDLE_IsInit = false;
|
bool PADDLE_IsInit = false;
|
||||||
bool BLOCK_IsInit = false;
|
bool BLOCK_IsInit = false;
|
||||||
|
Mix_Chunk * deathSound;
|
||||||
|
|
||||||
void BREAKOUT_INITIALIZE(SDL_Renderer * renderer){
|
void BREAKOUT_INITIALIZE(SDL_Renderer * renderer){
|
||||||
if (!BREAKOUT_IsInit) {
|
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[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[2] = (SDL_Rect) {.x = 245, .y = 1, .w = 443, .h = 665 };
|
||||||
BREAKOUT_CountdownSourceRects[3] = (SDL_Rect) {.x = 690, .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");
|
printf("Game initialized!\n");
|
||||||
BREAKOUT_IsInit = true;
|
BREAKOUT_IsInit = true;
|
||||||
} else printf("Game is already initialized!\n");
|
} else printf("Game is already initialized!\n");
|
||||||
@ -231,6 +234,7 @@ void BREAKOUT_DrawLivesHUD(SDL_Renderer * renderer, Scenery * scenery){
|
|||||||
void BREAKOUT_DEINITIALIZE(){
|
void BREAKOUT_DEINITIALIZE(){
|
||||||
if (BREAKOUT_IsInit) {
|
if (BREAKOUT_IsInit) {
|
||||||
printf("De-initializing Game...\n");
|
printf("De-initializing Game...\n");
|
||||||
|
Mix_FreeChunk(deathSound);
|
||||||
SDL_DestroyTexture(BREAKOUT_CountdownTexture);
|
SDL_DestroyTexture(BREAKOUT_CountdownTexture);
|
||||||
SDL_DestroyTexture(BREAKOUT_PausedTexture);
|
SDL_DestroyTexture(BREAKOUT_PausedTexture);
|
||||||
free(PADDLE_MoveLeftKeys);
|
free(PADDLE_MoveLeftKeys);
|
||||||
@ -462,6 +466,7 @@ void BALL_Update(Ball * obj, Scenery * scenery){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((obj->Location).y > height) { // Collide with box boundaries
|
if ((obj->Location).y > height) { // Collide with box boundaries
|
||||||
|
Mix_PlayChannel(-1, deathSound, 0);
|
||||||
scenery->IsGameOver = true;
|
scenery->IsGameOver = true;
|
||||||
printf("Ball called game_over!\n");
|
printf("Ball called game_over!\n");
|
||||||
} else BALL_CollideWithBorders(obj);
|
} else BALL_CollideWithBorders(obj);
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
#include <SDL2/SDL_image.h>
|
||||||
|
#include <SDL2/SDL_mixer.h>
|
||||||
|
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
|
|
||||||
|
6
main.c
6
main.c
@ -6,6 +6,7 @@
|
|||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL2/SDL_image.h>
|
#include <SDL2/SDL_image.h>
|
||||||
#include <SDL2/SDL_ttf.h>
|
#include <SDL2/SDL_ttf.h>
|
||||||
|
#include <SDL2/SDL_mixer.h>
|
||||||
|
|
||||||
#include "breakout.h"
|
#include "breakout.h"
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
@ -188,6 +189,8 @@ void INITIALIZE() {
|
|||||||
else printf("IMG was successfully initialized!\n");
|
else printf("IMG was successfully initialized!\n");
|
||||||
if (TTF_Init() == -1) printf("TTF could not initialize! Error: %s\n", TTF_GetError());
|
if (TTF_Init() == -1) printf("TTF could not initialize! Error: %s\n", TTF_GetError());
|
||||||
else printf("TTF was successfully initialized!\n");
|
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);
|
window = SDL_CreateWindow("BreakING", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL);
|
||||||
SDL_SetWindowResizable(window, true);
|
SDL_SetWindowResizable(window, true);
|
||||||
@ -200,7 +203,7 @@ void INITIALIZE() {
|
|||||||
Load_Textures(renderer);
|
Load_Textures(renderer);
|
||||||
HIGHSCORES_Initialize();
|
HIGHSCORES_Initialize();
|
||||||
BACKGROUND_Initialize(renderer, width, height);
|
BACKGROUND_Initialize(renderer, width, height);
|
||||||
Settings_Initialize(renderer,&scenery);
|
Settings_Initialize(renderer, &scenery);
|
||||||
GAMEOVER_Initialize(renderer);
|
GAMEOVER_Initialize(renderer);
|
||||||
printf("Initializing finished!\n");
|
printf("Initializing finished!\n");
|
||||||
} /* INITIALIZE */
|
} /* INITIALIZE */
|
||||||
@ -213,6 +216,7 @@ void QUIT(){
|
|||||||
HIGHSCORES_Deinitialize();
|
HIGHSCORES_Deinitialize();
|
||||||
BREAKOUT_DestroyObject(&scenery);
|
BREAKOUT_DestroyObject(&scenery);
|
||||||
BREAKOUT_DEINITIALIZE();
|
BREAKOUT_DEINITIALIZE();
|
||||||
|
Mix_CloseAudio();
|
||||||
TTF_Quit();
|
TTF_Quit();
|
||||||
IMG_Quit();
|
IMG_Quit();
|
||||||
printf("Quitting SDL_IMG finished!\n");
|
printf("Quitting SDL_IMG finished!\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user