-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathArrowBubble.cs
More file actions
106 lines (81 loc) · 2.68 KB
/
Copy pathArrowBubble.cs
File metadata and controls
106 lines (81 loc) · 2.68 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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using Microsoft.Xna.Framework;
using Monocle;
namespace Celeste.Mod.IsaGrabBag {
public class ArrowBubble : Booster {
static Vector2 GravityDir;
static FieldInfo sprite = typeof(Booster).GetField("sprite", BindingFlags.NonPublic | BindingFlags.Instance),
cannotUseTimer = typeof(Booster).GetField("cannotUseTimer", BindingFlags.NonPublic | BindingFlags.Instance),
respawnTimer = typeof(Booster).GetField("respawnTimer", BindingFlags.NonPublic | BindingFlags.Instance);
private Sprite sprites;
public static void Load() {
On.Celeste.Player.RedDashEnd += Player_RedDashEnd;
On.Celeste.Player.RedDashUpdate += Player_RedDashUpdate;
}
public static void Unload() {
On.Celeste.Player.RedDashEnd -= Player_RedDashEnd;
On.Celeste.Player.RedDashUpdate -= Player_RedDashUpdate;
}
private static void Player_RedDashEnd(On.Celeste.Player.orig_RedDashEnd orig, Player self) {
orig(self);
if (GravityDir != Vector2.Zero) {
self.UseRefill(false);
}
GravityDir = Vector2.Zero;
}
private static int Player_RedDashUpdate(On.Celeste.Player.orig_RedDashUpdate orig, Player self) {
if (self.CanDash && self.LastBooster != null) {
respawnTimer.SetValue(self.LastBooster, 1);
cannotUseTimer.SetValue(self.LastBooster, 0);
}
int value = orig(self);
if (GravityDir != Vector2.Zero) {
float approachSpeed = 350 * Engine.DeltaTime;
void changeValue(ref float val, float dir) {
val = Calc.Approach(val, (val * dir) >= 0 ? (360 * dir) : 0, approachSpeed);
}
if (GravityDir.X != 0)
changeValue(ref self.Speed.X, GravityDir.X);
if (GravityDir.Y != 0)
changeValue(ref self.Speed.Y, GravityDir.Y);
self.DashDir = self.Speed.SafeNormalize();
}
return value;
}
public Vector2 gravityDirection;
public ArrowBubble(EntityData data, Vector2 offset) : base(data.Position + offset, true) {
string dir = data.Attr("direction", "down");
Add(new PlayerCollider(OnPlayer));
switch (dir) {
default:
dir = "down";
gravityDirection = Vector2.UnitY;
break;
case "up":
gravityDirection = -Vector2.UnitY;
break;
case "left":
gravityDirection = -Vector2.UnitX;
break;
case "right":
gravityDirection = Vector2.UnitX;
break;
}
Remove(Get<Sprite>());
sprites = GrabBagModule.sprites.Create($"booster_{dir}");
Add(sprites);
sprite.SetValue(this, sprites);
}
void OnPlayer(Player player) {
if (player.StateMachine != Player.StRedDash) {
GravityDir = gravityDirection;
}
sprites.FlipX = false;
}
}
}