diff options
| author | miguel <miguel@localhost> | 2017-09-13 11:55:36 +0200 |
|---|---|---|
| committer | miguel <miguel@localhost> | 2017-09-13 11:55:36 +0200 |
| commit | 1555b96b32a919c3e3b9e44ac1d80dab005d9ab8 (patch) | |
| tree | 1e067e6a8915d638509adc2c16229b5ed600209c /main.cpp | |
| parent | e2063047ee1d145dbdf1963a23f183cc9db9bf52 (diff) | |
added coin collecting sounds
Diffstat (limited to 'main.cpp')
| -rw-r--r-- | main.cpp | 45 |
1 files changed, 39 insertions, 6 deletions
@@ -6,10 +6,39 @@ using SDLInitType=std::pair<int,std::pair<SDL_Window*,SDL_Renderer*>>; +// audio from http://www.brainybetty.com/soundsforpowerpoint2.htm +// https://freesound.org/people/ProjectsU012/sounds/341695/ +void sdl_play_sound() +{ + + static bool first=true; + static SDL_AudioSpec wavSpec; + static Uint32 wavLength; + static Uint8 *wavBuffer; + static SDL_AudioDeviceID deviceId; + + if (first) + { + SDL_LoadWAV("coin.wav", &wavSpec, &wavBuffer, &wavLength); + deviceId = SDL_OpenAudioDevice(NULL, 0, &wavSpec, NULL, 0); + SDL_PauseAudioDevice(deviceId, 0); + first=false; + } + +// SDL_LoadWAV("died.wav", &wavSpec, &wavBuffer, &wavLength); +// SDL_LoadWAV("music.wav", &wavSpec, &wavBuffer, &wavLength); +// SDL_LoadWAV("win.wav", &wavSpec, &wavBuffer, &wavLength); + + int success = SDL_QueueAudio(deviceId, wavBuffer, wavLength); + + //SDL_CloseAudioDevice(deviceId); + //SDL_FreeWAV(wavBuffer); +} + SDLInitType sdl_start(int win_width, int win_height) { //First we need to start up SDL, and make sure it went ok - if (SDL_Init(SDL_INIT_VIDEO) != 0){ + if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) != 0){ std::cout << "SDL_Init Error: " << SDL_GetError() << std::endl; return {1,{nullptr,nullptr}}; } @@ -151,7 +180,6 @@ int main(int, char**){ textures.push_back(sdl_load_texture("gridder01.bmp",255,255,255,ren)); textures.push_back(sdl_load_texture("gridder02.bmp",255,255,255,ren)); - // init world LEVEL 1 World world(1); @@ -177,9 +205,9 @@ int main(int, char**){ { if (event.type == SDL_WINDOWEVENT && (event.window.event==SDL_WINDOWEVENT_RESIZED || event.window.event==SDL_WINDOWEVENT_SIZE_CHANGED)) { - SDL_Log("Window %d size changed to %dx%d", - event.window.windowID, event.window.data1, - event.window.data2); +// SDL_Log("Window %d size changed to %dx%d", + // event.window.windowID, event.window.data1, + //event.window.data2); win_width=event.window.data1; win_height=event.window.data2; @@ -267,7 +295,7 @@ int main(int, char**){ // HUD std::stringstream strbuffer; - strbuffer << "COINS: " << world.coins << " LEVEL: " << world.level << " FPS: " << fps ; + strbuffer << "SCORE:" << world.coins << " | LVL:" << world.level << " | FPS:" << fps << " | RES:"<<win_width << "*" << win_height ; sdl_put_str(ren, textures[3],10, 10, 4,strbuffer.str(),190,190,222); if(world.player.dead) { @@ -289,6 +317,11 @@ int main(int, char**){ // finish rendering SDL_RenderPresent(ren); + if(world.player.collected_coin) + { + sdl_play_sound(); + world.player.collected_coin=false; + } // progress world simu world.sim(deltaTime); |
