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

This commit is contained in:
2025-10-05 21:19:14 +01:00
17 changed files with 335 additions and 127 deletions

View File

@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdbool.h>
#include <SDL3/SDL.h>
#include <SDL3/SDL_keycode.h>
#define STB_IMAGE_IMPLEMENTATION 1
#include <stb_image.h>
@@ -23,11 +24,13 @@
#include "game/impl/world.c"
#include "game/impl/npc.c"
#include "game/impl/bandit.c"
#include "game/testnavmesh.h"
int main(int argc, char **argv) {
(void) argc;
(void) argv;
int main(int argc, char **argv)
{
(void)argc;
(void)argv;
if (!SDL_Init(SDL_INIT_VIDEO))
{
@@ -65,35 +68,52 @@ int main(int argc, char **argv) {
camera->fov = 60.0f;
camera->nearp = 0.01f;
camera->farp = 1000.0f;
camera->farp = 1000.0f;
game->draw.camera = camera;
World *world = M_ArenaPush(arena, World);
game->world = world;
world->random = Random_Seed(29237489723847);
world->npcCount = 1;
for(U32 i = 0; i < world->npcCount; i++) {
NPC *npc1 = &world->npcs[i];
npc1->collision.pos.x = 15;
npc1->collision.pos.y = 15;
npc1->collision.size.x = 1;
npc1->collision.size.y = 1;
npc1->name = S("Matt");
npc1->mode = NPC_ACTION_WAITING;
npc1->waitTime = 0;
npc1->maxWaitTime = 5;
npc1->currentNavNode = 0;
npc1->collision.pos.x = 15;
npc1->collision.pos.y = 15;
npc1->collision.size.x = 10;
npc1->collision.size.y = 10;
}
Bandit *badman = &world->bandit;
badman->collision.pos.x = 15;
badman->collision.pos.y = 15;
badman->collision.size.x = 10;
badman->collision.size.y = 10;
badman->name = S("Leroy Brown");
badman->mode = BANDIT_WAITING;
badman->waitTime = 0;
badman->maxWaitTime = 2;
badman->poiCount = 2;
badman->pointsOfInterest[0] = 937;
badman->pointsOfInterest[1] = 12;
world->navMesh = &TestNavMesh;
world->npcPOI[0] = 100;
world->player.pos.x = 0;
world->player.pos.y = 0;
world->player.bulletsLoaded = PLAYER_BULLET_COUNT;
world->player.reloadTimer = 0;
}
bool running = true;
World world = {
.npcCount = 2,
.npcs = {
{
.collision = {{10, 10}, {10, 10}},
.name = S("Matt"),
.mode = NPC_ACTION_WAITING,
.waitTime = 0,
.maxWaitTime = 5,
.currentNavNode = 87
},{
.collision = {{15, 15}, {10, 10}},
.name = S("James"),
.mode = NPC_ACTION_WAITING,
.waitTime = 0,
.maxWaitTime = 10,
.currentNavNode = 0
}
},
.navMesh = &TestNavMesh,
.npcPOI = {100},
.player = {.pos = {0,0}}
};
printf("%zu size in bytes\n", sizeof(TestNavMesh));
@@ -106,36 +126,21 @@ int main(int argc, char **argv) {
{
running = false;
}
else if (e.type == SDL_EVENT_KEY_DOWN) {
if (e.key.key == SDLK_W) {
game->camera.p.y -= 0.2f;
}
if (e.key.key == SDLK_S) {
game->camera.p.y += 0.2f;
}
if (e.key.key == SDLK_A) {
game->camera.p.x -= 0.2f;
}
if (e.key.key == SDLK_D) {
game->camera.p.x += 0.2f;
}
}
ProcessEvents(&e, &world);
ProcessEvents(&e, game->world);
}
UpdateWorld(1.0f / 60.0f, &world);
UpdateWorld(1.0f / 60.0f, game->world);
game->camera.p.x = game->world->player.pos.x;
game->camera.p.y = game->world->player.pos.y;
int w, h;
SDL_GetWindowSizeInPixels(window, &w, &h);
game->draw.window_width = w;
game->draw.window_width = w;
game->draw.window_height = h;
G_CalculateCamera(&game->camera, (F32) w / (F32) h);
G_CalculateCamera(&game->camera, (F32)w / (F32)h);
Vk_Frame *frame = Vk_FrameBegin(window);
VkCommandBuffer cmd = frame->cmd;
@@ -147,24 +152,29 @@ int main(int argc, char **argv) {
clear_colour.color.float32[3] = 1.0f;
VkRenderingAttachmentInfo colour_attachment = {0};
colour_attachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO;
colour_attachment.imageView = vk.swapchain.views[frame->image];
colour_attachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO;
colour_attachment.imageView = vk.swapchain.views[frame->image];
colour_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
colour_attachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
colour_attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
colour_attachment.clearValue = clear_colour;
colour_attachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
colour_attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
colour_attachment.clearValue = clear_colour;
VkRenderingInfo rendering_info = {0};
rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
rendering_info.renderArea = (VkRect2D) { 0, 0, w, h };
rendering_info.layerCount = 1;
rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
rendering_info.renderArea = (VkRect2D){0, 0, w, h};
rendering_info.layerCount = 1;
rendering_info.colorAttachmentCount = 1;
rendering_info.pColorAttachments = &colour_attachment;
rendering_info.pColorAttachments = &colour_attachment;
vk.CmdBeginRendering(cmd, &rendering_info);
D_Begin(&game->draw, frame, D_MAX_RECTS);
RenderWorld(game->world, &game->draw);
D_Rect(&game->draw, 0.0f, 0.0f, .texture = 1);
D_Rect(&game->draw, -8.0f, 0.0f, .texture = 2, .scale = 2.0f);
D_Rect(&game->draw, 6.0f, 0.0f, .texture = 3);
D_End(&game->draw, frame);
vk.CmdEndRendering(cmd);