add the shock mechanic

This commit is contained in:
Lephenixnoir 2021-08-30 14:53:02 +02:00
parent 59a26e0d1d
commit dc37d1f533
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
3 changed files with 34 additions and 11 deletions

Binary file not shown.

View File

@ -224,11 +224,15 @@ effect_area_t *effect_area_new_attack(uint16_t type, entity_t *e, int facing)
if(type == EFFECT_ATTACK_HIT
|| type == EFFECT_ATTACK_SLASH
|| type == EFFECT_ATTACK_IMPALE
|| type == EFFECT_ATTACK_SHOCK) {
|| type == EFFECT_ATTACK_IMPALE) {
area->data.slash.strength = e->ATK;
area->data.slash.dir = facing;
}
else if(type == EFFECT_ATTACK_SHOCK) {
area->data.shock.strength = e->ATK;
area->data.shock.origin = entity_pos(e);
area->repeat_delay = fix(0.15);
}
effect_area_set_anim(area, anim);
return area;
@ -250,7 +254,7 @@ static effect_area_record_t *effect_record(effect_area_t *ea, entity_t *e)
return NULL;
}
static bool slash_hit_apply(game_t *game, effect_area_t *ea, entity_t *e)
static bool attack_apply(game_t *game, effect_area_t *ea, entity_t *e)
{
/* No friendly fire */
bool origin_is_monster = (ea->origin->identity != 0);
@ -260,15 +264,31 @@ static bool slash_hit_apply(game_t *game, effect_area_t *ea, entity_t *e)
/* Dash invincibility */
if(entity_dashing(e)) return false;
/* Inflict damage */
int damage = entity_damage(e, ea->data.slash.strength);
/* Knockback */
fixed_t r = (rand() & (fix(0.25)-1)) + fix(0.875);
/* Half knockback against players */
if(e->identity == 0) r /= 2;
fpoint_t dir = fdir(ea->data.slash.dir);
fpoint_t dir = { 0, 0 };
int damage = 0;
if(ea->type == EFFECT_ATTACK_HIT
|| ea->type == EFFECT_ATTACK_SLASH
|| ea->type == EFFECT_ATTACK_IMPALE) {
dir = fdir(ea->data.slash.dir);
damage = ea->data.slash.strength;
}
else if(ea->type == EFFECT_ATTACK_SHOCK) {
dir.x = e->movement.x - ea->data.shock.origin.x;
dir.y = e->movement.y - ea->data.shock.origin.y;
dir = fnormalize(dir);
damage = ea->data.shock.strength * 3 / 2;
}
/* Inflict damage */
damage = entity_damage(e, damage);
/* Apply knockback */
e->movement.vx += fmul(dir.x, fmul(r, KNOCKBACK_SPEED));
e->movement.vy += fmul(dir.y, fmul(r, KNOCKBACK_SPEED));
@ -295,8 +315,9 @@ void effect_area_apply(game_t *game, effect_area_t *ea, entity_t *e)
if(ea->type == EFFECT_ATTACK_HIT
|| ea->type == EFFECT_ATTACK_SLASH
|| ea->type == EFFECT_ATTACK_IMPALE)
was_hit = slash_hit_apply(game, ea, e);
|| ea->type == EFFECT_ATTACK_IMPALE
|| ea->type == EFFECT_ATTACK_SHOCK)
was_hit = attack_apply(game, ea, e);
if(!was_hit) return;

View File

@ -166,10 +166,12 @@ typedef struct effect_area {
uint16_t type;
/* Effect data (type-dependent) */
union {
/* EFFECT_HIT: source and ATK strength */
/* EFFECT_ATTACK_HIT: source and ATK strength */
struct { int strength; int dir; } hit;
/* EFFECT_SLASH: source and ATK strength */
/* EFFECT_ATTACK_SLASH: source and ATK strength */
struct { int strength; int dir; } slash;
/* EFFECT_ATTACK_SHOCK: origin and ATK strength */
struct { int strength; fpoint_t origin; } shock;
} data;
} effect_area_t;