From f418812c321e94376bf738aad4b0ff77b2d45517 Mon Sep 17 00:00:00 2001 From: Christoph Sommer Date: Mon, 27 Mar 2006 23:12:28 +0000 Subject: [PATCH] Titlescreen features a jumping Tux again SVN-Revision: 3123 --- data/levels/misc/menu.stl | 8 -------- src/title.cpp | 45 ++++++++++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/data/levels/misc/menu.stl b/data/levels/misc/menu.stl index 8b00d12db..93fff4df0 100644 --- a/data/levels/misc/menu.stl +++ b/data/levels/misc/menu.stl @@ -337,15 +337,7 @@ (mode "normal") ) - (background - (image "arctis.jpg") - (speed 0.500000) - ) (spawnpoint (name "main") (x 0) (y 0)) - (background - (image "arctis.jpg") - (speed 0.500000) - ) ) ) diff --git a/src/title.cpp b/src/title.cpp index c23186478..8a77d3a91 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -66,9 +66,6 @@ static Surface* bkg_title; static Surface* logo; //static Surface* img_choose_subset; -static bool walking; -static Timer random_timer; - static int frame; static GameSession* titlesession; @@ -243,8 +240,12 @@ void check_contrib_subset_menu() void draw_demo(float elapsed_time) { + static Timer randomWaitTimer; + static Timer jumpPushTimer; + static Timer jumpRecoverTimer; static float last_tux_x_pos = -1; static float last_tux_y_pos = -1; + Sector* sector = titlesession->get_current_sector(); Player* tux = sector->player; @@ -252,18 +253,31 @@ void draw_demo(float elapsed_time) controller->update(); controller->press(Controller::RIGHT); + + // Determine how far we moved since last frame + float dx = fabsf(last_tux_x_pos - tux->get_pos().x); + float dy = fabsf(last_tux_y_pos - tux->get_pos().y); + + // Calculate space to check for obstacles + Rect lookahead = Rect(tux->get_bbox()); + lookahead.move(Vector(lookahead.get_width()*2,0)); - if(random_timer.check() || - (walking && fabsf(last_tux_x_pos - tux->get_pos().x)) < .1) { - walking = false; - } else { - if(!walking && fabsf(tux->get_pos().y - last_tux_y_pos) < .1) { - random_timer.start(float(rand() % 3000 + 3000) / 1000.); - walking = true; - } + // Check if we should press the jump button + bool randomJump = !randomWaitTimer.started(); + bool mayJump = !jumpRecoverTimer.started(); + bool notMoving = (dx+dy < 0.1); + bool pathBlocked = !sector->is_free_space(lookahead); + if ((notMoving || pathBlocked || randomJump) && mayJump) { + float jumpDuration = float(rand() % 200 + 500) / 1000.0; + jumpPushTimer.start(jumpDuration); + jumpRecoverTimer.start(jumpDuration+0.1); + randomWaitTimer.start(float(rand() % 3000 + 3000) / 1000.0); } - if(!walking) - controller->press(Controller::JUMP); + + // Keep jump button pressed + if (jumpPushTimer.started()) controller->press(Controller::JUMP); + + // Remember last position, so we can determine if we moved last_tux_x_pos = tux->get_pos().x; last_tux_y_pos = tux->get_pos().y; @@ -280,7 +294,6 @@ void draw_demo(float elapsed_time) /* --- TITLE SCREEN --- */ void title() { - walking = true; //LevelEditor* leveleditor; controller = new CodeController(); @@ -300,8 +313,6 @@ void title() /* --- Main title loop: --- */ frame = 0; - random_timer.start(float(rand() % 2000 + 2000) / 1000.0); - Uint32 lastticks = SDL_GetTicks(); Menu::set_current(main_menu); @@ -340,7 +351,7 @@ void title() context.draw_surface(logo, Vector(SCREEN_WIDTH/2 - logo->get_width()/2, 30), LAYER_FOREGROUND1+1); - context.draw_text(white_small_text, " SuperTux " PACKAGE_VERSION "\n", + context.draw_text(white_small_text, " SuperTux " PACKAGE_VERSION " - This is an unsupported, experimental branch made by Christoph Sommer\n", Vector(0, SCREEN_HEIGHT - 50), LEFT_ALLIGN, LAYER_FOREGROUND1); context.draw_text(white_small_text, _( -- 2.11.0