Merge branch 'main' of yibble.dev:bulmanator/ld58

This commit is contained in:
2025-10-07 14:09:59 +01:00
9 changed files with 187 additions and 52 deletions

View File

@@ -11,7 +11,7 @@ bool AABB_Collide(AABB a, AABB b)
bool AABB_Point(AABB a, V2f v)
{
bool collision_x = a.pos.x + a.size.x >= v.x && a.pos.x <= v.x;
bool collision_y = a.pos.x + a.size.y >= v.y && a.pos.y <= v.y;
bool collision_y = a.pos.y + a.size.y >= v.y && a.pos.y <= v.y;
return collision_x && collision_y;
}
@@ -45,4 +45,4 @@ bool AABB_Circle(F32 rad, V2f radOrigin, AABB a)
F32 xSq = (Abs(aCentre.x) - Abs(radOrigin.x)) * (Abs(aCentre.x) - Abs(radOrigin.x));
F32 ySq = (Abs(aCentre.y) - Abs(radOrigin.y)) * (Abs(aCentre.y) - Abs(radOrigin.y));
return SDL_sqrt(xSq + ySq) < rad;
}
}

View File

@@ -10,6 +10,11 @@ V2f shootTowards(Bandit *bandit, V2f target, Random* r)
}
void UpdateBandit(F32 delta, Bandit *bandit, World *world) {
for(U32 i = 0; i < world->portalCount; i++) {
if(AABB_Collide(world->portals[0].box, bandit->collision)) {
bandit->currentArea = world->portals[0].area;
}
}
if (
world->player.controls.shot && AABB_Slab(world->player.collision.pos, world->player.shotPos, bandit->collision) && bandit->currentArea == world->player.currentArea)
{

View File

@@ -4,6 +4,11 @@
#include "core/math.h"
void UpdateNPC(F32 delta, NPC *npc, World *world) {
for(U32 i = 0; i < world->portalCount; i++) {
if(AABB_Collide(world->portals[0].box, npc->collision)) {
npc->currentArea = world->portals[0].area;
}
}
switch (npc->mode) {
case NPC_ACTION_WAITING:
npc->waitTime+=delta;

View File

@@ -165,6 +165,12 @@ void PlayerUpdate(F32 delta, Player *player) {
player->collision.pos.x += dir.x;
player->collision.pos.y += dir.y;
for(U32 i = 0; i < player->world->portalCount; i++) {
if(AABB_Collide(player->world->portals[i].box, player->collision)) {
player->currentArea = player->world->portals[i].area;
}
}
V2f test;
test.x = player->collision.pos.x - 14;
test.y = player->collision.pos.y - 14;
@@ -174,6 +180,7 @@ void PlayerUpdate(F32 delta, Player *player) {
Audio_ChangeVolume(player->world->audio, player->world->audio_handles[1], vol);
Audio_ChangeVolume(player->world->audio, player->world->audio_handles[0], 1.0f - vol);
}
void PlayerDraw(D_Context *draw, Player *player) {

View File

@@ -64,16 +64,6 @@ void RenderWorld(World *world, D_Context *draw) {
);
}
}
for (U32 i = 0; i < world->navMesh->nodeCount; i++) {
NavNode n = world->navMesh->nodes[i];
D_Rect(
draw,
n.pos.x,
n.pos.y,
.texture = 0,
.scale = 0.2f,
);
}
for(U32 i = 0; i < world->npcCount; i++) {
NPC npc = world->npcs[i];
if(npc.currentArea == world->player.currentArea) {
@@ -124,6 +114,8 @@ void SaveWorld(World *world) {
WRITEN(world->map, WORLD_MAP_MAX);
WRITE(world->portalCount);
WRITEN(world->portals, WORLD_PORTAL_MAX);
FS_FileClose(file);
printf("--- World Saved ---\n");
@@ -197,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
@@ -217,11 +209,24 @@ void LoadWorld(M_Arena *arena, World *world) {
base += (WORLD_MAP_MAX * sizeof(U32));
}
{
U32 n_portals = *(U32 *) base; base += 4;
World_Portal *portals = (World_Portal *) base;
world->portalCount = n_portals;
world->portals = M_ArenaPush(arena, World_Portal, .count = WORLD_PORTAL_MAX);
M_CopySize(world->portals, portals, n_portals * sizeof(World_Portal));
base += (WORLD_PORTAL_MAX * sizeof(World_Portal));
}
if (base != (data.data + data.count)) {
printf("--- OFFSET MISMATCH ---\n");
}
printf("loaded world\n");
printf(" - %d props\n", world->propCount);
printf(" - %d hitboxes\n", world->hitboxCount);
@@ -237,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;
}
@@ -245,14 +250,10 @@ void GenerateNavMesh(M_Arena *arena, World *world) {
if(skip) {continue;}
world->navMesh->nodes[world->navMesh->nodeCount].pos.x = cast(F32) x;
world->navMesh->nodes[world->navMesh->nodeCount].pos.y = cast(F32) y;
U32 cost = 20;
if(Str8_Equal(world->tileTypes[world->map[i]].tag, S("path_middle"), STR8_EQUAL_IGNORE_CASE)) {
cost = 10;
}
world->navMesh->nodes[world->navMesh->nodeCount].connectionCount = 0;
for(int nx = -1; nx < 2; nx++){
for(int ny = -1; ny < 2; ny++){
if((nx==ny) && nx==0) {continue;}
if(nx==0 && ny==0) {continue;}
if(x+nx < 0 || x+nx > 95) {
continue;
}
@@ -261,19 +262,47 @@ 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;
}
}
if(skip) {continue;}
U32 index = x+nx + (y+ny)*96;
U32 nCount = world->navMesh->nodeCount;
S32 index = -1;
for (U32 ohgod = 0; ohgod < nCount; ohgod++) {
if(world->navMesh->nodes[ohgod].pos.x == nx+x&& world->navMesh->nodes[ohgod].pos.y == y+ny) {
index=ohgod;
break;
}
}
F32 cost = 20;
if(ny+nx == 2) {
cost = 40;
};
if(Str8_Equal(world->tileTypes[world->map[i]].tag, S("path_middle"), STR8_EQUAL_IGNORE_CASE)) {
cost = 1;
if(Abs(ny+nx) == 2) {
cost = 4;
};
}
if(index < 0) {continue;}
skip |= (index > (S32) nCount);
if(skip) {continue;}
world->navMesh->nodes[nCount].connections[world->navMesh->nodes[nCount].connectionCount].NodeIndex = index;
world->navMesh->nodes[nCount].connections[world->navMesh->nodes[nCount].connectionCount].Cost = cast(F32) cost;
world->navMesh->nodes[nCount].connections[world->navMesh->nodes[nCount].connectionCount].Cost = cost;
world->navMesh->nodes[index].connections[world->navMesh->nodes[index].connectionCount].NodeIndex = nCount;
world->navMesh->nodes[index].connections[world->navMesh->nodes[index].connectionCount].Cost = cost;
world->navMesh->nodes[nCount].connectionCount++;
world->navMesh->nodes[index].connectionCount++;
}
}
world->navMesh->nodeCount++;
}
for(U32 i = 0; i < world->npcCount; i++) {
world->npcs[i].mode = NPC_ACTION_WAITING;
world->npcs[i].maxWaitTime = Random_F32(&world->random, 20, 140);
world->npcs[i].waitTime = 0;
world->npcs[i].currentNavNode=0;
world->npcs[i].pathIndex = 0;
}
}