Skip to content

Commit 9080f55

Browse files
committed
Implement health effects
1 parent 1b451f1 commit 9080f55

File tree

8 files changed

+92
-36
lines changed

8 files changed

+92
-36
lines changed

osu.Game.Rulesets.Rush/Judgements/HeartJudgement.cs

+2
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ public class HeartJudgement : RushJudgement
77
{
88
public override bool AffectsCombo => false;
99
public override bool IsBonus => true;
10+
11+
public override double HealthPoints => 50;
1012
}
1113
}

osu.Game.Rulesets.Rush/Judgements/RushJudgement.cs

+7-19
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,14 @@ namespace osu.Game.Rulesets.Rush.Judgements
88
{
99
public class RushJudgement : Judgement
1010
{
11-
protected override int NumericResultFor(HitResult result)
12-
{
13-
switch (result)
11+
protected override int NumericResultFor(HitResult result) =>
12+
result switch
1413
{
15-
default:
16-
return 0;
14+
HitResult.Great => 200,
15+
HitResult.Perfect => 300,
16+
_ => 0
17+
};
1718

18-
case HitResult.Meh:
19-
return 50;
20-
21-
case HitResult.Ok:
22-
return 100;
23-
24-
case HitResult.Good:
25-
return 200;
26-
27-
case HitResult.Great:
28-
case HitResult.Perfect:
29-
return 300;
30-
}
31-
}
19+
public virtual double HealthPoints => -10;
3220
}
3321
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (c) Shane Woolcock. Licensed under the MIT Licence.
2+
// See the LICENCE file in the repository root for full licence text.
3+
4+
namespace osu.Game.Rulesets.Rush.Judgements
5+
{
6+
public class SawbladeJudgement : RushJudgement
7+
{
8+
public override double HealthPoints => -20;
9+
}
10+
}

osu.Game.Rulesets.Rush/Objects/Drawables/DrawableLanedHit.cs

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public class DrawableLanedHit<TLanedHit> : DrawableRushHitObject<TLanedHit>, IDr
2828

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

31+
public LanedHitLane Lane => HitObject.Lane;
32+
3133
public DrawableLanedHit(TLanedHit hitObject)
3234
: base(hitObject)
3335
{

osu.Game.Rulesets.Rush/Objects/Drawables/IDrawableLanedHit.cs

+1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ public interface IDrawableLanedHit
1010
{
1111
Color4 LaneAccentColour { get; }
1212
Anchor LaneAnchor { get; }
13+
LanedHitLane Lane { get; }
1314
}
1415
}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
// Copyright (c) Shane Woolcock. Licensed under the MIT Licence.
22
// See the LICENCE file in the repository root for full licence text.
33

4+
using osu.Game.Rulesets.Judgements;
5+
using osu.Game.Rulesets.Rush.Judgements;
46
using osu.Game.Rulesets.Rush.Scoring;
57
using osu.Game.Rulesets.Scoring;
68

79
namespace osu.Game.Rulesets.Rush.Objects
810
{
911
public class Sawblade : LanedHit
1012
{
13+
public override Judgement CreateJudgement() => new SawbladeJudgement();
14+
1115
protected override HitWindows CreateHitWindows() => new SawbladeHitWindows();
1216
}
1317
}

osu.Game.Rulesets.Rush/Scoring/RushHealthProcessor.cs

+16-13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using osu.Framework.Allocation;
55
using osu.Game.Rulesets.Judgements;
66
using osu.Game.Rulesets.Objects;
7+
using osu.Game.Rulesets.Rush.Judgements;
78
using osu.Game.Rulesets.Rush.Objects;
89
using osu.Game.Rulesets.Rush.UI;
910
using osu.Game.Rulesets.Scoring;
@@ -12,12 +13,6 @@ namespace osu.Game.Rulesets.Rush.Scoring
1213
{
1314
public class RushHealthProcessor : HealthProcessor
1415
{
15-
private const float sawblade_points = -20f;
16-
private const float minion_points = -10f;
17-
private const float orb_points = -10f;
18-
private const float miniboss_points = -10f;
19-
private const float heart_points = 50f;
20-
2116
public double PlayerHealthPercentage { get; }
2217

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

33-
protected override double GetHealthIncreaseFor(JudgementResult result) =>
34-
result.HitObject switch
28+
protected override double GetHealthIncreaseFor(JudgementResult result)
29+
{
30+
var healthAmount = result.Judgement is RushJudgement rushJudgement ? healthForPoints(rushJudgement.HealthPoints) : 0;
31+
32+
return result.HitObject switch
3533
{
36-
Heart _ when result.IsHit => healthForPoints(heart_points),
37-
Sawblade _ when !result.IsHit => healthForPoints(sawblade_points),
38-
Minion _ when !result.IsHit && collidesWith(result.HitObject) => healthForPoints(minion_points),
39-
Orb _ when !result.IsHit && collidesWith(result.HitObject) => healthForPoints(orb_points),
40-
MiniBoss _ when !result.IsHit => healthForPoints(miniboss_points),
34+
// requires hit
35+
Heart _ when result.IsHit => healthAmount,
36+
// requires not hit
37+
Sawblade _ when !result.IsHit => healthAmount,
38+
MiniBoss _ when !result.IsHit => healthAmount,
39+
// requires collision
40+
Minion _ when !result.IsHit && collidesWith(result.HitObject) => healthAmount,
41+
Orb _ when !result.IsHit && collidesWith(result.HitObject) => healthAmount,
42+
// default
4143
_ => 0
4244
};
45+
}
4346

4447
private bool collidesWith(HitObject hitObject) => drawableRushRuleset.Playfield.PlayerSprite.CollidesWith(hitObject);
4548
}

osu.Game.Rulesets.Rush/UI/RushPlayfield.cs

+50-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
using osu.Framework.Graphics;
88
using osu.Framework.Graphics.Containers;
99
using osu.Framework.Graphics.Shapes;
10+
using osu.Framework.Graphics.Sprites;
1011
using osu.Framework.Graphics.Textures;
1112
using osu.Framework.Input.Bindings;
1213
using osu.Game.Rulesets.Judgements;
1314
using osu.Game.Rulesets.Objects.Drawables;
15+
using osu.Game.Rulesets.Rush.Judgements;
1416
using osu.Game.Rulesets.Rush.Objects;
1517
using osu.Game.Rulesets.Rush.Objects.Drawables;
1618
using osu.Game.Rulesets.UI;
@@ -37,6 +39,7 @@ public class RushPlayfield : ScrollingPlayfield, IKeyBindingHandler<RushAction>
3739
private readonly Container underEffectContainer;
3840
private readonly Container overEffectContainer;
3941
private readonly Container halfPaddingOverEffectContainer;
42+
private readonly Container overPlayerEffectsContainer;
4043
private readonly JudgementContainer<DrawableRushJudgement> judgementContainer;
4144

4245
public RushPlayfield()
@@ -81,7 +84,7 @@ public RushPlayfield()
8184
RelativeSizeAxes = Axes.Both,
8285
Padding = new MarginPadding { Left = HIT_TARGET_OFFSET }
8386
},
84-
judgementContainer = new JudgementContainer<DrawableRushJudgement>()
87+
judgementContainer = new JudgementContainer<DrawableRushJudgement>
8588
{
8689
Name = "Judgement",
8790
RelativeSizeAxes = Axes.Both,
@@ -102,7 +105,7 @@ public RushPlayfield()
102105
},
103106
halfPaddingOverEffectContainer = new Container
104107
{
105-
Name = "Over Effects (No Padding)",
108+
Name = "Over Effects (Half Padding)",
106109
RelativeSizeAxes = Axes.Both,
107110
Padding = new MarginPadding { Left = HIT_TARGET_OFFSET / 2f }
108111
}
@@ -130,6 +133,12 @@ public RushPlayfield()
130133
Position = new Vector2(PLAYER_OFFSET, DEFAULT_HEIGHT),
131134
Scale = new Vector2(0.75f),
132135
},
136+
overPlayerEffectsContainer = new Container
137+
{
138+
Origin = Anchor.Centre,
139+
Anchor = Anchor.Centre,
140+
RelativeSizeAxes = Axes.Both,
141+
}
133142
}
134143
}
135144
}
@@ -178,6 +187,9 @@ private void onMiniBossAttacked(DrawableMiniBoss drawableMiniBoss, double timeOf
178187
private void onNewResult(DrawableHitObject judgedObject, JudgementResult result)
179188
{
180189
DrawableRushHitObject rushJudgedObject = (DrawableRushHitObject)judgedObject;
190+
int healthAmount = (int)((result.Judgement as RushJudgement)?.HealthPoints ?? 0);
191+
var healthPosition = new Vector2(overPlayerEffectsContainer.DrawWidth * 0.75f, overPlayerEffectsContainer.DrawHeight * 0.5f);
192+
181193
PlayerSprite.HandleResult(rushJudgedObject, result);
182194

183195
const float animation_time = 200f;
@@ -233,9 +245,25 @@ private void onNewResult(DrawableHitObject judgedObject, JudgementResult result)
233245
underEffectContainer.Add(explosion);
234246
explosion.ScaleTo(0.5f, 200f).FadeOutFromOne(200f).OnComplete(d => d.Expire());
235247
}
236-
else
248+
else if (PlayerSprite.CollidesWith(result.HitObject))
237249
{
238-
// TODO: ouch!!!
250+
var damageText = new SpriteText
251+
{
252+
Origin = Anchor.Centre,
253+
Colour = Color4.Red,
254+
Font = FontUsage.Default.With(size: 40),
255+
Scale = new Vector2(1.2f),
256+
Text = $"{healthAmount:D}",
257+
Position = healthPosition,
258+
};
259+
260+
overPlayerEffectsContainer.Add(damageText);
261+
262+
damageText.ScaleTo(1f, animation_time)
263+
.Then()
264+
.FadeOutFromOne(animation_time)
265+
.MoveToOffset(new Vector2(0f, -20f), animation_time)
266+
.OnComplete(d => d.Expire());
239267
}
240268

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

280+
var healthIncrease = new SpriteText
281+
{
282+
Origin = Anchor.Centre,
283+
Colour = Color4.Green,
284+
Font = FontUsage.Default.With(size: 40),
285+
Scale = new Vector2(1.2f),
286+
Text = $"+{healthAmount:D}",
287+
Position = healthPosition,
288+
};
289+
252290
overEffectContainer.Add(heartFlash);
253291

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

296+
overPlayerEffectsContainer.Add(healthIncrease);
297+
298+
healthIncrease.ScaleTo(1f, animation_time)
299+
.Then()
300+
.FadeOutFromOne(animation_time)
301+
.MoveToOffset(new Vector2(0f, -20f), animation_time)
302+
.OnComplete(d => d.Expire());
303+
258304
// TODO: green floating plus signs
259305

260306
break;

0 commit comments

Comments
 (0)