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,6 +14,7 @@ struct Bandit {
//// Personal
AABB collision;
Str8 name;
World_Area currentArea;
//// Actions
BANDIT_ACTION mode;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);
}

View File

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

View File

@@ -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