-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathArrowBlock.cs
347 lines (290 loc) · 14 KB
/
ArrowBlock.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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Monocle;
using Celeste;
using Celeste.Mod;
using System.Collections.Generic;
namespace Celeste.Mod.IsaGrabBag
{
public class ArrowBlock : Solid
{
private const float MoveSpeed = 500, TurnSpeed = 750;
private const bool JoystickAlways = false;
private enum ArrowDirection {
no_limit,
horizontal,
vertical,
cardinal,
diagonal
}
private bool UseAnalog
{
get
{
return (JoystickAlways || SaveData.Instance.Assists.ThreeSixtyDashing) && (limitation != ArrowDirection.cardinal && limitation != ArrowDirection.diagonal);
}
}
public int InvertVal { get { return Inverted ? -1 : 1; } }
public bool Inverted { get; private set; }
public int Distance { get; private set; }
private Vector2 moveDir, localPos, previousDirection;
private Vector2 originalPosition;
private ArrowDirection limitation;
private Vector2 glowDirection;
public ArrowBlock(EntityData _data, Vector2 _offset) : base(_data.Position + _offset, _data.Width, _data.Height, false)
{
Distance = _data.Int("distance", 16);
Inverted = _data.Bool("inverted", false);
originalPosition = _data.Position + _offset;
limitation = _data.Enum("movementRestriction", ArrowDirection.no_limit);
int num = (int)(base.Width / 8f) - 1;
int num2 = (int)(base.Height / 8f) - 1;
List<MTexture> atlasSubtextures = GFX.Game.GetAtlasSubtextures("isafriend/objects/arrowblock/block");
MTexture idle;
switch (limitation) {
default:
idle = atlasSubtextures[0];
break;
case ArrowDirection.horizontal:
idle = atlasSubtextures[1];
break;
case ArrowDirection.vertical:
idle = atlasSubtextures[2];
break;
case ArrowDirection.cardinal:
idle = atlasSubtextures[3];
break;
case ArrowDirection.diagonal:
idle = atlasSubtextures[4];
break;
}
face = new Image(GFX.Game["isafriend/objects/arrowblock/idle_face"]);
face.CenterOrigin();
face.Position = new Vector2(Width / 2, Height / 2);
Add(face);
for (int i = 1; i < num; i++) {
AddImage(idle, i, 0, Calc.Random.Choose(1, 2), 0, 0, -1);
AddImage(idle, i, num2, Calc.Random.Choose(1, 2), 3, 0, 1);
}
for (int j = 1; j < num2; j++) {
AddImage(idle, 0, j, 0, Calc.Random.Choose(1, 2), -1, 0);
AddImage(idle, num, j, 3, Calc.Random.Choose(1, 2), 1, 0);
}
AddImage(idle, 0, 0, 0, 0, -1, -1);
AddImage(idle, num, 0, 3, 0, 1, -1);
AddImage(idle, 0, num2, 0, 3, -1, 1);
AddImage(idle, num, num2, 3, 3, 1, 1);
Add(new LightOcclude(0.2f));
}
private Vector2 GetOffsetPosition()
{
if (GrabBagModule.playerInstance == null || GrabBagModule.playerInstance.Dead)
return Vector2.Zero;
Vector2 move = UseAnalog ? Input.Feather.Value : new Vector2(Input.MoveX, Input.MoveY);
if (move.X != 0 || move.Y != 0)
move.Normalize();
switch (limitation) {
default:
break;
case ArrowDirection.horizontal:
move.Y = 0;
if (move.X != 0)
move.X = Math.Sign(move.X);
break;
case ArrowDirection.vertical:
move.X = 0;
if (move.Y != 0)
move.Y = Math.Sign(move.Y);
break;
case ArrowDirection.cardinal:
if (move.X != 0 && move.Y != 0) {
move = Vector2.Zero;
}
break;
case ArrowDirection.diagonal:
move = move.Rotate(MathHelper.PiOver4);
if (Math.Abs(move.X) > 0.001f && Math.Abs(move.Y) > 0.001f) {
move = Vector2.Zero;
}
else {
move = move.Rotate(-MathHelper.PiOver4);
}
break;
}
return move * InvertVal;
}
public override void Update()
{
base.Update();
previousDirection = GetOffsetPosition();
var newPos = GetOffsetPosition() * Distance;
var dir = newPos - localPos;
if (dir.X != 0 || dir.Y != 0)
{
dir.Normalize();
}
moveDir += dir * Engine.DeltaTime * TurnSpeed;
if (moveDir.Length() > MoveSpeed)
{
moveDir = (moveDir.SafeNormalize() * MoveSpeed);
}
if (Calc.AbsAngleDiff(moveDir.Angle(), dir.Angle()) > MathHelper.PiOver2)
{
moveDir = Vector2.Zero;
}
var movement = moveDir * Engine.DeltaTime;
if (Vector2.Distance(localPos, newPos) < movement.Length())
{
localPos = newPos;
moveDir = Vector2.Zero;
}
else
{
localPos += movement;
}
if (localPos.Length() > Distance)
{
localPos.Normalize();
localPos *= Distance;
moveDir = Vector2.Zero;
}
glowDirection = Calc.Approach(glowDirection, previousDirection, 10 * Engine.DeltaTime);
MoveTo(originalPosition + localPos);
}
private void AddImage(MTexture idle, int x, int y, int tx, int ty, int borderX = 0, int borderY = 0) {
MTexture subtexture = idle.GetSubtexture(tx * 8, ty * 8, 8, 8, null);
Vector2 vector = new Vector2((float)(x * 8), (float)(y * 8));
if (borderX != 0) {
Add(new Image(subtexture) {
Color = Color.Black,
Position = vector + new Vector2((float)borderX, 0f)
});
}
if (borderY != 0) {
Add(new Image(subtexture) {
Color = Color.Black,
Position = vector + new Vector2(0f, (float)borderY)
});
}
Image image = new Image(subtexture);
image.Position = vector;
Add(image);
idleImages.Add(image);
if (borderX != 0 || borderY != 0) {
if (borderX < 0 && (limitation != ArrowDirection.diagonal && limitation != ArrowDirection.vertical)) {
Image image2 = new Image(GFX.Game["isafriend/objects/arrowblock/lit_left"].GetSubtexture(0, ty * 8, 8, 8, null));
activeLeftImages.Add(image2);
image2.Position = vector;
Add(image2);
}
else if (borderX > 0 && (limitation != ArrowDirection.diagonal && limitation != ArrowDirection.vertical)) {
Image image3 = new Image(GFX.Game["isafriend/objects/arrowblock/lit_right"].GetSubtexture(0, ty * 8, 8, 8, null));
activeRightImages.Add(image3);
image3.Position = vector;
Add(image3);
}
if (borderY < 0 && (limitation != ArrowDirection.diagonal && limitation != ArrowDirection.horizontal)) {
Image image4 = new Image(GFX.Game["isafriend/objects/arrowblock/lit_top"].GetSubtexture(tx * 8, 0, 8, 8, null));
activeTopImages.Add(image4);
image4.Position = vector;
Add(image4);
}
if (borderY > 0 && (limitation != ArrowDirection.diagonal && limitation != ArrowDirection.horizontal)) {
Image image5 = new Image(GFX.Game["isafriend/objects/arrowblock/lit_bottom"].GetSubtexture(tx * 8, 0, 8, 8, null));
activeBottomImages.Add(image5);
image5.Position = vector;
Add(image5);
}
if (borderX < 0 && borderY < 0) {
topleftCorner = new Image(GFX.Game["isafriend/objects/arrowblock/lit_topleft"]);
topleftCorner.Position = vector;
Add(topleftCorner);
}
if (borderX < 0 && borderY > 0) {
bottomleftCorner = new Image(GFX.Game["isafriend/objects/arrowblock/lit_bottomleft"]);
bottomleftCorner.Position = vector;
Add(bottomleftCorner);
}
if (borderX > 0 && borderY < 0) {
toprightCorner = new Image(GFX.Game["isafriend/objects/arrowblock/lit_topright"]);
toprightCorner.Position = vector;
Add(toprightCorner);
}
if (borderX > 0 && borderY > 0) {
bottomrightCorner = new Image(GFX.Game["isafriend/objects/arrowblock/lit_bottomright"]);
bottomrightCorner.Position = vector;
Add(bottomrightCorner);
}
}
}
List<Image> idleImages = new List<Image>();
List<Image> activeTopImages = new List<Image>();
List<Image> activeRightImages = new List<Image>();
List<Image> activeLeftImages = new List<Image>();
List<Image> activeBottomImages = new List<Image>();
Image topleftCorner, toprightCorner, bottomleftCorner, bottomrightCorner, face;
public override void Render() {
Rectangle rect = Collider.Bounds;
face.Position = new Vector2(Width / 2, Height / 2) + glowDirection * 2;
face.FlipY = Inverted;
rect.Inflate(-3, -3);
Draw.Rect(rect, Calc.HexToColor("483b69"));
float lightStrength = Calc.ClampedMap(glowDirection.Y, 0, -.9f, 0, 1);
foreach (var img in activeTopImages) {
img.Color = Color.Lerp(Color.Transparent, Color.White, lightStrength * lightStrength * lightStrength);
}
lightStrength = Calc.ClampedMap(glowDirection.Y, 0, .9f, 0, 1);
foreach (var img in activeBottomImages) {
img.Color = Color.Lerp(Color.Transparent, Color.White, lightStrength * lightStrength * lightStrength);
}
lightStrength = Calc.ClampedMap(glowDirection.X, 0, -.9f, 0, 1);
foreach (var img in activeLeftImages) {
img.Color = Color.Lerp(Color.Transparent, Color.White, lightStrength * lightStrength * lightStrength);
}
lightStrength = Calc.ClampedMap(glowDirection.X, 0, .9f, 0, 1);
foreach (var img in activeRightImages) {
img.Color = Color.Lerp(Color.Transparent, Color.White, lightStrength * lightStrength * lightStrength);
}
switch (limitation) {
default: {
Vector2 dir = Calc.Rotate(glowDirection, MathHelper.PiOver4);
lightStrength = Calc.ClampedMap(dir.Y, 0, -.9f, 0, 1);
topleftCorner.Color = Color.Lerp(Color.Transparent, Color.White, lightStrength * lightStrength * lightStrength);
lightStrength = Calc.ClampedMap(dir.X, 0, .9f, 0, 1);
toprightCorner.Color = Color.Lerp(Color.Transparent, Color.White, lightStrength * lightStrength * lightStrength);
lightStrength = Calc.ClampedMap(dir.X, 0, -.9f, 0, 1);
bottomleftCorner.Color = Color.Lerp(Color.Transparent, Color.White, lightStrength * lightStrength * lightStrength);
lightStrength = Calc.ClampedMap(dir.Y, 0, .9f, 0, 1);
bottomrightCorner.Color = Color.Lerp(Color.Transparent, Color.White, lightStrength * lightStrength * lightStrength);
}
break;
case ArrowDirection.horizontal: {
lightStrength = Calc.ClampedMap(glowDirection.X, 0, -.9f, 0, 1);
topleftCorner.Color = Color.Lerp(Color.Transparent, Color.White, lightStrength * lightStrength * lightStrength);
bottomleftCorner.Color = Color.Lerp(Color.Transparent, Color.White, lightStrength * lightStrength * lightStrength);
lightStrength = Calc.ClampedMap(glowDirection.X, 0, .9f, 0, 1);
toprightCorner.Color = Color.Lerp(Color.Transparent, Color.White, lightStrength * lightStrength * lightStrength);
bottomrightCorner.Color = Color.Lerp(Color.Transparent, Color.White, lightStrength * lightStrength * lightStrength);
}
break;
case ArrowDirection.vertical: {
lightStrength = Calc.ClampedMap(glowDirection.Y, 0, -.9f, 0, 1);
topleftCorner.Color = Color.Lerp(Color.Transparent, Color.White, lightStrength * lightStrength * lightStrength);
toprightCorner.Color = Color.Lerp(Color.Transparent, Color.White, lightStrength * lightStrength * lightStrength);
lightStrength = Calc.ClampedMap(glowDirection.Y, 0, .9f, 0, 1);
bottomleftCorner.Color = Color.Lerp(Color.Transparent, Color.White, lightStrength * lightStrength * lightStrength);
bottomrightCorner.Color = Color.Lerp(Color.Transparent, Color.White, lightStrength * lightStrength * lightStrength);
}
break;
case ArrowDirection.cardinal:
topleftCorner.Visible = false;
toprightCorner.Visible = false;
bottomleftCorner.Visible = false;
bottomrightCorner.Visible = false;
break;
}
base.Render();
}
}
}