Compare commits
10 Commits
72a86ddb41
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
874b2b59f7
|
|||
|
dbff261805
|
|||
|
8363560fd2
|
|||
|
31863b0d31
|
|||
| 7f77d7ad52 | |||
|
df2c02a6a9
|
|||
|
f18d9d2b0e
|
|||
|
59f643b72c
|
|||
|
c01a6be4e5
|
|||
|
f93b543924
|
BIN
assets/heart.png
Normal file
BIN
assets/heart.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 289 B |
BIN
assets/poster.png
Normal file
BIN
assets/poster.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
BIN
assets/saloon_outside.wav
Normal file
BIN
assets/saloon_outside.wav
Normal file
Binary file not shown.
@@ -47,6 +47,11 @@ V3f V3f_Sub(V3f a, V3f b) {
|
||||
return result;
|
||||
}
|
||||
|
||||
F32 V2f_Dot(V2f a, V2f b) {
|
||||
F32 result = (a.x * b.x) + (a.y * b.y);
|
||||
return result;
|
||||
}
|
||||
|
||||
F32 V3f_Dot(V3f a, V3f b) {
|
||||
F32 result = (a.x * b.x) + (a.y * b.y) + (a.z * b.z);
|
||||
return result;
|
||||
|
||||
@@ -118,6 +118,7 @@ function V3f V3f_Neg(V3f x);
|
||||
function V3f V3f_Scale(V3f x, F32 s);
|
||||
function V3f V3f_Sub(V3f a, V3f b);
|
||||
|
||||
function F32 V2f_Dot(V2f a, V2f b);
|
||||
function F32 V3f_Dot(V3f a, V3f b);
|
||||
function F32 V4f_Dot(V4f a, V4f b);
|
||||
|
||||
|
||||
97
code/first.c
97
code/first.c
@@ -24,6 +24,7 @@
|
||||
#include "game/impl/world.c"
|
||||
#include "game/impl/npc.c"
|
||||
#include "game/impl/bandit.c"
|
||||
#include "game/impl/outfit.c"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
@@ -43,30 +44,6 @@ int main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_AudioStream *austream;
|
||||
Str8 audio_data;
|
||||
M_TempScope(0, 0) {
|
||||
SDL_AudioSpec spec;
|
||||
spec.format = SDL_AUDIO_S16LE;
|
||||
spec.channels = 2;
|
||||
spec.freq = 44100;
|
||||
|
||||
austream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, 0, 0);
|
||||
|
||||
if (!austream) {
|
||||
printf("Failed to open audio stream (%s)\n", SDL_GetError());
|
||||
}
|
||||
|
||||
Str8 exec = FS_SystemPath(temp.arena, FS_SYSTEM_PATH_EXE);
|
||||
Str8 path = Sf(temp.arena, "%.*s/assets/outside_ambience.wav", Sv(exec));
|
||||
|
||||
SDL_AudioSpec wav_spec;
|
||||
U32 count;
|
||||
|
||||
SDL_LoadWAV((const char *) path.data, &wav_spec, &audio_data.data, &count);
|
||||
audio_data.count = count;
|
||||
}
|
||||
|
||||
Vk_Setup(window);
|
||||
|
||||
G_State *game = 0;
|
||||
@@ -83,6 +60,14 @@ int main(int argc, char **argv)
|
||||
G_PipelinesLoad(game);
|
||||
G_AudioLoad(game);
|
||||
|
||||
Audio_Context *audio = M_ArenaPush(game->arena, Audio_Context);
|
||||
Audio_Init(game->arena, audio, 0.0f); // disabled audio
|
||||
|
||||
U32 bgm = Audio_Play(audio, 0);
|
||||
U32 saloon_music = Audio_Play(audio, 1);
|
||||
|
||||
SDL_ResumeAudioStreamDevice(audio->stream);
|
||||
|
||||
G_Camera *camera = &game->camera;
|
||||
|
||||
camera->x = V3F(1, 0, 0);
|
||||
@@ -99,9 +84,14 @@ int main(int argc, char **argv)
|
||||
World *world = M_ArenaPush(arena, World);
|
||||
LoadWorld(arena, world);
|
||||
game->world = world;
|
||||
|
||||
world->audio = audio;
|
||||
world->audio_handles[0] = bgm;
|
||||
world->audio_handles[1] = saloon_music;
|
||||
|
||||
world->arena = arena;
|
||||
world->random = Random_Seed(29237489723847);
|
||||
world->npcCount = 127;
|
||||
world->npcCount = 12;
|
||||
for(U32 i = 0; i < world->npcCount; i++) {
|
||||
NPC *npc1 = &world->npcs[i];
|
||||
npc1->collision.pos.x = 0;
|
||||
@@ -114,6 +104,7 @@ int main(int argc, char **argv)
|
||||
npc1->waitTime = 0;
|
||||
npc1->maxWaitTime = 1;
|
||||
npc1->currentNavNode = 0;
|
||||
GenOutfit(&npc1->outfit,world,game);
|
||||
}
|
||||
|
||||
Bandit *badman = &world->bandit;
|
||||
@@ -127,7 +118,7 @@ int main(int argc, char **argv)
|
||||
badman->maxWaitTime = 2;
|
||||
badman->poiCount = 2;
|
||||
badman->shootoutTimer = 1.5;
|
||||
badman->agroRadius = 600.0;
|
||||
badman->agroRadius = 6.0;
|
||||
badman->bullets = 6;
|
||||
badman->shootDelay = 1;
|
||||
badman->accuracyRange = 0.25;
|
||||
@@ -135,6 +126,8 @@ int main(int argc, char **argv)
|
||||
badman->reloadTimer = 0;
|
||||
badman->pointsOfInterest[0] = 937;
|
||||
badman->pointsOfInterest[1] = 12;
|
||||
badman->outfitChoices = GenOutfit(&badman->outfit, world, game);
|
||||
badman->currentArea = WORLD_AREA_OUTSIDE;
|
||||
|
||||
world->npcPOI[0] = 100;
|
||||
|
||||
@@ -202,7 +195,7 @@ int main(int argc, char **argv)
|
||||
world->propTypes[13].tag = S("house");
|
||||
world->propTypes[13].scale=6.875f;
|
||||
world->propTypes[14].tag = S("house_int");
|
||||
world->propTypes[14].scale=6.875f;
|
||||
world->propTypes[14].scale=12.875f;
|
||||
world->propTypes[15].tag=S("tile_detail_0");
|
||||
world->propTypes[15].scale=1;
|
||||
world->propTypes[16].tag = S("tile_detail_1");
|
||||
@@ -219,7 +212,7 @@ int main(int argc, char **argv)
|
||||
world->propTypes[21].scale=1;
|
||||
world->propCount = 0;
|
||||
world->props = M_ArenaPush(arena, World_Prop, .count=WORLD_PROP_MAX);
|
||||
world->hitboxes = M_ArenaPush(arena, AABB, .count=WORLD_HITBOX_MAX);
|
||||
world->hitboxes = M_ArenaPush(arena, World_Hitbox, .count=WORLD_HITBOX_MAX);
|
||||
world->portals = M_ArenaPush(arena, World_Portal, .count=64);
|
||||
world->portalCount=0;
|
||||
GenerateNavMesh(arena, world);
|
||||
@@ -247,6 +240,7 @@ int main(int argc, char **argv)
|
||||
Player *player = &game->world->player;
|
||||
switch (e.key.key) {
|
||||
case SDLK_R: { PlayerInit(game, player); } break;
|
||||
case SDLK_F: {game->world->showPoster=!game->world->showPoster;}break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,11 +279,12 @@ int main(int argc, char **argv)
|
||||
}} else if(e.type==SDL_EVENT_MOUSE_BUTTON_UP && e.button.button == SDL_BUTTON_LEFT && game->editor.mode == G_EDITOR_MODE_HITBOX) {
|
||||
// Add hitbox
|
||||
V2f topLeft = V2F(Min(game->editor.cursor.x, game->editor.dragStart.x), Min(game->editor.cursor.y, game->editor.dragStart.y));
|
||||
game->world->hitboxes[game->world->hitboxCount].pos = topLeft;
|
||||
game->world->hitboxes[game->world->hitboxCount].size = V2F(
|
||||
game->world->hitboxes[game->world->hitboxCount].box.pos = topLeft;
|
||||
game->world->hitboxes[game->world->hitboxCount].box.size = V2F(
|
||||
Abs(game->editor.cursor.x-game->editor.dragStart.x),
|
||||
Abs(game->editor.cursor.y-game->editor.dragStart.y)
|
||||
);
|
||||
game->world->hitboxes[game->world->hitboxCount].area = game->editor.currentAsset;
|
||||
game->world->hitboxCount++;
|
||||
GenerateNavMesh(game->arena, game->world);
|
||||
} else if(e.type==SDL_EVENT_MOUSE_BUTTON_UP && e.button.button == SDL_BUTTON_LEFT && game->editor.mode == G_EDITOR_MODE_PORTAL) {
|
||||
@@ -367,6 +362,7 @@ int main(int argc, char **argv)
|
||||
switch(game->editor.mode) {
|
||||
case G_EDITOR_MODE_PROP: {game->world->propCount--;}
|
||||
case G_EDITOR_MODE_HITBOX: {game->world->hitboxCount--;}
|
||||
case G_EDITOR_MODE_PORTAL: {game->world->portalCount--;}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -375,7 +371,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if(!game->editor.enabled) {
|
||||
UpdateWorld(1.0f / 60.0f, game->world);
|
||||
UpdateWorld(1.0f / 250.0f, game->world);
|
||||
|
||||
game->camera.p.x = game->world->player.collision.pos.x;
|
||||
game->camera.p.y = game->world->player.collision.pos.y;
|
||||
@@ -417,15 +413,26 @@ int main(int argc, char **argv)
|
||||
|
||||
D_Begin(&game->draw, frame, D_MAX_RECTS);
|
||||
|
||||
|
||||
RenderWorld(game->world, &game->draw);
|
||||
|
||||
R3f bounds = G_CameraBounds(&game->camera);
|
||||
|
||||
if (game->world->showPoster) {
|
||||
D_Rect(&game->draw, bounds.min.x + 4.8f, bounds.min.y + 6.4f, .texture = D_ImageHandle(&game->draw, S("poster")), .scale = 12.0f);
|
||||
}
|
||||
|
||||
for (U32 i = 0; i < game->world->player.health; i++) {
|
||||
D_Rect(&game->draw, (bounds.max.x - 3) + i, bounds.min.y + 1, .texture = D_ImageHandle(&game->draw, S("heart")));
|
||||
}
|
||||
|
||||
//D_Text(&game->draw, game->draw.fonts, S("Small Test"), 0, 0);
|
||||
|
||||
if(game->editor.enabled) {
|
||||
G_Editor editor = game->editor;
|
||||
F32 tilex = cast(F32) floor(editor.cursor.x+TILE_SIZE/2);
|
||||
F32 tiley = cast(F32) floor(editor.cursor.y+TILE_SIZE/2);
|
||||
for (int i = 0; i < game->world->navMesh->nodeCount; i++) {
|
||||
for (U32 i = 0; i < game->world->navMesh->nodeCount; i++) {
|
||||
NavNode n = game->world->navMesh->nodes[i];
|
||||
D_Rect(
|
||||
&game->draw,
|
||||
@@ -435,7 +442,7 @@ int main(int argc, char **argv)
|
||||
.scale = 0.2f,
|
||||
);
|
||||
}
|
||||
for (int i = 0; i < game->world->navMesh->nodeCount; i++) {
|
||||
for (U32 i = 0; i < game->world->navMesh->nodeCount; i++) {
|
||||
NavNode n = game->world->navMesh->nodes[i];
|
||||
if(i == editor.selectedNode) {
|
||||
D_Rect(
|
||||
@@ -471,16 +478,18 @@ int main(int argc, char **argv)
|
||||
}
|
||||
case G_EDITOR_MODE_HITBOX: {
|
||||
for(U32 i = 0; i < game->world->hitboxCount; i++) {
|
||||
V2f centre = AABB_Centre(game->world->hitboxes[i]);
|
||||
D_Rect(
|
||||
&game->draw,
|
||||
centre.x,
|
||||
centre.y,
|
||||
.texture=0,
|
||||
.dim=game->world->hitboxes[i].size,
|
||||
.flags=D_RECT_IGNORE_ASPECT,
|
||||
.c=V4F(100,0,0,0.7f),
|
||||
);
|
||||
if(game->world->player.currentArea == game->world->hitboxes[i].area) {
|
||||
V2f centre = AABB_Centre(game->world->hitboxes[i].box);
|
||||
D_Rect(
|
||||
&game->draw,
|
||||
centre.x,
|
||||
centre.y,
|
||||
.texture=0,
|
||||
.dim=game->world->hitboxes[i].box.size,
|
||||
.flags=D_RECT_IGNORE_ASPECT,
|
||||
.c=V4F(100,0,0,0.7f),
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -494,7 +503,7 @@ int main(int argc, char **argv)
|
||||
.texture=0,
|
||||
.dim=game->world->portals[i].box.size,
|
||||
.flags=D_RECT_IGNORE_ASPECT,
|
||||
.c=V4F(0,0,100,0.7),
|
||||
.c=V4F(0,0,100,0.7f),
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -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);
|
||||
@@ -10,7 +10,7 @@ V2f shootTowards(Bandit *bandit, V2f target, Random* r)
|
||||
}
|
||||
|
||||
void UpdateBandit(F32 delta, Bandit *bandit, World *world) {
|
||||
for(int i = 0; i < world->portalCount; i++) {
|
||||
for(U32 i = 0; i < world->portalCount; i++) {
|
||||
if(AABB_Collide(world->portals[0].box, bandit->collision)) {
|
||||
bandit->currentArea = world->portals[0].area;
|
||||
}
|
||||
@@ -18,12 +18,10 @@ void UpdateBandit(F32 delta, Bandit *bandit, World *world) {
|
||||
if (
|
||||
world->player.controls.shot && AABB_Slab(world->player.collision.pos, world->player.shotPos, bandit->collision) && bandit->currentArea == world->player.currentArea)
|
||||
{
|
||||
printf("You shot the bandit %*.s\n", Sv(bandit->name));
|
||||
bandit->health--;
|
||||
}
|
||||
if (AABB_Circle(bandit->agroRadius, AABB_Centre(bandit->collision), world->player.collision) && !(bandit->mode == BANDIT_SHOOTING || bandit->mode == BANDIT_SHOOTOUT))
|
||||
{
|
||||
printf("begin shootout");
|
||||
// shootout time o.o
|
||||
bandit->mode = BANDIT_SHOOTOUT;
|
||||
}
|
||||
@@ -71,17 +69,14 @@ void UpdateBandit(F32 delta, Bandit *bandit, World *world) {
|
||||
bandit->reloadTimer -= delta;
|
||||
if (bandit->shootCooldownTimer < 0 && bandit->reloadTimer < 0)
|
||||
{
|
||||
printf("shoot 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");
|
||||
world->player.health--;
|
||||
}
|
||||
if(bandit->bullets == 0){
|
||||
printf("enemy reload");
|
||||
bandit->bullets = 6;
|
||||
bandit->reloadTimer = bandit->reloadTime;
|
||||
}
|
||||
@@ -90,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "core/math.h"
|
||||
|
||||
void UpdateNPC(F32 delta, NPC *npc, World *world) {
|
||||
for(int i = 0; i < world->portalCount; i++) {
|
||||
for(U32 i = 0; i < world->portalCount; i++) {
|
||||
if(AABB_Collide(world->portals[0].box, npc->collision)) {
|
||||
npc->currentArea = world->portals[0].area;
|
||||
}
|
||||
@@ -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 (
|
||||
@@ -128,7 +100,6 @@ void PlayerUpdate(F32 delta, Player *player) {
|
||||
player->controls.shot = false;
|
||||
V2f dir = V2F(0, 0);
|
||||
if(player->health == 0){
|
||||
printf("dead :(");
|
||||
player->health = 3;
|
||||
}
|
||||
if(player->controls.upDown) {
|
||||
@@ -165,11 +136,23 @@ void PlayerUpdate(F32 delta, Player *player) {
|
||||
dir = V2f_Scale(NormaliseV2F(dir), PLAYER_SPEED*delta);
|
||||
player->collision.pos.x += dir.x;
|
||||
player->collision.pos.y += dir.y;
|
||||
for(int i = 0; i < player->world->portalCount; i++) {
|
||||
if(AABB_Collide(player->world->portals[0].box, player->collision)) {
|
||||
player->currentArea = player->world->portals[0].area;
|
||||
|
||||
for(U32 i = 0; i < player->world->portalCount; i++) {
|
||||
if(AABB_Collide(player->world->portals[i].box, player->collision)) {
|
||||
player->currentArea = player->world->portals[i].area;
|
||||
}
|
||||
}
|
||||
|
||||
V2f test;
|
||||
test.x = player->collision.pos.x - 14;
|
||||
test.y = player->collision.pos.y - 14;
|
||||
|
||||
F32 len = V2f_Dot(test, test);
|
||||
F32 vol = Max(0.0f, 1.0f - (len / 25.0f));
|
||||
|
||||
Audio_ChangeVolume(player->world->audio, player->world->audio_handles[1], vol);
|
||||
Audio_ChangeVolume(player->world->audio, player->world->audio_handles[0], 1.0f - vol);
|
||||
|
||||
}
|
||||
|
||||
void PlayerDraw(D_Context *draw, Player *player) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -189,14 +185,14 @@ void LoadWorld(M_Arena *arena, World *world) {
|
||||
//
|
||||
{
|
||||
U32 n_hitbox = *(U32 *) base; base += 4;
|
||||
AABB *boxes = (AABB *) base;
|
||||
World_Hitbox *boxes = (World_Hitbox *) base;
|
||||
|
||||
world->hitboxCount = n_hitbox;
|
||||
world->hitboxes = M_ArenaPush(arena, AABB, .count = WORLD_HITBOX_MAX);
|
||||
world->hitboxes = M_ArenaPush(arena, World_Hitbox, .count = WORLD_HITBOX_MAX);
|
||||
|
||||
M_CopySize(world->hitboxes, boxes, n_hitbox * sizeof(AABB));
|
||||
M_CopySize(world->hitboxes, boxes, n_hitbox * sizeof(World_Hitbox));
|
||||
|
||||
base += (WORLD_HITBOX_MAX * sizeof(AABB));
|
||||
base += (WORLD_HITBOX_MAX * sizeof(World_Hitbox));
|
||||
}
|
||||
|
||||
// Map
|
||||
@@ -242,14 +238,14 @@ void GenerateNavMesh(M_Arena *arena, World *world) {
|
||||
U32 y = (i / 96);
|
||||
bool skip = false;
|
||||
for(U32 hi = 0; hi < world->hitboxCount; hi++) {
|
||||
if(AABB_Point(world->hitboxes[hi], V2F((F32) x, (F32) y))) {
|
||||
if(AABB_Point(world->hitboxes[hi].box, V2F((F32) x, (F32) y))) {
|
||||
skip = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(skip) {continue;}
|
||||
world->navMesh->nodes[world->navMesh->nodeCount].pos.x = x;
|
||||
world->navMesh->nodes[world->navMesh->nodeCount].pos.y = y;
|
||||
world->navMesh->nodes[world->navMesh->nodeCount].pos.x = cast(F32) x;
|
||||
world->navMesh->nodes[world->navMesh->nodeCount].pos.y = cast(F32) y;
|
||||
world->navMesh->nodes[world->navMesh->nodeCount].connectionCount = 0;
|
||||
for(int nx = -1; nx < 2; nx++){
|
||||
for(int ny = -1; ny < 2; ny++){
|
||||
@@ -262,14 +258,14 @@ void GenerateNavMesh(M_Arena *arena, World *world) {
|
||||
}
|
||||
// It's quad for loop time :D
|
||||
for(U32 hi = 0; hi < world->hitboxCount; hi++) {
|
||||
if(AABB_Point(world->hitboxes[hi], V2F((F32) (x + nx), (F32) (y + ny)))) {
|
||||
if(AABB_Point(world->hitboxes[hi].box, V2F((F32) (x + nx), (F32) (y + ny)))) {
|
||||
skip = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
U32 nCount = world->navMesh->nodeCount;
|
||||
S32 index = -1;
|
||||
for(int ohgod = 0; ohgod < nCount; ohgod++) {
|
||||
for (U32 ohgod = 0; ohgod < nCount; ohgod++) {
|
||||
if(world->navMesh->nodes[ohgod].pos.x == nx+x&& world->navMesh->nodes[ohgod].pos.y == y+ny) {
|
||||
index=ohgod;
|
||||
break;
|
||||
@@ -286,7 +282,7 @@ void GenerateNavMesh(M_Arena *arena, World *world) {
|
||||
};
|
||||
}
|
||||
if(index < 0) {continue;}
|
||||
skip |= index > nCount;
|
||||
skip |= (index > (S32) nCount);
|
||||
if(skip) {continue;}
|
||||
world->navMesh->nodes[nCount].connections[world->navMesh->nodes[nCount].connectionCount].NodeIndex = index;
|
||||
world->navMesh->nodes[nCount].connections[world->navMesh->nodes[nCount].connectionCount].Cost = cost;
|
||||
@@ -298,7 +294,7 @@ void GenerateNavMesh(M_Arena *arena, World *world) {
|
||||
}
|
||||
world->navMesh->nodeCount++;
|
||||
}
|
||||
for(int i = 0; i < world->npcCount; i++) {
|
||||
for(U32 i = 0; i < world->npcCount; i++) {
|
||||
world->npcs[i].mode = NPC_ACTION_WAITING;
|
||||
world->npcs[i].maxWaitTime = Random_F32(&world->random, 20, 140);
|
||||
world->npcs[i].waitTime = 0;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -45,6 +45,8 @@ struct World_Portal
|
||||
AABB box;
|
||||
World_Area area;
|
||||
};
|
||||
typedef World_Portal World_Hitbox;
|
||||
|
||||
|
||||
typedef struct World World;
|
||||
#include "player.h"
|
||||
@@ -62,14 +64,16 @@ struct World {
|
||||
World_Tile *tileTypes;
|
||||
World_PropType *propTypes;
|
||||
World_Prop *props;
|
||||
AABB *hitboxes;
|
||||
World_Hitbox *hitboxes;
|
||||
World_Portal *portals;
|
||||
U32 *map;
|
||||
|
||||
bool showPoster;
|
||||
U32 propCount;
|
||||
U32 portalCount;
|
||||
U32 hitboxCount;
|
||||
|
||||
Audio_Context *audio;
|
||||
U32 audio_handles[2];
|
||||
|
||||
//// Player
|
||||
Player player;
|
||||
|
||||
43
code/os/audio.h
Normal file
43
code/os/audio.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#if !defined(LD_OS_AUDIO_H_)
|
||||
#define LD_OS_AUDIO_H_
|
||||
|
||||
typedef struct Audio_Data Audio_Data;
|
||||
struct Audio_Data {
|
||||
S16 *samples;
|
||||
U32 n_frames;
|
||||
};
|
||||
|
||||
typedef struct Audio_Track Audio_Track;
|
||||
struct Audio_Track {
|
||||
B32 playing;
|
||||
|
||||
Audio_Data *data;
|
||||
|
||||
F32 volume;
|
||||
|
||||
U32 n_played;
|
||||
U32 next; // to play if playing, free otherwise
|
||||
};
|
||||
|
||||
typedef struct Audio_Context Audio_Context;
|
||||
struct Audio_Context {
|
||||
SDL_AudioStream *stream;
|
||||
|
||||
U32 n_tracks;
|
||||
Audio_Track tracks[16];
|
||||
|
||||
U32 head;
|
||||
U32 free;
|
||||
|
||||
F32 volume;
|
||||
|
||||
U32 n_sounds;
|
||||
Audio_Data *sounds;
|
||||
};
|
||||
|
||||
function void Audio_Init(M_Arena *arena, Audio_Context *audio, F32 volume);
|
||||
function U32 Audio_Play(Audio_Context *audio, U32 index);
|
||||
|
||||
function void Audio_ChangeVolume(Audio_Context *audio, U32 handle, F32 volume);
|
||||
|
||||
#endif // LD_OS_AUDIO_H_
|
||||
162
code/os/core.c
162
code/os/core.c
@@ -4,7 +4,6 @@
|
||||
#include "impl/linux/core.c"
|
||||
#endif
|
||||
|
||||
|
||||
Str8 FS_ReadEntireFile(M_Arena *arena, Str8 path) {
|
||||
Str8 result = { 0 };
|
||||
|
||||
@@ -19,3 +18,164 @@ Str8 FS_ReadEntireFile(M_Arena *arena, Str8 path) {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
internal void SDL_SubmitAudio(void *user, SDL_AudioStream *stream, int needed, int total) {
|
||||
Audio_Context *audio = cast(Audio_Context *) user;
|
||||
|
||||
(void) total;
|
||||
|
||||
M_TempScope(0, 0) {
|
||||
U32 prev = 0;
|
||||
U32 it = audio->head;
|
||||
|
||||
U32 n_samples = needed >> 1;
|
||||
U32 n_frames = n_samples >> 1;
|
||||
|
||||
F32 *left_f32 = M_ArenaPush(temp.arena, F32, .count = n_frames);
|
||||
F32 *right_f32 = M_ArenaPush(temp.arena, F32, .count = n_frames);
|
||||
|
||||
while (it != 0) {
|
||||
Audio_Track *track = &audio->tracks[it];
|
||||
U32 next = track->next;
|
||||
|
||||
F32 *l0 = left_f32;
|
||||
F32 *r0 = right_f32;
|
||||
|
||||
Assert(track->playing);
|
||||
|
||||
U32 remain = track->data->n_frames - track->n_played;
|
||||
U32 play = Min(n_frames, remain);
|
||||
U32 off = track->n_played << 1; // played n frames, thus double to n samples
|
||||
|
||||
for (U32 f = 0; f < play; ++f) {
|
||||
*l0++ += cast(F32) (track->data->samples[off + (2 * f) + 0]) * track->volume * audio->volume;
|
||||
*r0++ += cast(F32) (track->data->samples[off + (2 * f) + 1]) * track->volume * audio->volume;
|
||||
}
|
||||
|
||||
track->n_played += play;
|
||||
|
||||
if (track->n_played == track->data->n_frames) {
|
||||
if (prev == 0) {
|
||||
// Head has finished playing
|
||||
//
|
||||
audio->head = track->next;
|
||||
track->next = audio->free;
|
||||
audio->free = it;
|
||||
}
|
||||
else {
|
||||
// We're in the middle somewhere so prev->next == it->next
|
||||
//
|
||||
audio->tracks[prev].next = track->next;
|
||||
track->next = audio->free;
|
||||
audio->free = it;
|
||||
}
|
||||
|
||||
track->playing = false;
|
||||
}
|
||||
|
||||
it = next;
|
||||
}
|
||||
|
||||
F32 *l0 = left_f32;
|
||||
F32 *r0 = right_f32;
|
||||
|
||||
S16 *interleaved = M_ArenaPush(temp.arena, S16, .count = n_samples);
|
||||
S16 *i0 = interleaved;
|
||||
|
||||
for (U32 n = 0; n < n_frames; ++n) {
|
||||
*i0++ = cast(S16) (l0[n] + 0.5f);
|
||||
*i0++ = cast(S16) (r0[n] + 0.5f);
|
||||
}
|
||||
|
||||
SDL_PutAudioStreamData(stream, interleaved, needed);
|
||||
}
|
||||
}
|
||||
|
||||
void Audio_Init(M_Arena *arena, Audio_Context *audio, F32 volume) {
|
||||
SDL_AudioSpec spec = { 0 };
|
||||
spec.format = SDL_AUDIO_S16LE;
|
||||
spec.channels = 2;
|
||||
spec.freq = 44100;
|
||||
|
||||
audio->stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, SDL_SubmitAudio, audio);
|
||||
|
||||
if (audio->stream) {
|
||||
M_TempScope(0, 0) {
|
||||
Str8 exec = FS_SystemPath(temp.arena, FS_SYSTEM_PATH_EXE);
|
||||
Str8 path = Sf(temp.arena, "%.*s/assets", Sv(exec));
|
||||
|
||||
FS_List files = FS_PathList(temp.arena, path);
|
||||
|
||||
U32 n_audio = 0;
|
||||
for (FS_Entry *it = files.first; it != 0; it = it->next) {
|
||||
if (Str8_EndsWith(it->basename, S("wav"))) {
|
||||
n_audio += 1;
|
||||
}
|
||||
}
|
||||
|
||||
audio->n_sounds = 0;
|
||||
audio->sounds = M_ArenaPush(arena, Audio_Data, .count = n_audio);
|
||||
|
||||
for (FS_Entry *it = files.first; it != 0; it = it->next) {
|
||||
if (Str8_EndsWith(it->basename, S("wav"))) {
|
||||
Audio_Data *sound = &audio->sounds[audio->n_sounds];
|
||||
|
||||
U8 *data;
|
||||
U32 count;
|
||||
SDL_AudioSpec wav;
|
||||
|
||||
SDL_LoadWAV((const char *) it->path.data, &wav, &data, &count);
|
||||
|
||||
Assert(wav.freq == 44100);
|
||||
|
||||
sound->samples = (S16 *) data;
|
||||
sound->n_frames = (count >> 2);
|
||||
|
||||
audio->n_sounds += 1;
|
||||
}
|
||||
}
|
||||
|
||||
audio->n_tracks = 16;
|
||||
|
||||
for (U32 it = 1; it < audio->n_tracks; ++it) {
|
||||
audio->tracks[it].next = it + 1;
|
||||
}
|
||||
|
||||
audio->tracks[audio->n_tracks - 1].next = 0;
|
||||
|
||||
audio->volume = volume;
|
||||
audio->head = 0;
|
||||
audio->free = 1;
|
||||
|
||||
printf("--- Loaded %d sounds ---\n", audio->n_sounds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
U32 Audio_Play(Audio_Context *audio, U32 index) {
|
||||
U32 result = 0;
|
||||
if (audio->free != 0 && SDL_LockAudioStream(audio->stream)) {
|
||||
result = audio->free;
|
||||
|
||||
Audio_Track *track = &audio->tracks[result];
|
||||
audio->free = track->next;
|
||||
|
||||
track->playing = true;
|
||||
track->data = &audio->sounds[index];
|
||||
track->n_played = 0;
|
||||
track->volume = 1.0f;
|
||||
track->next = audio->head;
|
||||
audio->head = result;
|
||||
|
||||
SDL_UnlockAudioStream(audio->stream);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Audio_ChangeVolume(Audio_Context *audio, U32 handle, F32 volume) {
|
||||
if (SDL_LockAudioStream(audio->stream)) {
|
||||
audio->tracks[handle].volume = volume;
|
||||
SDL_UnlockAudioStream(audio->stream);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,5 +17,6 @@ function void VM_Decommit(void *base, U64 size);
|
||||
function void VM_Release(void *base, U64 size);
|
||||
|
||||
#include "filesystem.h"
|
||||
#include "audio.h"
|
||||
|
||||
#endif // LD_OS_CORE_H_
|
||||
|
||||
BIN
code/world.sgdat
BIN
code/world.sgdat
Binary file not shown.
Reference in New Issue
Block a user