Skip to content

Commit 24433f0

Browse files
committed
highlight landing pad, tweaked collision
1 parent 08325ee commit 24433f0

File tree

4 files changed

+850
-846
lines changed

4 files changed

+850
-846
lines changed

code/applications/lander.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@ static void draw_terrain(struct Terrain *terrain) {
6767
lcd_drawLine(terrain->p2.x, terrain->p2.y, terrain->p3.x, terrain->p3.y, 1);
6868
lcd_drawLine(terrain->p3.x, terrain->p3.y, DISPLAY_WIDTH - 1 - landing_pad_width, terrain->landing_y, 1);
6969
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);
7071
}
7172

7273
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;
7476
}
7577
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;
7779
if (p.x > landing_pad_width && p.x <= terrain->p1.x &&
7880
p.y > line_height_at_x((u8Vec){landing_pad_width, DISPLAY_HEIGHT - 1}, terrain->p1, p.x)) return true;
7981
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) {
8284
p.y > line_height_at_x(terrain->p2, terrain->p3, p.x)) return true;
8385
if (p.x > terrain->p3.x && p.x <= DISPLAY_WIDTH - 1 - landing_pad_width &&
8486
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;
8688
return false;
8789
}
8890

@@ -104,15 +106,15 @@ static struct LanderGamestate new_stage() {
104106
.t1p1 = {0, -10}, .t1p2 = {5, 5},
105107
.t1p3 = {-5, 5}, .t2p3 = {0, -1}},
106108
.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)
108110
}
109111
};
110112
}
111113

112114
static bool lander_landed(struct LanderGamestate *s) {
113115
if (s->lander.pos.x >= DISPLAY_WIDTH - 1 - landing_pad_width / 2 - 5
114116
&& 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
116118
&& s->lander.dir.y < -0.97K /* something like 10-15° tilt*/
117119
&& absfx(s->lander.v.x) < 0.1K && absfx(s->lander.v.y) < 0.1K ) return true;
118120
return false;
24 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)