rework timers, update overlap/intersect and other procedures, some other things i dont remember

This commit is contained in:
veclavtalica
2024-10-22 14:45:30 +03:00
parent a527036436
commit a22bcfd97e
6 changed files with 144 additions and 115 deletions

View File

@ -11,9 +11,9 @@
static void update_timers(Player *player) {
tick_timer(&player->jump_air_timer);
tick_timer(&player->jump_coyote_timer);
tick_timer(&player->jump_buffer_timer);
player->jump_air_timer = timer_tick_frames(player->jump_air_timer);
player->jump_coyote_timer = timer_tick_frames(player->jump_coyote_timer);
player->jump_buffer_timer = timer_tick_frames(player->jump_buffer_timer);
}

View File

@ -39,8 +39,8 @@ static void drawdef_debug(struct World *world) {
for (size_t i = 0; i < world->tilemap_height * world->tilemap_width; ++i) {
if (world->tiles[i].type == TILE_TYPE_VOID) continue;
draw_rectangle(to_frect(world->tiles[i].rect),
(Color) { 255, 0, 255, 128 });
draw_rectangle(to_rect(world->tiles[i].rect),
(Color) { 255, 0, 255, 128 });
}
}
@ -106,7 +106,7 @@ void world_drawdef(struct World *world) {
if (world->tiles[i].type == TILE_TYPE_VOID)
continue;
m_sprite("/assets/white.png", to_frect(world->tiles[i].rect));
m_sprite("/assets/white.png", to_rect(world->tiles[i].rect));
}
drawdef_debug(world);
@ -121,19 +121,12 @@ bool world_find_intersect_frect(struct World *world, Rect rect, Rect *intersecti
if (world->tiles[i].type == TILE_TYPE_VOID)
continue;
Rect tile_frect = {
.x = (float)(world->tiles[i].rect.x),
.y = (float)(world->tiles[i].rect.y),
.w = (float)(world->tiles[i].rect.w),
.h = (float)(world->tiles[i].rect.h),
};
Rect const tile_frect = to_rect(world->tiles[i].rect);
if (intersection == NULL) {
Rect temp;
is_intersecting = overlap_frect(&rect, &tile_frect, &temp);
} else {
is_intersecting = overlap_frect(&rect, &tile_frect, intersection);
}
is_intersecting = intersect_rect(rect, tile_frect);
if (intersection)
*intersection = overlap_rect(rect, tile_frect);
if (is_intersecting)
break;
@ -151,14 +144,12 @@ bool world_find_intersect_rect(struct World *world, Recti rect, Recti *intersect
if (world->tiles[i].type == TILE_TYPE_VOID)
continue;
Recti *tile_rect = &world->tiles[i].rect;
Recti const tile_rect = world->tiles[i].rect;
if (intersection == NULL) {
Recti temp;
is_intersecting = overlap_rect(&rect, tile_rect, &temp);
} else {
is_intersecting = overlap_rect(&rect, tile_rect, intersection);
}
is_intersecting = intersect_recti(rect, tile_rect);
if (intersection)
*intersection = overlap_recti(rect, tile_rect);
if (is_intersecting)
break;