begin firing/bullet work

This commit is contained in:
jacob 2024-08-12 19:41:39 -05:00
parent 81d02f3c80
commit 57e0d0a84a
4 changed files with 26 additions and 7 deletions

View File

@ -7,7 +7,6 @@
enum entity_prop {
ENTITY_PROP_NONE,
ENTITY_PROP_ANIMATING,
ENTITY_PROP_PLAYER_CONTROLLED,
ENTITY_PROP_CAMERA,
ENTITY_PROP_CAMERA_ACTIVE,

View File

@ -115,7 +115,6 @@ INTERNAL void spawn_test_entities(void)
struct xform xf = XFORM_TRS(.t = pos, .r = r, .s = size);
entity_set_xform(e, xf);
entity_enable_prop(e, ENTITY_PROP_ANIMATING);
e->sprite = sprite_tag_from_path(STR("res/graphics/tim.ase"));
e->sprite_span_name = STR("idle.unarmed");
//e->sprite_span_name = STR("idle.one_handed");
@ -142,7 +141,6 @@ INTERNAL void spawn_test_entities(void)
struct xform xf = XFORM_TRS(.t = pos, .r = r, .s = size);
entity_set_local_xform(e, xf);
entity_enable_prop(e, ENTITY_PROP_ANIMATING);
e->sprite = sprite_tag_from_path(STR("res/graphics/gun.ase"));
entity_enable_prop(e, ENTITY_PROP_WEAPON);
@ -226,8 +224,7 @@ INTERNAL void game_update(struct game_cmd_array game_cmds)
/* Clear level */
case GAME_CMD_KIND_CLEAR_ALL: {
logf_info("Clearing level");
u64 count = store->count;
for (u64 i = 0; i < count; ++i) {
for (u64 i = 0; i < store->count; ++i) {
struct entity *ent = &store->entities[i];
if (ent->valid && !ent->is_root) {
entity_release(store, ent);
@ -256,7 +253,7 @@ INTERNAL void game_update(struct game_cmd_array game_cmds)
/* Update animation */
if (entity_has_prop(ent, ENTITY_PROP_ANIMATING)) {
{
struct sprite_sheet *sheet = sprite_sheet_from_tag_await(sprite_frame_scope, ent->sprite);
struct sprite_sheet_span span = sprite_sheet_get_span(sheet, ent->sprite_span_name);
@ -281,7 +278,7 @@ INTERNAL void game_update(struct game_cmd_array game_cmds)
ent->animation_frame = frame_index;
}
/* Update sprite xform */
/* Update sprite local xform */
struct sprite_sheet *sheet = sprite_sheet_from_tag_await(sprite_frame_scope, ent->sprite);
struct sprite_sheet_slice slice = sprite_sheet_get_slice(sheet, STR("pivot"), ent->animation_frame);
@ -423,10 +420,27 @@ INTERNAL void game_update(struct game_cmd_array game_cmds)
/* Fire weapon */
if (entity_has_prop(ent, ENTITY_PROP_WEAPON)) {
#if 1
f32 r = 1.0f * ((f32)sys_rand_u32() / U32_MAX);
f32 g = 1.0f * ((f32)sys_rand_u32() / U32_MAX);
f32 b = 1.0f * ((f32)sys_rand_u32() / U32_MAX);
ent->sprite_tint = RGBA_32_F(r, g, b, 1);
#else
struct xform xf = entity_get_xform(ent);
struct sprite_tag sprite = ent->sprite;
u32 animation_frame = ent->animation_frame;
struct xform sprite_xform = xform_mul(xf, ent->sprite_local_xform);
struct sprite_sheet *sheet = sprite_sheet_from_tag_await(sprite_frame_scope, sprite);
struct sprite_sheet_slice out_slice = sprite_sheet_get_slice(sheet, STR("out"), animation_frame);
struct v2 out_pos = xform_mul_v2(sprite_xform, out_slice.center);
struct v2 out_dir = xform_basis_mul_v2(sprite_xform, out_slice.dir);
(UNUSED)out_pos;
(UNUSED)out_dir;
#endif
}
}

View File

@ -9,6 +9,11 @@ void world_alloc(struct world *world)
world->entity_store = entity_store_alloc();
}
void world_release(struct world *world)
{
entity_store_release(world->entity_store);
}
void world_copy_replace(struct world *dest, struct world *src)
{
__prof;

View File

@ -16,6 +16,7 @@ struct world {
};
void world_alloc(struct world *world);
void world_release(struct world *world);
void world_copy_replace(struct world *dest, struct world *src);
#endif