Compare commits

...

2 Commits

Author SHA1 Message Date
En Yi 3f5e1648c1 Fix regression in AABB collision 2023-11-16 00:03:26 +08:00
En Yi bfab7df718 Play SFX on destroying wooden tile 2023-11-16 00:02:52 +08:00
3 changed files with 6 additions and 5 deletions

View File

@ -3,7 +3,7 @@
uint8_t find_1D_overlap(Vector2 l1, Vector2 l2, float* overlap) uint8_t find_1D_overlap(Vector2 l1, Vector2 l2, float* overlap)
{ {
// No Overlap // No Overlap
if (l1.y < l2.x || l2.y < l1.x) return 0; if (l1.y <= l2.x || l2.y <= l1.x) return 0;
if ( if (
(l1.x >= l2.x && l1.y <= l2.y) (l1.x >= l2.x && l1.y <= l2.y)
@ -110,13 +110,13 @@ bool line_in_AABB(Vector2 p1, Vector2 p2, Rectangle box)
l1.y = p2.x; l1.y = p2.x;
l2.x = box.x; l2.x = box.x;
l2.y = box.x + box.width; l2.y = box.x + box.width;
uint8_t x_res = find_1D_overlap(l1, l2, &overlap.x);
find_1D_overlap(l1, l2, &overlap.x);
l1.x = p1.y; l1.x = p1.y;
l1.y = p2.y; l1.y = p2.y;
l2.x = box.y; l2.x = box.y;
l2.y = box.y + box.height; l2.y = box.y + box.height;
find_1D_overlap(l1, l2, &overlap.y); uint8_t y_res = find_1D_overlap(l1, l2, &overlap.y);
return (overlap.x != 0 && overlap.y != 0); return (x_res != 0 && y_res != 0);
} }

View File

@ -1701,6 +1701,7 @@ void boulder_destroy_wooden_tile_system(Scene_t* scene)
if (tilemap.tiles[tile_idx].tile_type == ONEWAY_TILE) if (tilemap.tiles[tile_idx].tile_type == ONEWAY_TILE)
{ {
play_sfx(scene->engine, WOOD_DESTROY_SFX);
destroy_tile(data, tile_idx); destroy_tile(data, tile_idx);
if (tile_x > 0 && tilemap.tiles[tile_idx - 1].tile_type == ONEWAY_TILE) if (tile_x > 0 && tilemap.tiles[tile_idx - 1].tile_type == ONEWAY_TILE)
{ {

View File

@ -86,7 +86,7 @@ static void test_AABB_overlap(void **state)
p2.x = 10; p2.x = 10;
p2.y = 10; p2.y = 10;
assert_int_equal(find_AABB_overlap(p1, sz1, p2, sz2, &overlap), 2); // Smaller one is complete overlap assert_int_equal(find_AABB_overlap(p1, sz1, p2, sz2, &overlap), 2); // Smaller one is complete overlap
assert_int_equal(find_AABB_overlap(p2, sz2, p1, sz1, &overlap), 1); // Bigger on is not assert_int_equal(find_AABB_overlap(p2, sz2, p1, sz1, &overlap), 2); // This is also considered complete overlap
p2.x = 15; p2.x = 15;
p2.y = 15; p2.y = 15;