mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-04-27 04:21:47 +00:00
Broly: convert to C++
This commit is contained in:
parent
940ce281ae
commit
dc20fca17d
3 changed files with 107 additions and 78 deletions
|
|
@ -8,7 +8,7 @@ target_sources(SRB2SDL2 PRIVATE
|
||||||
orbinaut.c
|
orbinaut.c
|
||||||
jawz.c
|
jawz.c
|
||||||
duel-bomb.c
|
duel-bomb.c
|
||||||
broly.c
|
broly.cpp
|
||||||
ufo.c
|
ufo.c
|
||||||
monitor.c
|
monitor.c
|
||||||
item-spot.c
|
item-spot.c
|
||||||
|
|
|
||||||
|
|
@ -1,77 +0,0 @@
|
||||||
#include "../doomdef.h"
|
|
||||||
#include "../info.h"
|
|
||||||
#include "../k_kart.h"
|
|
||||||
#include "../k_objects.h"
|
|
||||||
#include "../m_easing.h"
|
|
||||||
#include "../p_local.h"
|
|
||||||
#include "../s_sound.h"
|
|
||||||
|
|
||||||
/* 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,
|
|
||||||
tic_t duration)
|
|
||||||
{
|
|
||||||
mobj_t *x;
|
|
||||||
|
|
||||||
if (duration <= 0)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
x = P_SpawnMobjFromMobj(
|
|
||||||
source, 0, 0, 0, MT_BROLY);
|
|
||||||
|
|
||||||
P_SetTarget(&x->target, source);
|
|
||||||
|
|
||||||
// Shrink into center of source object.
|
|
||||||
x->z = (source->z + source->height / 2);
|
|
||||||
|
|
||||||
x->colorized = true;
|
|
||||||
x->color = source->color;
|
|
||||||
x->hitlag = 0; // do not copy source hitlag
|
|
||||||
|
|
||||||
broly_maxscale(x) = 64 * mapobjectscale;
|
|
||||||
broly_duration(x) = duration;
|
|
||||||
|
|
||||||
x->tics = (duration + BUFFER_TICS);
|
|
||||||
|
|
||||||
K_ReduceVFXForEveryone(x);
|
|
||||||
|
|
||||||
S_StartSound(x, sfx_cdfm74);
|
|
||||||
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean
|
|
||||||
Obj_BrolyKiThink (mobj_t *x)
|
|
||||||
{
|
|
||||||
if (broly_duration(x) <= 0)
|
|
||||||
{
|
|
||||||
P_RemoveMobj(x);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fixed_t
|
|
||||||
t = get_unit_linear(x),
|
|
||||||
n = Easing_OutSine(t, 0, broly_maxscale(x));
|
|
||||||
|
|
||||||
P_InstaScale(x, n);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
106
src/objects/broly.cpp
Normal file
106
src/objects/broly.cpp
Normal file
|
|
@ -0,0 +1,106 @@
|
||||||
|
// DR. ROBOTNIK'S RING RACERS
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Copyright (C) 2023 by James Robert Roman
|
||||||
|
//
|
||||||
|
// This program is free software distributed under the
|
||||||
|
// terms of the GNU General Public License, version 2.
|
||||||
|
// See the 'LICENSE' file for more details.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "../math/fixed.hpp"
|
||||||
|
#include "../mobj.hpp"
|
||||||
|
|
||||||
|
#include "../doomdef.h"
|
||||||
|
#include "../info.h"
|
||||||
|
#include "../k_kart.h"
|
||||||
|
#include "../k_objects.h"
|
||||||
|
#include "../m_easing.h"
|
||||||
|
#include "../p_local.h"
|
||||||
|
#include "../s_sound.h"
|
||||||
|
|
||||||
|
using srb2::Mobj;
|
||||||
|
using srb2::math::Fixed;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
struct Broly : Mobj
|
||||||
|
{
|
||||||
|
/* An object may not be visible on the same tic:
|
||||||
|
1) that it spawned
|
||||||
|
2) that it cycles to the next state */
|
||||||
|
static constexpr int kBufferTics = 2;
|
||||||
|
|
||||||
|
void extravalue1() = delete;
|
||||||
|
tic_t duration() const { return mobj_t::extravalue1; }
|
||||||
|
void duration(tic_t n) { mobj_t::extravalue1 = n; }
|
||||||
|
|
||||||
|
void extravalue2() = delete;
|
||||||
|
Fixed max_scale() const { return mobj_t::extravalue2; }
|
||||||
|
void max_scale(Fixed n) { mobj_t::extravalue2 = n; }
|
||||||
|
|
||||||
|
bool valid() const { return duration(); }
|
||||||
|
|
||||||
|
tic_t remaining() const { return tics - kBufferTics; }
|
||||||
|
|
||||||
|
Fixed linear() const { return (remaining() * FRACUNIT) / duration(); }
|
||||||
|
|
||||||
|
static Broly* spawn(Mobj* source, tic_t duration)
|
||||||
|
{
|
||||||
|
if (duration == 0)
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Broly* x = source->spawn_from<Broly>({}, MT_BROLY);
|
||||||
|
|
||||||
|
x->target(source);
|
||||||
|
|
||||||
|
// Shrink into center of source object.
|
||||||
|
x->z = (source->z + source->height / 2);
|
||||||
|
|
||||||
|
x->colorized = true;
|
||||||
|
x->color = source->color;
|
||||||
|
x->mobj_t::hitlag = 0; // do not copy source hitlag
|
||||||
|
|
||||||
|
x->max_scale(64 * mapobjectscale);
|
||||||
|
x->duration(duration);
|
||||||
|
|
||||||
|
x->tics = (duration + kBufferTics);
|
||||||
|
|
||||||
|
K_ReduceVFXForEveryone(x);
|
||||||
|
|
||||||
|
x->voice(sfx_cdfm74);
|
||||||
|
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool think()
|
||||||
|
{
|
||||||
|
if (!valid())
|
||||||
|
{
|
||||||
|
remove();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
scale(Easing_OutSine(linear(), 0, max_scale()));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}; // namespace
|
||||||
|
|
||||||
|
mobj_t *
|
||||||
|
Obj_SpawnBrolyKi
|
||||||
|
( mobj_t * source,
|
||||||
|
tic_t duration)
|
||||||
|
{
|
||||||
|
return Broly::spawn(static_cast<Mobj*>(source), duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean
|
||||||
|
Obj_BrolyKiThink (mobj_t *x)
|
||||||
|
{
|
||||||
|
return static_cast<Broly*>(x)->think();
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue