X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fgameloop.cpp;h=6fa78367c47df0e188054ccc1e83f002a8a0422d;hb=42503cac8eac1199cccec2d4fbed7fde41a2bb55;hp=0ccf68d20d3c60e2f6c1d9e87ce945f63f05660a;hpb=07a60074d2369ec9f49754f15277f5242482df84;p=supertux.git diff --git a/src/gameloop.cpp b/src/gameloop.cpp index 0ccf68d20..6fa78367c 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -99,6 +99,9 @@ GameSession::GameSession(const std::string& levelname_, int mode, bool flip_leve if(flip_levels_mode) flip_level = true; + last_swap_point = Vector(-1, -1); + last_swap_stats.reset(); + restart_level(); } @@ -129,6 +132,11 @@ GameSession::restart_level() if(flip_level) level->do_vertical_flip(); + global_stats.reset(); + global_stats.set_total_points(COINS_COLLECTED_STAT, level->get_total_coins()); + global_stats.set_total_points(BADGUYS_KILLED_STAT, level->get_total_badguys()); + global_stats.set_total_points(TIME_NEEDED_STAT, level->time_left); + currentsector = level->get_sector("main"); if(!currentsector) Termination::abort("Level has no main sector.", ""); @@ -138,9 +146,19 @@ GameSession::restart_level() if(tux_pos.x != -1) { tux_pos = currentsector->get_best_spawn_point(tux_pos); + + if(last_swap_point.x > tux_pos.x) + tux_pos = last_swap_point; + else // new swap point + { + last_swap_point = tux_pos; + + last_swap_stats += global_stats; + } + currentsector->player->base.x = tux_pos.x; currentsector->player->base.y = tux_pos.y; - + // has to reset camera on swapping currentsector->camera->reset(Vector(currentsector->player->base.x, currentsector->player->base.y)); @@ -152,8 +170,6 @@ GameSession::restart_level() levelintro(); } - global_stats.reset(); - time_left.init(true); start_timers(); currentsector->play_music(LEVEL_MUSIC); @@ -175,8 +191,10 @@ GameSession::levelintro(void) DrawingContext context; currentsector->background->draw(context); - context.draw_text(gold_text, level->get_name(), Vector(screen->w/2, 160), - CENTER_ALLIGN, LAYER_FOREGROUND1); +// context.draw_text(gold_text, level->get_name(), Vector(screen->w/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), @@ -230,11 +248,12 @@ GameSession::on_escape_press() it could have nasty bugs, like going allways to the right or whatever that key does */ Player& tux = *(currentsector->player); - tux.key_event((SDLKey)keymap.jump, UP); - tux.key_event((SDLKey)keymap.duck, UP); + tux.key_event((SDLKey)keymap.up, UP); + tux.key_event((SDLKey)keymap.down, UP); tux.key_event((SDLKey)keymap.left, UP); tux.key_event((SDLKey)keymap.right, UP); - tux.key_event((SDLKey)keymap.fire, UP); + tux.key_event((SDLKey)keymap.jump, UP); + tux.key_event((SDLKey)keymap.power, UP); Menu::set_current(game_menu); Ticks::pause_start(); @@ -425,6 +444,11 @@ GameSession::process_events() player_status.lives--; last_keys.clear(); } + if(compare_last(last_keys, "grease")) + { + tux.physic.set_velocity_x(tux.physic.get_velocity_x()*3); + last_keys.clear(); + } if(compare_last(last_keys, "invincible")) { // be invincle for the rest of the level tux.invincible_timer.start(time_left.get_left()); @@ -436,7 +460,8 @@ GameSession::process_events() last_keys.clear(); } if(compare_last(last_keys, "kill")) - { // kill Tux + { // kill Tux, but without losing a life + player_status.lives++; tux.kill(tux.KILL); last_keys.clear(); } @@ -476,11 +501,20 @@ GameSession::process_events() else if (event.jaxis.axis == joystick_keymap.y_axis) { if (event.jaxis.value > joystick_keymap.dead_zone) - tux.input.down = DOWN; - else if (event.jaxis.value < -joystick_keymap.dead_zone) + { + tux.input.up = DOWN; tux.input.down = UP; + } + else if (event.jaxis.value < -joystick_keymap.dead_zone) + { + tux.input.up = UP; + tux.input.down = DOWN; + } else - tux.input.down = UP; + { + tux.input.up = DOWN; + tux.input.down = DOWN; + } } break; @@ -507,7 +541,7 @@ GameSession::process_events() case SDL_JOYBUTTONDOWN: if (event.jbutton.button == joystick_keymap.a_button) - tux.input.up = DOWN; + tux.input.jump = DOWN; else if (event.jbutton.button == joystick_keymap.b_button) tux.input.fire = DOWN; else if (event.jbutton.button == joystick_keymap.start_button) @@ -515,7 +549,7 @@ GameSession::process_events() break; case SDL_JOYBUTTONUP: if (event.jbutton.button == joystick_keymap.a_button) - tux.input.up = UP; + tux.input.jump = UP; else if (event.jbutton.button == joystick_keymap.b_button) tux.input.fire = UP; break; @@ -539,6 +573,7 @@ GameSession::check_end_conditions() if(end_sequence && !endsequence_timer.check()) { exit_status = ES_LEVEL_FINISHED; + global_stats += last_swap_stats; // add swap points stats return; } else if(end_sequence == ENDSEQUENCE_RUNNING && endtile && endtile->data >= 1) @@ -548,14 +583,15 @@ GameSession::check_end_conditions() else if(!end_sequence && endtile && endtile->data == 0) { end_sequence = ENDSEQUENCE_RUNNING; - random_timer.start(200); // start 1st firework + endsequence_timer.start(7000); // 5 seconds until we finish the map last_x_pos = -1; SoundManager::get()->play_music(level_end_song, 0); - endsequence_timer.start(7000); // 5 seconds until we finish the map tux->invincible_timer.start(7000); //FIXME: Implement a winning timer for the end sequence (with special winning animation etc.) // add left time to stats global_stats.set_points(TIME_NEEDED_STAT, time_left.get_gone() / 1000); + + random_timer.start(200); // start 1st firework } else if (!end_sequence && tux->is_dead()) { @@ -593,7 +629,8 @@ GameSession::action(double frame_ratio) } // on end sequence make a few fireworks - if(end_sequence == ENDSEQUENCE_RUNNING && !random_timer.check()) + if(end_sequence == ENDSEQUENCE_RUNNING && !random_timer.check() && + currentsector->end_sequence_animation() == FIREWORKS_ENDSEQ_ANIM) { Vector epicenter = currentsector->camera->get_translation(); epicenter.x += screen->w * ((float)rand() / RAND_MAX); @@ -946,6 +983,7 @@ bool process_load_game_menu() WorldMapNS::WorldMap worldmap; + worldmap.set_map_filename("icyisland.stwm"); // Load the game or at least set the savegame_file variable worldmap.loadgame(slotfile);