From fc33ecbc0ef177df4e3e2a0c3db6ccb97f582f0e Mon Sep 17 00:00:00 2001 From: Vladimir Borisov Date: Fri, 24 Aug 2018 20:02:39 +0300 Subject: [PATCH] Fixed Hero Walk bug --- game_bb.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/game_bb.cpp b/game_bb.cpp index b939918..9a51700 100644 --- a/game_bb.cpp +++ b/game_bb.cpp @@ -150,7 +150,7 @@ static void platform_new(void) { distance -= SCROLL_STEP; display_background(); display_platform(platformFuture, WHITE); - display_hero(0, distance + bridge, HERO_LEVEL, WHITE); + display_hero(0, platform_end(data->platformNext) - HERO_OFFSET, HERO_LEVEL, WHITE); gr->display(); } @@ -192,10 +192,15 @@ static void hero_score(int8_t up) { static int8_t hero_walk(int8_t from, int8_t to) { - int8_t bridge_end; + const int8_t bridge_end = platform_end(data->platformCurr) + bridge; + const int8_t bridge_over = bridge_end - 1 > platform_end(data->platformNext); int8_t hero_state = 0; int8_t claim_bonus = 0; int8_t i = from; + + if(! bridge_over) { + to = min(to, platform_end(data->platformNext) - HERO_OFFSET); + } while(i < to) { if (!gr->nextFrame()) { continue; @@ -209,13 +214,9 @@ static int8_t hero_walk(int8_t from, int8_t to) { gr->display(); // Game over? - bridge_end = platform_end(data->platformCurr) + bridge; // TODO: simplify this condition - if((i + HERO_OFFSET >= bridge_end && - (data->platformNext.x >= bridge_end || - bridge_end - 1 > platform_end(data->platformNext))) || - (hero_state && - i + HERO_OFFSET + HERO_OFFSET > data->platformNext.x)) { + if((i + HERO_OFFSET >= bridge_end && (data->platformNext.x >= bridge_end || bridge_over)) || + (hero_state && i + HERO_OFFSET + HERO_OFFSET > data->platformNext.x)) { data->gameOn = 0; hero_fall(i + HERO_OFFSET + (hero_state ? -1 : 1), HERO_LEVEL - (hero_state ? 0 : HERO_HEIGHT));