Skip to content

Commit

Permalink
Add hit explosion on miniboss
Browse files Browse the repository at this point in the history
  • Loading branch information
swoolcock committed Jun 1, 2020
1 parent 19603ed commit bd94761
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
5 changes: 5 additions & 0 deletions osu.Game.Rulesets.Rush/Objects/Drawables/DrawableMiniBoss.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class DrawableMiniBoss : DrawableRushHitObject<MiniBoss>

private readonly Container<DrawableMiniBossTick> ticks;

public event Action<DrawableMiniBoss> Attacked;

public DrawableMiniBoss(MiniBoss hitObject)
: base(hitObject)
{
Expand Down Expand Up @@ -146,6 +148,7 @@ protected override void CheckForResult(bool userTriggered, double timeOffset)

// if (numHits == HitObject.RequiredHits)
// ApplyResult(r => r.Type = HitResult.Great);
OnAttacked(this);
}
else
{
Expand Down Expand Up @@ -203,5 +206,7 @@ protected override void UpdateStateTransforms(ArmedState state)
break;
}
}

protected virtual void OnAttacked(DrawableMiniBoss drawableMiniBoss) => Attacked?.Invoke(drawableMiniBoss);
}
}
54 changes: 41 additions & 13 deletions osu.Game.Rulesets.Rush/UI/RushPlayfield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using osu.Game.Rulesets.Rush.Objects.Drawables;
using osu.Game.Rulesets.UI.Scrolling;
using osuTK;
using osuTK.Graphics;

namespace osu.Game.Rulesets.Rush.UI
{
Expand All @@ -32,6 +33,7 @@ public class RushPlayfield : ScrollingPlayfield

private readonly Container underEffectContainer;
private readonly Container overEffectContainer;
private readonly Container halfPaddingOverEffectContainer;

public RushPlayfield()
{
Expand Down Expand Up @@ -87,6 +89,12 @@ public RushPlayfield()
Name = "Over Effects",
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Left = HIT_TARGET_OFFSET }
},
halfPaddingOverEffectContainer = new Container
{
Name = "Over Effects (No Padding)",
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Left = HIT_TARGET_OFFSET / 2f }
}
}
},
Expand Down Expand Up @@ -127,6 +135,9 @@ public override void Add(DrawableHitObject hitObject)
{
hitObject.OnNewResult += onNewResult;

if (hitObject is DrawableMiniBoss drawableMiniBoss)
drawableMiniBoss.Attacked += onMiniBossAttacked;

base.Add(hitObject);
}

Expand All @@ -136,9 +147,22 @@ public override bool Remove(DrawableHitObject hitObject)
return false;

hitObject.OnNewResult -= onNewResult;

if (hitObject is DrawableMiniBoss drawableMiniBoss)
drawableMiniBoss.Attacked -= onMiniBossAttacked;

return true;
}

private void onMiniBossAttacked(DrawableMiniBoss drawableMiniBoss)
{
var explosion = createHitExplosion(Color4.Yellow.Darken(0.5f), drawableMiniBoss.Anchor);
explosion.Scale *= 1.5f;
halfPaddingOverEffectContainer.Add(explosion);
explosion.ScaleTo(explosion.Scale * 0.5f, 200f).FadeOutFromOne(200f);
explosion.Delay(200).Expire(true);
}

private void onNewResult(DrawableHitObject judgedObject, JudgementResult result)
{
if (!result.IsHit)
Expand Down Expand Up @@ -194,20 +218,8 @@ private void onNewResult(DrawableHitObject judgedObject, JudgementResult result)
case Orb _:
Debug.Assert(drawableLanedHit != null, nameof(drawableLanedHit) + " != null");

// some random rotation and scale for variety
var startScale = 0.9f + random.NextDouble() * 0.2f;
var rotation = random.NextDouble() * 360;
var explosion = new DefaultHitExplosion(drawableLanedHit.LaneAccentColour)
{
Origin = Anchor.Centre,
Anchor = drawableLanedHit.LaneAnchor,
Size = new Vector2(200, 200),
Scale = new Vector2((float)startScale),
Rotation = (float)rotation
};

var explosion = createHitExplosion(drawableLanedHit.LaneAccentColour, drawableLanedHit.LaneAnchor);
underEffectContainer.Add(explosion);

explosion.ScaleTo(0.5f, 200f).FadeOutFromOne(200f);
explosion.Delay(200).Expire(true);

Expand All @@ -219,5 +231,21 @@ private void onNewResult(DrawableHitObject judgedObject, JudgementResult result)

// TODO: display judgment text etc.
}

private Drawable createHitExplosion(Color4 colour, Anchor anchor = Anchor.Centre)
{
// some random rotation and scale for variety
var startScale = 0.9f + random.NextDouble() * 0.2f;
var rotation = random.NextDouble() * 360;

return new DefaultHitExplosion(colour)
{
Origin = Anchor.Centre,
Anchor = anchor,
Size = new Vector2(200, 200),
Scale = new Vector2((float)startScale),
Rotation = (float)rotation
};
}
}
}

0 comments on commit bd94761

Please sign in to comment.