Add shooting recoil
This commit is contained in:
8
game.c
8
game.c
@@ -10,6 +10,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#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)
|
||||
|
||||
Reference in New Issue
Block a user