Merge branch 'main' of yibble.dev:bulmanator/ld58
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#if !defined(LD_GAME_BANDIT_H_)
|
||||
#define LD_GAME_BANDIT_H_
|
||||
#include "outfit.h"
|
||||
|
||||
typedef enum BANDIT_ACTION BANDIT_ACTION;
|
||||
enum BANDIT_ACTION
|
||||
@@ -62,8 +63,12 @@ struct Bandit {
|
||||
F32 accuracyRange;
|
||||
// A the circle around the bandit where they will trigger the quicktime reaction scene
|
||||
F32 agroRadius;
|
||||
// What the bandit is wearing
|
||||
G_Outfit outfit;
|
||||
// What the bandit's outfit id's are
|
||||
U32 *outfitChoices;
|
||||
};
|
||||
|
||||
function V2f shootTowards(Bandit* bandit, V2f target, Random* r);
|
||||
|
||||
function V2f ShootTowards(Bandit* bandit, V2f target, Random* r);
|
||||
function void BanditDraw(D_Context *draw, Bandit *bandit);
|
||||
#endif // LD_GAME_BANDIT_H_
|
||||
|
||||
@@ -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,7 +71,7 @@ void UpdateBandit(F32 delta, Bandit *bandit, World *world) {
|
||||
{
|
||||
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
|
||||
world->player.health--;
|
||||
@@ -85,3 +85,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->npcCount; 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,10 +46,15 @@ struct NPC {
|
||||
U32 targetNavNode;
|
||||
// How long the npc has been walking to the next index
|
||||
F32 walkTimer;
|
||||
|
||||
// Space within you can interact with the NPC.
|
||||
F32 interationRadius;
|
||||
//// Knowledge
|
||||
// What the NPC knows about the bandit.
|
||||
NPC_LOOK banditKnowledge;
|
||||
// NPC clothes
|
||||
G_Outfit outfit;
|
||||
// if the NPC has given info
|
||||
bool infoGiven;
|
||||
};
|
||||
|
||||
function void NPCDraw(D_Context *draw, NPC *npc);
|
||||
#endif // LD_GAME_NPC_H_
|
||||
|
||||
45
code/game/outfit.h
Normal file
45
code/game/outfit.h
Normal file
@@ -0,0 +1,45 @@
|
||||
|
||||
#if !defined(LD_GAME_OUTFIT_H)
|
||||
#define LD_GAME_OUTFIT_H
|
||||
|
||||
#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))
|
||||
|
||||
function U32* GenOutfit(G_Outfit *o, World *world, G_State *game);
|
||||
|
||||
#endif // LD_GAME_OUTFIT_H
|
||||
@@ -34,6 +34,9 @@ struct Player
|
||||
|
||||
U32 health;
|
||||
F32 reloadTimer;
|
||||
|
||||
U32 *knownDetails;
|
||||
U32 detailCount;
|
||||
};
|
||||
|
||||
function void PlayerInit(G_State *game, Player *player);
|
||||
|
||||
@@ -67,7 +67,7 @@ struct World {
|
||||
World_Hitbox *hitboxes;
|
||||
World_Portal *portals;
|
||||
U32 *map;
|
||||
|
||||
bool showPoster;
|
||||
U32 propCount;
|
||||
U32 portalCount;
|
||||
U32 hitboxCount;
|
||||
|
||||
Reference in New Issue
Block a user