-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathRushPlayfield.cs
250 lines (214 loc) · 9.82 KB
/
RushPlayfield.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
// Copyright (c) Shane Woolcock. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Pooling;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;
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.Rush.UI.Fever;
using osu.Game.Rulesets.Rush.UI.Ground;
using osu.Game.Rulesets.UI.Scrolling;
using osuTK;
namespace osu.Game.Rulesets.Rush.UI
{
[Cached]
public class RushPlayfield : ScrollingPlayfield, IKeyBindingHandler<RushAction>
{
public const float DEFAULT_HEIGHT = 178;
public const float HIT_TARGET_OFFSET = 240;
public const float HIT_TARGET_SIZE = 100;
public const float PLAYER_OFFSET = 130;
public const float JUDGEMENT_OFFSET = 100;
public const float JUDGEMENT_MOVEMENT = 300;
public const double HIT_EXPLOSION_DURATION = 200f;
public RushPlayerSprite PlayerSprite { get; }
private readonly Container halfPaddingOverEffectContainer;
internal readonly Container OverPlayerEffectsContainer;
public readonly LanePlayfield AirLane;
public readonly LanePlayfield GroundLane;
public IEnumerable<DrawableHitObject> AllAliveHitObjects
{
get
{
if (HitObjectContainer == null)
return Enumerable.Empty<DrawableHitObject>();
// Intentionally counting on the fact that we don't have nested playfields in our nested playfields
var enumerable = HitObjectContainer.AliveObjects
.Concat(NestedPlayfields.SelectMany(p => p.HitObjectContainer.AliveObjects))
.OrderBy(d => d.HitObject.StartTime);
return enumerable;
}
}
private DrawablePool<DrawableRushJudgement> judgementPool;
private DrawablePool<DefaultHitExplosion> explosionPool;
private DrawablePool<StarSheetHitExplosion> sheetExplosionPool;
private DrawablePool<HeartHitExplosion> heartExplosionPool;
private DrawablePool<HealthText> healthTextPool;
[Resolved]
private FeverProcessor feverProcessor { get; set; }
[Cached]
private readonly RushHitPolicy hitPolicy;
public RushPlayfield()
{
hitPolicy = new RushHitPolicy(this);
RelativeSizeAxes = Axes.X;
Size = new Vector2(1, DEFAULT_HEIGHT);
Anchor = Origin = Anchor.Centre;
InternalChildren = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
Child = new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
AirLane = new LanePlayfield(LanedHitLane.Air),
GroundLane = new LanePlayfield(LanedHitLane.Ground),
// Contains miniboss and duals for now
new Container
{
Name = "Hit Objects",
RelativeSizeAxes = Axes.Both,
Child = new Container
{
Name = "Hit Objects",
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Left = HIT_TARGET_OFFSET },
Child = HitObjectContainer
},
},
}
}
},
halfPaddingOverEffectContainer = new Container
{
Name = "Over Effects (Half Padding)",
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Left = HIT_TARGET_OFFSET * 0.75f }
},
new GroundDisplay(),
PlayerSprite = new RushPlayerSprite(),
OverPlayerEffectsContainer = new Container
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Left = PLAYER_OFFSET }
},
new FeverBar()
};
AddNested(AirLane);
AddNested(GroundLane);
NewResult += onNewResult;
}
[BackgroundDependencyLoader]
private void load()
{
RegisterPool<MiniBoss, DrawableMiniBoss>(4);
RegisterPool<MiniBossTick, DrawableMiniBossTick>(10);
RegisterPool<DualHit, DrawableDualHit>(8);
RegisterPool<DualHitPart, DrawableDualHitPart>(16);
RegisterPool<FeverBonus, DrawableFeverBonus>(8);
AddRangeInternal(new Drawable[]
{
judgementPool = new DrawablePool<DrawableRushJudgement>(5),
explosionPool = new DrawablePool<DefaultHitExplosion>(15),
sheetExplosionPool = new DrawablePool<StarSheetHitExplosion>(10),
heartExplosionPool = new DrawablePool<HeartHitExplosion>(2),
healthTextPool = new DrawablePool<HealthText>(2),
});
}
protected override void OnNewDrawableHitObject(DrawableHitObject drawableHitObject)
{
base.OnNewDrawableHitObject(drawableHitObject);
if (drawableHitObject is DrawableMiniBoss drawableMiniBoss)
drawableMiniBoss.Attacked += onMiniBossAttacked;
if (drawableHitObject is DrawableRushHitObject drho)
drho.CheckHittable = hitPolicy.IsHittable;
}
public override void Add(HitObject hitObject)
{
switch (hitObject)
{
case LanedHit laned:
laned.LaneBindable.BindValueChanged(lane =>
{
if (lane.OldValue != lane.NewValue)
playfieldForLane(lane.OldValue).Remove(hitObject);
playfieldForLane(lane.OldValue).Add(hitObject);
}, true);
return;
}
base.Add(hitObject);
}
private LanePlayfield playfieldForLane(LanedHitLane lane) => lane == LanedHitLane.Air ? AirLane : GroundLane;
private void onMiniBossAttacked(DrawableMiniBoss drawableMiniBoss, double timeOffset)
{
halfPaddingOverEffectContainer.Add(explosionPool.Get(h => h.Apply(drawableMiniBoss)));
PlayerSprite.Target = PlayerTargetLane.MiniBoss;
}
private void onNewResult(DrawableHitObject judgedObject, JudgementResult result)
{
DrawableRushHitObject rushJudgedObject = (DrawableRushHitObject)judgedObject;
RushJudgementResult rushResult = (RushJudgementResult)result;
PlayerSprite.HandleResult(rushJudgedObject, result);
// Display hit explosions for objects that allow it.
if (result.IsHit && rushJudgedObject.DisplayExplosion)
{
Drawable explosion = rushJudgedObject switch
{
DrawableStarSheetHead head => sheetExplosionPool.Get(s => s.Apply(head)),
DrawableStarSheetTail tail => sheetExplosionPool.Get(s => s.Apply(tail)),
DrawableHeart heart => heartExplosionPool.Get(h => h.Apply(heart)),
_ => explosionPool.Get(h => h.Apply(rushJudgedObject)),
};
if (rushJudgedObject is IDrawableLanedHit laned)
playfieldForLane(laned.Lane).AddExplosion(explosion);
}
// Display health point difference if the judgement result implies it.
var pointDifference = rushResult.Judgement.HealthPointIncreaseFor(rushResult);
if (pointDifference != 0)
OverPlayerEffectsContainer.Add(healthTextPool.Get(h => h.Apply(pointDifference)));
// Display judgement results in a drawable for objects that allow it.
if (rushJudgedObject.DisplayResult)
{
DrawableRushJudgement judgementDrawable = judgementPool.Get(j => j.Apply(result, judgedObject));
LanedHitLane judgementLane = LanedHitLane.Air;
// TODO: showing judgements based on the judged object suggests that
// this may want to be inside the object class as well.
switch (rushJudgedObject.HitObject)
{
case Sawblade sawblade:
judgementLane = sawblade.Lane.Opposite();
break;
case LanedHit lanedHit:
judgementLane = lanedHit.Lane;
break;
case MiniBoss _:
break;
}
playfieldForLane(judgementLane).AddJudgement(judgementDrawable);
}
}
public bool OnPressed(KeyBindingPressEvent<RushAction> e)
{
if (e.Action == RushAction.Fever)
return feverProcessor.TryActivateFever();
return PlayerSprite.HandleAction(e.Action);
}
public void OnReleased(KeyBindingReleaseEvent<RushAction> e)
{
}
}
}