Skip to content

Commit 3ec0b48

Browse files
committed
Bridge Builder hills in background
1 parent a7b103e commit 3ec0b48

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

game_bb.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#define BRIDGE_LEVEL 54
88
#define PLATFORM_LEVEL 55
99

10+
#define HILLS 9
11+
const uint8_t bg_hills[][2] = {{0, 35}, {72, 20}, {96, 30}, {110, 26}, {127, 35},
12+
{199, 20}, {223, 30}, {237, 26}, {254, 35}};
13+
1014
struct platform_t {
1115
int8_t x;
1216
int8_t width;
@@ -20,6 +24,7 @@ struct data_t {
2024
uint8_t bonus;
2125
struct platform_t platformCurr;
2226
struct platform_t platformNext;
27+
int8_t bg;
2328
};
2429

2530
static Arduboy2 *gr;
@@ -82,6 +87,14 @@ static void display_hero(int8_t state, int8_t x, int8_t y, uint8_t color) {
8287

8388
static void display_background(void) {
8489
gr->clear();
90+
91+
// The hills
92+
data->bg = data->bg % 128;
93+
for(int i = 0;++i < HILLS;) {
94+
gr->drawLine(bg_hills[i - 1][0] - data->bg, bg_hills[i - 1][1],
95+
bg_hills[i][0] - data->bg, bg_hills[i][1]);
96+
}
97+
8598
// The score
8699
gr->drawBitmap(64+29, 1, cupBmp, 8, 8, WHITE);
87100
gr->fillRect(65, 2, 28, 5, BLACK);
@@ -116,6 +129,7 @@ static void platform_new(void) {
116129
platformFuture.x += distance * 2;
117130
while(distance > SCROLL_STEP) {
118131
if(! gr->nextFrame()) continue;
132+
data->bg++;
119133
data->platformCurr.x -= SCROLL_STEP;
120134
data->platformNext.x -= SCROLL_STEP;
121135
platformFuture.x -= SCROLL_STEP * 3;
@@ -335,6 +349,7 @@ static void game_on(void) {
335349
}
336350
gr->pollButtons();
337351
display_background();
352+
338353
display_hero(0, platform_end(data->platformCurr) - HERO_OFFSET,
339354
HERO_LEVEL, WHITE);
340355
if(buttonPressed(gr) && ! gr->justPressed(B_BUTTON)) {

0 commit comments

Comments
 (0)