npc and bandit dressup, bits of UI added, WIP NPC interaction

This commit is contained in:
2025-10-06 23:08:15 +01:00
parent f18d9d2b0e
commit 7f77d7ad52
13 changed files with 166 additions and 58 deletions

View File

@@ -1,7 +1,7 @@
#include "game/world.h"
#include "game/bandit.h"
V2f shootTowards(Bandit *bandit, V2f target, Random* r)
V2f ShootTowards(Bandit *bandit, V2f target, Random* r)
{
V2f shooterV2 = bandit->collision.pos;
F32 randX = Random_F32(r, -bandit->accuracyRange, bandit->accuracyRange);
@@ -71,17 +71,17 @@ void UpdateBandit(F32 delta, Bandit *bandit, World *world) {
bandit->reloadTimer -= delta;
if (bandit->shootCooldownTimer < 0 && bandit->reloadTimer < 0)
{
printf("shoot at player\n");
printf("\nshoot at player");
bandit->bullets--;
bandit->shootCooldownTimer = bandit->shootDelay;
V2f banditShot = shootTowards(bandit, world->player.collision.pos, &world->random);
V2f banditShot = ShootTowards(bandit, world->player.collision.pos, &world->random);
if(AABB_Slab(bandit->collision.pos, banditShot, world->player.collision)){
// gets shot lmao
printf("hit\n");
printf("\nhit");
world->player.health--;
}
if(bandit->bullets == 0){
printf("enemy reload\n");
printf("\nenemy reload");
bandit->bullets = 6;
bandit->reloadTimer = bandit->reloadTime;
}
@@ -90,3 +90,23 @@ void UpdateBandit(F32 delta, Bandit *bandit, World *world) {
// TODO Running away
}
}
void BanditDraw(D_Context *draw, Bandit *bandit)
{
G_Outfit *outfit = &bandit->outfit;
R2f pframe = D_AnimationFrame(&outfit->state);
for (U32 it = 0; it < G_OUTFIT_COMPONENT_COUNT; ++it)
{
U32 flipped = (outfit->dir & G_OUTFIT_DIR_FLIPPED) != 0;
U32 dir = (outfit->dir & ~G_OUTFIT_DIR_FLIPPED);
U32 tid = outfit->e[dir].e[it];
if (tid != 0)
{
U32 flags = D_RECT_UV_ASPECT | (flipped ? D_RECT_FLIP_X : 0);
D_Rect(draw, bandit->collision.pos.x, bandit->collision.pos.y, .texture = tid, .uv = pframe, .flags = flags);
}
}
}