-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathBoomBoxZip.cs
More file actions
201 lines (176 loc) · 9.4 KB
/
BoomBoxZip.cs
File metadata and controls
201 lines (176 loc) · 9.4 KB
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
using Celeste;
using Celeste.Mod.Entities;
using Microsoft.Xna.Framework;
using Monocle;
using System;
using System.Collections;
namespace FactoryHelper.Entities {
[CustomEntity("FactoryHelper/BoomBoxZip")]
public class BoomBoxZip : BoomBox {
public float percent;
public Vector2 start, target;
private ZipMoverPathRenderer pathRenderer;
public BoomBoxZip(EntityData data, Vector2 offset)
: this(data.Position + offset, data.Attr("activationId", ""), data.Float("initialDelay", 0f), data.Bool("startActive", false), data.Nodes[0] + offset) {
}
public BoomBoxZip(Vector2 position, string activationId, float initialDelay, bool startActive, Vector2 target)
: base(position, activationId, initialDelay, startActive) {
Add(new Coroutine(ZipMoverSequence()));
this.start = this.Position;
this.target = target;
}
public override void Added(Scene scene) {
base.Added(scene);
scene.Add(pathRenderer = new ZipMoverPathRenderer(this));
}
private IEnumerator ZipMoverSequence() {
start = Position;
while (true) {
if (!HasPlayerRider()) {
yield return null;
continue;
}
Input.Rumble(RumbleStrength.Medium, RumbleLength.Short);
StartShaking(0.1f);
yield return 0.1f;
StopPlayerRunIntoAnimation = false;
float at2 = 0f;
while (at2 < 1f) {
yield return null;
at2 = Calc.Approach(at2, 1f, 2f * Engine.DeltaTime);
percent = Ease.SineIn(at2);
Vector2 vector = Vector2.Lerp(start, target, percent);
ScrapeParticlesCheck(vector);
if (Scene.OnInterval(0.1f)) {
pathRenderer.CreateSparks();
}
MoveTo(vector);
_boomCollider.Position = vector + new Vector2(Width / 2, Height / 2);
}
StartShaking(0.2f);
Input.Rumble(RumbleStrength.Strong, RumbleLength.Medium);
SceneAs<Level>().Shake();
StopPlayerRunIntoAnimation = true;
yield return 0.5f;
StopPlayerRunIntoAnimation = false;
at2 = 0f;
while (at2 < 1f) {
yield return null;
at2 = Calc.Approach(at2, 1f, 0.5f * Engine.DeltaTime);
percent = 1f - Ease.SineIn(at2);
Vector2 position = Vector2.Lerp(target, start, Ease.SineIn(at2));
MoveTo(position);
_boomCollider.Position = position + new Vector2(Width / 2, Height / 2);
}
StopPlayerRunIntoAnimation = true;
StartShaking(0.2f);
yield return 0.5f;
}
}
private void ScrapeParticlesCheck(Vector2 to) {
if (!base.Scene.OnInterval(0.03f)) {
return;
}
bool flag = to.Y != base.ExactPosition.Y;
bool flag2 = to.X != base.ExactPosition.X;
if (flag && !flag2) {
int num = Math.Sign(to.Y - base.ExactPosition.Y);
Vector2 value = (num != 1) ? base.TopLeft : base.BottomLeft;
int num2 = 4;
if (num == 1) {
num2 = Math.Min((int)base.Height - 12, 20);
}
int num3 = (int)base.Height;
if (num == -1) {
num3 = Math.Max(16, (int)base.Height - 16);
}
if (base.Scene.CollideCheck<Solid>(value + new Vector2(-2f, num * -2))) {
for (int i = num2; i < num3; i += 8) {
SceneAs<Level>().ParticlesFG.Emit(ZipMover.P_Scrape, base.TopLeft + new Vector2(0f, (float)i + (float)num * 2f), (num == 1) ? (-(float)Math.PI / 4f) : ((float)Math.PI / 4f));
}
}
if (base.Scene.CollideCheck<Solid>(value + new Vector2(base.Width + 2f, num * -2))) {
for (int j = num2; j < num3; j += 8) {
SceneAs<Level>().ParticlesFG.Emit(ZipMover.P_Scrape, base.TopRight + new Vector2(-1f, (float)j + (float)num * 2f), (num == 1) ? ((float)Math.PI * -3f / 4f) : ((float)Math.PI * 3f / 4f));
}
}
} else {
if (!flag2 || flag) {
return;
}
int num4 = Math.Sign(to.X - base.ExactPosition.X);
Vector2 value2 = (num4 != 1) ? base.TopLeft : base.TopRight;
int num5 = 4;
if (num4 == 1) {
num5 = Math.Min((int)base.Width - 12, 20);
}
int num6 = (int)base.Width;
if (num4 == -1) {
num6 = Math.Max(16, (int)base.Width - 16);
}
if (base.Scene.CollideCheck<Solid>(value2 + new Vector2(num4 * -2, -2f))) {
for (int k = num5; k < num6; k += 8) {
SceneAs<Level>().ParticlesFG.Emit(ZipMover.P_Scrape, base.TopLeft + new Vector2((float)k + (float)num4 * 2f, -1f), (num4 == 1) ? ((float)Math.PI * 3f / 4f) : ((float)Math.PI / 4f));
}
}
if (base.Scene.CollideCheck<Solid>(value2 + new Vector2(num4 * -2, base.Height + 2f))) {
for (int l = num5; l < num6; l += 8) {
SceneAs<Level>().ParticlesFG.Emit(ZipMover.P_Scrape, base.BottomLeft + new Vector2((float)l + (float)num4 * 2f, 0f), (num4 == 1) ? ((float)Math.PI * -3f / 4f) : (-(float)Math.PI / 4f));
}
}
}
}
private class ZipMoverPathRenderer : Entity {
private static readonly Color ropeColor = Calc.HexToColor("4d3c22");
private static readonly Color ropeLightColor = Calc.HexToColor("766c49");
public BoomBoxZip zipMover;
private MTexture cog;
private Vector2 from;
private Vector2 to;
private Vector2 sparkAdd;
private float sparkDirFromA;
private float sparkDirFromB;
private float sparkDirToA;
private float sparkDirToB;
public ZipMoverPathRenderer(BoomBoxZip zipMover) {
base.Depth = 5000;
this.zipMover = zipMover;
from = this.zipMover.start + new Vector2(this.zipMover.Width / 2f, this.zipMover.Height / 2f);
to = this.zipMover.target + new Vector2(this.zipMover.Width / 2f, this.zipMover.Height / 2f);
sparkAdd = (from - to).SafeNormalize(5f).Perpendicular();
float num = (from - to).Angle();
sparkDirFromA = num + (float)Math.PI / 8f;
sparkDirFromB = num - (float)Math.PI / 8f;
sparkDirToA = num + (float)Math.PI - (float)Math.PI / 8f;
sparkDirToB = num + (float)Math.PI + (float)Math.PI / 8f;
cog = GFX.Game["objects/zipmover/cog"];
}
public void CreateSparks() {
SceneAs<Level>().ParticlesBG.Emit(ZipMover.P_Sparks, from + sparkAdd + Calc.Random.Range(-Vector2.One, Vector2.One), sparkDirFromA);
SceneAs<Level>().ParticlesBG.Emit(ZipMover.P_Sparks, from - sparkAdd + Calc.Random.Range(-Vector2.One, Vector2.One), sparkDirFromB);
SceneAs<Level>().ParticlesBG.Emit(ZipMover.P_Sparks, to + sparkAdd + Calc.Random.Range(-Vector2.One, Vector2.One), sparkDirToA);
SceneAs<Level>().ParticlesBG.Emit(ZipMover.P_Sparks, to - sparkAdd + Calc.Random.Range(-Vector2.One, Vector2.One), sparkDirToB);
}
public override void Render() {
DrawCogs(Vector2.UnitY, Color.Black);
DrawCogs(Vector2.Zero);
}
private void DrawCogs(Vector2 offset, Color? colorOverride = null) {
Vector2 vector = (to - from).SafeNormalize();
Vector2 value = vector.Perpendicular() * 3f;
Vector2 value2 = -vector.Perpendicular() * 4f;
float rotation = zipMover.percent * (float)Math.PI * 2f;
Draw.Line(from + value + offset, to + value + offset, colorOverride.HasValue ? colorOverride.Value : ropeColor);
Draw.Line(from + value2 + offset, to + value2 + offset, colorOverride.HasValue ? colorOverride.Value : ropeColor);
for (float num = 4f - zipMover.percent * (float)Math.PI * 8f % 4f; num < (to - from).Length(); num += 4f) {
Vector2 value3 = from + value + vector.Perpendicular() + vector * num;
Vector2 value4 = to + value2 - vector * num;
Draw.Line(value3 + offset, value3 + vector * 2f + offset, colorOverride.HasValue ? colorOverride.Value : ropeLightColor);
Draw.Line(value4 + offset, value4 - vector * 2f + offset, colorOverride.HasValue ? colorOverride.Value : ropeLightColor);
}
cog.DrawCentered(from + offset, colorOverride.HasValue ? colorOverride.Value : Color.White, 1f, rotation);
cog.DrawCentered(to + offset, colorOverride.HasValue ? colorOverride.Value : Color.White, 1f, rotation);
}
}
}
}