X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fgameloop.cpp;h=ca9a0bcea8c9996982c66cfa461d57b596751bea;hb=1d613f782e21f55f915b6e5fa808e7435896461a;hp=3b593f955e95d12961ecde83c8e8385aea9850e7;hpb=626ab69641b179048b9d0fc528cd1626886fe9db;p=supertux.git diff --git a/src/gameloop.cpp b/src/gameloop.cpp index 3b593f955..ca9a0bcea 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -62,6 +62,7 @@ #include "statistics.h" #include "timer.h" #include "object/fireworks.h" +#include "textscroller.h" GameSession* GameSession::current_ = 0; @@ -103,15 +104,6 @@ GameSession::restart_level() last_keys.clear(); -#if 0 - Vector tux_pos = Vector(-1,-1); - if (currentsector) - { - // Tux has lost a life, so we try to respawn him at the nearest reset point - tux_pos = currentsector->player->base; - } -#endif - delete level; currentsector = 0; @@ -167,20 +159,20 @@ GameSession::levelintro() } } -// context.draw_text(gold_text, level->get_name(), Vector(screen->w/2, 160), +// context.draw_text(gold_text, level->get_name(), Vector(SCREEN_WIDTH/2, 160), // CENTER_ALLIGN, LAYER_FOREGROUND1); context.draw_center_text(gold_text, level->get_name(), Vector(0, 160), LAYER_FOREGROUND1); sprintf(str, "TUX x %d", player_status.lives); - context.draw_text(white_text, str, Vector(screen->w/2, 210), + context.draw_text(white_text, str, Vector(SCREEN_WIDTH/2, 210), CENTER_ALLIGN, LAYER_FOREGROUND1); if((level->get_author().size()) && (level->get_author() != "SuperTux Team")) //TODO make author check case/blank-insensitive context.draw_text(white_small_text, std::string(_("contributed by ")) + level->get_author(), - Vector(screen->w/2, 350), CENTER_ALLIGN, LAYER_FOREGROUND1); + Vector(SCREEN_WIDTH/2, 350), CENTER_ALLIGN, LAYER_FOREGROUND1); if(best_level_statistics != NULL) @@ -332,7 +324,7 @@ GameSession::process_events() snprintf(buf, sizeof(buf), "P: %4.1f,%4.1f", tux.get_pos().x, tux.get_pos().y); context->draw_text(white_text, buf, - Vector(0, screen->h - white_text->get_height()), + Vector(0, SCREEN_HEIGHT - white_text->get_height()), LEFT_ALLIGN, LAYER_FOREGROUND1); context->do_drawing(); SDL_Delay(1000); @@ -466,17 +458,15 @@ GameSession::handle_cheats() // Cheating words (the goal of this is really for debugging, // but could be used for some cheating, nothing wrong with that) if(compare_last(last_keys, "grow")) { - tux.grow(false); + tux.set_bonus(GROWUP_BONUS, false); last_keys.clear(); } if(compare_last(last_keys, "fire")) { - tux.grow(false); - tux.got_power = tux.FIRE_POWER; + tux.set_bonus(FIRE_BONUS, false); last_keys.clear(); } if(compare_last(last_keys, "ice")) { - tux.grow(false); - tux.got_power = tux.ICE_POWER; + tux.set_bonus(ICE_BONUS, false); last_keys.clear(); } if(compare_last(last_keys, "lifeup")) { @@ -520,7 +510,7 @@ GameSession::handle_cheats() if(compare_last(last_keys, "gotoend")) { // goes to the end of the level tux.move(Vector( - (currentsector->solids->get_width()*32) - (screen->w*2), 0)); + (currentsector->solids->get_width()*32) - (SCREEN_WIDTH*2), 0)); currentsector->camera->reset( Vector(tux.get_pos().x, tux.get_pos().y)); last_keys.clear(); @@ -555,8 +545,6 @@ GameSession::check_end_conditions() exit_status = ES_LEVEL_FINISHED; return; } else if (!end_sequence && tux->is_dead()) { - player_status.bonus = PlayerStatus::NO_BONUS; - if (player_status.lives < 0) { // No more lives!? exit_status = ES_GAME_OVER; } else { // Still has lives, so reset Tux to the levelstart @@ -571,19 +559,22 @@ void GameSession::action(float elapsed_time) { // advance timers - if (exit_status == ES_NONE && !currentsector->player->growing_timer.check()) - { - // Update Tux and the World - currentsector->action(elapsed_time); - } + if(!currentsector->player->growing_timer.started()) { + // Update Tux and the World + currentsector->action(elapsed_time); + } // respawning in new sector? if(newsector != "" && newspawnpoint != "") { Sector* sector = level->get_sector(newsector); + if(sector == 0) { + std::cerr << "Sector '" << newsector << "' not found.\n"; + } + sector->activate(newspawnpoint); + sector->play_music(LEVEL_MUSIC); currentsector = sector; - currentsector->activate(newspawnpoint); - currentsector->play_music(LEVEL_MUSIC); - newsector = newspawnpoint = ""; + newsector = ""; + newspawnpoint = ""; } } @@ -594,46 +585,46 @@ GameSession::draw() drawstatus(*context); if(game_pause) - { - int x = screen->h / 20; - for(int i = 0; i < x; ++i) - { - context->draw_filled_rect( - Vector(i % 2 ? (pause_menu_frame * i)%screen->w : - -((pause_menu_frame * i)%screen->w) - ,(i*20+pause_menu_frame)%screen->h), - Vector(screen->w,10), - Color(20,20,20, rand() % 20 + 1), LAYER_FOREGROUND1+1); - } - context->draw_filled_rect( - Vector(0,0), Vector(screen->w, screen->h), - Color(rand() % 50, rand() % 50, rand() % 50, 128), LAYER_FOREGROUND1); - context->draw_text(blue_text, _("PAUSE - Press 'P' To Play"), - Vector(screen->w/2, 230), CENTER_ALLIGN, LAYER_FOREGROUND1+2); - - char str1[60]; - char str2[124]; - sprintf(str1, _("Playing: ")); - sprintf(str2, level->name.c_str()); - - context->draw_text(blue_text, str1, - Vector((screen->w - (blue_text->get_text_width(str1) + white_text->get_text_width(str2)))/2, 340), - LEFT_ALLIGN, LAYER_FOREGROUND1+2); - context->draw_text(white_text, str2, - Vector(((screen->w - (blue_text->get_text_width(str1) + white_text->get_text_width(str2)))/2)+blue_text->get_text_width(str1), 340), - LEFT_ALLIGN, LAYER_FOREGROUND1+2); - } + draw_pause(); - if(Menu::current()) - { - Menu::current()->draw(*context); - mouse_cursor->draw(*context); - } + if(Menu::current()) { + Menu::current()->draw(*context); + mouse_cursor->draw(*context); + } context->do_drawing(); } void +GameSession::draw_pause() +{ + int x = SCREEN_HEIGHT / 20; + for(int i = 0; i < x; ++i) { + context->draw_filled_rect( + Vector(i % 2 ? (pause_menu_frame * i)%SCREEN_WIDTH : + -((pause_menu_frame * i)%SCREEN_WIDTH) + ,(i*20+pause_menu_frame)%SCREEN_HEIGHT), + Vector(SCREEN_WIDTH,10), + Color(20,20,20, rand() % 20 + 1), LAYER_FOREGROUND1+1); + } + context->draw_filled_rect( + Vector(0,0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT), + Color(rand() % 50, rand() % 50, rand() % 50, 128), LAYER_FOREGROUND1); + context->draw_text(blue_text, _("PAUSE - Press 'P' To Play"), + Vector(SCREEN_WIDTH/2, 230), CENTER_ALLIGN, LAYER_FOREGROUND1+2); + + const char* str1 = _("Playing: "); + const char* str2 = level->get_name().c_str(); + + context->draw_text(blue_text, str1, + Vector((SCREEN_WIDTH - (blue_text->get_text_width(str1) + white_text->get_text_width(str2)))/2, 340), + LEFT_ALLIGN, LAYER_FOREGROUND1+2); + context->draw_text(white_text, str2, + Vector(((SCREEN_WIDTH - (blue_text->get_text_width(str1) + white_text->get_text_width(str2)))/2)+blue_text->get_text_width(str1), 340), + LEFT_ALLIGN, LAYER_FOREGROUND1+2); +} + +void GameSession::process_menu() { Menu* menu = Menu::current(); @@ -781,6 +772,29 @@ GameSession::set_reset_point(const std::string& sector, const Vector& pos) } void +GameSession::display_info_box(const std::string& text) +{ + InfoBox* box = new InfoBox(text); + + bool running = true; + while(running) { + SDL_Event event; + while (SDL_PollEvent(&event)) { + switch(event.type) { + case SDL_KEYDOWN: + running = false; + break; + } + } + + box->draw(*context); + draw(); + } + + delete box; +} + +void GameSession::start_sequence(const std::string& sequencename) { if(sequencename == "endsequence" || sequencename == "fireworks") { @@ -824,52 +838,52 @@ GameSession::drawstatus(DrawingContext& context) } if(time_left.get_timeleft() < 0) { - context.draw_text(white_text, _("TIME's UP"), Vector(screen->w/2, 0), + context.draw_text(white_text, _("TIME's UP"), Vector(SCREEN_WIDTH/2, 0), CENTER_ALLIGN, LAYER_FOREGROUND1); } else if (time_left.get_timeleft() > TIME_WARNING || int(global_time * 2.5) % 2) { sprintf(str, " %d", int(time_left.get_timeleft())); context.draw_text(white_text, _("TIME"), - Vector(screen->w/2, 0), CENTER_ALLIGN, LAYER_FOREGROUND1); + Vector(SCREEN_WIDTH/2, 0), CENTER_ALLIGN, LAYER_FOREGROUND1); context.draw_text(gold_text, str, - Vector(screen->w/2 + 4*16, 0), CENTER_ALLIGN, LAYER_FOREGROUND1); + Vector(SCREEN_WIDTH/2 + 4*16, 0), CENTER_ALLIGN, LAYER_FOREGROUND1); } sprintf(str, " %d", player_status.distros); context.draw_text(white_text, _("COINS"), - Vector(screen->w - white_text->get_text_width(_("COINS"))-white_text->get_text_width(" 99"), 0), + Vector(SCREEN_WIDTH - white_text->get_text_width(_("COINS"))-white_text->get_text_width(" 99"), 0), LEFT_ALLIGN, LAYER_FOREGROUND1); context.draw_text(gold_text, str, - Vector(screen->w - gold_text->get_text_width(" 99"), 0),LEFT_ALLIGN, LAYER_FOREGROUND1); + Vector(SCREEN_WIDTH - gold_text->get_text_width(" 99"), 0),LEFT_ALLIGN, LAYER_FOREGROUND1); if (player_status.lives >= 5) { sprintf(str, "%dx", player_status.lives); - float x = screen->w - gold_text->get_text_width(str) - tux_life->w; + float x = SCREEN_WIDTH - gold_text->get_text_width(str) - tux_life->w; context.draw_text(gold_text, str, Vector(x, 20), LEFT_ALLIGN, LAYER_FOREGROUND1); - context.draw_surface(tux_life, Vector(screen->w - 16, 20), + context.draw_surface(tux_life, Vector(SCREEN_WIDTH - 16, 20), LAYER_FOREGROUND1); } else { for(int i= 0; i < player_status.lives; ++i) context.draw_surface(tux_life, - Vector(screen->w - tux_life->w*4 +(tux_life->w*i), 20), + Vector(SCREEN_WIDTH - tux_life->w*4 +(tux_life->w*i), 20), LAYER_FOREGROUND1); } context.draw_text(white_text, _("LIVES"), - Vector(screen->w - white_text->get_text_width(_("LIVES")) - white_text->get_text_width(" 99"), 20), + Vector(SCREEN_WIDTH - white_text->get_text_width(_("LIVES")) - white_text->get_text_width(" 99"), 20), LEFT_ALLIGN, LAYER_FOREGROUND1); if(show_fps) { sprintf(str, "%2.1f", fps_fps); context.draw_text(white_text, "FPS", - Vector(screen->w - white_text->get_text_width("FPS "), 40), + Vector(SCREEN_WIDTH - white_text->get_text_width("FPS "), 40), LEFT_ALLIGN, LAYER_FOREGROUND1); context.draw_text(gold_text, str, - Vector(screen->w-4*16, 40), LEFT_ALLIGN, LAYER_FOREGROUND1); + Vector(SCREEN_WIDTH-4*16, 40), LEFT_ALLIGN, LAYER_FOREGROUND1); } } @@ -887,14 +901,14 @@ GameSession::drawresultscreen() } } - context.draw_text(blue_text, _("Result:"), Vector(screen->w/2, 200), + context.draw_text(blue_text, _("Result:"), Vector(SCREEN_WIDTH/2, 200), CENTER_ALLIGN, LAYER_FOREGROUND1); sprintf(str, _("SCORE: %d"), global_stats.get_points(SCORE_STAT)); - context.draw_text(gold_text, str, Vector(screen->w/2, 224), CENTER_ALLIGN, LAYER_FOREGROUND1); + context.draw_text(gold_text, str, Vector(SCREEN_WIDTH/2, 224), CENTER_ALLIGN, LAYER_FOREGROUND1); sprintf(str, _("COINS: %d"), player_status.distros); - context.draw_text(gold_text, str, Vector(screen->w/2, 256), CENTER_ALLIGN, LAYER_FOREGROUND1); + context.draw_text(gold_text, str, Vector(SCREEN_WIDTH/2, 256), CENTER_ALLIGN, LAYER_FOREGROUND1); context.do_drawing(); @@ -941,7 +955,7 @@ bool process_load_game_menu() fadeout(256); DrawingContext context; context.draw_text(white_text, "Loading...", - Vector(screen->w/2, screen->h/2), CENTER_ALLIGN, LAYER_FOREGROUND1); + Vector(SCREEN_WIDTH/2, SCREEN_HEIGHT/2), CENTER_ALLIGN, LAYER_FOREGROUND1); context.do_drawing(); WorldMapNS::WorldMap worldmap;