diff --git a/src/k_objects.h b/src/k_objects.h index fc15a2153..4cc4ed1c3 100644 --- a/src/k_objects.h +++ b/src/k_objects.h @@ -56,5 +56,6 @@ void Obj_DuelBombInit(mobj_t *bomb); /* Broly Ki */ mobj_t *Obj_SpawnBrolyKi(mobj_t *source, tic_t duration); +void Obj_BrolyKiThink(mobj_t *ki); #endif/*k_objects_H*/ diff --git a/src/objects/broly.c b/src/objects/broly.c index 8c743a64a..d041c23b7 100644 --- a/src/objects/broly.c +++ b/src/objects/broly.c @@ -2,9 +2,33 @@ #include "../info.h" #include "../k_kart.h" #include "../k_objects.h" +#include "../m_easing.h" #include "../p_local.h" #include "../s_sound.h" +// TODO: generic function +static void P_InstaScale(mobj_t *thing, fixed_t scale) +{ + P_SetScale(thing, scale); + thing->destscale = scale; +} + +/* An object may not be visible on the same tic: + 1) that it spawned + 2) that it cycles to the next state */ +#define BUFFER_TICS (2) + +#define broly_duration(o) ((o)->extravalue1) +#define broly_maxscale(o) ((o)->extravalue2) + +static inline fixed_t +get_unit_linear (const mobj_t *x) +{ + const tic_t t = (x->tics - BUFFER_TICS); + + return t * FRACUNIT / broly_duration(x); +} + mobj_t * Obj_SpawnBrolyKi ( mobj_t * source, @@ -25,13 +49,10 @@ Obj_SpawnBrolyKi x->color = source->color; x->hitlag = 0; // do not copy source hitlag - P_SetScale(x, 64 * mapobjectscale); - x->scalespeed = x->scale / duration; + broly_maxscale(x) = 64 * mapobjectscale; + broly_duration(x) = duration; - // The last tic doesn't actually get rendered so in order - // to show scale = destscale, add one buffer tic. - x->tics = (duration + 1); - x->destscale = 1; // 0 also doesn't work + x->tics = (duration + BUFFER_TICS); K_ReduceVFX(x, NULL); @@ -39,3 +60,13 @@ Obj_SpawnBrolyKi return x; } + +void +Obj_BrolyKiThink (mobj_t *x) +{ + const fixed_t + t = get_unit_linear(x), + n = Easing_OutSine(t, 0, broly_maxscale(x)); + + P_InstaScale(x, n); +} diff --git a/src/p_mobj.c b/src/p_mobj.c index efddf4fb8..c2fc1dd58 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -6508,6 +6508,9 @@ static void P_MobjSceneryThink(mobj_t *mobj) case MT_DRIFTELECTRICSPARK: mobj->renderflags ^= RF_DONTDRAW; break; + case MT_BROLY: + Obj_BrolyKiThink(mobj); + break; case MT_VWREF: case MT_VWREB: {