Fixed ???
Some files have been renamed
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#if !defined(LD_GAME_CORE_H_)
|
||||
#define LD_GAME_CORE_H_
|
||||
#include "world.h"
|
||||
|
||||
typedef struct World World;
|
||||
|
||||
typedef struct G_Camera G_Camera;
|
||||
struct G_Camera {
|
||||
@@ -44,6 +45,48 @@ struct G_State {
|
||||
World *world;
|
||||
};
|
||||
|
||||
typedef U32 G_OutfitDirection;
|
||||
enum {
|
||||
G_OUTFIT_DIR_FRONT = 0,
|
||||
G_OUTFIT_DIR_SIDE,
|
||||
G_OUTFIT_DIR_BACK,
|
||||
|
||||
G_OUTFIT_DIR_FLIPPED = (1 << 16)
|
||||
};
|
||||
|
||||
typedef union G_OutfitSet G_OutfitSet;
|
||||
union G_OutfitSet {
|
||||
struct {
|
||||
U32 base;
|
||||
U32 eyes;
|
||||
U32 face;
|
||||
U32 hair;
|
||||
U32 hat;
|
||||
U32 shirt;
|
||||
U32 shoes;
|
||||
U32 trousers;
|
||||
};
|
||||
|
||||
U32 e[8];
|
||||
};
|
||||
|
||||
typedef struct G_Outfit G_Outfit;
|
||||
struct G_Outfit {
|
||||
D_Animation state; // .id in here isn't used for drawing
|
||||
|
||||
G_OutfitDirection dir;
|
||||
|
||||
union {
|
||||
struct {
|
||||
G_OutfitSet front;
|
||||
G_OutfitSet side;
|
||||
G_OutfitSet back;
|
||||
};
|
||||
|
||||
G_OutfitSet e[3];
|
||||
};
|
||||
};
|
||||
|
||||
function void G_ImagesLoad(G_State *game);
|
||||
function void G_PipelinesLoad(G_State *game);
|
||||
function void G_AudioLoad(G_State *game);
|
||||
@@ -56,6 +99,7 @@ function V3f G_CameraUnproject(G_Camera *camera, V2f clip);
|
||||
|
||||
function R3f G_CameraBounds(G_Camera *camera);
|
||||
|
||||
#include "world.h"
|
||||
#include "aabb.h"
|
||||
#include "player.h"
|
||||
#include "nav.h"
|
||||
|
||||
@@ -3,6 +3,75 @@
|
||||
#include <SDL3/SDL_keycode.h>
|
||||
#include <stdio.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;
|
||||
player->world = world;
|
||||
|
||||
world->player.bulletsLoaded = PLAYER_BULLET_COUNT;
|
||||
world->player.currentArea = WORLD_AREA_OUTSIDE;
|
||||
|
||||
G_Outfit *outfit = &player->outfit;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerInput(SDL_Event *event, Player *player)
|
||||
{
|
||||
SDL_KeyboardEvent key = event->key;
|
||||
@@ -34,7 +103,7 @@ void PlayerInput(SDL_Event *event, Player *player)
|
||||
}
|
||||
}
|
||||
if (
|
||||
event->type == SDL_EVENT_MOUSE_BUTTON_DOWN
|
||||
event->type == SDL_EVENT_MOUSE_BUTTON_DOWN
|
||||
&& mouseBtn.button == SDL_BUTTON_LEFT
|
||||
) {
|
||||
if(player->bulletsLoaded > 0) {
|
||||
@@ -47,7 +116,7 @@ void PlayerInput(SDL_Event *event, Player *player)
|
||||
player->reloadTimer = PLAYER_RELOAD_TIME;
|
||||
printf("reloading\n");
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerUpdate(F32 delta, Player *player) {
|
||||
@@ -55,16 +124,28 @@ void PlayerUpdate(F32 delta, Player *player) {
|
||||
V2f dir = V2F(0, 0);
|
||||
if(player->controls.upDown) {
|
||||
dir.y -= 1;
|
||||
player->outfit.dir = G_OUTFIT_DIR_BACK;
|
||||
}
|
||||
if(player->controls.downDown) {
|
||||
dir.y += 1;
|
||||
player->outfit.dir = G_OUTFIT_DIR_FRONT;
|
||||
}
|
||||
if(player->controls.leftDown) {
|
||||
dir.x -= 1;
|
||||
player->outfit.dir = G_OUTFIT_DIR_SIDE | G_OUTFIT_DIR_FLIPPED;
|
||||
}
|
||||
if(player->controls.rightDown) {
|
||||
dir.x += 1;
|
||||
player->outfit.dir = G_OUTFIT_DIR_SIDE;
|
||||
}
|
||||
|
||||
if (dir.x != 0 || dir.y != 0) {
|
||||
D_AnimationUpdate(&player->outfit.state, delta);
|
||||
}
|
||||
else {
|
||||
player->outfit.state.index = 0;
|
||||
}
|
||||
|
||||
if(player->reloadTimer > 0) {
|
||||
player->reloadTimer-=delta;
|
||||
if(player->reloadTimer <= 0) {
|
||||
@@ -76,3 +157,20 @@ void PlayerUpdate(F32 delta, Player *player) {
|
||||
player->pos.x += dir.x;
|
||||
player->pos.y += dir.y;
|
||||
}
|
||||
|
||||
void PlayerDraw(D_Context *draw, Player *player) {
|
||||
G_Outfit *outfit = &player->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, player->pos.x, player->pos.y, .texture = tid, .uv = pframe, .flags = flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ void RenderWorld(World *world, D_Context *draw) {
|
||||
);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < world->propCount; i++) {
|
||||
for (U32 i = 0; i < world->propCount; i++) {
|
||||
if(world->props[i].area == world->player.currentArea) {
|
||||
D_Rect(
|
||||
draw,
|
||||
@@ -69,10 +69,13 @@ void RenderWorld(World *world, D_Context *draw) {
|
||||
V2f drawPos = AABB_Centre(world->bandit.collision);
|
||||
D_Rect(draw, drawPos.x, drawPos.y, .texture = 9);
|
||||
}
|
||||
D_Rect(draw, world->player.pos.x, world->player.pos.y, .texture = 1);
|
||||
|
||||
PlayerDraw(draw, &world->player);
|
||||
}
|
||||
|
||||
void SaveWorld(M_Arena *arena, World *world) {
|
||||
(void) arena;
|
||||
|
||||
printf("Saving world\n");
|
||||
OS_Handle file = FS_FileOpen(S("world.sgdat"), FS_ACCESS_WRITE);
|
||||
FS_FileWrite(file, world, sizeof(World)+sizeof(NavMesh), 0);
|
||||
|
||||
@@ -29,9 +29,14 @@ struct Player
|
||||
ControlState controls;
|
||||
V2f shotPos;
|
||||
|
||||
G_Outfit outfit;
|
||||
|
||||
F32 reloadTimer;
|
||||
};
|
||||
|
||||
function void PlayerInit(G_State *game, Player *player);
|
||||
function void PlayerDraw(D_Context *draw, Player *player);
|
||||
|
||||
function void PlayerInput(SDL_Event *event, Player *player);
|
||||
function void PlayerUpdate(F32 delta, Player *player);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user