feat: different rooms added

feat: shooting bandit added
This commit is contained in:
2025-10-05 23:36:50 +01:00
parent 319bb441ed
commit 64a84e3a8d
7 changed files with 37 additions and 16 deletions

View File

@@ -14,7 +14,6 @@
#include "core/core.h" #include "core/core.h"
#include "core/types.h" #include "core/types.h"
#include "game/npc.h"
#include "os/core.h" #include "os/core.h"
#include "vulkan/core.h" #include "vulkan/core.h"
@@ -77,7 +76,7 @@ int main(int argc, char **argv)
World *world = M_ArenaPush(arena, World); World *world = M_ArenaPush(arena, World);
game->world = world; game->world = world;
world->random = Random_Seed(29237489723847); world->random = Random_Seed(29237489723847);
world->npcCount = 1; world->npcCount = 2;
for(U32 i = 0; i < world->npcCount; i++) { for(U32 i = 0; i < world->npcCount; i++) {
NPC *npc1 = &world->npcs[i]; NPC *npc1 = &world->npcs[i];
npc1->collision.pos.x = 15; npc1->collision.pos.x = 15;
@@ -86,16 +85,17 @@ int main(int argc, char **argv)
npc1->collision.size.y = 2; npc1->collision.size.y = 2;
npc1->name = S("Matt"); npc1->name = S("Matt");
npc1->mode = NPC_ACTION_WAITING; npc1->mode = NPC_ACTION_WAITING;
npc1->currentArea = i;
npc1->waitTime = 0; npc1->waitTime = 0;
npc1->maxWaitTime = 5000; npc1->maxWaitTime = 5;
npc1->currentNavNode = 0; npc1->currentNavNode = 0;
} }
Bandit *badman = &world->bandit; Bandit *badman = &world->bandit;
badman->collision.pos.x = 15; badman->collision.pos.x = 15;
badman->collision.pos.y = 15; badman->collision.pos.y = 15;
badman->collision.size.x = 10; badman->collision.size.x = 1;
badman->collision.size.y = 10; badman->collision.size.y = 2;
badman->name = S("Leroy Brown"); badman->name = S("Leroy Brown");
badman->mode = BANDIT_WAITING; badman->mode = BANDIT_WAITING;
badman->waitTime = 0; badman->waitTime = 0;
@@ -111,6 +111,7 @@ int main(int argc, char **argv)
world->player.pos.y = 0; world->player.pos.y = 0;
world->player.bulletsLoaded = PLAYER_BULLET_COUNT; world->player.bulletsLoaded = PLAYER_BULLET_COUNT;
world->player.reloadTimer = 0; world->player.reloadTimer = 0;
world->player.currentArea = 0;
} }
bool running = true; bool running = true;

View File

@@ -14,6 +14,7 @@ struct Bandit {
//// Personal //// Personal
AABB collision; AABB collision;
Str8 name; Str8 name;
World_Area currentArea;
//// Actions //// Actions
BANDIT_ACTION mode; BANDIT_ACTION mode;

View File

@@ -2,6 +2,14 @@
#include "game/bandit.h" #include "game/bandit.h"
void UpdateBandit(F32 delta, Bandit *bandit, World *world) { 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) { switch (bandit->mode) {
case BANDIT_WAITING: case BANDIT_WAITING:
bandit->waitTime+=delta; bandit->waitTime+=delta;

View File

@@ -5,7 +5,6 @@
void PlayerInput(SDL_Event *event, Player *player) void PlayerInput(SDL_Event *event, Player *player)
{ {
player->controls.shot = false;
SDL_KeyboardEvent key = event->key; SDL_KeyboardEvent key = event->key;
SDL_MouseButtonEvent mouseBtn = event->button; SDL_MouseButtonEvent mouseBtn = event->button;
if(event->type == SDL_EVENT_KEY_DOWN || event->type == SDL_EVENT_KEY_UP) { 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) { void PlayerUpdate(F32 delta, Player *player) {
player->controls.shot = false;
V2f dir = V2F(0, 0); V2f dir = V2F(0, 0);
if(player->controls.upDown) { if(player->controls.upDown) {
dir.y -= 1; dir.y -= 1;

View File

@@ -15,10 +15,14 @@ void UpdateNPCs(F32 delta, World *world)
{ {
for (U32 i = 0; i < world->npcCount; i++) for (U32 i = 0; i < world->npcCount; i++)
{ {
UpdateNPC(delta, &world->npcs[i], world); NPC *npc = &world->npcs[i];
if(world->player.controls.shot && AABB_Point(world->npcs[i].collision, world->player.shotPos)) { UpdateNPC(delta, npc, world);
// TODO we need to unproject the mouse location !!! if(
printf("You shot %.*s\n", Sv(world->npcs[i].name)); 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) { void RenderWorld(World *world, D_Context *draw) {
for(U32 i = 0; i < world->npcCount; i++) { for(U32 i = 0; i < world->npcCount; i++) {
NPC npc = world->npcs[i]; NPC npc = world->npcs[i];
V2f drawPos = AABB_Centre(npc.collision); if(npc.currentArea == world->player.currentArea) {
D_Rect(draw, drawPos.x, drawPos.y, .texture = 1); V2f drawPos = AABB_Centre(npc.collision);
D_Rect(draw, drawPos.x, drawPos.y, .texture = 0, .dim = npc.collision.size, .flags = D_RECT_IGNORE_ASPECT); 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); D_Rect(draw, world->player.pos.x, world->player.pos.y, .texture = 1);
} }

View File

@@ -22,6 +22,7 @@ struct NPC {
AABB collision; AABB collision;
Str8 name; Str8 name;
NPC_LOOK look; NPC_LOOK look;
World_Area currentArea;
bool customPOI; bool customPOI;
U32 customPOICount; U32 customPOICount;

View File

@@ -1,8 +1,6 @@
#if !defined(LD_GAME_WORLD_H_) #if !defined(LD_GAME_WORLD_H_)
#define LD_GAME_WORLD_H_ #define LD_GAME_WORLD_H_
#include "npc.h"
#include "bandit.h"
#include "../core/math.h" #include "../core/math.h"
// Areas are which // Areas are which
@@ -14,6 +12,8 @@ enum World_Area {
typedef struct World World; typedef struct World World;
#include "player.h" #include "player.h"
#include "npc.h"
#include "bandit.h"
struct World { struct World {
//// Static stuff //// Static stuff