npc and bandit dressup, bits of UI added, WIP NPC interaction
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,3 +46,23 @@ void UpdateNPC(F32 delta, NPC *npc, World *world) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void NPCDraw(D_Context *draw, NPC *npc)
|
||||
{
|
||||
G_Outfit *outfit = &npc->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, npc->collision.pos.x, npc->collision.pos.y, .texture = tid, .uv = pframe, .flags = flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
31
code/game/impl/outfit.c
Normal file
31
code/game/impl/outfit.c
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
|
||||
U32* GenOutfit(G_Outfit *o, World *world, G_State *game)
|
||||
{
|
||||
U32 *outfitChoices = M_ArenaPush(world->arena, U32, .count = 8);
|
||||
G_Outfit *outfit = o;
|
||||
|
||||
D_AnimationInit(&outfit->state, 0, 1, 4, 1.0f / 6.0f);
|
||||
|
||||
M_TempScope(0, 0)
|
||||
{
|
||||
for (U32 it = 0; it < G_OUTFIT_COMPONENT_COUNT; ++it)
|
||||
{
|
||||
U32 idx = Random_Next(&world->random) % __outfit_counts[it];
|
||||
|
||||
// We just allow face, hair and hat to default to 0 meaning the player doesn't have one
|
||||
if (idx != 0 || it < 2 || it > 4)
|
||||
{
|
||||
outfit->front.e[it] = OUTFIT_IMG(front, idx);
|
||||
outfit->side.e[it] = OUTFIT_IMG(side, idx);
|
||||
|
||||
if ((idx + 1) <= __outfit_counts[it])
|
||||
{
|
||||
outfit->back.e[it] = OUTFIT_IMG(back, idx);
|
||||
}
|
||||
}
|
||||
outfitChoices[it] = idx;
|
||||
}
|
||||
}
|
||||
return outfitChoices;
|
||||
}
|
||||
@@ -2,47 +2,9 @@
|
||||
#include <SDL3/SDL_events.h>
|
||||
#include <SDL3/SDL_keycode.h>
|
||||
#include <stdio.h>
|
||||
#include "outfit.h"
|
||||
#include <npc.h>
|
||||
|
||||
// @Todo: move/extern these so the npc/bandit can use them
|
||||
//
|
||||
#define G_OUTFIT_COMPONENT_COUNT 8
|
||||
|
||||
global_var Str8 __outfit_names[] = {
|
||||
Sl("npc_%s_base_%d"),
|
||||
Sl("npc_%s_eyes_%d"),
|
||||
Sl("npc_%s_face_%d"),
|
||||
Sl("npc_%s_hair_%d"),
|
||||
Sl("npc_%s_hat_%d"),
|
||||
Sl("npc_%s_shirt_%d"),
|
||||
Sl("npc_%s_shoes_%d"),
|
||||
Sl("npc_%s_trousers_%d")
|
||||
};
|
||||
|
||||
global_var U32 __outfit_counts[] = {
|
||||
2, // base
|
||||
3, // eyes
|
||||
5, // face
|
||||
4, // hair
|
||||
3, // hat
|
||||
2, // shirt
|
||||
1, // shoes
|
||||
2 // trousers
|
||||
};
|
||||
|
||||
global_var U32 __outfit_back_counts[] = {
|
||||
2, // base
|
||||
0, // eyes
|
||||
3, // face
|
||||
4, // hair
|
||||
3, // hat
|
||||
2, // shirt
|
||||
1, // shoes
|
||||
2 // trousers
|
||||
};
|
||||
|
||||
StaticAssert(ArraySize(__outfit_names) == ArraySize(__outfit_counts));
|
||||
|
||||
#define OUTFIT_IMG(dir, n) D_ImageHandle(&game->draw, Sf(temp.arena, (const char *) __outfit_names[it].data, #dir, n))
|
||||
|
||||
void PlayerInit(G_State *game, Player *player) {
|
||||
World *world = game->world;
|
||||
@@ -105,6 +67,16 @@ void PlayerInput(SDL_Event *event, Player *player)
|
||||
player->controls.downDown = val;
|
||||
break;
|
||||
}
|
||||
case SDLK_E:
|
||||
{
|
||||
for(int i = 0; player->world->npmCount; i++){
|
||||
NPC *npc = player->world->npcs[i];
|
||||
if(AABB_Circle(npc->interationRadius, npc->collision.pos, player->collision) && !npc->infoGiven){
|
||||
npc->infoGiven=true;
|
||||
player->knownDetails[player->detailCount] = player->world->bandit->outfitChoices[player->detailCount];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (
|
||||
|
||||
@@ -67,15 +67,11 @@ void RenderWorld(World *world, D_Context *draw) {
|
||||
for(U32 i = 0; i < world->npcCount; i++) {
|
||||
NPC npc = world->npcs[i];
|
||||
if(npc.currentArea == world->player.currentArea) {
|
||||
V2f drawPos = AABB_Centre(npc.collision);
|
||||
D_Rect(draw, drawPos.x, drawPos.y, .texture = 1);
|
||||
NPCDraw(draw, &world->npcs[i]);
|
||||
}
|
||||
}
|
||||
if(world->bandit.currentArea == world->player.currentArea) {
|
||||
V2f drawPos = AABB_Centre(world->bandit.collision);
|
||||
D_Rect(draw, drawPos.x, drawPos.y, .texture = 9);
|
||||
}
|
||||
|
||||
BanditDraw(draw, &world->bandit);
|
||||
PlayerDraw(draw, &world->player);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user