Skip to content

Commit 9f47174

Browse files
committed
Add Spiked Jump Through Controller
1 parent 15c1a57 commit 9f47174

File tree

6 files changed

+135
-0
lines changed

6 files changed

+135
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module SpringCollab2020SpikeJumpThroughController
2+
3+
using ..Ahorn, Maple
4+
5+
@mapdef Entity "SpringCollab2020/SpikeJumpThroughController" SpikeJumpThroughController(x::Integer, y::Integer, persistent::Bool=false)
6+
7+
const placements = Ahorn.PlacementDict(
8+
"Spiked Jump Through Controller (SpringCollab2020)" => Ahorn.EntityPlacement(
9+
SpikeJumpThroughController,
10+
"point"
11+
)
12+
)
13+
14+
sprite = "ahorn/SpringCollab2020/spikeJumpThroughController"
15+
16+
function Ahorn.selection(entity::SpikeJumpThroughController)
17+
x, y = Ahorn.position(entity)
18+
19+
return Ahorn.getSpriteRectangle(sprite, x, y)
20+
end
21+
22+
function Ahorn.render(ctx::Ahorn.Cairo.CairoContext, entity::SpikeJumpThroughController, room::Maple.Room)
23+
Ahorn.drawSprite(ctx, sprite, 0, -0)
24+
end
25+
26+
end

Ahorn/lang/en_gb.lang

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ placements.entities.SpringCollab2020/returnBerry.tooltips.SpringCollab2020_ignor
1313
placements.entities.SpringCollab2020/glassBerry.tooltips.checkpointID=Manually determine what checkpoint section strawberries are visually grouped up in, showing up on the start menu during gameplay and level select. Overrides Everest's automatic berry IDs. (Default = -1)
1414
placements.entities.SpringCollab2020/glassBerry.tooltips.order=Manually determine what order strawberries are visually placed in on the start menu during gameplay and level select. Overrides Everest's automatic berry IDs. (Default = -1)
1515

16+
# Spike Jump Through Controller
17+
placements.entities.SpringCollab2020/SpikeJumpThroughController.tooltips.persistent=Whether or not the controller should stay active across rooms. If set to true, the controller's effects will stay active until the player leaves a room with a non-persistent controller.
18+
1619
# Lightning Dash Switch
1720
placements.entities.SpringCollab2020/LightningDashSwitch.tooltips.side=Which direction the switch is facing.
1821
placements.entities.SpringCollab2020/LightningDashSwitch.tooltips.sprite=Changes the visual appearance of the switch.
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
using Microsoft.Xna.Framework;
2+
using Monocle;
3+
using Celeste.Mod.SpringCollab2020;
4+
using Celeste.Mod.Entities;
5+
using System.Linq;
6+
7+
// Based on RainbowSpinnerColorController
8+
// from SpringCollab2020 / MaxHelpingHand
9+
10+
namespace Celeste.Mod.SpringCollab2020.Entities {
11+
[CustomEntity("SpringCollab2020/SpikeJumpThroughController")]
12+
class SpikeJumpThroughController : Entity {
13+
private static bool SpikeHooked;
14+
private static SpikeJumpThroughController CurrentController;
15+
private static SpikeJumpThroughController NextController;
16+
private static float TransitionProgress = -1f;
17+
18+
public SpikeJumpThroughController(EntityData data, Vector2 offset) : this(data.Bool("persistent", false), offset) { }
19+
20+
public SpikeJumpThroughController(bool persistent, Vector2 offset) : base(offset) {
21+
SpringCollab2020Module.Instance.Session.SpikeJumpThroughHooked = persistent;
22+
23+
Add(new TransitionListener {
24+
OnIn = progress => TransitionProgress = progress,
25+
OnOut = progress => TransitionProgress = progress,
26+
OnInBegin = () => TransitionProgress = 0f,
27+
OnInEnd = () => TransitionProgress = -1f
28+
});
29+
30+
Logger.Log("s", SpringCollab2020Module.Instance.Session.SpikeJumpThroughHooked.ToString());
31+
32+
}
33+
34+
public static void Load() {
35+
On.Celeste.Level.LoadLevel += OnLoadLevelHook;
36+
}
37+
38+
public static void Unload() {
39+
On.Celeste.Level.LoadLevel -= OnLoadLevelHook;
40+
}
41+
42+
public override void Update() {
43+
base.Update();
44+
if (TransitionProgress == -1f && CurrentController == null) {
45+
CurrentController = this;
46+
NextController = null;
47+
}
48+
}
49+
50+
public override void Awake(Scene scene) {
51+
base.Awake(scene);
52+
53+
NextController = this;
54+
if (!SpikeHooked) {
55+
On.Celeste.Spikes.OnCollide += OnCollideHook;
56+
SpikeHooked = true;
57+
}
58+
}
59+
60+
public override void Removed(Scene scene) {
61+
base.Removed(scene);
62+
63+
CurrentController = NextController;
64+
NextController = null;
65+
66+
TransitionProgress = -1f;
67+
68+
if (SpikeHooked && CurrentController == null) {
69+
On.Celeste.Spikes.OnCollide -= OnCollideHook;
70+
SpikeHooked = false;
71+
}
72+
}
73+
74+
public override void SceneEnd(Scene scene) {
75+
base.SceneEnd(scene);
76+
77+
CurrentController = NextController = null;
78+
if (SpikeHooked) {
79+
On.Celeste.Spikes.OnCollide -= OnCollideHook;
80+
SpikeHooked = false;
81+
}
82+
}
83+
84+
private static void OnLoadLevelHook(On.Celeste.Level.orig_LoadLevel orig, Level level, Player.IntroTypes introType, bool isFromLoader) {
85+
orig(level, introType, isFromLoader);
86+
87+
if (SpringCollab2020Module.Instance.Session.SpikeJumpThroughHooked && !level.Session.LevelData.Entities.Any(entity => entity.Name == "SpringCollab2020/SpikeJumpThroughController")) {
88+
level.Add(new SpikeJumpThroughController(SpringCollab2020Module.Instance.Session.SpikeJumpThroughHooked, Vector2.Zero));
89+
level.Entities.UpdateLists();
90+
}
91+
}
92+
93+
private static void OnCollideHook(On.Celeste.Spikes.orig_OnCollide orig, Spikes spikes, Player player) {
94+
// If the player is picking up a holdable, don't kill them.
95+
if (player.StateMachine.State == 8) {
96+
return;
97+
}
98+
99+
orig(spikes, player);
100+
}
101+
}
102+
}
367 Bytes
Loading

SpringCollab2020Module.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public override void Load() {
4949
LeaveTheoBehindTrigger.Load();
5050
BadelineBounceDirectionTrigger.Load();
5151
WaterRocketLaunchingComponent.Load();
52+
SpikeJumpThroughController.Load();
5253
Everest.Events.Level.OnLoadBackdrop += onLoadBackdrop;
5354

5455
IL.Celeste.Level.Reload += resetFlagsOnTimerResets;
@@ -98,6 +99,7 @@ public override void Unload() {
9899
LeaveTheoBehindTrigger.Unload();
99100
BadelineBounceDirectionTrigger.Unload();
100101
WaterRocketLaunchingComponent.Unload();
102+
SpikeJumpThroughController.Unload();
101103
Everest.Events.Level.OnLoadBackdrop -= onLoadBackdrop;
102104

103105
IL.Celeste.Level.Reload -= resetFlagsOnTimerResets;

SpringCollab2020Session.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public class MultiRoomStrawberrySeedInfo {
1818

1919
public bool LightSourcesDisabled { get; set; } = false;
2020

21+
public bool SpikeJumpThroughHooked { get; set; } = false;
22+
2123
public class SpeedBasedMusicParamInfo {
2224
public float MinimumSpeed { get; set; }
2325
public float MaximumSpeed { get; set; }

0 commit comments

Comments
 (0)