bullet trail testing

This commit is contained in:
jacob 2024-08-13 19:29:03 -05:00
parent 45c6d94009
commit ca6c058675
4 changed files with 42 additions and 3 deletions

BIN
res/graphics/bullet.ase (Stored with Git LFS)

Binary file not shown.

View File

@ -14,6 +14,7 @@ enum entity_prop {
ENTITY_PROP_CAMERA, ENTITY_PROP_CAMERA,
ENTITY_PROP_CAMERA_ACTIVE, ENTITY_PROP_CAMERA_ACTIVE,
ENTITY_PROP_BULLET,
ENTITY_PROP_WEAPON, ENTITY_PROP_WEAPON,
ENTITY_PROP_TRIGGERING_EQUIPPED, ENTITY_PROP_TRIGGERING_EQUIPPED,
ENTITY_PROP_TRIGGERED_THIS_TICK, ENTITY_PROP_TRIGGERED_THIS_TICK,
@ -122,6 +123,11 @@ struct entity {
f32 trigger_delay; /* Minimum time between triggers */ f32 trigger_delay; /* Minimum time between triggers */
f32 last_triggered; f32 last_triggered;
/* ====================================================================== */
/* Bullet */
struct entity_handle bullet_src_ent;
/* ====================================================================== */ /* ====================================================================== */
/* Testing */ /* Testing */

View File

@ -557,15 +557,21 @@ INTERNAL void game_update(struct game_cmd_array game_cmds)
struct v2 out_pos = xform_mul_v2(sprite_xform, out_slice.center); struct v2 out_pos = xform_mul_v2(sprite_xform, out_slice.center);
struct v2 out_vec = xform_basis_mul_v2(sprite_xform, out_slice.dir); struct v2 out_vec = xform_basis_mul_v2(sprite_xform, out_slice.dir);
out_vec = v2_norm(out_vec); out_vec = v2_norm(out_vec);
out_vec = v2_mul(out_vec, 5); out_vec = v2_mul(out_vec, 25);
{ {
/* FIXME: Weapon velocity should affect bullet velocity
* (This should also make bullet_src_ent unnecessary for
* drawing bullet trails) */
/* Spawn bullet */ /* Spawn bullet */
struct entity *bullet = entity_alloc(root); struct entity *bullet = entity_alloc(root);
bullet->sprite = sprite_tag_from_path(STR("res/graphics/bullet.ase")); bullet->sprite = sprite_tag_from_path(STR("res/graphics/bullet.ase"));
struct xform bullet_xf = XFORM_POS(out_pos); struct xform bullet_xf = XFORM_POS(out_pos);
entity_set_xform(bullet, bullet_xf); entity_set_xform(bullet, bullet_xf);
bullet->velocity = out_vec; bullet->velocity = out_vec;
bullet->bullet_src_ent = ent->handle;
entity_enable_prop(bullet, ENTITY_PROP_BULLET);
} }
} }
} }

View File

@ -809,6 +809,33 @@ INTERNAL void user_update(void)
struct xform sprite_xform = xf; struct xform sprite_xform = xf;
/* Draw bullet trail */
if (entity_has_prop(ent, ENTITY_PROP_BULLET)) {
f32 max_len = 0.75;
f32 thickness = 0.0025;
u32 color = RGBA_32_F(1, 1, 1, 1);
struct v2 end = xf.og;
struct v2 start;
struct entity *src = entity_from_handle(store, ent->bullet_src_ent);
if (src->valid) {
start = xform_mul_v2(src->sprite_local_xform, sprite_sheet_get_slice(sprite_sheet_from_tag_await(sprite_frame_scope, src->sprite), STR("out"), src->animation_frame).center);
start = xform_mul_v2(entity_get_xform(src), start);
} else {
start = v2_sub(end, v2_div(ent->velocity, 50));
}
struct v2 rel = v2_sub(start, end);
if (v2_len(rel) > max_len) {
rel = v2_mul(v2_norm(rel), max_len);
start = v2_add(end, rel);
}
draw_solid_line(G.world_canvas, start, end, thickness, color);
}
/* Draw sprite */ /* Draw sprite */
if (!sprite_tag_is_nil(sprite)) { if (!sprite_tag_is_nil(sprite)) {
/* Calculate sprite xform */ /* Calculate sprite xform */