Skip to content

Commit fc33ecb

Browse files
committed
Fixed Hero Walk bug
1 parent 3ffe05b commit fc33ecb

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

game_bb.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ static void platform_new(void) {
150150
distance -= SCROLL_STEP;
151151
display_background();
152152
display_platform(platformFuture, WHITE);
153-
display_hero(0, distance + bridge, HERO_LEVEL, WHITE);
153+
display_hero(0, platform_end(data->platformNext) - HERO_OFFSET, HERO_LEVEL, WHITE);
154154
gr->display();
155155
}
156156

@@ -192,10 +192,15 @@ static void hero_score(int8_t up) {
192192

193193

194194
static int8_t hero_walk(int8_t from, int8_t to) {
195-
int8_t bridge_end;
195+
const int8_t bridge_end = platform_end(data->platformCurr) + bridge;
196+
const int8_t bridge_over = bridge_end - 1 > platform_end(data->platformNext);
196197
int8_t hero_state = 0;
197198
int8_t claim_bonus = 0;
198199
int8_t i = from;
200+
201+
if(! bridge_over) {
202+
to = min(to, platform_end(data->platformNext) - HERO_OFFSET);
203+
}
199204
while(i < to) {
200205
if (!gr->nextFrame()) {
201206
continue;
@@ -209,13 +214,9 @@ static int8_t hero_walk(int8_t from, int8_t to) {
209214
gr->display();
210215

211216
// Game over?
212-
bridge_end = platform_end(data->platformCurr) + bridge;
213217
// TODO: simplify this condition
214-
if((i + HERO_OFFSET >= bridge_end &&
215-
(data->platformNext.x >= bridge_end ||
216-
bridge_end - 1 > platform_end(data->platformNext))) ||
217-
(hero_state &&
218-
i + HERO_OFFSET + HERO_OFFSET > data->platformNext.x)) {
218+
if((i + HERO_OFFSET >= bridge_end && (data->platformNext.x >= bridge_end || bridge_over)) ||
219+
(hero_state && i + HERO_OFFSET + HERO_OFFSET > data->platformNext.x)) {
219220
data->gameOn = 0;
220221
hero_fall(i + HERO_OFFSET + (hero_state ? -1 : 1),
221222
HERO_LEVEL - (hero_state ? 0 : HERO_HEIGHT));

0 commit comments

Comments
 (0)