From 319bb441ed410d70da1a20474b549b2b468ef91f Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 5 Oct 2025 22:35:34 +0100 Subject: [PATCH 1/4] feat: Added basic shooting --- code/core/impl/math.c | 9 +++++++++ code/core/math.h | 2 ++ code/first.c | 18 +++++++++++------- code/game/aabb.h | 1 + code/game/impl/aabb.c | 4 ++++ code/game/impl/player.c | 4 ++-- code/game/impl/world.c | 6 ++++-- code/game/player.h | 2 ++ code/game/world.h | 4 +++- linux | 2 +- 10 files changed, 39 insertions(+), 13 deletions(-) diff --git a/code/core/impl/math.c b/code/core/impl/math.c index c1a2cd7..36d0876 100644 --- a/code/core/impl/math.c +++ b/code/core/impl/math.c @@ -222,3 +222,12 @@ F32 Random_Bilateral(Random *rnd) { F32 result = -1.0f + (2.0f * Random_Unilateral(rnd)); return result; } + +V2f V2f_Clip(V2f screen_xy, V2f screen_size) { + V2f result; + result.x = ((screen_xy.x / screen_size.w) * 2.0f) - 1.0f; + result.y = ((screen_xy.y / screen_size.h) * 2.0f) - 1.0f; + + return result; +} + diff --git a/code/core/math.h b/code/core/math.h index 4dd6d84..f49cc00 100644 --- a/code/core/math.h +++ b/code/core/math.h @@ -147,4 +147,6 @@ function U32 Random_U32(Random *rnd, U32 min, U32 max); function F32 Random_Unilateral(Random *rnd); function F32 Random_Bilateral(Random *rnd); +V2f V2f_Clip(V2f screen_xy, V2f screen_size); + #endif // LD_CORE_MATH_H_ diff --git a/code/first.c b/code/first.c index ddfc93e..63d1dce 100644 --- a/code/first.c +++ b/code/first.c @@ -27,6 +27,9 @@ #include "game/impl/bandit.c" #include "game/testnavmesh.h" +const int width = 1280; +const int height = 720; + int main(int argc, char **argv) { (void)argc; @@ -80,16 +83,12 @@ int main(int argc, char **argv) npc1->collision.pos.x = 15; npc1->collision.pos.y = 15; npc1->collision.size.x = 1; - npc1->collision.size.y = 1; + npc1->collision.size.y = 2; npc1->name = S("Matt"); npc1->mode = NPC_ACTION_WAITING; npc1->waitTime = 0; - npc1->maxWaitTime = 5; + npc1->maxWaitTime = 5000; 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; @@ -107,6 +106,7 @@ int main(int argc, char **argv) world->navMesh = &TestNavMesh; world->npcPOI[0] = 100; + world->player.world = world; world->player.pos.x = 0; world->player.pos.y = 0; world->player.bulletsLoaded = PLAYER_BULLET_COUNT; @@ -126,7 +126,11 @@ int main(int argc, char **argv) { running = false; } - + V3f projection = G_CameraUnproject(&game->camera, V2f_Clip( + V2F(e.button.x, e.button.y), + V2F(width, height) + )); + game->world->mouseProjected = V2F(projection.x, projection.y); ProcessEvents(&e, game->world); } diff --git a/code/game/aabb.h b/code/game/aabb.h index 9344521..5c22fb3 100644 --- a/code/game/aabb.h +++ b/code/game/aabb.h @@ -13,5 +13,6 @@ struct AABB function bool AABB_Collide(AABB a, AABB b); function bool AABB_Point(AABB a, V2f v); function bool AABB_Slab(V2f origin, V2f point, AABB a); +function V2f AABB_Centre(AABB a); #endif // LD_GAME_AABB_H_ diff --git a/code/game/impl/aabb.c b/code/game/impl/aabb.c index dfeb99b..f927452 100644 --- a/code/game/impl/aabb.c +++ b/code/game/impl/aabb.c @@ -34,3 +34,7 @@ bool AABB_Slab(V2f origin, V2f point, AABB a) return tMax >= tMin; } + +V2f AABB_Centre(AABB a) { + return V2F(a.pos.x + a.size.x/2, a.pos.y + a.size.y/2); +} diff --git a/code/game/impl/player.c b/code/game/impl/player.c index f9c442c..07d57eb 100644 --- a/code/game/impl/player.c +++ b/code/game/impl/player.c @@ -42,8 +42,8 @@ void PlayerInput(SDL_Event *event, Player *player) // shooting player->bulletsLoaded -= 1; player->controls.shot = true; - player->shotPos = V2F(mouseBtn.x, mouseBtn.y); - printf("shot %f %f\n", mouseBtn.x, mouseBtn.y); + player->shotPos = player->world->mouseProjected; + printf("shot %f %f\n", player->shotPos.x, player->shotPos.y); } else if(player->reloadTimer == 0) { player->reloadTimer = PLAYER_RELOAD_TIME; printf("reloading\n"); diff --git a/code/game/impl/world.c b/code/game/impl/world.c index 3734e08..bbca252 100644 --- a/code/game/impl/world.c +++ b/code/game/impl/world.c @@ -1,6 +1,7 @@ #include "../world.h" #include "../npc.h" #include "../player.h" +#include "../aabb.h" #include void UpdateWorld(F32 delta, World *world) @@ -30,8 +31,9 @@ void ProcessEvents(SDL_Event *event, World *world) void RenderWorld(World *world, D_Context *draw) { for(U32 i = 0; i < world->npcCount; i++) { NPC npc = world->npcs[i]; - D_Rect(draw, npc.collision.pos.x, npc.collision.pos.y, .texture = 1); - D_Rect(draw, npc.collision.pos.x, npc.collision.pos.y, .texture = 0, .dim = npc.collision.size); + 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); } 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); diff --git a/code/game/player.h b/code/game/player.h index 5a994dc..a727453 100644 --- a/code/game/player.h +++ b/code/game/player.h @@ -22,7 +22,9 @@ struct ControlState { typedef struct Player Player; struct Player { + World *world; V2f pos; + World_Area currentArea; U32 bulletsLoaded; ControlState controls; V2f shotPos; diff --git a/code/game/world.h b/code/game/world.h index 2cd96eb..eeaaf8a 100644 --- a/code/game/world.h +++ b/code/game/world.h @@ -1,7 +1,6 @@ #if !defined(LD_GAME_WORLD_H_) #define LD_GAME_WORLD_H_ -#include "player.h" #include "npc.h" #include "bandit.h" #include "../core/math.h" @@ -14,10 +13,13 @@ enum World_Area { }; typedef struct World World; +#include "player.h" + struct World { //// Static stuff NavMesh *navMesh; Random random; + V2f mouseProjected; //// Player Player player; diff --git a/linux b/linux index e259fee..eee3913 100755 --- a/linux +++ b/linux @@ -57,7 +57,7 @@ glslangValidator -o "assets/shaders/basic.frag.spv" --target-env "vulkan1.3" ".. echo "[Building source]" -COMPILER_OPTS="-Wall -Wno-missing-braces -Wno-unused-function -Ideps/stb -I../code" +COMPILER_OPTS="-Wall -Wno-override-init-side-effects -Wno-missing-braces -Wno-unused-function -Ideps/stb -I../code" LINKER_OPTS="-lSDL3 -lm" if [[ $release == 1 ]] From 64a84e3a8d0fb8b34711095f4b431c1523a88c5a Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 5 Oct 2025 23:36:50 +0100 Subject: [PATCH 2/4] feat: different rooms added feat: shooting bandit added --- code/first.c | 11 ++++++----- code/game/bandit.h | 1 + code/game/impl/bandit.c | 8 ++++++++ code/game/impl/player.c | 2 +- code/game/impl/world.c | 26 ++++++++++++++++++-------- code/game/npc.h | 1 + code/game/world.h | 4 ++-- 7 files changed, 37 insertions(+), 16 deletions(-) diff --git a/code/first.c b/code/first.c index 63d1dce..d80911f 100644 --- a/code/first.c +++ b/code/first.c @@ -14,7 +14,6 @@ #include "core/core.h" #include "core/types.h" -#include "game/npc.h" #include "os/core.h" #include "vulkan/core.h" @@ -77,7 +76,7 @@ int main(int argc, char **argv) World *world = M_ArenaPush(arena, World); game->world = world; world->random = Random_Seed(29237489723847); - world->npcCount = 1; + world->npcCount = 2; for(U32 i = 0; i < world->npcCount; i++) { NPC *npc1 = &world->npcs[i]; npc1->collision.pos.x = 15; @@ -86,16 +85,17 @@ int main(int argc, char **argv) npc1->collision.size.y = 2; npc1->name = S("Matt"); npc1->mode = NPC_ACTION_WAITING; + npc1->currentArea = i; npc1->waitTime = 0; - npc1->maxWaitTime = 5000; + npc1->maxWaitTime = 5; npc1->currentNavNode = 0; } 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->collision.size.x = 1; + badman->collision.size.y = 2; badman->name = S("Leroy Brown"); badman->mode = BANDIT_WAITING; badman->waitTime = 0; @@ -111,6 +111,7 @@ int main(int argc, char **argv) world->player.pos.y = 0; world->player.bulletsLoaded = PLAYER_BULLET_COUNT; world->player.reloadTimer = 0; + world->player.currentArea = 0; } bool running = true; diff --git a/code/game/bandit.h b/code/game/bandit.h index 3814017..a55f973 100644 --- a/code/game/bandit.h +++ b/code/game/bandit.h @@ -14,6 +14,7 @@ struct Bandit { //// Personal AABB collision; Str8 name; + World_Area currentArea; //// Actions BANDIT_ACTION mode; diff --git a/code/game/impl/bandit.c b/code/game/impl/bandit.c index 5aeb2a4..f8e3f35 100644 --- a/code/game/impl/bandit.c +++ b/code/game/impl/bandit.c @@ -2,6 +2,14 @@ #include "game/bandit.h" void UpdateBandit(F32 delta, Bandit *bandit, World *world) { + if( + world->player.controls.shot + && AABB_Point(bandit->collision, world->player.shotPos) + && bandit->currentArea == world->player.currentArea + ) { + printf("You shot the bandit %*.s\n", Sv(bandit->name)); + bandit->health--; + } switch (bandit->mode) { case BANDIT_WAITING: bandit->waitTime+=delta; diff --git a/code/game/impl/player.c b/code/game/impl/player.c index 07d57eb..8375d1e 100644 --- a/code/game/impl/player.c +++ b/code/game/impl/player.c @@ -5,7 +5,6 @@ void PlayerInput(SDL_Event *event, Player *player) { - player->controls.shot = false; SDL_KeyboardEvent key = event->key; SDL_MouseButtonEvent mouseBtn = event->button; if(event->type == SDL_EVENT_KEY_DOWN || event->type == SDL_EVENT_KEY_UP) { @@ -52,6 +51,7 @@ void PlayerInput(SDL_Event *event, Player *player) } void PlayerUpdate(F32 delta, Player *player) { + player->controls.shot = false; V2f dir = V2F(0, 0); if(player->controls.upDown) { dir.y -= 1; diff --git a/code/game/impl/world.c b/code/game/impl/world.c index bbca252..3c36632 100644 --- a/code/game/impl/world.c +++ b/code/game/impl/world.c @@ -15,10 +15,14 @@ void UpdateNPCs(F32 delta, World *world) { for (U32 i = 0; i < world->npcCount; i++) { - 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)); + NPC *npc = &world->npcs[i]; + UpdateNPC(delta, npc, world); + if( + world->player.controls.shot + && AABB_Point(npc->collision, world->player.shotPos) + && npc->currentArea == world->player.currentArea + ) { + printf("You shot %*.s\n", Sv(world->npcs[i].name)); } } } @@ -31,11 +35,17 @@ void ProcessEvents(SDL_Event *event, World *world) void RenderWorld(World *world, D_Context *draw) { for(U32 i = 0; i < world->npcCount; i++) { NPC npc = world->npcs[i]; - 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); + if(npc.currentArea == world->player.currentArea) { + 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); + } + } + if(world->bandit.currentArea == world->player.currentArea) { + V2f drawPos = AABB_Centre(world->bandit.collision); + D_Rect(draw, drawPos.x, drawPos.y, .texture = 9); + D_Rect(draw, drawPos.x, drawPos.y, .texture = 0, .dim = world->bandit.collision.size, .flags = D_RECT_IGNORE_ASPECT); } - 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); } diff --git a/code/game/npc.h b/code/game/npc.h index 3805ba4..eff6157 100644 --- a/code/game/npc.h +++ b/code/game/npc.h @@ -22,6 +22,7 @@ struct NPC { AABB collision; Str8 name; NPC_LOOK look; + World_Area currentArea; bool customPOI; U32 customPOICount; diff --git a/code/game/world.h b/code/game/world.h index eeaaf8a..be8a8aa 100644 --- a/code/game/world.h +++ b/code/game/world.h @@ -1,8 +1,6 @@ #if !defined(LD_GAME_WORLD_H_) #define LD_GAME_WORLD_H_ -#include "npc.h" -#include "bandit.h" #include "../core/math.h" // Areas are which @@ -14,6 +12,8 @@ enum World_Area { typedef struct World World; #include "player.h" +#include "npc.h" +#include "bandit.h" struct World { //// Static stuff From b09bdc620954f22a04358f875227e8d6828408c9 Mon Sep 17 00:00:00 2001 From: declan Date: Mon, 6 Oct 2025 00:38:10 +0100 Subject: [PATCH 3/4] map tiles --- code/game/impl/world.c | 6 ++++ code/game/map.h | 65 ++++++++++++++++++++++++++++++++++++++++++ code/game/world.h | 23 +++++++++++---- 3 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 code/game/map.h diff --git a/code/game/impl/world.c b/code/game/impl/world.c index 3c36632..320170c 100644 --- a/code/game/impl/world.c +++ b/code/game/impl/world.c @@ -3,6 +3,7 @@ #include "../player.h" #include "../aabb.h" #include +#include "../map.h" void UpdateWorld(F32 delta, World *world) { @@ -33,6 +34,11 @@ void ProcessEvents(SDL_Event *event, World *world) } void RenderWorld(World *world, D_Context *draw) { + World_Tile tileTypes[] = {dirt, middlePath, middlePathEdgeTop, middlePathEdgeRight, middlePathEdgeBottom, middlePathEdgeLeft, middlePathCornerTopLeft, middlePathCornerTopRight, middlePathCornerBottomRight, middlePathCornerTurnBottomLeft}; + for (int i = 0; i < 4800; i++) + { + D_Rect(draw, (i % 96), __floor(i / 96), .texture = tileTypes[map[i]].tile, .angle = tileTypes[map[i]].rotation); + } for(U32 i = 0; i < world->npcCount; i++) { NPC npc = world->npcs[i]; if(npc.currentArea == world->player.currentArea) { diff --git a/code/game/map.h b/code/game/map.h new file mode 100644 index 0000000..56efae5 --- /dev/null +++ b/code/game/map.h @@ -0,0 +1,65 @@ +#include "world.h" + + +World_Tile dirt = {.rotation=0,.collision=false,.tile=16};//0 +World_Tile middlePath = {.rotation=0,.collision=false,.tile=6};//1 +World_Tile middlePathEdgeTop = {.rotation=0,.collision=false,.tile=7};//2 +World_Tile middlePathEdgeRight = {.rotation=PI_F32/2,.collision=false,.tile=7};//3 +World_Tile middlePathEdgeBottom = {.rotation=PI_F32,.collision=false,.tile=7};//4 +World_Tile middlePathEdgeLeft = {.rotation=-PI_F32/2,.collision=false,.tile=7};//5 +World_Tile middlePathCornerTopLeft = {.rotation=0,.collision=false,.tile=5};//6 +World_Tile middlePathCornerTopRight = {.rotation=PI_F32/2,.collision=false,.tile=5};//7 +World_Tile middlePathCornerBottomRight = {.rotation=-PI_F32,.collision=false,.tile=5};//8 +World_Tile middlePathCornerTurnBottomLeft = {.rotation=-PI_F32/2,.collision=false,.tile=5};//9 +int map[] = { + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,0,5,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +}; \ No newline at end of file diff --git a/code/game/world.h b/code/game/world.h index be8a8aa..18772e9 100644 --- a/code/game/world.h +++ b/code/game/world.h @@ -5,9 +5,22 @@ // Areas are which typedef U32 World_Area; -enum World_Area { +enum World_Area +{ WORLD_AREA_OUTSIDE = (1 << 0), - WORLD_AREA_SALOON = (1 << 1), + WORLD_AREA_SALOON = (1 << 1), + WORLD_PATH_MIDDLE_EDGE = (1 << 2), + WORLD_PATH_MIDDLE = (1 << 3), + WORLD_PATH_CORNER = (1 << 4), + WORLD_PATH_CORNER_EDGE = (1 << 5), +}; + +typedef struct World_Tile World_Tile; +struct World_Tile +{ + World_Area tile; + double rotation; + bool collision; }; typedef struct World World; @@ -22,7 +35,7 @@ struct World { V2f mouseProjected; //// Player - Player player; + Player player; //// NPCs U32 npcCount; @@ -37,10 +50,10 @@ struct World { }; function void UpdateWorld(F32 delta, World *world); -function void RenderWorld(World *world, D_Context *drawContext ); +function void RenderWorld(World *world, D_Context *drawContext); function void ProcessEvents(SDL_Event *event, World *world); function void UpdateNPCs(F32 delta, World *world); function void UpdateNPC(F32 delta, NPC *npc, World *world); function void UpdateBandit(F32 delta, Bandit *bandit, World *world); -#endif // LD_GAME_WORLD_H_ +#endif // LD_GAME_WORLD_H_ From 24e9b472c3fdc752830966b3c90e219874e6654a Mon Sep 17 00:00:00 2001 From: declan Date: Mon, 6 Oct 2025 00:48:41 +0100 Subject: [PATCH 4/4] use slab aabb for gunshots --- code/game/impl/bandit.c | 8 +++----- code/game/impl/world.c | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/code/game/impl/bandit.c b/code/game/impl/bandit.c index f8e3f35..bd5d1d5 100644 --- a/code/game/impl/bandit.c +++ b/code/game/impl/bandit.c @@ -2,11 +2,9 @@ #include "game/bandit.h" void UpdateBandit(F32 delta, Bandit *bandit, World *world) { - if( - world->player.controls.shot - && AABB_Point(bandit->collision, world->player.shotPos) - && bandit->currentArea == world->player.currentArea - ) { + if ( + world->player.controls.shot && AABB_Slab(world->player.pos, world->player.shotPos, bandit->collision) && bandit->currentArea == world->player.currentArea) + { printf("You shot the bandit %*.s\n", Sv(bandit->name)); bandit->health--; } diff --git a/code/game/impl/world.c b/code/game/impl/world.c index 320170c..74f9741 100644 --- a/code/game/impl/world.c +++ b/code/game/impl/world.c @@ -18,11 +18,9 @@ void UpdateNPCs(F32 delta, World *world) { NPC *npc = &world->npcs[i]; UpdateNPC(delta, npc, world); - if( - world->player.controls.shot - && AABB_Point(npc->collision, world->player.shotPos) - && npc->currentArea == world->player.currentArea - ) { + if ( + world->player.controls.shot && AABB_Slab(world->player.pos, world->player.shotPos, npc->collision) && npc->currentArea == world->player.currentArea) + { printf("You shot %*.s\n", Sv(world->npcs[i].name)); } }