Skip to content

Commit

Permalink
Implement health effects
Browse files Browse the repository at this point in the history
  • Loading branch information
swoolcock committed Jun 4, 2020
1 parent 1b451f1 commit 9080f55
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 36 deletions.
2 changes: 2 additions & 0 deletions osu.Game.Rulesets.Rush/Judgements/HeartJudgement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ public class HeartJudgement : RushJudgement
{
public override bool AffectsCombo => false;
public override bool IsBonus => true;

public override double HealthPoints => 50;
}
}
26 changes: 7 additions & 19 deletions osu.Game.Rulesets.Rush/Judgements/RushJudgement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,14 @@ namespace osu.Game.Rulesets.Rush.Judgements
{
public class RushJudgement : Judgement
{
protected override int NumericResultFor(HitResult result)
{
switch (result)
protected override int NumericResultFor(HitResult result) =>
result switch
{
default:
return 0;
HitResult.Great => 200,
HitResult.Perfect => 300,
_ => 0
};

case HitResult.Meh:
return 50;

case HitResult.Ok:
return 100;

case HitResult.Good:
return 200;

case HitResult.Great:
case HitResult.Perfect:
return 300;
}
}
public virtual double HealthPoints => -10;
}
}
10 changes: 10 additions & 0 deletions osu.Game.Rulesets.Rush/Judgements/SawbladeJudgement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) Shane Woolcock. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

namespace osu.Game.Rulesets.Rush.Judgements
{
public class SawbladeJudgement : RushJudgement
{
public override double HealthPoints => -20;
}
}
2 changes: 2 additions & 0 deletions osu.Game.Rulesets.Rush/Objects/Drawables/DrawableLanedHit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class DrawableLanedHit<TLanedHit> : DrawableRushHitObject<TLanedHit>, IDr

public Anchor TrailingAnchor => Direction.Value == ScrollingDirection.Left ? Anchor.CentreRight : Anchor.CentreLeft;

public LanedHitLane Lane => HitObject.Lane;

public DrawableLanedHit(TLanedHit hitObject)
: base(hitObject)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public interface IDrawableLanedHit
{
Color4 LaneAccentColour { get; }
Anchor LaneAnchor { get; }
LanedHitLane Lane { get; }
}
}
4 changes: 4 additions & 0 deletions osu.Game.Rulesets.Rush/Objects/Sawblade.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// Copyright (c) Shane Woolcock. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Rush.Judgements;
using osu.Game.Rulesets.Rush.Scoring;
using osu.Game.Rulesets.Scoring;

namespace osu.Game.Rulesets.Rush.Objects
{
public class Sawblade : LanedHit
{
public override Judgement CreateJudgement() => new SawbladeJudgement();

protected override HitWindows CreateHitWindows() => new SawbladeHitWindows();
}
}
29 changes: 16 additions & 13 deletions osu.Game.Rulesets.Rush/Scoring/RushHealthProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using osu.Framework.Allocation;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Rush.Judgements;
using osu.Game.Rulesets.Rush.Objects;
using osu.Game.Rulesets.Rush.UI;
using osu.Game.Rulesets.Scoring;
Expand All @@ -12,12 +13,6 @@ namespace osu.Game.Rulesets.Rush.Scoring
{
public class RushHealthProcessor : HealthProcessor
{
private const float sawblade_points = -20f;
private const float minion_points = -10f;
private const float orb_points = -10f;
private const float miniboss_points = -10f;
private const float heart_points = 50f;

public double PlayerHealthPercentage { get; }

private double healthForPoints(double points) => points / PlayerHealthPercentage;
Expand All @@ -30,16 +25,24 @@ public RushHealthProcessor(double playerHealthPercentage = 100f)
PlayerHealthPercentage = playerHealthPercentage;
}

protected override double GetHealthIncreaseFor(JudgementResult result) =>
result.HitObject switch
protected override double GetHealthIncreaseFor(JudgementResult result)
{
var healthAmount = result.Judgement is RushJudgement rushJudgement ? healthForPoints(rushJudgement.HealthPoints) : 0;

return result.HitObject switch
{
Heart _ when result.IsHit => healthForPoints(heart_points),
Sawblade _ when !result.IsHit => healthForPoints(sawblade_points),
Minion _ when !result.IsHit && collidesWith(result.HitObject) => healthForPoints(minion_points),
Orb _ when !result.IsHit && collidesWith(result.HitObject) => healthForPoints(orb_points),
MiniBoss _ when !result.IsHit => healthForPoints(miniboss_points),
// requires hit
Heart _ when result.IsHit => healthAmount,
// requires not hit
Sawblade _ when !result.IsHit => healthAmount,
MiniBoss _ when !result.IsHit => healthAmount,
// requires collision
Minion _ when !result.IsHit && collidesWith(result.HitObject) => healthAmount,
Orb _ when !result.IsHit && collidesWith(result.HitObject) => healthAmount,
// default
_ => 0
};
}

private bool collidesWith(HitObject hitObject) => drawableRushRuleset.Playfield.PlayerSprite.CollidesWith(hitObject);
}
Expand Down
54 changes: 50 additions & 4 deletions osu.Game.Rulesets.Rush/UI/RushPlayfield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.Input.Bindings;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Rush.Judgements;
using osu.Game.Rulesets.Rush.Objects;
using osu.Game.Rulesets.Rush.Objects.Drawables;
using osu.Game.Rulesets.UI;
Expand All @@ -37,6 +39,7 @@ public class RushPlayfield : ScrollingPlayfield, IKeyBindingHandler<RushAction>
private readonly Container underEffectContainer;
private readonly Container overEffectContainer;
private readonly Container halfPaddingOverEffectContainer;
private readonly Container overPlayerEffectsContainer;
private readonly JudgementContainer<DrawableRushJudgement> judgementContainer;

public RushPlayfield()
Expand Down Expand Up @@ -81,7 +84,7 @@ public RushPlayfield()
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Left = HIT_TARGET_OFFSET }
},
judgementContainer = new JudgementContainer<DrawableRushJudgement>()
judgementContainer = new JudgementContainer<DrawableRushJudgement>
{
Name = "Judgement",
RelativeSizeAxes = Axes.Both,
Expand All @@ -102,7 +105,7 @@ public RushPlayfield()
},
halfPaddingOverEffectContainer = new Container
{
Name = "Over Effects (No Padding)",
Name = "Over Effects (Half Padding)",
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Left = HIT_TARGET_OFFSET / 2f }
}
Expand Down Expand Up @@ -130,6 +133,12 @@ public RushPlayfield()
Position = new Vector2(PLAYER_OFFSET, DEFAULT_HEIGHT),
Scale = new Vector2(0.75f),
},
overPlayerEffectsContainer = new Container
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
}
}
}
}
Expand Down Expand Up @@ -178,6 +187,9 @@ private void onMiniBossAttacked(DrawableMiniBoss drawableMiniBoss, double timeOf
private void onNewResult(DrawableHitObject judgedObject, JudgementResult result)
{
DrawableRushHitObject rushJudgedObject = (DrawableRushHitObject)judgedObject;
int healthAmount = (int)((result.Judgement as RushJudgement)?.HealthPoints ?? 0);
var healthPosition = new Vector2(overPlayerEffectsContainer.DrawWidth * 0.75f, overPlayerEffectsContainer.DrawHeight * 0.5f);

PlayerSprite.HandleResult(rushJudgedObject, result);

const float animation_time = 200f;
Expand Down Expand Up @@ -233,9 +245,25 @@ private void onNewResult(DrawableHitObject judgedObject, JudgementResult result)
underEffectContainer.Add(explosion);
explosion.ScaleTo(0.5f, 200f).FadeOutFromOne(200f).OnComplete(d => d.Expire());
}
else
else if (PlayerSprite.CollidesWith(result.HitObject))
{
// TODO: ouch!!!
var damageText = new SpriteText
{
Origin = Anchor.Centre,
Colour = Color4.Red,
Font = FontUsage.Default.With(size: 40),
Scale = new Vector2(1.2f),
Text = $"{healthAmount:D}",
Position = healthPosition,
};

overPlayerEffectsContainer.Add(damageText);

damageText.ScaleTo(1f, animation_time)
.Then()
.FadeOutFromOne(animation_time)
.MoveToOffset(new Vector2(0f, -20f), animation_time)
.OnComplete(d => d.Expire());
}

break;
Expand All @@ -249,12 +277,30 @@ private void onNewResult(DrawableHitObject judgedObject, JudgementResult result)
Scale = new Vector2(0.5f)
};

var healthIncrease = new SpriteText
{
Origin = Anchor.Centre,
Colour = Color4.Green,
Font = FontUsage.Default.With(size: 40),
Scale = new Vector2(1.2f),
Text = $"+{healthAmount:D}",
Position = healthPosition,
};

overEffectContainer.Add(heartFlash);

heartFlash.ScaleTo(1.25f, animation_time)
.FadeOutFromOne(animation_time)
.OnComplete(d => d.Expire());

overPlayerEffectsContainer.Add(healthIncrease);

healthIncrease.ScaleTo(1f, animation_time)
.Then()
.FadeOutFromOne(animation_time)
.MoveToOffset(new Vector2(0f, -20f), animation_time)
.OnComplete(d => d.Expire());

// TODO: green floating plus signs

break;
Expand Down

0 comments on commit 9080f55

Please sign in to comment.