From f18d9d2b0efec2b42cb579c5c11ab5dd6a9f2ec9 Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 6 Oct 2025 21:57:06 +0100 Subject: [PATCH] feat: made hitboxes area dependent --- code/first.c | 30 +++++++++++++++++------------- code/game/impl/world.c | 12 ++++++------ code/game/world.h | 4 +++- code/world.sgdat | Bin 120960 -> 137092 bytes 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/code/first.c b/code/first.c index 9799124..6f2762c 100644 --- a/code/first.c +++ b/code/first.c @@ -219,7 +219,7 @@ int main(int argc, char **argv) world->propTypes[21].scale=1; world->propCount = 0; world->props = M_ArenaPush(arena, World_Prop, .count=WORLD_PROP_MAX); - world->hitboxes = M_ArenaPush(arena, AABB, .count=WORLD_HITBOX_MAX); + world->hitboxes = M_ArenaPush(arena, World_Hitbox, .count=WORLD_HITBOX_MAX); world->portals = M_ArenaPush(arena, World_Portal, .count=64); world->portalCount=0; GenerateNavMesh(arena, world); @@ -285,11 +285,12 @@ int main(int argc, char **argv) }} else if(e.type==SDL_EVENT_MOUSE_BUTTON_UP && e.button.button == SDL_BUTTON_LEFT && game->editor.mode == G_EDITOR_MODE_HITBOX) { // Add hitbox V2f topLeft = V2F(Min(game->editor.cursor.x, game->editor.dragStart.x), Min(game->editor.cursor.y, game->editor.dragStart.y)); - game->world->hitboxes[game->world->hitboxCount].pos = topLeft; - game->world->hitboxes[game->world->hitboxCount].size = V2F( + game->world->hitboxes[game->world->hitboxCount].box.pos = topLeft; + game->world->hitboxes[game->world->hitboxCount].box.size = V2F( Abs(game->editor.cursor.x-game->editor.dragStart.x), Abs(game->editor.cursor.y-game->editor.dragStart.y) ); + game->world->hitboxes[game->world->hitboxCount].area = game->editor.currentAsset; game->world->hitboxCount++; GenerateNavMesh(game->arena, game->world); } else if(e.type==SDL_EVENT_MOUSE_BUTTON_UP && e.button.button == SDL_BUTTON_LEFT && game->editor.mode == G_EDITOR_MODE_PORTAL) { @@ -367,6 +368,7 @@ int main(int argc, char **argv) switch(game->editor.mode) { case G_EDITOR_MODE_PROP: {game->world->propCount--;} case G_EDITOR_MODE_HITBOX: {game->world->hitboxCount--;} + case G_EDITOR_MODE_PORTAL: {game->world->portalCount--;} } break; } @@ -471,16 +473,18 @@ int main(int argc, char **argv) } case G_EDITOR_MODE_HITBOX: { for(U32 i = 0; i < game->world->hitboxCount; i++) { - V2f centre = AABB_Centre(game->world->hitboxes[i]); - D_Rect( - &game->draw, - centre.x, - centre.y, - .texture=0, - .dim=game->world->hitboxes[i].size, - .flags=D_RECT_IGNORE_ASPECT, - .c=V4F(100,0,0,0.7f), - ); + if(game->world->player.currentArea == game->world->hitboxes[i].area) { + V2f centre = AABB_Centre(game->world->hitboxes[i].box); + D_Rect( + &game->draw, + centre.x, + centre.y, + .texture=0, + .dim=game->world->hitboxes[i].box.size, + .flags=D_RECT_IGNORE_ASPECT, + .c=V4F(100,0,0,0.7f), + ); + } } break; } diff --git a/code/game/impl/world.c b/code/game/impl/world.c index cebe920..e979e52 100644 --- a/code/game/impl/world.c +++ b/code/game/impl/world.c @@ -189,14 +189,14 @@ void LoadWorld(M_Arena *arena, World *world) { // { U32 n_hitbox = *(U32 *) base; base += 4; - AABB *boxes = (AABB *) base; + World_Hitbox *boxes = (World_Hitbox *) base; world->hitboxCount = n_hitbox; - world->hitboxes = M_ArenaPush(arena, AABB, .count = WORLD_HITBOX_MAX); + world->hitboxes = M_ArenaPush(arena, World_Hitbox, .count = WORLD_HITBOX_MAX); - M_CopySize(world->hitboxes, boxes, n_hitbox * sizeof(AABB)); + M_CopySize(world->hitboxes, boxes, n_hitbox * sizeof(World_Hitbox)); - base += (WORLD_HITBOX_MAX * sizeof(AABB)); + base += (WORLD_HITBOX_MAX * sizeof(World_Hitbox)); } // Map @@ -242,7 +242,7 @@ void GenerateNavMesh(M_Arena *arena, World *world) { U32 y = (i / 96); bool skip = false; for(U32 hi = 0; hi < world->hitboxCount; hi++) { - if(AABB_Point(world->hitboxes[hi], V2F((F32) x, (F32) y))) { + if(AABB_Point(world->hitboxes[hi].box, V2F((F32) x, (F32) y))) { skip = true; break; } @@ -262,7 +262,7 @@ void GenerateNavMesh(M_Arena *arena, World *world) { } // It's quad for loop time :D for(U32 hi = 0; hi < world->hitboxCount; hi++) { - if(AABB_Point(world->hitboxes[hi], V2F((F32) (x + nx), (F32) (y + ny)))) { + if(AABB_Point(world->hitboxes[hi].box, V2F((F32) (x + nx), (F32) (y + ny)))) { skip = true; break; } diff --git a/code/game/world.h b/code/game/world.h index 32cf62e..6977581 100644 --- a/code/game/world.h +++ b/code/game/world.h @@ -45,6 +45,8 @@ struct World_Portal AABB box; World_Area area; }; +typedef World_Portal World_Hitbox; + typedef struct World World; #include "player.h" @@ -62,7 +64,7 @@ struct World { World_Tile *tileTypes; World_PropType *propTypes; World_Prop *props; - AABB *hitboxes; + World_Hitbox *hitboxes; World_Portal *portals; U32 *map; diff --git a/code/world.sgdat b/code/world.sgdat index e3a124fc5b13537f321f85882e503079a654699e..3feb28ad6f33faf6f7249708f495a5a05b85e1d7 100644 GIT binary patch delta 149 qcmZqJ$lkJ^qhSl1bMp|eF2So=52Zam{5)>R990F!=2sEJ3#idj@ z4h{})=u%8Th=Y6bUNQt1TjYdYX}lVV3vs->=tcZ#sLxNkjYXQ5X+9=0VmoG< z;v@~czfnpPb`~kLR8+ksQm}Y5{8l$#ask#A%*8ZGqp6UwGQe#I4E2#{n`nvXgs4Q6 z?Z*pY@3BV18VyESrf7#M#{?Hfu+`hAEcS3NPvm@t-pau1eZ^-bhtxyt_wFXnmKnd& zSA1S#W;@>h1KZfUf8du&cUZ6X(N}z|cv@NNO?;4>CbqPslK(}@+mZu6qaAwP-p3