cap player knockback when swarmed

This commit is contained in:
Lephenixnoir 2022-02-13 16:02:36 +01:00
parent bf1f585889
commit d330c22d66
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
4 changed files with 18 additions and 0 deletions

View File

@ -45,6 +45,15 @@ void mechanical_move(entity_t *e, vec2 direction, fixed_t dt, map_t const *map)
fixed_t friction_x = fmul(fmul(-target.x, limits->friction), dt);
fixed_t friction_y = fmul(fmul(-target.y, limits->friction), dt);
/* Limit maximum disruption (knockback) when it reaches extremes */
fixed_t dv2 = fmul(m->vdx, m->vdx) + fmul(m->vdy, m->vdy);
fixed_t max_dv = limits->max_disruption_speed;
if(dv2 > fmul(max_dv, max_dv)) {
fixed_t dv = fsqrt(dv2);
m->vdx = fmul(fdiv(m->vdx, dv), max_dv);
m->vdy = fmul(fdiv(m->vdy, dv), max_dv);
}
/* Get there exponentially fast */
m->vx = target.x + friction_x + m->vdx;
m->vy = target.y + friction_y + m->vdy;

View File

@ -25,6 +25,10 @@ typedef struct
/* Dash duration (s) */
fixed_t dash_duration;
/* Maximum disruption speed, mainly avoids extreme knockback on players
when attacked for multiple sides at once */
fixed_t max_disruption_speed;
} mechanical_limits_t;
typedef struct

View File

@ -24,6 +24,7 @@ static enemy_t const slime_1 = {
.limits = {
.max_speed = fix(1),
.friction = fix(0.6),
.max_disruption_speed = fix(999.0),
},
.stats = {
.HP = fix(1.4),
@ -44,6 +45,7 @@ static enemy_t const bat_2 = {
.limits = {
.max_speed = fix(1.8),
.friction = fix(0.8),
.max_disruption_speed = fix(999.0),
},
.stats = {
.HP = fix(1.5),
@ -64,6 +66,7 @@ static enemy_t const fire_slime_4 = {
.limits = {
.max_speed = fix(1),
.friction = fix(0.6),
.max_disruption_speed = fix(999.0),
},
.stats = {
.HP = fix(1.4),
@ -84,6 +87,7 @@ static enemy_t const gunslinger_8 = {
.limits = {
.max_speed = fix(1.8),
.friction = fix(0.8),
.max_disruption_speed = fix(999.0),
},
.stats = {
.HP = fix(1.3),

View File

@ -93,6 +93,7 @@ int main(void)
.friction = fix(0.7),
.dash_speed = fix(20),
.dash_duration = fix(1) / 8,
.max_disruption_speed = fix(3.0),
},
.stat_model = {
.HP = fix(1.5),