From 5d6835ece38bf455951e242508a5f9f0f397c112 Mon Sep 17 00:00:00 2001 From: jacob Date: Sat, 11 Jan 2025 10:22:27 -0600 Subject: [PATCH] bullet_has_hit --- src/entity.h | 1 + src/game.c | 52 +++++++++++++++++++++++++++------------------------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/entity.h b/src/entity.h index 206bf7ab..9a6d6fa1 100644 --- a/src/entity.h +++ b/src/entity.h @@ -229,6 +229,7 @@ struct entity { struct v2 bullet_src_pos; struct v2 bullet_src_dir; f32 bullet_impulse; + b32 bullet_has_hit; /* Has the bullet hit a target this tick */ /* ====================================================================== */ /* Testing */ diff --git a/src/game.c b/src/game.c index beeec1ba..be5b21cd 100644 --- a/src/game.c +++ b/src/game.c @@ -960,33 +960,35 @@ INTERNAL void game_update(struct game_cmd_array game_cmds) if (entity_has_prop(e0, ENTITY_PROP_BULLET) || entity_has_prop(e1, ENTITY_PROP_BULLET)) { struct entity *bullet = entity_has_prop(e0, ENTITY_PROP_BULLET) ? e0 : e1; struct entity *target = e0 == bullet ? e1 : e0; + if (!bullet->bullet_has_hit) { + bullet->bullet_has_hit = true; + (UNUSED)bullet; + (UNUSED)target; + #if 0 + { + /* Set bullet position to hit position */ + struct xform xf = entity_get_xform(bullet); + xf.og = event->point; + entity_set_xform(bullet, xf); + /* Release after publish so user sees bullet in final postiion */ + entity_enable_prop(bullet, ENTITY_PROP_RELEASE_AFTER_PUBLISH); + } + #else + entity_enable_prop(bullet, ENTITY_PROP_RELEASE_BEFORE_PUBLISH); + #endif - (UNUSED)bullet; - (UNUSED)target; -#if 0 - { - /* Set bullet position to hit position */ - struct xform xf = entity_get_xform(bullet); - xf.og = event->point; - entity_set_xform(bullet, xf); - /* Release after publish so user sees bullet in final postiion */ - entity_enable_prop(bullet, ENTITY_PROP_RELEASE_AFTER_PUBLISH); - } -#else - entity_enable_prop(bullet, ENTITY_PROP_RELEASE_BEFORE_PUBLISH); -#endif + /* Create test blood */ + /* TODO: Remove this */ + { + struct xform xf = XFORM_TRS(.t = event->point); + struct entity *decal = entity_alloc(root); + decal->sprite = sprite_tag_from_path(STR("res/graphics/blood.ase")); + entity_set_xform(decal, xf); - /* Create test blood */ - /* TODO: Remove this */ - { - struct xform xf = XFORM_TRS(.t = event->point); - struct entity *decal = entity_alloc(root); - decal->sprite = sprite_tag_from_path(STR("res/graphics/blood.ase")); - entity_set_xform(decal, xf); - - entity_enable_prop(decal, ENTITY_PROP_PHYSICAL_KINEMATIC); - decal->linear_velocity = v2_mul(v2_norm(event->normal), 0.5f); - decal->angular_velocity = 1 - (((f32)sys_rand_u32() / (f32)U32_MAX) * 2); + entity_enable_prop(decal, ENTITY_PROP_PHYSICAL_KINEMATIC); + decal->linear_velocity = v2_mul(v2_norm(event->normal), 0.5f); + decal->angular_velocity = 1 - (((f32)sys_rand_u32() / (f32)U32_MAX) * 2); + } } } }