Compare commits
2 Commits
d54b4df4c2
...
cb10bd10b6
| Author | SHA1 | Date | |
|---|---|---|---|
|
cb10bd10b6
|
|||
|
a6577f520b
|
BIN
assets/npc_back_base_0.png
Normal file
|
After Width: | Height: | Size: 650 B |
BIN
assets/npc_back_base_1.png
Normal file
|
After Width: | Height: | Size: 677 B |
BIN
assets/npc_back_face_1.png
Normal file
|
After Width: | Height: | Size: 232 B |
BIN
assets/npc_back_face_2.png
Normal file
|
After Width: | Height: | Size: 204 B |
BIN
assets/npc_back_hair_1.png
Normal file
|
After Width: | Height: | Size: 483 B |
BIN
assets/npc_back_hair_2.png
Normal file
|
After Width: | Height: | Size: 395 B |
BIN
assets/npc_back_hair_3.png
Normal file
|
After Width: | Height: | Size: 243 B |
BIN
assets/npc_back_hat_1.png
Normal file
|
After Width: | Height: | Size: 319 B |
BIN
assets/npc_back_hat_2.png
Normal file
|
After Width: | Height: | Size: 298 B |
BIN
assets/npc_back_shirt_0.png
Normal file
|
After Width: | Height: | Size: 560 B |
BIN
assets/npc_back_shirt_1.png
Normal file
|
After Width: | Height: | Size: 521 B |
BIN
assets/npc_back_shoes_0.png
Normal file
|
After Width: | Height: | Size: 274 B |
BIN
assets/npc_back_trousers_0.png
Normal file
|
After Width: | Height: | Size: 337 B |
BIN
assets/npc_back_trousers_1.png
Normal file
|
After Width: | Height: | Size: 325 B |
|
Before Width: | Height: | Size: 732 B After Width: | Height: | Size: 732 B |
|
Before Width: | Height: | Size: 737 B After Width: | Height: | Size: 737 B |
|
Before Width: | Height: | Size: 232 B After Width: | Height: | Size: 232 B |
|
Before Width: | Height: | Size: 207 B After Width: | Height: | Size: 207 B |
|
Before Width: | Height: | Size: 217 B After Width: | Height: | Size: 217 B |
|
Before Width: | Height: | Size: 227 B After Width: | Height: | Size: 227 B |
|
Before Width: | Height: | Size: 186 B After Width: | Height: | Size: 186 B |
|
Before Width: | Height: | Size: 157 B After Width: | Height: | Size: 157 B |
|
Before Width: | Height: | Size: 191 B After Width: | Height: | Size: 191 B |
|
Before Width: | Height: | Size: 393 B After Width: | Height: | Size: 393 B |
|
Before Width: | Height: | Size: 334 B After Width: | Height: | Size: 334 B |
|
Before Width: | Height: | Size: 191 B After Width: | Height: | Size: 191 B |
|
Before Width: | Height: | Size: 326 B After Width: | Height: | Size: 326 B |
|
Before Width: | Height: | Size: 300 B After Width: | Height: | Size: 300 B |
|
Before Width: | Height: | Size: 528 B After Width: | Height: | Size: 528 B |
|
Before Width: | Height: | Size: 479 B After Width: | Height: | Size: 479 B |
|
Before Width: | Height: | Size: 273 B After Width: | Height: | Size: 273 B |
|
Before Width: | Height: | Size: 361 B After Width: | Height: | Size: 361 B |
|
Before Width: | Height: | Size: 354 B After Width: | Height: | Size: 354 B |
BIN
assets/npc_side_base_0.png
Normal file
|
After Width: | Height: | Size: 636 B |
BIN
assets/npc_side_base_1.png
Normal file
|
After Width: | Height: | Size: 639 B |
BIN
assets/npc_side_eyes_0.png
Normal file
|
After Width: | Height: | Size: 199 B |
BIN
assets/npc_side_eyes_1.png
Normal file
|
After Width: | Height: | Size: 191 B |
BIN
assets/npc_side_eyes_2.png
Normal file
|
After Width: | Height: | Size: 176 B |
BIN
assets/npc_side_eyes_closed.png
Normal file
|
After Width: | Height: | Size: 124 B |
BIN
assets/npc_side_face_1.png
Normal file
|
After Width: | Height: | Size: 257 B |
BIN
assets/npc_side_face_2.png
Normal file
|
After Width: | Height: | Size: 242 B |
BIN
assets/npc_side_face_3.png
Normal file
|
After Width: | Height: | Size: 135 B |
BIN
assets/npc_side_face_4.png
Normal file
|
After Width: | Height: | Size: 133 B |
BIN
assets/npc_side_hair_1.png
Normal file
|
After Width: | Height: | Size: 346 B |
BIN
assets/npc_side_hair_2.png
Normal file
|
After Width: | Height: | Size: 329 B |
BIN
assets/npc_side_hair_3.png
Normal file
|
After Width: | Height: | Size: 235 B |
BIN
assets/npc_side_hat_1.png
Normal file
|
After Width: | Height: | Size: 321 B |
BIN
assets/npc_side_hat_2.png
Normal file
|
After Width: | Height: | Size: 328 B |
BIN
assets/npc_side_shirt_0.png
Normal file
|
After Width: | Height: | Size: 448 B |
BIN
assets/npc_side_shirt_1.png
Normal file
|
After Width: | Height: | Size: 403 B |
BIN
assets/npc_side_shoes_0.png
Normal file
|
After Width: | Height: | Size: 259 B |
BIN
assets/npc_side_trousers_0.png
Normal file
|
After Width: | Height: | Size: 421 B |
BIN
assets/npc_side_trousers_1.png
Normal file
|
After Width: | Height: | Size: 393 B |
@@ -3,6 +3,7 @@
|
||||
|
||||
#define S(x) Str8_Wrap(sizeof(x) - sizeof(*(x)), (U8 *) (x))
|
||||
#define Sz(x) Str8_WrapZ((U8 *) (x))
|
||||
#define Sl(x) { sizeof(x) - sizeof(*(x)), (U8 *) (x) }
|
||||
|
||||
#define Sv(x) (int) (x).count, (x).data
|
||||
#define Sf(arena, fmt, ...) Str8_Format(arena, fmt, ##__VA_ARGS__)
|
||||
|
||||
@@ -151,6 +151,8 @@ void _D_Rect(D_Context *draw, D_RectOpts *opts) {
|
||||
|
||||
rect->texture = opts->texture;
|
||||
|
||||
F32 w, h;
|
||||
|
||||
rect->x = opts->p.x;
|
||||
rect->y = opts->p.y;
|
||||
|
||||
@@ -177,11 +179,19 @@ void _D_Rect(D_Context *draw, D_RectOpts *opts) {
|
||||
}
|
||||
|
||||
if (opts->flags & D_RECT_IGNORE_ASPECT) {
|
||||
rect->w = opts->dim.w;
|
||||
rect->h = opts->dim.h;
|
||||
w = opts->dim.w;
|
||||
h = opts->dim.h;
|
||||
}
|
||||
else {
|
||||
Vk_Image *image = &draw->images[opts->texture].image;
|
||||
Vk_Image *image = 0;
|
||||
if (opts->texture >= draw->n_images) {
|
||||
// @hack: first font texture
|
||||
//
|
||||
image = &draw->fonts->image;
|
||||
}
|
||||
else {
|
||||
image = &draw->images[opts->texture].image;
|
||||
}
|
||||
|
||||
F32 width = cast(F32) image->width;
|
||||
F32 height = cast(F32) image->height;
|
||||
@@ -191,53 +201,42 @@ void _D_Rect(D_Context *draw, D_RectOpts *opts) {
|
||||
height *= (opts->uv.max.y - opts->uv.min.y);
|
||||
}
|
||||
|
||||
F32 aspect_w = (width > height) ? (width / height) : 1.0f;
|
||||
F32 aspect_h = (width > height) ? 1.0f : (height / width);
|
||||
F32 aspect_w = (width > height) ? 1.0f : (width / height);
|
||||
F32 aspect_h = (width > height) ? (height / width) : 1.0f;
|
||||
|
||||
rect->w = opts->scale * aspect_w;
|
||||
rect->h = opts->scale * aspect_h;
|
||||
w = opts->scale * aspect_w;
|
||||
h = opts->scale * aspect_h;
|
||||
}
|
||||
|
||||
if (opts->flags & D_RECT_FLIP_X) { w *= -1.0f; }
|
||||
if (opts->flags & D_RECT_FLIP_Y) { h *= -1.0f; }
|
||||
|
||||
rect->w = w;
|
||||
rect->h = h;
|
||||
|
||||
draw->n_rects += 1;
|
||||
}
|
||||
}
|
||||
|
||||
void D_Text(D_Context *draw, D_Font *font, Str8 text, F32 x, F32 y) {
|
||||
F32 xoff = x;
|
||||
local_persist B32 done = 0;
|
||||
|
||||
// @Todo: control scale
|
||||
F32 scale = 1.0f / (font->ascent - font->descent);
|
||||
|
||||
for (S64 it = 0; it < text.count; ++it) {
|
||||
if (text.data[it] >= ' ' && text.data[it] <= '~') {
|
||||
D_Glyph *glyph = &font->glyphs[text.data[it] - ' '];
|
||||
|
||||
V2f size;
|
||||
size.w = (glyph->box.max.x - glyph->box.min.x);
|
||||
size.h = (glyph->box.max.y - glyph->box.min.y);
|
||||
F32 image_scale = scale * Max(glyph->dim.w, glyph->dim.h);
|
||||
F32 advance = scale * glyph->advance;
|
||||
|
||||
V2f dim;
|
||||
V2f offset = V2f_Scale(glyph->offset, scale);
|
||||
|
||||
F32 scale = 150.0f / (font->ascent - font->descent);
|
||||
|
||||
if (size.w > size.h) {
|
||||
dim.w = scale * (size.w / size.h);
|
||||
dim.h = scale;
|
||||
}
|
||||
else {
|
||||
dim.w = scale;
|
||||
dim.h = scale * (size.h / size.w);
|
||||
}
|
||||
|
||||
// @Hardcode: need font index in font struct
|
||||
D_Rect(draw, xoff, y, .texture = 0, .c = V4F(0, 1, 1, 1), .dim = dim, .flags = D_RECT_IGNORE_ASPECT);
|
||||
D_Rect(draw, xoff, y, .texture = draw->n_images, .uv = glyph->box, .dim = dim, .flags = D_RECT_IGNORE_ASPECT);
|
||||
xoff += (1.05f * dim.w); // glyph->advance; //+ glyph->offset.x;
|
||||
|
||||
if (!done) { printf(" %f (%f, %f)", xoff, dim.w, dim.h); }
|
||||
D_Rect(draw, xoff + offset.x, y + offset.y, .texture = font->id, .uv = glyph->box, .scale = image_scale, .flags = D_RECT_UV_ASPECT);
|
||||
xoff += advance;
|
||||
}
|
||||
}
|
||||
|
||||
if (!done) { printf("\n"); }
|
||||
done = true;
|
||||
}
|
||||
|
||||
void D_FontLoad(D_Context *draw, Str8 name, F32 size) {
|
||||
@@ -252,7 +251,7 @@ void D_FontLoad(D_Context *draw, Str8 name, F32 size) {
|
||||
stbtt_fontinfo info = { 0 };
|
||||
stbtt_InitFont(&info, font_data.data, 0);
|
||||
|
||||
F32 scale = stbtt_ScaleForPixelHeight(&info, 20);
|
||||
F32 scale = stbtt_ScaleForPixelHeight(&info, 256);
|
||||
|
||||
U32 w = 512;
|
||||
U32 h = 512;
|
||||
@@ -268,14 +267,12 @@ void D_FontLoad(D_Context *draw, Str8 name, F32 size) {
|
||||
|
||||
D_Font *font = M_ArenaPush(draw->arena, D_Font);
|
||||
|
||||
font->px = size;
|
||||
|
||||
S32 asc, desc, line;
|
||||
stbtt_GetFontVMetrics(&info, &asc, &desc, &line);
|
||||
|
||||
font->line_advance = cast(F32) line;
|
||||
font->ascent = cast(F32) asc;
|
||||
font->descent = cast(F32) desc;
|
||||
font->line_advance = cast(F32) (scale * line);
|
||||
font->ascent = cast(F32) (scale * asc);
|
||||
font->descent = cast(F32) (scale * desc);
|
||||
|
||||
font->glyphs = M_ArenaPush(draw->arena, D_Glyph, .count = count);
|
||||
|
||||
@@ -286,10 +283,14 @@ void D_FontLoad(D_Context *draw, Str8 name, F32 size) {
|
||||
S32 left, width;
|
||||
stbtt_GetCodepointHMetrics(&info, ' ' + it, &width, &left);
|
||||
|
||||
glyph->box = R2F(V2F(chr->x0 / (F32) w, chr->y0 / (F32) h), V2F(chr->x1 / (F32) w, chr->y1 / (F32) h));
|
||||
glyph->box.min = V2F(chr->x0 / (F32) w, chr->y0 / (F32) h);
|
||||
glyph->box.max = V2F(chr->x1 / (F32) w, chr->y1 / (F32) h);
|
||||
|
||||
glyph->advance = glyph->box.max.x - glyph->box.min.x; //chr->xadvance * scale;
|
||||
glyph->offset = V2F(chr->xoff * scale, chr->yoff * scale);
|
||||
glyph->advance = chr->xadvance;
|
||||
glyph->dim.w = cast(F32) (chr->x1 - chr->x0);
|
||||
glyph->dim.h = cast(F32) (chr->y1 - chr->y0);
|
||||
glyph->offset.x = (0.5f * glyph->dim.w) + chr->xoff;
|
||||
glyph->offset.y = (0.5f * glyph->dim.h) + chr->yoff;
|
||||
}
|
||||
|
||||
Vk_Buffer *staging = &draw->staging;
|
||||
@@ -302,6 +303,8 @@ void D_FontLoad(D_Context *draw, Str8 name, F32 size) {
|
||||
|
||||
Vk_CommandBuffer *cmds = Vk_CommandBufferPush();
|
||||
|
||||
font->id = draw->n_images + draw->n_fonts;
|
||||
|
||||
font->image.width = w;
|
||||
font->image.height = h;
|
||||
|
||||
|
||||
@@ -6,7 +6,10 @@
|
||||
typedef struct D_Glyph D_Glyph;
|
||||
struct D_Glyph {
|
||||
F32 advance;
|
||||
|
||||
V2f offset;
|
||||
V2f dim;
|
||||
|
||||
R2f box;
|
||||
};
|
||||
|
||||
@@ -14,13 +17,13 @@ typedef struct D_Font D_Font;
|
||||
struct D_Font {
|
||||
D_Font *next;
|
||||
|
||||
F32 px;
|
||||
U32 id;
|
||||
|
||||
F32 line_advance;
|
||||
F32 ascent;
|
||||
F32 descent;
|
||||
|
||||
F32 *kerning;
|
||||
F32 *kerning; // @incomplete: we don't load this
|
||||
D_Glyph *glyphs;
|
||||
|
||||
Vk_Image image;
|
||||
@@ -108,6 +111,8 @@ enum D_RectFlags {
|
||||
D_RECT_IGNORE_ASPECT = (1 << 0), // by default only width is used as a "dimension"
|
||||
D_RECT_PER_VERTEX_COLOUR = (1 << 1), // split colours per vertex
|
||||
D_RECT_UV_ASPECT = (1 << 2), // get the aspect from the uv rect rather than the full image
|
||||
D_RECT_FLIP_X = (1 << 3),
|
||||
D_RECT_FLIP_Y = (1 << 4)
|
||||
};
|
||||
|
||||
typedef struct D_RectOpts D_RectOpts;
|
||||
|
||||
53
code/first.c
@@ -79,6 +79,8 @@ int main(int argc, char **argv)
|
||||
game->draw.arena = arena;
|
||||
|
||||
G_ImagesLoad(game);
|
||||
D_FontLoad(&game->draw, S("ubuntu"), 60);
|
||||
|
||||
G_PipelinesLoad(game);
|
||||
G_AudioLoad(game);
|
||||
|
||||
@@ -87,7 +89,7 @@ int main(int argc, char **argv)
|
||||
camera->x = V3F(1, 0, 0);
|
||||
camera->y = V3F(0, 1, 0);
|
||||
camera->z = V3F(0, 0, 1);
|
||||
camera->p = V3F(0, 0, 48);
|
||||
camera->p = V3F(0, 0, 16);
|
||||
|
||||
camera->fov = 60.0f;
|
||||
|
||||
@@ -136,15 +138,9 @@ int main(int argc, char **argv)
|
||||
badman->pointsOfInterest[1] = 12;
|
||||
|
||||
world->npcPOI[0] = 100;
|
||||
world->player.world = world;
|
||||
world->player.collision.pos.x = 0;
|
||||
world->player.collision.pos.y = 0;
|
||||
world->player.collision.size.x = 1;
|
||||
world->player.collision.size.y = 2;
|
||||
world->player.bulletsLoaded = PLAYER_BULLET_COUNT;
|
||||
world->player.reloadTimer = 0;
|
||||
world->player.health = 3;
|
||||
world->player.currentArea = WORLD_AREA_OUTSIDE;
|
||||
|
||||
PlayerInit(game, &world->player);
|
||||
|
||||
for(int i =0; i< 4200; i++) {
|
||||
world->map[i] = map[i];
|
||||
}
|
||||
@@ -230,17 +226,8 @@ int main(int argc, char **argv)
|
||||
game->editor.mode = G_EDITOR_MODE_TILE;
|
||||
game->editor.currentLevel = WORLD_AREA_OUTSIDE;
|
||||
|
||||
|
||||
D_Animation animation;
|
||||
{
|
||||
U32 id = D_ImageHandle(&game->draw, S("npc_front_base_white"));
|
||||
D_AnimationInit(&animation, id, 1, 4, 1.0f / 20.0f);
|
||||
}
|
||||
|
||||
bool running = true;
|
||||
|
||||
printf("%zu size in bytes\n", sizeof(TestNavMesh));
|
||||
|
||||
const int width = 1280;
|
||||
const int height = 720;
|
||||
|
||||
@@ -253,6 +240,13 @@ int main(int argc, char **argv)
|
||||
{
|
||||
running = false;
|
||||
}
|
||||
else if (e.type == SDL_EVENT_KEY_DOWN) {
|
||||
Player *player = &game->world->player;
|
||||
switch (e.key.key) {
|
||||
case SDLK_R: { PlayerInit(game, player); } break;
|
||||
}
|
||||
}
|
||||
|
||||
V3f projection = G_CameraUnproject(&game->camera, V2f_Clip(
|
||||
V2F(e.button.x, e.button.y),
|
||||
V2F((F32) width, (F32) height)
|
||||
@@ -267,8 +261,8 @@ int main(int argc, char **argv)
|
||||
if(e.type==SDL_EVENT_MOUSE_BUTTON_DOWN && e.button.button == SDL_BUTTON_LEFT) {
|
||||
switch(game->editor.mode){
|
||||
case G_EDITOR_MODE_TILE: {
|
||||
F32 tilex = (S32)(game->editor.cursor.x+TILE_SIZE/2);
|
||||
F32 tiley = (S32)(game->editor.cursor.y+TILE_SIZE/2);
|
||||
F32 tilex = (F32) (S32)(game->editor.cursor.x+TILE_SIZE/2);
|
||||
F32 tiley = (F32) (S32)(game->editor.cursor.y+TILE_SIZE/2);
|
||||
game->world->map[(S32)tilex + (S32)tiley * 96] = game->editor.currentAsset;
|
||||
break;
|
||||
}
|
||||
@@ -285,7 +279,7 @@ 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
|
||||
// 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(
|
||||
@@ -353,10 +347,10 @@ int main(int argc, char **argv)
|
||||
|
||||
if(!game->editor.enabled) {
|
||||
UpdateWorld(1.0f / 60.0f, game->world);
|
||||
|
||||
game->camera.p.x = game->world->player.collision.pos.x;
|
||||
game->camera.p.y = game->world->player.collision.pos.y;
|
||||
}
|
||||
D_AnimationUpdate(&animation, 1.0f / 250.0f);
|
||||
}
|
||||
|
||||
int w, h;
|
||||
SDL_GetWindowSizeInPixels(window, &w, &h);
|
||||
@@ -396,17 +390,16 @@ int main(int argc, char **argv)
|
||||
|
||||
RenderWorld(game->world, &game->draw);
|
||||
|
||||
R2f aframe = D_AnimationFrame(&animation);
|
||||
D_Rect(&game->draw, 0, 0, .texture = animation.id, .uv = aframe, .flags = D_RECT_UV_ASPECT);
|
||||
D_Text(&game->draw, game->draw.fonts, S("Small Test"), 0, 0);
|
||||
|
||||
if(game->editor.enabled) {
|
||||
G_Editor editor = game->editor;
|
||||
F32 tilex = floor(editor.cursor.x+TILE_SIZE/2);
|
||||
F32 tiley = floor(editor.cursor.y+TILE_SIZE/2);
|
||||
F32 tilex = cast(F32) floor(editor.cursor.x+TILE_SIZE/2);
|
||||
F32 tiley = cast(F32) floor(editor.cursor.y+TILE_SIZE/2);
|
||||
switch(game->editor.mode) {
|
||||
case G_EDITOR_MODE_TILE: {
|
||||
World_Tile asset = game->world->tileTypes[editor.currentAsset];
|
||||
D_Rect(&game->draw, tilex, tiley, .texture=asset.tile, .angle=asset.rotation);
|
||||
D_Rect(&game->draw, tilex, tiley, .texture=asset.tile, .angle=(F32) asset.rotation);
|
||||
break;
|
||||
}
|
||||
case G_EDITOR_MODE_PROP: {
|
||||
@@ -415,7 +408,7 @@ int main(int argc, char **argv)
|
||||
break;
|
||||
}
|
||||
case G_EDITOR_MODE_HITBOX: {
|
||||
for(int i = 0; i < game->world->hitboxCount; i++) {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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,80 @@
|
||||
#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;
|
||||
|
||||
player->bulletsLoaded = PLAYER_BULLET_COUNT;
|
||||
player->currentArea = WORLD_AREA_OUTSIDE;
|
||||
|
||||
player->health = 3;
|
||||
|
||||
player->collision.size.x = 1;
|
||||
player->collision.size.x = 2;
|
||||
|
||||
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 +108,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 +121,7 @@ void PlayerInput(SDL_Event *event, Player *player)
|
||||
player->reloadTimer = PLAYER_RELOAD_TIME;
|
||||
printf("reloading\n");
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerUpdate(F32 delta, Player *player) {
|
||||
@@ -59,16 +133,28 @@ void PlayerUpdate(F32 delta, Player *player) {
|
||||
}
|
||||
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) {
|
||||
@@ -80,3 +166,20 @@ void PlayerUpdate(F32 delta, Player *player) {
|
||||
player->collision.pos.x += dir.x;
|
||||
player->collision.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->collision.pos.x, player->collision.pos.y, .texture = tid, .uv = pframe, .flags = flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,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,
|
||||
@@ -72,10 +72,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.collision.pos.x, world->player.collision.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,10 +29,16 @@ struct Player
|
||||
U32 bulletsLoaded;
|
||||
ControlState controls;
|
||||
V2f shotPos;
|
||||
|
||||
G_Outfit outfit;
|
||||
|
||||
U32 health;
|
||||
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);
|
||||
|
||||
|
||||