Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 1fd43da

Browse files
committed
Implement ALWAYSPINGPONG
1 parent c66eb52 commit 1fd43da

File tree

3 files changed

+59
-42
lines changed

3 files changed

+59
-42
lines changed

Entities/MOSRotating.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,43 +1614,6 @@ void MOSRotating::Update()
16141614

16151615
MOSprite::Update();
16161616

1617-
////////////////////////////////////////
1618-
// Animate the sprite, if applicable
1619-
1620-
if (m_FrameCount > 1)
1621-
{
1622-
if (m_SpriteAnimMode == ALWAYSLOOP)
1623-
{
1624-
float cycleTime = ((long)m_SpriteAnimTimer.GetElapsedSimTimeMS()) % m_SpriteAnimDuration;
1625-
m_Frame = floorf((cycleTime / (float)m_SpriteAnimDuration) * (float)m_FrameCount);
1626-
}
1627-
else if (m_SpriteAnimMode == ALWAYSRANDOM)
1628-
{
1629-
if (m_SpriteAnimTimer.GetElapsedSimTimeMS() > (m_SpriteAnimDuration / m_FrameCount))
1630-
{
1631-
// Quick switch to other frame if only two
1632-
if (m_FrameCount == 2)
1633-
m_Frame = m_Frame == 0 ? 1 : 0;
1634-
else
1635-
{
1636-
int prevFrame = m_Frame;
1637-
// Keep trying ot find a new frame
1638-
do
1639-
{
1640-
m_Frame = floorf((float)m_FrameCount * PosRand());
1641-
}
1642-
while (m_Frame == prevFrame);
1643-
}
1644-
1645-
m_SpriteAnimTimer.Reset();
1646-
}
1647-
}
1648-
else if (m_SpriteAnimMode == ALWAYSPINGPONG)
1649-
{
1650-
1651-
}
1652-
}
1653-
16541617
if (m_InheritEffectRotAngle)
16551618
m_EffectRotAngle = m_Rotation.GetRadAngle();
16561619

Entities/MOSprite.cpp

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ void MOSprite::Clear()
3737
m_SpriteAnimMode = NOANIM;
3838
m_SpriteAnimDuration = 500;
3939
m_SpriteAnimTimer.Reset();
40+
m_SpriteAnimIsReversingFrames = false;
4041
m_HFlipped = false;
4142
m_MaxRadius = 1;
4243
m_MaxDiameter = 2;
@@ -451,7 +452,7 @@ Vector MOSprite::UnRotateOffset(const Vector &offset) const
451452
return rotOff;
452453
}
453454

454-
/*
455+
455456
//////////////////////////////////////////////////////////////////////////////////////////
456457
// Pure v. method: Update
457458
//////////////////////////////////////////////////////////////////////////////////////////
@@ -460,8 +461,59 @@ Vector MOSprite::UnRotateOffset(const Vector &offset) const
460461
void MOSprite::Update()
461462
{
462463
MovableObject::Update();
464+
465+
////////////////////////////////////////
466+
// Animate the sprite, if applicable
467+
468+
if (m_FrameCount > 1)
469+
{
470+
if (m_SpriteAnimMode == ALWAYSLOOP)
471+
{
472+
float cycleTime = ((long)m_SpriteAnimTimer.GetElapsedSimTimeMS()) % m_SpriteAnimDuration;
473+
m_Frame = floorf((cycleTime / (float)m_SpriteAnimDuration) * (float)m_FrameCount);
474+
}
475+
else if (m_SpriteAnimMode == ALWAYSRANDOM)
476+
{
477+
if (m_SpriteAnimTimer.GetElapsedSimTimeMS() > (m_SpriteAnimDuration / m_FrameCount))
478+
{
479+
// Quick switch to other frame if only two
480+
if (m_FrameCount == 2)
481+
m_Frame = m_Frame == 0 ? 1 : 0;
482+
else
483+
{
484+
int prevFrame = m_Frame;
485+
// Keep trying ot find a new frame
486+
do
487+
{
488+
m_Frame = floorf((float)m_FrameCount * PosRand());
489+
} while (m_Frame == prevFrame);
490+
}
491+
492+
m_SpriteAnimTimer.Reset();
493+
}
494+
}
495+
else if (m_SpriteAnimMode == ALWAYSPINGPONG)
496+
{
497+
int realFrameCount = m_FrameCount - 1;
498+
float perFrameTime = ((m_SpriteAnimDuration / m_FrameCount) / 2);
499+
if (m_SpriteAnimTimer.IsPastSimMS(perFrameTime))
500+
{
501+
m_SpriteAnimTimer.Reset();
502+
(m_SpriteAnimIsReversingFrames) ? (m_Frame--) : (m_Frame++);
503+
}
504+
505+
if (m_Frame == realFrameCount)
506+
{
507+
m_SpriteAnimIsReversingFrames = true;
508+
}
509+
else if (m_Frame == 0)
510+
{
511+
m_SpriteAnimIsReversingFrames = false;
512+
}
513+
}
514+
}
463515
}
464-
*/
516+
465517

466518
//////////////////////////////////////////////////////////////////////////////////////////
467519
// Virtual method: Draw

Entities/MOSprite.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,16 +586,16 @@ ENTITYALLOCATION(MOSprite)
586586

587587
virtual void SetSpriteAnimDuration(int newDuration) { m_SpriteAnimDuration = newDuration; }
588588

589-
/*
589+
590590
//////////////////////////////////////////////////////////////////////////////////////////
591591
// Virtual method: Update
592592
//////////////////////////////////////////////////////////////////////////////////////////
593593
// Description: Updates this MovableObject. Supposed to be done every frame.
594594
// Arguments: None.
595595
// Return value: None.
596596

597-
virtual void Update() = 0;
598-
*/
597+
virtual void Update();
598+
599599

600600
//////////////////////////////////////////////////////////////////////////////////////////
601601
// Virtual method: Draw
@@ -651,6 +651,8 @@ ENTITYALLOCATION(MOSprite)
651651
int m_SpriteAnimDuration;
652652
// The timer to keep track of the body animation
653653
Timer m_SpriteAnimTimer;
654+
// Keep track of animation direction (mainly for ALWAYSPINGPONG), true is increasing frame, false is decreasing frame
655+
bool m_SpriteAnimIsReversingFrames;
654656
// Whether flipped horizontally or not.
655657
bool m_HFlipped;
656658
// The precalculated maximum possible radius and diameter of this, in pixels

0 commit comments

Comments
 (0)