void Sound::stopMusic() { Mix_HaltMusic(); printf("stop\n"); }
void SDLManager::stopMusic() { if (SDLManager::musicPlaying() || SDLManager::musicPaused()) Mix_HaltMusic(); }
// play specified stream file ------------------------------------------------- // int AUDs_PlayAudioStream( char *fname ) { if (SoundDisabled) return 1; ASSERT(fname!=NULL); if (Mix_PlayingMusic()) Mix_HaltMusic(); if (music != NULL) { Mix_FreeMusic(music); FREEMEM(tmp_music_buffer); tmp_music_buffer = NULL; music = NULL; } // because SDL_RWFromFP doesn't work cross platform, we need // to get a little bit kinky // set up a buffer for the file size_t tmp_music_size = 0; // get the size of this sample tmp_music_size = SYS_GetFileLength(fname); if (tmp_music_size <= 0) { return 1; // return on error } // alloc space for the buffer if (tmp_music_buffer != NULL) { printf("ERROR: Shouldn't be this far without being cleaned up previously\n"); FREEMEM(tmp_music_buffer); tmp_music_buffer = NULL; } tmp_music_buffer = (char *)ALLOCMEM(tmp_music_size + 1); // open the sample file FILE *musicfp = SYS_fopen(fname, "rb"); if (musicfp == NULL) return 1; // read the file into the temp_sample_buffer int read_rc = SYS_fread((void *)tmp_music_buffer, 1, tmp_music_size, musicfp); if(read_rc <= 0) { MSGOUT("ERROR: Error reading music %s.", fname); return FALSE; } SDL_RWops *musicrwops = SDL_RWFromMem((void *)tmp_music_buffer, tmp_music_size); music = Mix_LoadMUS_RW(musicrwops, 1); //MSGOUT(" PlayAudioStream() with %s ", fname); if (music == NULL) { printf("Mix_LoadMUS(\"%s\"): %s\n", fname, Mix_GetError()); // this might be a critical error... FREEMEM(tmp_music_buffer); tmp_music_buffer = NULL; return 1; } Mix_VolumeMusic(128); if (music != NULL) { Mix_PlayMusic(music, 0); } //Pick up your your toys when you finish SYS_fclose(musicfp); return 1; }
void SoundManager::stopMusic() { //Stop the music Mix_HaltMusic(); }
// // StopSong // static void StopSong() { if (music) Mix_HaltMusic(); }
int welcome_main() { int i,j; int mx,my; int welcome = true; int option_screen = false; int score_screen = false; int first_run = true; int credits_screen = false; SDL_Rect temp; TTF_Font *MyFont; SDL_Color GREEN = {0,255,0}; SDL_Color WHITE = {255,255,255}; SDL_Surface *message = NULL; int option = -1; init_buttons(); init_images(); draw_image(backk,screen,NULL,0,0); gameLog("Welcome screen initialized..."); //draw_image(message,screen,NULL,0,0); //Mix_PlayMusic(background_music,-1); while(welcome) { while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_MOUSEMOTION: for(i=0;i<TOTAL_NO_BUTTON;++i) { handle_mouseover(&button[i],event.motion.x,event.motion.y); } break; case SDL_MOUSEBUTTONDOWN: mx = event.button.x; my = event.button.y; for( i = 0; i < TOTAL_NO_BUTTON; ++i) { if(check_click(button[i],mx,my)==true) { if(sound)Mix_PlayChannel(-1,click_sound,4); animate_button(button[i],i); first_run = true; switch(i) { case 0: option = 1; welcome = false; break; case 1: option_screen = true; break; case 2: score_screen = true; break; case 3: credits_screen = true; break; case 4: option = -1; welcome = false; break; } } } break; case SDL_QUIT: welcome = false; option = -1; break; case SDL_KEYDOWN: switch(event.key.keysym.sym) { case SDLK_p: animate_button(button[0],0); welcome = false; option = 1; break; case SDLK_x: animate_button(button[4],4); welcome = false; option = -1; break; case SDLK_1: if(Mix_PlayingMusic() == 0) { Mix_PlayMusic(background_music,-1); } else { if(Mix_PausedMusic() == 1) { sound = true; Mix_ResumeMusic(); } else { sound = false; Mix_PauseMusic(); } } break; case SDLK_0: Mix_HaltMusic(); break; } } } //---=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- while(option_screen == true) { if(first_run) { draw_image(option_screen_image,screen,NULL,0,0); draw_image(back_button_image,screen,NULL,back_button.dimension.x, back_button.dimension.y); first_run = false; } draw_image(sound_icon[sound],screen,NULL,sound_button.dimension.x,sound_button.dimension.y); while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_MOUSEBUTTONDOWN: if(sound)Mix_PlayChannel(-1,click_sound,0); mx = event.button.x; my = event.button.y; if(check_click(sound_button,mx,my) == true) { if(sound == 0) sound = 1; else sound =0; } if(check_click(back_button,mx,my)== true) { draw_image(backk,screen,NULL,0,0); option_screen = false; } } } SDL_Flip(screen); } //========================================================================================== while(score_screen == true) { if(first_run) { draw_image(score_screen_image,screen,NULL,0,0); draw_image(back_button_image,screen,NULL,back_button.dimension.x, back_button.dimension.y); show_scores(); first_run = false; } while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_MOUSEBUTTONDOWN: if(sound)Mix_PlayChannel(-1,click_sound,0); mx = event.button.x; my = event.button.y; if(check_click(back_button,mx,my)== true) { draw_image(backk,screen,NULL,0,0); score_screen = false; } } } SDL_Flip(screen); } //========================================================================================== //========================================================================================== while(credits_screen == true) { if(first_run) { temp.x = 0; temp.y = 0; temp.w = 1100; temp.h = 600; clear_image(temp); MyFont = TTF_OpenFont("fonts\\lfont.ttf",32); message = TTF_RenderText_Blended(MyFont,"Developed By:",WHITE); draw_image(message,screen,NULL,100,100); SDL_FreeSurface(message); message = NULL; TTF_CloseFont(MyFont); MyFont = TTF_OpenFont("fonts\\sfont.ttf",20); message = TTF_RenderText_Blended(MyFont,"-> Bishruti Siku",GREEN); draw_image(message,screen,NULL,100,150); SDL_FreeSurface(message); message = NULL; message = TTF_RenderText_Blended(MyFont,"-> Nitish Dhaubhadel",GREEN); draw_image(message,screen,NULL,100,170); SDL_FreeSurface(message); message = NULL; message = TTF_RenderText_Blended(MyFont,"-> Iksha Gurung",GREEN); draw_image(message,screen,NULL,100,190); SDL_FreeSurface(message); message = NULL; message = TTF_RenderText_Blended(MyFont,"-> Pranaya Pradhananga",GREEN); draw_image(message,screen,NULL,100,210); SDL_FreeSurface(message); message = NULL; message = TTF_RenderText_Blended(MyFont,"-> Sandip Sahani",GREEN); draw_image(message,screen,NULL,100,230); SDL_FreeSurface(message); message = NULL; message = TTF_RenderText_Blended(MyFont,"Computer Engineering",WHITE); draw_image(message,screen,NULL,100,300); SDL_FreeSurface(message); message = NULL; message = TTF_RenderText_Blended(MyFont,"Kathmandu University",WHITE); draw_image(message,screen,NULL,100,320); SDL_FreeSurface(message); message = NULL; draw_image(back_button_image,screen,NULL,back_button.dimension.x, back_button.dimension.y); first_run = false; } while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_MOUSEBUTTONDOWN: if(sound)Mix_PlayChannel(-1,click_sound,0); mx = event.button.x; my = event.button.y; if(check_click(back_button,mx,my)== true) { draw_image(backk,screen,NULL,0,0); credits_screen = false; } } } SDL_Flip(screen); } //========================================================================================== for(i=0;i<TOTAL_NO_BUTTON;++i) { draw_image(button_image[i][button[i].state],screen,NULL,button[i].dimension.x,button[i].dimension.y); } SDL_Flip(screen); } SDL_FreeSurface(option_screen_image); SDL_FreeSurface(score_screen_image); SDL_FreeSurface(back_button_image); SDL_FreeSurface(sound_icon[0]); SDL_FreeSurface(sound_icon[1]); SDL_FreeSurface(message); message = NULL; SDL_FreeSurface(backk); for(i=0;i<TOTAL_NO_BUTTON;++i) { for(j=0;j<2;++j) { SDL_FreeSurface(button_image[i][j]); } } //TTF_CloseFont(font); gameLog("Welcome screen closed..."); return option; }
int displayAbout(SDL_Surface *screen, dataStore *data) { int done, mouseX, mouseY; SDL_Event event; SDL_Color textColor = { 255, 255, 255,0}; SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0x00, 0x00, 0x00 )); myButton button; button.rect.x = screen->clip_rect.w/2-BUTTONWIDTH/2; button.rect.y = screen->clip_rect.h-BUTTONHEIGHT-100; button.rect.w = BUTTONWIDTH; button.rect.h = BUTTONHEIGHT; button.name="Back"; drawButton(screen, &button); TTF_Font *font = theFont(20); char aboutText[10][100] = {"Hedgewood is a game written by:"," - toco"," - tk"," - JTR"," "," we hope you enjoy it."," ","Thanks to:"," - friend of tk for the grapics"," - our great tutor Arne"}; if (!(renderMultiLineText(font, 150, 100, &aboutText[0],10, textColor,screen))) printf("%s\n",TTF_GetError()); SDL_Flip(screen); TTF_CloseFont(font); // SDL_FreeSurface(message); unsigned int startTime, stopTime, diffTime; unsigned int innerStartTime, innerStopTime; done = 0; while ( !done ) { startTime = SDL_GetTicks(); /* Check for events */ while ( SDL_PollEvent(&event) ) { innerStartTime = SDL_GetTicks(); switch (event.type) { case SDL_MOUSEMOTION: break; case SDL_MOUSEBUTTONUP: SDL_GetMouseState(&mouseX,&mouseY); if (isButtonClicked(&button, mouseX, mouseY)) { done = 1; } #if (DEBUG==1) printf("Cusor-Position x: %d y: %d\n",mouseX,mouseY); #endif break; case SDL_KEYDOWN: /* Any keypress quits the app... */ switch( event.key.keysym.sym ) { case SDLK_f: break; case SDLK_0: printf ("Music off\n"); Mix_HaltMusic(); Mix_HaltChannel(-1); data->soundEnabled=0; break; case SDLK_m: printf ("Music on /Pause\n"); if( Mix_PlayingMusic() == 0 ) Mix_PlayMusic( data->ingamemusic, -1); if( Mix_PausedMusic() == 1 ) Mix_ResumeMusic(); else Mix_PauseMusic(); break; case SDLK_ESCAPE: case SDLK_q: done = 1; quitSDL(data); break; default: break; } break; /* case SDL_QUIT: done = 1; break; */ default: break; } innerStopTime = SDL_GetTicks(); diffTime=(innerStopTime-innerStartTime); //25 Frames per second (40 Milliseconds per frame) if (MS_FRAMETIME>diffTime) SDL_Delay(MS_FRAMETIME-diffTime); } stopTime = SDL_GetTicks(); diffTime = (stopTime-startTime); //25 Frames per second (40 Milliseconds per frame) if (MS_FRAMETIME>diffTime) SDL_Delay(MS_FRAMETIME-diffTime); } return 0; }
void destroystartscreen() { // SDL_FreeSurface(menu.getSurface()); menu.destroy(); Mix_HaltMusic(); Mix_FreeMusic(music); }
void destroymenu() { menu.destroy(); Mix_HaltMusic(); Mix_FreeMusic(music); }
int main( int argc, char* args[] ) { //Start up SDL and create window if( !init() ) { printf( "Failed to initialize!\n" ); } else { //Load media if( !loadMedia() ) { printf( "Failed to load media!\n" ); } else { //Main loop flag bool quit = false; //Event handler SDL_Event e; //While application is running while( !quit ) { //Handle events on queue while( SDL_PollEvent( &e ) != 0 ) { //User requests quit if( e.type == SDL_QUIT ) { quit = true; } //Handle key press else if( e.type == SDL_KEYDOWN ) { switch( e.key.keysym.sym ) { //Play high sound effect case SDLK_1: Mix_PlayChannel( -1, gHigh, 0 ); break; //Play medium sound effect case SDLK_2: Mix_PlayChannel( -1, gMedium, 0 ); break; //Play low sound effect case SDLK_3: Mix_PlayChannel( -1, gLow, 0 ); break; //Play scratch sound effect case SDLK_4: Mix_PlayChannel( -1, gScratch, 0 ); break; case SDLK_9: //If there is no music playing if( Mix_PlayingMusic() == 0 ) { //Play the music Mix_PlayMusic( gMusic, -1 ); } //If music is being played else { //If the music is paused if( Mix_PausedMusic() == 1 ) { //Resume the music Mix_ResumeMusic(); } //If the music is playing else { //Pause the music Mix_PauseMusic(); } } break; case SDLK_0: //Stop the music Mix_HaltMusic(); break; } } } //Clear screen SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); SDL_RenderClear( gRenderer ); //Render prompt gPromptTexture.render( 0, 0 ); //Update screen SDL_RenderPresent( gRenderer ); } } } //Free resources and close SDL close(); return 0; }
/*notice the default arguments for main. SDL expects main to look like that, so don't change it*/ int main(int argc, char *argv[]) { // SDL_Surface *temp = NULL; int done;// the player const Uint8 *keys;// the player /* This section starts by loading the BG as a surface and converting it to a texture This will have to change if I can manage to scroll the trexture arond the player*/ SDL_CreateWindowAndRenderer(800, 600, SDL_WINDOW_RESIZABLE, &mainWindow, &renderer); SDL_SetWindowTitle(mainWindow, "Nitro Hotness"); if( TTF_Init() == -1 ) { return false; } if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 ) { return false; } InitSpriteSystem(); InitEntitySystem(entityMax); map mymap = setWorld(); ObstacleList ol = newObstacleList(); mew = newPlayer(); Obstacle Doh = newObstacle(0); Road_M Path = initRoad(); AI rival = new_AI(); GUI HUD = InitGUI(); mew.position=0; done = 0; //The music that will be played Mix_Music *music = NULL; Mix_Chunk *buzz = NULL; buzz = Mix_LoadWAV( "sfx/buzz.wav" ); readSave(&mew); showTitle(); showMain(); oldTime = 0; currentTime = 0; mytime = 0; do { oldTime = 0; currentTime = 0; mytime = 0; if( Mix_PlayingMusic() == 0 ) { //Play the music if( Mix_PlayMusic( level_music, -1 ) == -1 ) { return 1; } } SDL_Event e; SDL_PollEvent( &e ); if(&e) { //User requests quit if( e.type == SDL_QUIT ) { done = 1; } //user presses enter to go to next menu //User presses a key else if( e.type == SDL_KEYDOWN ) { //Select surfaces based on key press switch( e.key.keysym.sym ) { case SDLK_LEFT: // slog("left is down"); mew.playerX += 3; mew.accel = (mew.accel - .000001); break; case SDLK_RIGHT: // slog("right is down"); mew.playerX -= 3; mew.accel = (mew.accel - .000001); break; case SDLK_UP: // slog("up is down"); mew.accel = (mew.accel + .00007); Mix_PlayChannel( 1, buzz, 0 ); break; case SDLK_DOWN: // slog("down is down"); mew.accel = (mew.accel - .00008); break; } } else if( e.type == SDL_KEYUP ) { //Select surfaces based on key press switch( e.key.keysym.sym ) { case SDLK_RETURN : if(mew.done ==1) { Mix_HaltMusic(); if(GP == 1) { mew.done=0; lvl++; //slog("new level is %i",lvl); mew.position = 0; rival.position =0; setWorld(); Results(mew.rank,lvl); } else if (GP == 0) { mew.done=0; mew.position = 0; rival.position =0; levelSelect(); } } else { slog("too soon"); } case SDLK_LEFT: // slog("left is up"); e.type = SDLK_CLEAR; break; case SDLK_RIGHT: // slog("right is up"); e.type = SDLK_CLEAR; break; case SDLK_UP: // slog("up is up"); mew.accel = (mew.accel - .001); Mix_HaltChannel(1); e.type = SDLK_CLEAR; break; case SDLK_DOWN: // slog("down is up"); mew.accel = 0; e.type = SDLK_CLEAR; break; default: //slog("simple decel"); mew.accel = (mew.accel-0.00001); break; } } if(mew.position > rival.position) { mew.rank = 1 ; } else if( rival.position > mew.position ) { mew.rank = 2 ; } SDL_RenderClear(renderer); DrawBG(BG1,BG2); roadUpdate(Path,mymap,mew); roadDraw(Path,mymap,&mew); roadFetch(Path,mymap,&mew); checkForObstacles(ol , &mew, Doh); update_AI(&rival, &mew); UpdatePlayer(&mew); DrawGui(HUD,mew); NextFrame(); keys = SDL_GetKeyboardState(NULL); if(keys[SDL_SCANCODE_ESCAPE]) { done = 1; } } }while(!done); //Free the sound effects //Free the music Mix_FreeMusic( music ); CloseEntitySystem(); CloseSpriteSystem(); exit(0); /*technically this will end the program, but the compiler likes all functions that can return a value TO return a value*/ return 0; }
/////////////////////////////////////////////////////////// // ME stop /////////////////////////////////////////////////////////// void Audio::ME_Stop() { if (me_playing) { Mix_HaltMusic(); me_playing = false; } }
void GameSound::stopMusic() { Mix_HaltMusic(); musicPlaying = false; myTimer->stop(); }
int main( int argc, char* args[] ) { bool quit = false; if( init() == false ) return 1; if( load_files() == false ) return 1; //clip the sprite sheet //set_clips(); //make button //Button myButton( 170, 120, 320, 240 ); /*up = TTF_RenderText_Solid(font, "Up", textColor); down = TTF_RenderText_Solid( font, "Down", textColor); left = TTF_RenderText_Solid( font, "Left", textColor ); right = TTF_RenderText_Solid( font, "Right", textColor ); if( up == NULL ) return 1; if( down == NULL ) return 1; if( left == NULL ) return 1; if( right == NULL ) return 1;*/ apply_surface( 0, 0, background, screen ); message = TTF_RenderText_Solid( font, "Press 1, 2, 3, or 4 to play a sound effect", textColor ); if( message == NULL ) return 1; apply_surface( ( SCREEN_WIDTH - message->w ) / 2, 100, message, screen ); SDL_FreeSurface( message ); message = TTF_RenderText_Solid( font, "Press 9 to play or pause the music", textColor ); if( message == NULL ) return 1; apply_surface( ( SCREEN_WIDTH - message->w ) / 2, 200, message, screen ); SDL_FreeSurface( message ); message = TTF_RenderText_Solid( font, "Press 0 to stop the music", textColor ); if( message == NULL ) return 1; apply_surface( ( SCREEN_WIDTH - message->w ) / 2, 300, message, screen ); SDL_FreeSurface( message ); if( SDL_Flip( screen ) == -1 ) return 1; while( quit == false) { while( SDL_PollEvent(&event) ) { if( event.type == SDL_KEYDOWN ) { if( event.key.keysym.sym == SDLK_1 ) { //play scratch if( Mix_PlayChannel( -1, scratch, 0 ) == -1 ) return 1; } else if( event.key.keysym.sym == SDLK_2 ) { //play high if( Mix_PlayChannel( -1, high, 0 ) == -1 ) return 1; } else if( event.key.keysym.sym == SDLK_3 ) { //play med if( Mix_PlayChannel( -1, med, 0 ) == -1 ) return 1; } else if( event.key.keysym.sym == SDLK_4 ) { //play low if( Mix_PlayChannel( -1, low, 0 ) == -1 ) return 1; } else if( event.key.keysym.sym == SDLK_9 ) { //if no music if( Mix_PlayingMusic() == 0 ) { //play music if( Mix_PlayMusic( music, -1 ) == -1 ) return 1; } else { if( Mix_PausedMusic() == 1 ) Mix_ResumeMusic(); else Mix_PauseMusic(); } } else if( event.key.keysym.sym == SDLK_0 ) Mix_HaltMusic(); } if( event.type == SDL_QUIT ) quit = true; } /* Uint8 *keystates = SDL_GetKeyState( NULL ); //if up if( keystates[ SDLK_UP ] ) { apply_surface( ( SCREEN_WIDTH - up->w ) / 2, ( SCREEN_HEIGHT / 2 - up->h ) / 2, up, screen ); } //if down if( keystates[ SDLK_DOWN ] ) apply_surface( ( SCREEN_WIDTH - down->w ) / 2, ( SCREEN_HEIGHT / 2 - down->h ) / 2 + ( SCREEN_HEIGHT / 2 ), down, screen ); //if left if( keystates[ SDLK_LEFT ] ) apply_surface( ( SCREEN_WIDTH / 2 - left->w ) / 2, ( SCREEN_HEIGHT - left->h ) / 2, left, screen ); //if right if( keystates[ SDLK_RIGHT ] ) apply_surface( ( SCREEN_WIDTH / 2 - right->w ) / 2 + (SCREEN_WIDTH / 2 ), ( SCREEN_HEIGHT - right->h ) / 2, right, screen ); if( SDL_Flip( screen ) == -1 ) return 1; */ } clean_up(); return 0; }
/* * @brief Stops music playback. */ static void S_StopMusic(void) { Mix_HaltMusic(); s_music_state.current_music = NULL; }
void SDLAudio::stopMusic() // Stop just the music that is currently playing (does not stop any sounds) { Mix_HaltMusic(); }
void AudioManager::stopMusic() { Mix_HaltMusic(); }
void CMusic::Stop() { Mix_HaltMusic(); }
void Music::stop() { Mix_HaltMusic(); Log::debug("Music::stop"); }
int main( int argc, char *argv[]) { // this was a quick test of InetOpenURL #if 0 HINTERNET hnet = InternetOpen( "Game", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 ); HINTERNET hfile = InternetOpenUrl( hnet, "http://www.yahoo.com", NULL, 0, INTERNET_FLAG_DONT_CACHE, 0); char buff[5000]; unsigned long nread; InternetReadFile( hfile, buff, 5000, &nread ); buff[nread] = 0; printf( buff ); #endif if ( SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_AUDIO|SDL_INIT_VIDEO |SDL_INIT_JOYSTICK) < 0 ) { fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); exit(1); } if( SDL_SetVideoMode( 800, 600, 16, SDL_OPENGL /*| SDL_FULLSCREEN */ ) == 0 ) { fprintf(stderr, "Unable to set video mode: %s\n", SDL_GetError()); exit(1); } SDL_WM_SetCaption( "The Halloween Machine", NULL ); // Init SDL_Mixer if (Mix_OpenAudio( 22050, AUDIO_S16, 2, 4096 )) { fprintf(stderr, "Unable to open audio\n"); exit(1); } // Initialize Joysticks/Gamepads printf("%d Controllers found.\n", SDL_NumJoysticks() ); for (int i=0; i < SDL_NumJoysticks(); i++) { printf( "Controller %d: %s\n", i, SDL_JoystickName(i) ); } gamepad.name = "No gamepad detected."; gamepad.sdlinfo = NULL; gamepad.stick = vec2f(0.0, 0.0 ); gamepad.stick2 = vec2f(0.0, 0.0 ); // Only use the first controller if (SDL_NumJoysticks() > 0 ) { gamepad.sdlinfo = SDL_JoystickOpen(0); } // init highscores readHighScores(); if (gamepad.sdlinfo) { gamepad.name = strdup( SDL_JoystickName(0) ); printf( "Gamepad: Number of axes: %d\n", SDL_JoystickNumAxes(gamepad.sdlinfo) ); printf( "Gamepad: Number of buttons: %d\n", SDL_JoystickNumButtons(gamepad.sdlinfo) ); printf( "Gamepad: Number of balls: %d\n", SDL_JoystickNumBalls(gamepad.sdlinfo) ); printf( "Gamepad: Number of hats: %d\n", SDL_JoystickNumHats(gamepad.sdlinfo) ); } // initialize DevIL ilInit(); ilutRenderer( ILUT_OPENGL ); // Setup glgameFont // Load the font image ilGenImages( 1, &ilFontId ); ilBindImage( ilFontId ); if (!ilLoadImage( "gamedata/magic.png" )) { printf("Loading font image failed\n"); } // Make a GL texture for it glFontTexId = ilutGLBindTexImage(); // Create a font by passing in an opengl texture id fntFontId = gfCreateFont( glFontTexId ); // A .finfo file contains the metrics for a font. These // are generated by the Fontpack utility. gfLoadFontMetrics( fntFontId, "gamedata/magic.finfo"); printf("font has %d chars\n", gfGetFontMetric( fntFontId, GF_FONT_NUMCHARS ) ); gfEnableFont( fntFontId, 25 ); sfx[0] = Mix_LoadWAV("gamedata/whiit.wav"); sfx[1] = Mix_LoadWAV("gamedata/didge.wav"); sfx[2] = Mix_LoadWAV("gamedata/sfx_boom.wav"); sfx[3] = Mix_LoadWAV("gamedata/harp.wav"); sfx[4] = Mix_LoadWAV("gamedata/secret.wav"); music_title = Mix_LoadMUS( "gamedata/AutumnLeft.ogg" ); music_gameover = Mix_LoadMUS( "gamedata/YouDiedLoser.ogg" ); music_ingame = Mix_LoadMUS( "gamedata/ingame.ogg" ); if (!music_title) { printf("Error loading music %s\n", Mix_GetError() ); } else { printf("Music loaded\n"); } Mix_PlayMusic( music_title, -1 ); // Start up the game g_game = new GameState(); g_game->init(); g_game->loadLevels( "gamedata/levels.txt" ); g_view = new ViewSimple2D( g_game ); g_game->setView( g_view ); ////////////////////// // Event Loop ////////////////////// while (1) { SDL_Event event; /* Grab all the events off the queue. */ while( SDL_PollEvent( &event ) ) { switch( event.type ) { case SDL_KEYDOWN: // are we reading highscore?? if (ndxGetName >=0 ) { char buff[10]; if ( ((event.key.keysym.sym >= SDLK_a) && (event.key.keysym.sym <= SDLK_z)) || ((event.key.keysym.sym >= SDLK_0) && (event.key.keysym.sym <= SDLK_9))) { sprintf( buff, "%c", (char)event.key.keysym.sym ); if (event.key.keysym.mod & (KMOD_LSHIFT|KMOD_RSHIFT)) { buff[0] = toupper(buff[0]); } if (!strcmp(g_highScoreTable[ndxGetName].m_name.c_str(), HISCORE_PROMPT)) { g_highScoreTable[ndxGetName].m_name = ""; } g_highScoreTable[ndxGetName].m_name.append( buff); } else if ( (event.key.keysym.sym==SDLK_BACKSPACE) ) { if (g_highScoreTable[ndxGetName].m_name.length()){ g_highScoreTable[ndxGetName].m_name.erase( g_highScoreTable[ndxGetName].m_name.end()-1 ); } } else if ( (event.key.keysym.sym==SDLK_RETURN) || (event.key.keysym.sym==SDLK_ESCAPE) ) { if (!g_highScoreTable[ndxGetName].m_name.length()) { g_highScoreTable[ndxGetName].m_name = "Anonymous"; } ndxGetName = -1; writeHighScores(); } break; } switch( event.key.keysym.sym ) { case SDLK_ESCAPE: if ( (g_state==STATE_TITLE) && (g_menuState == MENU_MAINMENU)) { do_quit(); } else { backToTitleScreen(); } break; case SDLK_a: g_view->toggleAnim(); break; case SDLK_p: paused = !paused; break; // Cheat codes.. enable for testing #if 0 case SDLK_z: if (g_state==STATE_GAMEOVER) { ndxGetName = 3; break; } case SDLK_1: g_game->dbgNextPumpkin( PUMPKIN ); break; case SDLK_2: g_game->dbgNextPumpkin( PUMPKIN_ORANGE ); break; case SDLK_3: g_game->dbgNextPumpkin( PUMPKIN_YELLOW ); break; case SDLK_4: g_game->dbgNextPumpkin( PUMPKIN_RED ); break; case SDLK_5: g_game->dbgNextPumpkin( SKULL ); break; case SDLK_6: g_game->dbgNextPumpkin( FISH_HEAD ); break; case SDLK_7: g_game->dbgNextPumpkin( BLACKBIRD ); break; case SDLK_8: g_game->dbgClearQueue(); break; #endif case SDLK_s: ilutGLScreenie(); break; case SDLK_d: bDrawGamepad = !bDrawGamepad; break; case SDLK_m: if (!musicOn) { printf("Playing\n"); if (g_state==STATE_TITLE) { Mix_PlayMusic( music_title, -1 ); } else if (g_state==STATE_PLAYING) { Mix_PlayMusic( music_ingame, -1 ); } else if (g_state==STATE_GAMEOVER) { // easter egg.. kindof.. you get to hear the // game over music again. woo. Mix_PlayMusic( music_gameover, 0 ); } musicOn = 1; } else { printf("Halting\n"); Mix_HaltMusic(); musicOn = 0; } case SDLK_LEFT: g_view->nextStation(); break; case SDLK_RIGHT: g_view->prevStation(); break; case SDLK_SPACE: case SDLK_RETURN: if (g_state == STATE_PLAYING) { doActivateStation(); } else { doStartButton(); } break; case SDLK_UP: if (g_state==STATE_PLAYING) { //g_view->activateStation(); doActivateStation(); } else if (g_state==STATE_TITLE ) { prevMenuItem(); } break; case SDLK_DOWN: if (g_state==STATE_TITLE ) { nextMenuItem(); } break; default: break; } break; case SDL_JOYAXISMOTION: /* Handle Joystick Motion */ if ( ( event.jaxis.value < -3200 ) || (event.jaxis.value > 3200 ) ) { switch(event.jaxis.axis) { case 0: gamepad.stick[0] = (float)(event.jaxis.value) / 32768.0f; break; case 1: gamepad.stick[1] = (float)(event.jaxis.value) / 32768.0f; break; case 2: gamepad.throttle = (float)(event.jaxis.value) / 32768.0f; break; case 3: gamepad.stick2[0] = (float)(event.jaxis.value) / 32768.0f; break; case 4: gamepad.stick2[1] = (float)(event.jaxis.value) / 32768.0f; break; } } else { // prevent jitter near the center positions switch(event.jaxis.axis) { case 0: gamepad.stick[0] = 0.0; break; case 1: gamepad.stick[1] = 0.0; break; case 2: gamepad.throttle = 0.0; break; case 3: gamepad.stick2[0] = 0.0; break; case 4: gamepad.stick2[1] = 0.0; break; } } break; case SDL_JOYBUTTONDOWN: /* Handle Joystick Button Presses */ gamepad.button[event.jbutton.button] = true; switch (event.jbutton.button) { case 0: //g_view->activateStation(); if (g_state==STATE_PLAYING) { doActivateStation(); } else { doStartButton(); } break; //case 1: // sfx_chan[1] = Mix_PlayChannel(-1, sfx[1], 0); // break; //case 2: // sfx_chan[2] = Mix_PlayChannel(-1, sfx[2], 0); // break; case 8: // start button doStartButton(); break; } break; case SDL_JOYBUTTONUP: /* Handle Joystick Button Release */ gamepad.button[event.jbutton.button] = false; break; case SDL_JOYHATMOTION: /* Handle Hat Motion */ gamepad.hat = event.jhat.value; if (g_state==STATE_PLAYING) { if (gamepad.hat & SDL_HAT_LEFT) { g_view->nextStation(); } if (gamepad.hat & SDL_HAT_RIGHT) { g_view->prevStation(); } } else { if (gamepad.hat & SDL_HAT_UP) { prevMenuItem(); } if (gamepad.hat & SDL_HAT_DOWN) { nextMenuItem(); } } break; case SDL_QUIT: /* Handle quit requests (like Ctrl-c). */ if ( (g_state==STATE_TITLE) && (g_menuState == MENU_MAINMENU)) { do_quit(); } else { backToTitleScreen(); } break; } } redraw(); } return 0; }
// // NextMap // void Game::NextMap() { RaycasterSetup setup; int i; char spriteMapFilename[MAX_STR_LENGTH], filename[MAX_STR_LENGTH], completeFilename[MAX_STR_LENGTH]; Mix_HaltMusic(); framework->PlaySound(LVLClear); Loading1 = framework->LoadImage("Images/loading.bmp"); framework->Draw(Loading1, 0, 0); framework->DrawTextCentered("Loading next map...", Colors::white, true); SDL_Flip(framework->GetScreen()); Mix_FreeMusic(music1); for(i=0; i<MAX_SPRITES; i++) { if(textures[i] != NULL) SDL_FreeSurface(spriteImgs[i]); else break; } for(i=0; i<MAX_TEXTURES; i++) { if(textures[i][0] != NULL) { SDL_FreeSurface(textures[i][0]); SDL_FreeSurface(textures[i][1]); } else break; } for(i=0; i<MAX_SPRITES; i++) spriteImgs[i] = NULL; for(i=0; i<MAX_TEXTURES; i++) { textures[i][0] = NULL; textures[i][1] = NULL; } curMapNr++; buildNameLbl: sprintf(mapFilename, DATA_PREFIX "maps/map%d", curMapNr); strcpy(spriteMapFilename, mapFilename); strcat(spriteMapFilename, "sprites"); if(!framework->FileExists(mapFilename)) { curMapNr = 1; goto buildNameLbl; } if(curMapNr == 1) music1 = framework->LoadMusic("music/music1.ogg"); else if(curMapNr == 2) music1 = framework->LoadMusic("music/music2.ogg"); else if(curMapNr == 3) music1 = framework->LoadMusic("music/music3.ogg"); else if(curMapNr == 4) music1 = framework->LoadMusic("music/music4.ogg"); else if(curMapNr == 5) music1 = framework->LoadMusic("music/music5.ogg"); else music1 = framework->LoadMusic("music/music_orig.ogg"); for(i=0; i<MAX_TEXTURES; i++) { sprintf(filename, "textures/map%d/tex%d.bmp", curMapNr, i+1); sprintf(completeFilename, "%s%s", DATA_PREFIX, filename); if(framework->FileExists(completeFilename)) { textures[i][0] = framework->LoadImage(filename, false); sprintf(filename, "textures/map%d/tex%dDark.bmp", curMapNr, i+1); textures[i][1] = framework->LoadImage(filename, false); } else break; } numTextures = i; for(i=0; i<MAX_SPRITES; i++) { sprintf(filename, "sprites/map%d/sprite%d.bmp", curMapNr, i+1); sprintf(completeFilename, "%s%s", DATA_PREFIX, filename); if(framework->FileExists(completeFilename)) spriteImgs[i] = framework->LoadImage(filename, true); else break; } strcpy(setup.mapFilename, mapFilename); setup.numTextures = numTextures; for(i=0; i<setup.numTextures; i++) { setup.textures[i][0] = textures[i][0]; setup.textures[i][1] = textures[i][1]; } setup.sprites = &sprites; setup.target = framework->GetScreen(); setup.lowQuality = lowQuality; setup.badQuality = badQuality; setup.crosshairRect = &crosshairRect; fireVisible = false; fireStart = SDL_GetTicks(); delete raycaster; raycaster = new Raycaster(&setup); raycaster->LoadMap(mapFilename); sprites.clear(); LoadSpriteMap(spriteMapFilename); raycaster->SetAlpha(0.0f); player->SetHasKey(false); if(player->GetHealth()<100) player->SetHealth(100); if(player->GetAmmo()<35) player->SetAmmo(35); if(player->GetMGAmmo()<70) player->SetMGAmmo(70); /*delete player; player = new Player();*/ SDL_Delay(3000); framework->FillRect(NULL, Colors::black.ToUint32()); SDL_FreeSurface(Loading1); framework->PlayMusic(music1, -0); }
void MainMenu::cleanUp() { Mix_HaltMusic(); //Mix_FreeMusic(_music); }
void VideoState::init() { State::init(); bool wasLetterboxed = CutsceneState::initDisplay(); bool ufoIntroSoundFileDosExists = false; bool ufoIntroSoundFileWinExists = false; int prevMusicVol = Options::musicVolume; int prevSoundVol = Options::soundVolume; if (_useUfoAudioSequence) { const std::set<std::string> &soundDir = FileMap::getVFolderContents("SOUND"); ufoIntroSoundFileDosExists = soundDir.end() != soundDir.find("intro.cat"); ufoIntroSoundFileWinExists = soundDir.end() != soundDir.find("sample3.cat"); if (!ufoIntroSoundFileDosExists && !ufoIntroSoundFileWinExists) { _useUfoAudioSequence = false; } else { // ensure user can hear both music and sound effects for the // vanilla intro sequence Options::musicVolume = Options::soundVolume = std::max(prevMusicVol, prevSoundVol/8); _game->setVolume(Options::soundVolume, Options::musicVolume, -1); } } _game->getCursor()->setVisible(false); int dx = (Options::baseXResolution - Screen::ORIGINAL_WIDTH) / 2; int dy = (Options::baseYResolution - Screen::ORIGINAL_HEIGHT) / 2; FlcPlayer *flcPlayer = NULL; for (std::vector<std::string>::const_iterator it = _videos->begin(); it != _videos->end(); ++it) { std::string videoFileName = FileMap::getFilePath(*it); if (!CrossPlatform::fileExists(videoFileName)) { continue; } if (!flcPlayer) { flcPlayer = new FlcPlayer(); } if (_useUfoAudioSequence) { audioSequence = new AudioSequence(_game->getResourcePack(), flcPlayer); } flcPlayer->init(videoFileName.c_str(), _useUfoAudioSequence ? &audioHandler : NULL, _game, dx, dy); flcPlayer->play(_useUfoAudioSequence); if (_useUfoAudioSequence) { flcPlayer->delay(10000); delete audioSequence; audioSequence = NULL; } flcPlayer->deInit(); if (flcPlayer->wasSkipped()) { break; } } if (flcPlayer) { delete flcPlayer; } #ifndef __NO_MUSIC // fade out! Mix_FadeOutChannel(-1, 45 * 20); if (Mix_GetMusicType(0) != MUS_MID) { // SDL_Mixer has trouble with native midi and volume on windows, // which is the most likely use case, so f@%# it. Mix_FadeOutMusic(45 * 20); func_fade(); } else { Mix_HaltMusic(); } #endif SDL_Color pal[256]; SDL_Color pal2[256]; memcpy(pal, _game->getScreen()->getPalette(), sizeof(SDL_Color) * 256); for (int i = 20; i > 0; --i) { SDL_Event event; if (SDL_PollEvent(&event) && event.type == SDL_KEYDOWN) break; for (int color = 0; color < 256; ++color) { pal2[color].r = (((int)pal[color].r) * i) / 20; pal2[color].g = (((int)pal[color].g) * i) / 20; pal2[color].b = (((int)pal[color].b) * i) / 20; pal2[color].unused = pal[color].unused; } _game->getScreen()->setPalette(pal2, 0, 256, true); _game->getScreen()->flip(); SDL_Delay(45); } _game->getScreen()->clear(); _game->getScreen()->flip(); if (_useUfoAudioSequence) { Options::musicVolume = prevMusicVol; Options::soundVolume = prevSoundVol; _game->setVolume(Options::soundVolume, Options::musicVolume, Options::uiVolume); } #ifndef __NO_MUSIC Sound::stop(); Music::stop(); #endif _game->getCursor()->setVisible(true); CutsceneState::resetDisplay(wasLetterboxed); _game->popState(); }
/** * Waits a cycle to load the resources so the screen is blitted first. * If the loading fails, it shows an error, otherwise moves on to the game. */ void StartState::think() { State::think(); switch (_load) { case LOADING_STARTED: try { Log(LOG_INFO) << "Loading ruleset..."; _game->loadRuleset(); Log(LOG_INFO) << "Ruleset loaded successfully."; Log(LOG_INFO) << "Loading resources..."; _game->setResourcePack(new XcomResourcePack(_game->getRuleset()->getExtraSprites(), _game->getRuleset()->getExtraSounds())); Log(LOG_INFO) << "Resources loaded successfully."; std::vector<std::string> langs = Language::getList(0); if (langs.empty()) { throw Exception("No languages available"); } _load = LOADING_SUCCESSFUL; // loading done? let's play intro! std::string introFile = CrossPlatform::getDataFile("UFOINTRO/UFOINT.FLI"); if (Options::getBool("playIntro") && CrossPlatform::fileExists(introFile)) { audioSequence = new AudioSequence(_game->getResourcePack()); Flc::flc.realscreen = _game->getScreen(); Flc::FlcInit(introFile.c_str()); Flc::flc.dx = (Options::getInt("baseXResolution") - 320) / 2; Flc::flc.dy = (Options::getInt("baseYResolution") - 200) / 2; Flc::flc.loop = 0; // just the one time, please Flc::FlcMain(&audioHandler); Flc::FlcDeInit(); delete audioSequence; // fade out! Mix_FadeOutChannel(-1, 45*20); if (Mix_GetMusicType(0) != MUS_MID) { Mix_FadeOutMusic(45*20); } // SDL_Mixer has trouble with native midi and volume on windows, which is the most likely use case, so f@%# it. else { Mix_HaltMusic(); } SDL_Color pal[256]; SDL_Color pal2[256]; memcpy(pal, _game->getScreen()->getPalette(), sizeof(SDL_Color) * 256); for (int i = 20; i > 0; --i) { SDL_Event event; if (SDL_PollEvent(&event) && event.type == SDL_KEYDOWN) break; for (int color = 0; color < 256; ++color) { pal2[color].r = (((int)pal[color].r) * i) / 20; pal2[color].g = (((int)pal[color].g) * i) / 20; pal2[color].b = (((int)pal[color].b) * i) / 20; } _game->getScreen()->setPalette(pal2, 0, 256, true); _game->getScreen()->flip(); SDL_Delay(45); } _game->getScreen()->clear(); _game->getScreen()->flip(); _game->setVolume(Options::getInt("soundVolume"), Options::getInt("musicVolume")); Mix_HaltChannel(-1); } } catch (Exception &e) { _load = LOADING_FAILED; _surface->clear(); _surface->drawString(1, 9, "ERROR:", 2); _surface->drawString(1, 17, e.what(), 2); _surface->drawString(1, 49, "Make sure you installed OpenXcom", 1); _surface->drawString(1, 57, "correctly.", 1); _surface->drawString(1, 73, "Check the requirements and", 1); _surface->drawString(1, 81, "documentation for more details.", 1); _surface->drawString(75, 183, "Press any key to quit", 1); Log(LOG_ERROR) << e.what(); } break; case LOADING_NONE: _load = LOADING_STARTED; break; case LOADING_SUCCESSFUL: Log(LOG_INFO) << "OpenXcom started successfully!"; if (Options::getString("language").empty()) { _game->setState(new LanguageState(_game)); } else { try { _game->loadLanguage(Options::getString("language")); _game->setState(new MainMenuState(_game)); } catch (Exception) { _game->setState(new LanguageState(_game)); } } break; default: break; } }
//Do a normal stop int Mix_FadeOutMusic(int ms) { return Mix_HaltMusic(); }
void handleKey() { Mix_HaltMusic(); Mix_FreeMusic(music); music = NULL; }
void Music::stop() { Mix_HaltMusic(); }
void haltMusic() { Mix_HaltMusic(); }
int main(int argc, char *argv[]) { GList* list = NULL; json_t *root; SDL_Surface *optimized_surface = NULL; SDL_Surface *temp = NULL; Sound *bg_music = NULL; Sound *level_music = NULL; int done; const Uint8 *keys; char imagepath[512]; game_initialize_system(); SDL_ShowCursor(SDL_DISABLE); bg_music = sound_load_music("sounds/vanguard_bouncy.mp3"); if(!bg_music) { slog("Could not load music\n"); } level_music = sound_load_music("sounds/chippy_cloud_kid.mp3"); if(!level_music) { slog("Could not load music\n"); } Mix_VolumeMusic(5); if(temp) { optimized_surface = SDL_ConvertSurface( temp, graphics_surface->format, NULL ); SDL_FreeSurface(temp); } SDL_Event e; done = 0; int lock = true; do { if(menu_flag) { menu_draw(); if(lock == false) { Mix_HaltMusic(); lock = true; } if(Mix_PlayingMusic() == 0) { Mix_PlayMusic(bg_music->music, -1); } } else { tilemap_render_tile(); entity_draw_all(); if(lock == true) { Mix_HaltMusic(); lock = false; } if(Mix_PlayingMusic() == 0) { Mix_PlayMusic(level_music->music, -1); } } mouse_draw_self(); graphics_next_frame(); SDL_PumpEvents(); entity_think_all(); while(SDL_PollEvent(&e) != 0) { if(e.type == SDL_QUIT) { done = 1; } bool leftclick = false ; bool rightclick = false; if(e.type == SDL_MOUSEBUTTONDOWN) { if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) { leftclick = true; } else if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)) { rightclick = true; } } if(leftclick == true) { if(menu_flag) menu_click(); else tilemap_click(); } else if(rightclick == true) { if(menu_flag) menu_click(); else tilemap_remove_tile(); } bool pressed = false; if(e.type == SDL_KEYDOWN) { if(!pressed) { if(make_flag) { keys = SDL_GetKeyboardState(NULL); if(keys[SDL_SCANCODE_W]) { State state = UP; tilemap_m_click(state); } else if(keys[SDL_SCANCODE_A]) { State state = LEFT; tilemap_m_click(state); } else if(keys[SDL_SCANCODE_S]) { State state = DOWN; tilemap_m_click(state); } else if(keys[SDL_SCANCODE_D]) { State state = RIGHT; tilemap_m_click(state); } if(keys[SDL_SCANCODE_T]) { State state = UP; tilemap_c_click(state); } else if(keys[SDL_SCANCODE_F]) { State state = LEFT; tilemap_c_click(state); } else if(keys[SDL_SCANCODE_G]) { State state = DOWN; tilemap_c_click(state); } else if(keys[SDL_SCANCODE_H]) { State state = RIGHT; tilemap_c_click(state); } } } pressed = true; } else if(e.type == SDL_KEYUP) { pressed = false; } } keys = SDL_GetKeyboardState(NULL); if(keys[SDL_SCANCODE_ESCAPE]) { done = 1; } SDL_RenderPresent(graphics_renderer); // update the screen with any rendering performed since previous call } while(!done); exit(0); return 0; }
//finally here. Whew that's a lot of functions int main(int argc,char* args[]) { srand(time(NULL)); //spin the wheel! int i; //loop counter int frame=0; //total frames past if(init()==false) return 1; if(prepAssets()==false) return 1; if(Mix_PlayMusic(muBGM,-1)==-1) return 1; //read and store the string of appropriate language FILE *pLang; char strLang[25]; //language string if((pLang=fopen("text/en.WhyCantIHoldAllTheseFileExtensions","r"))!=NULL) { if(fgets(strLang,25,pLang)==NULL) return 1; } fclose(pLang); sfMenuPrompt=TTF_RenderText_Blended(fnMenu,strLang,clMenu); //read and store current highscore FILE *pHighScoreR; char strHighScore[10]; if((pHighScoreR=fopen("text/highscore.WhyCantIHoldAllTheseFileExtensions","r"))!=NULL) { if(fgets(strHighScore,10,pHighScoreR)==NULL) return 1; } fclose(pHighScoreR); sfHighScore=TTF_RenderText_Shaded(fnHighScore,strHighScore,clHighScore,clDefault); iHighScore=atoi(strHighScore); //string contents as an int //menu runs here while(quitMenu==false) { //display menu printb(0,0,sfMenu,sfScreen); printb((SCREEN_WIDTH-sfMenuPrompt->w)/2,315,sfMenuPrompt,sfScreen); //menu-only key controls while(SDL_PollEvent(&event)) { if(event.type==SDL_KEYDOWN) { switch(event.key.keysym.sym) { case SDLK_RETURN: quitMenu=true; break; case SDLK_ESCAPE: quitMenu=true; quitGame=true; quitOver=true; quitAll=true; break; default: ; } } //if the window gets X'd if(event.type==SDL_QUIT) { quitMenu=true; //quit the menu quitGame=true; //skip the game quitOver=true; quitAll=true; } } //refresh the screen if(SDL_Flip(sfScreen)==-1) return 1; } //game is starting! set up everything! tmTime.start(); tmFPS.start(); tmFPSUpd.start(); tmDelta.start(); tmMusic.start(); //REPLAY LOOP while(quitAll==false) { randBullets(); //game runs here while(quitGame==false) { //once wave time is up: level up and restart wave timer //setup phase is active if(waveZero==true&&tmTime.getTicks()>10000) { iWave++; nextWave(); tmTime.start(); waveZero=false; newBGM(); tmScore.start(); tmTimeAlive.start(); } //setup phase is off else if(tmTime.getTicks()>WAVE_LENGTH) { iWave++; nextWave(); tmTime.start(); } //change music after 90 seconds if(tmMusic.getTicks()>90000) { newBGM(); tmMusic.start(); } //score acceleration if(tmTimeAlive.getTicks()>30000) iScoreAccel=13; else if(tmTimeAlive.getTicks()>15000) iScoreAccel=6; else if(tmTimeAlive.getTicks()>7500) iScoreAccel=3; else if(tmTimeAlive.getTicks()>0) iScoreAccel=1; //score timing if(tmScore.getTicks()>250) { iScore+=iScoreAccel; tmScore.start(); } //1up timing if(tmTimeAlive.getTicks()>45000) { tmTimeAlive.start(); iLife++; //don't let player have too many lives //if 1up is allowed, play sound if(iLife>5)iLife=5; else if(Mix_PlayChannel(-1,chGain,0)==-1) return 1; } //while there's science to do while(SDL_PollEvent(&event)) { //ship controls myship.handleInput(); //other controls if(event.type==SDL_KEYDOWN) { switch(event.key.keysym.sym) { case SDLK_ESCAPE: quitGame=true; quitOver=true; quitAll=true; break; case SDLK_x: if(useBomb()==false) return 1; break; default: ; } } //if the window gets X'd if(event.type == SDL_QUIT) { quitGame = true; quitOver=true; quitAll=true; } } //update screen data myship.move(tmDelta.getTicks()); //update ship's position tmDelta.start(); //restart change of time timer printb(0,0,sfBG,sfScreen); //print background myship.show(); //print position to screen if(diedRecently==true) printb(120,0,sfDeathOverlay,sfScreen,NULL); if(bombedRecently==true) printb(120,0,sfBombFlash,sfScreen,NULL); if(waveZero==true) { //reset bullets to original when looping game printb(0,0,sfHowTo,sfScreen,NULL); iMaxBul=-1; } for(i=0; i<=iMaxBul; i++) { //player has died: do all relevant tracking if(isCol(myship.hitbox,b[i].hitbox)) { iLife--; iBomb=3; iScore-=50; if(iLife==0) quitGame=true; diedRecently=true; b[i].hitbox.x=rand()%420-120; b[i].hitbox.y=0; tmDeathOverlay.start(); tmTimeAlive.start(); if(Mix_PlayChannel(-1,chDeath,0)==-1) return 1; } if(b[i].hitbox.x>515) b[i].hitbox.x=120; if(b[i].hitbox.x<120) b[i].hitbox.x=515; //compensate for bullet width if(b[i].hitbox.y>480) { //because collision is counted from sScore of the picture b[i].hitbox.y=0; //so bulletwidth had to be subtracted b[i].xVel=rand()%5-2; //bullet can travel left or right b[i].yVel=rand()%4+1; //can only travel down } b[i].hitbox.y+=b[i].yVel; b[i].hitbox.x+=b[i].xVel; printb(b[i].hitbox.x,b[i].hitbox.y,sfBullet,sfScreen,NULL); } //expiry dates for death and bomb notifications if(tmDeathOverlay.getTicks()>500) diedRecently=false; if(tmBombFlash.getTicks()>250) bombedRecently=false; //display all stats renderHUD(); printb(7,50,sfHighScore,sfScreen,NULL); //refresh the screen if(SDL_Flip(sfScreen)==-1) return 1; //limit the frame rate if(tmFPS.getTicks()<1000/FRAMES_PER_SECOND) { SDL_Delay((1000/FRAMES_PER_SECOND)-tmFPS.getTicks()); tmFPS.start(); } frame++; //one frame has passed //update this once per second if(tmFPSUpd.getTicks()>1000) { std::stringstream newCaption; newCaption<<frame/(tmFPS.getTicks()/1000.f)<<" fps"; SDL_WM_SetCaption(newCaption.str().c_str(),NULL); tmFPSUpd.start(); //restart for the next one-second wait } } //store new high score, if there is one if(iScore>iHighScore) { FILE *pHighScoreW; if((pHighScoreW=fopen("text/highscore.WhyCantIHoldAllTheseFileExtensions","w"))!=NULL) { if(fprintf(pHighScoreW,"%d",iScore)==0) return 1; } fclose(pHighScoreW); newHighScore=true; } //stop playing music Mix_HaltMusic(); //game over runs here while(quitOver==false) { //some key events while(SDL_PollEvent(&event)) { if(event.type==SDL_KEYDOWN) { switch(event.key.keysym.sym) { case SDLK_RETURN: quitOver=true; break; case SDLK_ESCAPE: quitOver=true; quitAll=true; break; default: ; } } //if the window gets X'd if(event.type == SDL_QUIT) { quitOver=true; quitAll=true; } } //end surfaces std::stringstream finalScore; finalScore<<iScore; sfScore=TTF_RenderText_Blended(fnFinalScore,finalScore.str().c_str(),clMenu); //display restart prompt FILE *pRestart; char strRestart[30]; if((pRestart=fopen("text/enr.WhyCantIHoldAllTheseFileExtensions","r"))!=NULL) { if(fgets(strRestart,30,pRestart)==NULL) return 1; } fclose(pRestart); sfRestart=TTF_RenderText_Blended(fnMenu,strRestart,clScore); //print everything printb(0,0,sfOverBG,sfScreen,NULL); printb((SCREEN_WIDTH-sfRestart->w)/2,385,sfRestart,sfScreen,NULL); printb((SCREEN_WIDTH-sfScore->w)/2,240,sfScore,sfScreen,NULL); if(newHighScore==true) printb(430,280,sfNewHigh,sfScreen,NULL); //refresh the screen if(SDL_Flip(sfScreen)==-1) return 1; SDL_WM_SetCaption("Shutengu!!",NULL); } //reset loop conditions to allow replaying resetGame(); } //user has now quit cleanUp(); return 0; }