int Game::handlePauseInput() { pauseMusic(); setBackground(PAUSE_IMG); sf::Event event; while(renderArea->GetEvent(event)) { if(event.Type == sf::Event::Closed) renderArea->Close(); if(event.Type == sf::Event::KeyPressed) { if(event.Key.Code == sf::Key::P) { continueMusic(); setState(RUNNING); } if(event.Key.Code == sf::Key::R) restart(); if(event.Key.Code == sf::Key::M) return RETURN_MAIN; } } return CONTINUE; }
//----------------------------------------------------------------------------- bool MusicOggStream::release() { if (m_fileName == "") { // nothing is loaded return true; } pauseMusic(); m_fileName= ""; empty(); alDeleteSources(1, &m_soundSource); check("alDeleteSources"); alDeleteBuffers(2, m_soundBuffers); check("alDeleteBuffers"); // Handle error correctly if(!m_error) ov_clear(&m_oggStream); m_soundSource = -1; m_playing = false; return true; } // release
int Tune::getID3v1(unsigned char offset, char* infobuffer) { // pause track if already playing if (isPlaying()) { pauseMusic(); playState = pause; } // save current position for later unsigned long currentPosition = track.curPosition(); // save the value corresponding to the needed frame for later tagFrame = offset; unsigned char ID3v1[3]; // array to store the 'TAG' identifier of ID3v1 tags unsigned long tagPosition = track.fileSize(); // skip to end of file // skip to tag start tagPosition -= 128; track.seekSet(tagPosition); track.read(ID3v1, 3); // read the first 3 characters available // if they're 'TAG' if (ID3v1[0] == 'T' && ID3v1[1] == 'A' && ID3v1[2] == 'G') { // we found an ID3v1 tag ! // let's go find the frame we're looking for tagPosition = (track.curPosition() + offset); track.seekSet(tagPosition); track.read(infobuffer, 30); // read the tag and store it // go back to where we stopped and enable playback again track.seekSet(currentPosition); if (isPlaying()) { resumeMusic(); playState = playback; } return 1; } // if they're not else { // go back to where we stopped and enable playback again track.seekSet(currentPosition); if (isPlaying()) { resumeMusic(); playState = playback; } return 0; } }
int Game::handleGameOverInput() { pauseMusic(); recordBestScore(); if(getLevel() == 10 && getLinesCompleted() >= 100) setBackground("images/congrat.png"); else { setBackground(GAME_OVER_IMG); sf::String level, lines, score; level.SetText(toString(getLevel())); lines.SetText(toString(getLinesCompleted())); score.SetText(toString(getScore())); level.SetFont(vador); lines.SetFont(vador); score.SetFont(vador); level.SetSize(24.0); lines.SetSize(24.0); score.SetSize(24.0); level.SetPosition(270.0, 175.0); lines.SetPosition(270.0, 205.0); score.SetPosition(270.0, 230.0); renderArea->Draw(level); renderArea->Draw(lines); renderArea->Draw(score); } sf::Event event; while(renderArea->GetEvent(event)) { if(event.Type == sf::Event::Closed) renderArea->Close(); if(event.Type == sf::Event::KeyPressed) { if(event.Key.Code == sf::Key::R) restart(); if(event.Key.Code == sf::Key::M) return RETURN_MAIN; } } return CONTINUE; }
int Ultra::handleGameOverInput() { pauseMusic(); Ultra::recordBestScore(); if(Game::gameOver()) setBackground(GAME_OVER_IMG); if(timeElapsed()) setBackground(TIME_ELAPSED_IMG); sf::String level, lines, score; level.SetText(toString(getLevel())); lines.SetText(toString(getLinesCompleted())); score.SetText(toString(getScore())); level.SetFont(vador); lines.SetFont(vador); score.SetFont(vador); level.SetSize(24.0); lines.SetSize(24.0); score.SetSize(24.0); level.SetPosition(270.0, 175.0); lines.SetPosition(270.0, 205.0); score.SetPosition(270.0, 230.0); renderArea->Draw(level); renderArea->Draw(lines); renderArea->Draw(score); sf::Event event; while(renderArea->GetEvent(event)) { if(event.Type == sf::Event::Closed) renderArea->Close(); if(event.Type == sf::Event::KeyPressed) { if(event.Key.Code == sf::Key::R) restart(); if(event.Key.Code == sf::Key::M) return RETURN_MAIN; } } return CONTINUE; }
void playMusic(int id) { if (id >= 0 && id < 3 && canPlayMusic) { if (songs[id] == current) { pauseMusic(); } else if (musicMuted || songs[id] != current) { printf("Playing music\n"); nowPlaying = Mix_LoadMUS(songs[id]); if (nowPlaying == NULL) { printf("Mix_LoadMUS(\"%s\"): %s\n", songs[id], Mix_GetError()); } else { Mix_PlayMusic(nowPlaying, 1); Mix_HookMusicFinished(loopbackMusic); musicMuted = 0; current = songs[id]; } } } }
///事件音乐设置 void AudioManager::onEventOptionMusic(EventCustom* event) { bool isOpen = event->getUserData(); setbIsOpenMusic(isOpen); UserDefault::getInstance()->setBoolForKey("s_music_open", isOpen); DLog::d("music isOpen", isOpen); //设置背景音乐 if(isOpen) { resumeMusic(); } else { pauseMusic(); } setbIsOpenMusic(isOpen); }
int Tune::getID3v2(char* infobuffer) { // pause track if already playing if (isPlaying()) { pauseMusic(); playState = pause; } // save current position for later unsigned long currentPosition = track.curPosition(); unsigned char ID3v2[3]; // pointer to the first 3 characters we read in track.seekSet(0); track.read(ID3v2, 3); // if the first 3 characters are ID3 then we have an ID3v2 tag // we now need to find the length of the whole tag if (ID3v2[0] == 'I' && ID3v2[1] == 'D' && ID3v2[2] == '3') { // Read the version of the tag track.read(pb, 1); int tagVersion = pb[0]; // skip 2 bytes we don't need and read the last 4 bytes of the header // that contain the tag's length track.read(pb, 2); track.read(pb, 4); // to combine these 4 bytes together into a single value, we have to // shift one other to get it into its correct position // a quirk of the spec is that the MSb of each byte is set to 0 length = (((unsigned long) pb[0] << (7*3)) + ((unsigned long) pb[1] << (7*2)) + ((unsigned long) pb[2] << (7)) + pb[3]); if (tagVersion == 2) { findv22(infobuffer); // go back to where we stopped and enable playback again track.seekSet(currentPosition); if (isPlaying()) { resumeMusic(); playState = playback; } return 2; } else if (tagVersion == 3) { findv23(infobuffer); // go back to where we stopped and enable playback again track.seekSet(currentPosition); if (isPlaying()) { resumeMusic(); playState = playback; } return 3; } else { // go back to where we stopped and enable playback again track.seekSet(currentPosition); if (isPlaying()) { resumeMusic(); playState = playback; } return 9; } } else { // go back to where we stopped and enable playback again track.seekSet(currentPosition); if (isPlaying()) { resumeMusic(); playState = playback; } return 0; } }
/** * Author: Joel Denke * Description: Listen for input * Params: keysHeld Key statements for all buttons */ void listenInput(int * keysHeld) { struct timer_t2 fps; if (SDL_PollEvent(&event)) { switch (event.type) { case SDL_KEYDOWN : keysHeld[event.key.keysym.sym] = 1; break; case SDL_KEYUP : keysHeld[event.key.keysym.sym] = 0; break; case SDL_QUIT : state = gExit; break; } } if (keysHeld[SDLK_ESCAPE]) { state = gExit; } if (keysHeld[SDLK_LEFT]) { movePlayer("left"); } if (keysHeld[SDLK_RIGHT]) { movePlayer("right"); } if (keysHeld[SDLK_UP]) { movePlayer("up"); } if (keysHeld[SDLK_1] || keysHeld[SDLK_2] || keysHeld[SDLK_3] || keysHeld[SDLK_m]) { timer_start(&fps); if (keysHeld[SDLK_m]) { pauseMusic(); } else { int k; if (keysHeld[SDLK_1]) { k = 0; } else if (keysHeld[SDLK_2]) { k = 1; } else if (keysHeld[SDLK_3]) { k = 2; } playMusic(k); } if (timer_get_ticks(&fps) < 1000) { //delay the as much time as we need to get desired frames per second SDL_Delay((1000) - timer_get_ticks(&fps)); } } }
/** * Author: Joel Denke, Marcus Isaksson * Description: Run the game on client */ int main(int argc, char *argv[]) { int i, j, no, yb, keysHeld[323] = {0}; int result = 0; SDL_Thread * eventBuffer; SDL_Thread * runBuffer; struct timer_t2 fps; char * server_ip = malloc(sizeof(char) * 16); char * elem = malloc(sizeof(char) * MESSAGE_SIZE); pColor = malloc(sizeof(SDL_Color)); oColor = malloc(sizeof(SDL_Color)); connection = malloc(sizeof(connection_data)); for (i = 0; i < NO_BUFFERS; i++) { cb[i] = malloc(sizeof(cBuffer)); b_lock[i] = SDL_CreateMutex(); } strcpy(server_ip, "127.0.0.1"); pColor->r = 0; pColor->g = 255; pColor->b = 255; oColor->r = 0; oColor->g = 0; oColor->b = 255; initGraphics(); initSound(); printf("Render menu\n"); graphicsMenu(&gameWorld, server_ip); initSlots(cb[0], BUFFER_SIZE); initSlots(cb[1], NO_OBJECTS); initSlots(cb[2], BUFFER_SIZE); state = gStart; if (clientConnect(connection, server_ip) == 0) { eventBuffer = SDL_CreateThread(listenEventBuffer, &connection); while (1) { switch (state) { case gStart: runData(2); break; case gInit: timer_start(&fps); startDraw(); drawLoadScr(SCREEN_WIDTH, SCREEN_HEIGHT); endDraw(); initWorld(); if (timer_get_ticks(&fps) < 1000 / FPS) { //delay the as much time as we need to get desired frames per second SDL_Delay( ( 1000 / FPS ) - timer_get_ticks(&fps) ); } break; case gRunning : timer_start(&fps); drawGraphics(); listenInput(keysHeld); // i = 0: players; i = 1: objects; i = 2: messages for (i = 0; i < NO_BUFFERS; i++) { runData(i); } if (timer_get_ticks(&fps) < 1000 / FPS) { //delay the as much time as we need to get desired frames per second SDL_Delay( ( 1000 / FPS ) - timer_get_ticks(&fps) ); } break; case gExit : //sprintf(string, "%d,quit", connection->client_id); printf("Freeing music now\n"); pauseMusic(); freeMusic(); end_session(connection); printf("Player is exit game now\n"); exitClient(eventBuffer); break; default : printf("test\n"); break; } } } else { printf("Misslyckade med att kontakta servern på ip-adress: '%s'\n", server_ip); state = gExit; pauseMusic(); freeMusic(); exitClient(eventBuffer); } return 0; }
void GameApp::Pause() { pauseMusic(); }
void SoundManager::mute() { sounding = false; if (initialized) pauseMusic(); }
int Sprint::handleGameOverInput() { pauseMusic(); recordBestScore(); if(Game::gameOver()) { setBackground(SPRINT_GAMEOVER_IMG); sf::String lines, time; lines.SetFont(vador); lines.SetText(toString(getLinesCompleted()) + " / 40"); time.SetFont(vador); time.SetText(timer.format()); lines.SetSize(30.0); time.SetSize(30.0); lines.SetPosition(300.0, 187.0); time.SetPosition(300.0, 222.0); renderArea->Draw(lines); renderArea->Draw(time); } if(finished()) { setBackground(SPRINT_FINISHED_IMG); sf::String time; time.SetText(timer.format()); time.SetFont(vador); time.SetSize(48.0); time.SetPosition(245.0, 205.0); renderArea->Draw(time); } sf::Event event; while(renderArea->GetEvent(event)) { if(event.Type == sf::Event::Closed) renderArea->Close(); if(event.Type == sf::Event::KeyPressed) { if(event.Key.Code == sf::Key::R) restart(); if(event.Key.Code == sf::Key::M) return RETURN_MAIN; } } return CONTINUE; }