aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordrumsetmonkey <abelleisle@roadrunner.com>2015-10-01 09:22:42 -0400
committerdrumsetmonkey <abelleisle@roadrunner.com>2015-10-01 09:22:42 -0400
commitad53a45ac83da8efa9316db884e020de7f2ab829 (patch)
tree7ffb7206cbe25b655e3f9a40c8a3f4d946b29d0c
parent49b328bd30365b6fcb19eeebdaa43f4430285c50 (diff)
Added support for sound
-rw-r--r--assets/names_en-us1
-rw-r--r--include/common.h3
-rw-r--r--src/main.cpp23
3 files changed, 26 insertions, 1 deletions
diff --git a/assets/names_en-us b/assets/names_en-us
index c34e6cf..0f6195f 100644
--- a/assets/names_en-us
+++ b/assets/names_en-us
@@ -53,6 +53,7 @@ mAndy
mClyne
mPingu
mShrek
+mLogan
fShani
fIsidra
fAja
diff --git a/include/common.h b/include/common.h
index 985dddf..9f29fbb 100644
--- a/include/common.h
+++ b/include/common.h
@@ -47,4 +47,7 @@ extern unsigned int deltaTime;
extern FILE* config;
extern FILE* names;
+extern Mix_Music *music;
+extern Mix_Chunk *horn;
+
#endif // COMMON_H
diff --git a/src/main.cpp b/src/main.cpp
index ea57998..37e1712 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -28,6 +28,9 @@ std::vector<Structures *>build;
int mx, my;
FILE* names;
+Mix_Music *music;
+Mix_Chunk *horn;
+
extern void initEverything(void);
void logic();
@@ -40,7 +43,7 @@ unsigned int millis(void){
int main(int argc, char *argv[]){
// Initialize SDL
- if(SDL_Init(SDL_INIT_VIDEO)){
+ if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0){
std::cout << "SDL was not able to initialize! Error: " << SDL_GetError() << std::endl;
return -1;
}
@@ -51,6 +54,23 @@ int main(int argc, char *argv[]){
return -1;
}
atexit(IMG_Quit);
+
+ //Initialize SDL_mixer
+ if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) < 0 ){
+ std::cout << "SDL_mixer could not initialize! SDL_mixer Error: " << Mix_GetError() << std::endl;
+ }
+ atexit(Mix_Quit);
+
+ //Load music
+ music = Mix_LoadMUS("assets/BennyHillTheme.wav");
+ horn = Mix_LoadWAV("assets/air-horn-club-sample_1.wav");
+ if( music == NULL ){
+ printf( "Failed to load beat music! SDL_mixer Error: %s\n", Mix_GetError() );
+ }
+ Mix_PlayMusic( music, -1 );
+
+
+
// Turn on double buffering
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
// Create the window
@@ -196,6 +216,7 @@ void logic(){
if(SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(SDL_BUTTON_RIGHT)){
entity[i]->interact();
std::cout <<"["<<i<<"] -> "<< entity[i]->name << ", " << (std::string)(entity[i]->gender == MALE ? "Male" : "Female") << std::endl;
+ //Mix_PlayChannel( -1, horn, 0);
}
}else entity[i]->near=false;
}