feat: made hitboxes area dependent
This commit is contained in:
30
code/first.c
30
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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
BIN
code/world.sgdat
BIN
code/world.sgdat
Binary file not shown.
Reference in New Issue
Block a user