void GameSession::levelintro(void) { music_manager->halt_music(); char str[60]; if (get_level()->img_bkgd) get_level()->img_bkgd->draw(0, 0); else drawgradient(get_level()->bkgd_top, get_level()->bkgd_bottom); sprintf(str, "%s", world->get_level()->name.c_str()); gold_text->drawf(str, 0, 200, A_HMIDDLE, A_TOP, 1); sprintf(str, "TUX x %d", player_status.lives); white_text->drawf(str, 0, 224, A_HMIDDLE, A_TOP, 1); sprintf(str, "by %s", world->get_level()->author.c_str()); white_small_text->drawf(str, 0, 360, A_HMIDDLE, A_TOP, 1); flipscreen(); SDL_Event event; wait_for_event(event,1000,3000,true); }
/* just displays a Yes/No text that can be used to confirm stuff */ bool confirm_dialog(std::string text) { Surface* cap_screen = Surface::CaptureScreen(); Menu* dialog = new Menu; dialog->additem(MN_DEACTIVE, text,0,0); dialog->additem(MN_HL,"",0,0); dialog->additem(MN_ACTION,"Yes",0,0,true); dialog->additem(MN_ACTION,"No",0,0,false); dialog->additem(MN_HL,"",0,0); Menu::set_current(dialog); while(true) { SDL_Event event; while (SDL_PollEvent(&event)) { dialog->event(event); } cap_screen->draw(0,0); dialog->draw(); dialog->action(); switch (dialog->check()) { case true: delete cap_screen; Menu::set_current(0); delete dialog; return true; break; case false: delete cap_screen; Menu::set_current(0); delete dialog; return false; break; default: break; } mouse_cursor->draw(); flipscreen(); SDL_Delay(25); } }
void GameSession::drawresultscreen(void) { char str[80]; if (get_level()->img_bkgd) get_level()->img_bkgd->draw(0, 0); else drawgradient(get_level()->bkgd_top, get_level()->bkgd_bottom); blue_text->drawf("Result:", 0, 200, A_HMIDDLE, A_TOP, 1); sprintf(str, "SCORE: %d", player_status.score); gold_text->drawf(str, 0, 224, A_HMIDDLE, A_TOP, 1); sprintf(str, "COINS: %d", player_status.distros); gold_text->drawf(str, 0, 256, A_HMIDDLE, A_TOP, 1); flipscreen(); SDL_Event event; wait_for_event(event,2000,5000,true); }
/* --- TITLE SCREEN --- */ void title(void) { random_timer.init(true); walking = true; st_pause_ticks_init(); GameSession session(datadir + "/levels/misc/menu.stl", 0, ST_GL_DEMO_GAME); clearscreen(0, 0, 0); updatescreen(); /* Load images: */ bkg_title = new Surface(datadir + "/images/title/background.jpg", IGNORE_ALPHA); logo = new Surface(datadir + "/images/title/logo.png", USE_ALPHA); img_choose_subset = new Surface(datadir + "/images/status/choose-level-subset.png", USE_ALPHA); /* Generating contrib maps by only using a string_list */ // Since there isn't any world dir or anything, add a hardcoded entry for Bonus Island string_list_init(&worldmap_list); string_list_type files = dfiles("levels/worldmaps/", ".stwm", "couldn't list worldmaps"); for(int i = 0; i < files.num_items; ++i) { if(strcmp(files.item[i], "world1.stwm") == 0) continue; string_list_add_item(&worldmap_list, files.item[i]); } string_list_free(&files); /* --- Main title loop: --- */ frame = 0; /* Draw the title background: */ bkg_title->draw_bg(); update_time = st_get_ticks(); random_timer.start(rand() % 2000 + 2000); Menu::set_current(main_menu); while (Menu::current()) { // if we spent to much time on a menu entry if( (update_time - last_update_time) > 1000) update_time = last_update_time = st_get_ticks(); // Calculate the movement-factor double frame_ratio = ((double)(update_time-last_update_time))/((double)FRAME_RATE); if(frame_ratio > 1.5) /* Quick hack to correct the unprecise CPU clocks a little bit. */ frame_ratio = 1.5 + (frame_ratio - 1.5) * 0.85; /* Lower the frame_ratio that Tux doesn't jump to hectically throught the demo. */ frame_ratio /= 2; SDL_Event event; while (SDL_PollEvent(&event)) { if (Menu::current()) { Menu::current()->event(event); } // FIXME: QUIT signal should be handled more generic, not locally if (event.type == SDL_QUIT) Menu::set_current(0); } /* Draw the background: */ draw_demo(&session, frame_ratio); if (Menu::current() == main_menu) logo->draw( 160, 30); white_small_text->draw(" SuperTux " VERSION "\n" "Copyright (c) 2003 SuperTux Devel Team\n" "This game comes with ABSOLUTELY NO WARRANTY. This is free software, and you\n" "are welcome to redistribute it under certain conditions; see the file COPYING\n" "for details.\n", 0, 420, 0); /* Don't draw menu, if quit is true */ Menu* menu = Menu::current(); if(menu) { menu->draw(); menu->action(); if(menu == main_menu) { MusicManager* music_manager; MusicRef menu_song; switch (main_menu->check()) { case MNID_STARTGAME: // Start Game, ie. goto the slots menu update_load_save_game_menu(load_game_menu); break; case MNID_CONTRIB: // Contrib Menu puts("Entering contrib menu"); generate_contrib_menu(); break; case MNID_LEVELEDITOR: leveleditor(); Menu::set_current(main_menu); break; case MNID_CREDITS: music_manager = new MusicManager(); menu_song = music_manager->load_music(datadir + "/music/credits.ogg"); music_manager->halt_music(); music_manager->play_music(menu_song,0); display_text_file("CREDITS", bkg_title, SCROLL_SPEED_CREDITS); music_manager->halt_music(); menu_song = music_manager->load_music(datadir + "/music/theme.mod"); music_manager->play_music(menu_song); Menu::set_current(main_menu); break; case MNID_QUITMAINMENU: Menu::set_current(0); break; } } else if(menu == options_menu) { process_options_menu(); } else if(menu == load_game_menu) { if(event.key.keysym.sym == SDLK_DELETE) { int slot = menu->get_active_item_id(); char str[1024]; sprintf(str,"Are you sure you want to delete slot %d?", slot); draw_background(); if(confirm_dialog(str)) { sprintf(str,"%s/slot%d.stsg", st_save_dir, slot); printf("Removing: %s\n",str); remove(str); } update_load_save_game_menu(load_game_menu); update_time = st_get_ticks(); Menu::set_current(main_menu); } else if (process_load_game_menu()) { // FIXME: shouldn't be needed if GameSession doesn't relay on global variables // reset tux scroll_x = 0; //titletux.level_begin(); update_time = st_get_ticks(); } } else if(menu == contrib_menu) { check_contrib_menu(); } else if (menu == contrib_subset_menu) { check_contrib_subset_menu(); } } mouse_cursor->draw(); flipscreen(); /* Set the time of the last update and the time of the current update */ last_update_time = update_time; update_time = st_get_ticks(); /* Pause: */ frame++; SDL_Delay(25); } /* Free surfaces: */ free_contrib_menu(); string_list_free(&worldmap_list); delete bkg_title; delete logo; delete img_choose_subset; }
void save_hs(int score) { char str[80]; Surface* bkgd; SDL_Event event; bkgd = new Surface(datadir + "/images/highscore/highscore.png", IGNORE_ALPHA); hs_score = score; Menu::set_current(highscore_menu); if(!highscore_menu->item[0].input) highscore_menu->item[0].input = (char*) malloc(strlen(hs_name.c_str()) + 1); strcpy(highscore_menu->item[0].input,hs_name.c_str()); /* ask for player's name */ while(Menu::current()) { bkgd->draw_bg(); blue_text->drawf("Congratulations", 0, 130, A_HMIDDLE, A_TOP, 2, NO_UPDATE); blue_text->draw("Your score:", 150, 180, 1, NO_UPDATE); sprintf(str, "%d", hs_score); yellow_nums->draw(str, 350, 170, 1, NO_UPDATE); Menu::current()->draw(); Menu::current()->action(); flipscreen(); while(SDL_PollEvent(&event)) if(event.type == SDL_KEYDOWN) Menu::current()->event(event); switch (highscore_menu->check()) { case 0: if(highscore_menu->item[0].input != NULL) hs_name = highscore_menu->item[0].input; break; } SDL_Delay(25); } /* Save to file: */ FILE* fi; std::string filename; /* Save data file: */ filename = highscore_filename; fcreatedir(filename.c_str()); if(fwriteable(filename.c_str())) { fi = fopen(filename.c_str(), "w"); if (fi == NULL) { perror(filename.c_str()); } /* Write header: */ fprintf(fi,";SuperTux HighScores\n"); fprintf(fi,"(supertux-highscore\n"); /* Save title info: */ fprintf(fi," (name \"%s\")\n", hs_name.c_str()); /* Save the description: */ fprintf(fi," (score \"%i\")\n", hs_score); fprintf( fi,")"); fclose(fi); } /* fi = opendata(highscore_filename, "w"); if (fi != NULL) { fprintf(fi, "# Supertux highscore file\n\n"); fprintf(fi, "name=%s\n", hs_name); fprintf(fi, "highscore=%d\n", hs_score); fprintf(fi, "# (File automatically created.)\n"); fclose(fi); }*/ }
void title_loop() { // if we spent to much time on a menu entry if( (update_time - last_update_time) > 1000) update_time = last_update_time = st_get_ticks(); // Calculate the movement-factor double frame_ratio = ((double)(update_time-last_update_time))/((double)FRAME_RATE); if(frame_ratio > 1.5) /* Quick hack to correct the unprecise CPU clocks a little bit. */ frame_ratio = 1.5 + (frame_ratio - 1.5) * 0.85; /* Lower the frame_ratio that Tux doesn't jump to hectically throught the demo. */ frame_ratio /= 2; //printf("pxx: frame ratio: %f\n", frame_ratio); SDL_Event event; while (SDL_PollEvent(&event)) { if (Menu::current()) { Menu::current()->event(event); } // FIXME: QUIT signal should be handled more generic, not locally if (event.type == SDL_QUIT) Menu::set_current(0); } /* Draw the background: */ draw_demo(title_session, frame_ratio); if (Menu::current() == main_menu) logo->draw( 160, 30); white_small_text->draw(" SuperTux " VERSION "\n" "Copyright (c) 2003 SuperTux Devel Team\n" "This game comes with ABSOLUTELY NO WARRANTY. This is free software, and you\n" "are welcome to redistribute it under certain conditions; see the file COPYING\n" "for details.\n", 0, 420, 0); /* Don't draw menu, if quit is true */ Menu* menu = Menu::current(); if(menu) { menu->draw(); menu->action(); if(menu == main_menu) { MusicManager* music_manager; MusicRef menu_song; switch (main_menu->check()) { case MNID_STARTGAME: // Start Game, ie. goto the slots menu update_load_save_game_menu(load_game_menu); break; case MNID_CONTRIB: // Contrib Menu puts("Entering contrib menu"); generate_contrib_menu(); break; case MNID_LEVELEDITOR: leveleditor(); Menu::set_current(main_menu); break; case MNID_CREDITS: music_manager = new MusicManager(); menu_song = music_manager->load_music(datadir + "/music/credits.ogg"); //music_manager->halt_music(); music_manager->play_music(menu_song,0); display_text_file("CREDITS", bkg_title, SCROLL_SPEED_CREDITS); // music_manager->halt_music(); // menu_song = music_manager->load_music(datadir + "/music/theme.ogg"); // music_manager->play_music(menu_song); // Menu::set_current(main_menu); break; case MNID_QUITMAINMENU: Menu::set_current(0); break; } } else if(menu == options_menu) { process_options_menu(); } else if(menu == load_game_menu) { if(event.key.keysym.sym == SDLK_DELETE) { int slot = menu->get_active_item_id(); char str[1024]; sprintf(str,"Are you sure you want to delete slot %d?", slot); draw_background(); if(confirm_dialog(str)) { sprintf(str,"%s/slot%d.stsg", st_save_dir, slot); printf("Removing: %s\n",str); remove(str); } update_load_save_game_menu(load_game_menu); update_time = st_get_ticks(); Menu::set_current(main_menu); } else if (process_load_game_menu()) { // // FIXME: shouldn't be needed if GameSession doesn't relay on global variables // // reset tux // scroll_x = 0; // //titletux.level_begin(); // update_time = st_get_ticks(); } } else if(menu == contrib_menu) { check_contrib_menu(); } else if (menu == contrib_subset_menu) { check_contrib_subset_menu(); } } mouse_cursor->draw(); flipscreen(); /* Set the time of the last update and the time of the current update */ last_update_time = update_time; update_time = st_get_ticks(); /* Pause: */ frame++; //SDL_Delay(25); //printf("pxx: title loop finish\n"); }