@@ -67,13 +67,15 @@ static void draw_terrain(struct Terrain *terrain) {
67
67
lcd_drawLine (terrain -> p2 .x , terrain -> p2 .y , terrain -> p3 .x , terrain -> p3 .y , 1 );
68
68
lcd_drawLine (terrain -> p3 .x , terrain -> p3 .y , DISPLAY_WIDTH - 1 - landing_pad_width , terrain -> landing_y , 1 );
69
69
lcd_drawLine (DISPLAY_WIDTH - 1 - landing_pad_width , terrain -> landing_y , DISPLAY_WIDTH - 1 , terrain -> landing_y , 1 );
70
+ lcd_drawLine (DISPLAY_WIDTH - 1 - landing_pad_width , terrain -> landing_y + 1 , DISPLAY_WIDTH - 1 , terrain -> landing_y + 1 , 1 );
70
71
}
71
72
72
73
static accum __attribute__ ((noinline )) line_height_at_x (u8Vec line_p1 , u8Vec line_p2 , accum x ) {
73
- return ((accum ) line_p2 .y - line_p1 .y ) / (line_p2 .x - line_p1 .x ) * (x - line_p1 .x ) + line_p1 .y ;
74
+ // add 2 for some buffer (the displayed triangles don't reach to the points)
75
+ return 2 + ((accum ) line_p2 .y - line_p1 .y ) / (line_p2 .x - line_p1 .x ) * (x - line_p1 .x ) + line_p1 .y ;
74
76
}
75
77
static bool point_terrain_collision (AccVec p , struct Terrain * terrain ) {
76
- if (p .x <= landing_pad_width && p .y > DISPLAY_HEIGHT - 1 ) return true;
78
+ if (p .x <= landing_pad_width && p .y > 1 + DISPLAY_HEIGHT ) return true;
77
79
if (p .x > landing_pad_width && p .x <= terrain -> p1 .x &&
78
80
p .y > line_height_at_x ((u8Vec ){landing_pad_width , DISPLAY_HEIGHT - 1 }, terrain -> p1 , p .x )) return true;
79
81
if (p .x > terrain -> p1 .x && p .x <= terrain -> p2 .x &&
@@ -82,7 +84,7 @@ static bool point_terrain_collision(AccVec p, struct Terrain *terrain) {
82
84
p .y > line_height_at_x (terrain -> p2 , terrain -> p3 , p .x )) return true;
83
85
if (p .x > terrain -> p3 .x && p .x <= DISPLAY_WIDTH - 1 - landing_pad_width &&
84
86
p .y > line_height_at_x (terrain -> p3 , (u8Vec ){DISPLAY_WIDTH - 1 - landing_pad_width , terrain -> landing_y }, p .x )) return true;
85
- if (p .x > DISPLAY_WIDTH - 1 - landing_pad_width && p .y > terrain -> landing_y ) return true;
87
+ if (p .x > DISPLAY_WIDTH - 1 - landing_pad_width && p .y > 2 + terrain -> landing_y ) return true;
86
88
return false;
87
89
}
88
90
@@ -104,15 +106,15 @@ static struct LanderGamestate new_stage() {
104
106
.t1p1 = {0 , -10 }, .t1p2 = {5 , 5 },
105
107
.t1p3 = {-5 , 5 }, .t2p3 = {0 , -1 }},
106
108
.terrain = (struct Terrain ){.p1 = p1 , .p2 = p2 , .p3 = p3 ,
107
- .landing_y = randrange (20 , DISPLAY_HEIGHT - 1 )
109
+ .landing_y = randrange (20 , DISPLAY_HEIGHT - 2 )
108
110
}
109
111
};
110
112
}
111
113
112
114
static bool lander_landed (struct LanderGamestate * s ) {
113
115
if (s -> lander .pos .x >= DISPLAY_WIDTH - 1 - landing_pad_width / 2 - 5
114
116
&& s -> lander .pos .x <= DISPLAY_WIDTH - 1 - landing_pad_width / 2 + 5
115
- && s -> lander .pos .y > s -> terrain .landing_y - 6
117
+ && s -> lander .pos .y > s -> terrain .landing_y - 5
116
118
&& s -> lander .dir .y < -0.97 K /* something like 10-15° tilt*/
117
119
&& absfx (s -> lander .v .x ) < 0.1 K && absfx (s -> lander .v .y ) < 0.1 K ) return true;
118
120
return false;
0 commit comments