Files
ld58/code/game/impl/world.c

62 lines
1.6 KiB
C
Raw Normal View History

#include "../world.h"
#include "../npc.h"
#include "../player.h"
2025-10-05 22:35:34 +01:00
#include "../aabb.h"
#include <SDL3/SDL_events.h>
2025-10-05 16:05:57 +01:00
void UpdateWorld(F32 delta, World *world)
{
2025-10-05 21:05:29 +01:00
UpdateBandit(delta, &world->bandit, world);
UpdateNPCs(delta, world);
2025-10-05 18:05:01 +01:00
PlayerUpdate(delta, &world->player);
}
2025-10-05 16:05:57 +01:00
void UpdateNPCs(F32 delta, World *world)
{
for (U32 i = 0; i < world->npcCount; i++)
{
2025-10-05 21:05:29 +01:00
UpdateNPC(delta, &world->npcs[i], world);
if(world->player.controls.shot && AABB_Point(world->npcs[i].collision, world->player.shotPos)) {
// TODO we need to unproject the mouse location !!!
printf("You shot %.*s\n", Sv(world->npcs[i].name));
2025-10-05 21:05:29 +01:00
}
}
}
2025-10-05 16:05:57 +01:00
void ProcessEvents(SDL_Event *event, World *world)
{
2025-10-05 18:05:01 +01:00
PlayerInput(event, &world->player);
}
2025-10-05 16:49:18 +01:00
void RenderWorld(World *world, D_Context *draw) {
for(U32 i = 0; i < world->npcCount; i++) {
2025-10-05 21:05:29 +01:00
NPC npc = world->npcs[i];
2025-10-05 22:35:34 +01:00
V2f drawPos = AABB_Centre(npc.collision);
D_Rect(draw, drawPos.x, drawPos.y, .texture = 1);
D_Rect(draw, drawPos.x, drawPos.y, .texture = 0, .dim = npc.collision.size, .flags = D_RECT_IGNORE_ASPECT);
2025-10-05 16:49:18 +01:00
}
D_Rect(draw, world->bandit.collision.pos.x, world->bandit.collision.pos.y, .texture = 9);
D_Rect(draw, world->player.pos.x, world->player.pos.y, .texture = 1);
}
void G_WorldDraw(G_State *game, World *world) {
D_Context *draw = &game->draw;
(void) world;
for (F32 y = -128; y < 128; y += 1.1f) {
for (F32 x = -128; x < 128; x += 1.1f) {
U32 ux = (U32) x;
U32 uy = (U32) y;
U32 tid = 15;
if ((ux % 11) == 0 || ((uy % 7) == 0)) {
tid = 16;
}
D_Rect(draw, x, y, .texture = tid);
}
}
}