From 53158b25cc07e98b509b263942fa048e3955eeb0 Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Wed, 15 Oct 2025 13:02:02 +0100 Subject: [PATCH] Add shooting recoil --- game.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/game.c b/game.c index f35f068..1061342 100644 --- a/game.c +++ b/game.c @@ -10,6 +10,7 @@ #include #define SHIP_COLLIDE_R 0.05 +#define SHIP_MASS 0.5 #define FIRE_MEAN -0.15 #define FIRE_JITTER 0.01 @@ -138,7 +139,7 @@ static void shoot() if (entity_count >= MAX_ENTITIES || shape_count >= MAX_SHAPES) return; - const entity_t *ship = entities + ship_entity_id; + entity_t *ship = entities + ship_entity_id; const shape_t *ship_shape = shapes + ship_shape_id; unsigned id; @@ -155,6 +156,11 @@ static void shoot() s->visible = true; s->vert_count = NELEMS(shot_verts); memcpy(s->verts, shot_verts, sizeof(shot_verts)); + + const vec2_t ship_p = vec2_scale(ship->vel, SHIP_MASS); + const vec2_t shot_p = vec2_scale(e->vel, SHOT_MASS); + const vec2_t new_ship_p = vec2_sub(ship_p, shot_p); + ship->vel = vec2_scale(new_ship_p, 1 / SHIP_MASS); } static entity_t *gen_asteroid(float r_mean, unsigned *id_out)