Skip to content

Commit 4b02483

Browse files
authored
Merge pull request #89 from EverestAPI/no_dash_refill_spring
No dash refill spring
2 parents 2e7122d + a1a5a38 commit 4b02483

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
module SpringCollab2020NoDashRefillSpring
2+
3+
using ..Ahorn, Maple
4+
5+
@mapdef Entity "SpringCollab2020/NoDashRefillSpring" NoDashRefillSpring(x::Integer, y::Integer, playerCanUse::Bool=true)
6+
@mapdef Entity "SpringCollab2020/NoDashRefillSpringRight" NoDashRefillSpringRight(x::Integer, y::Integer)
7+
@mapdef Entity "SpringCollab2020/NoDashRefillSpringLeft" NoDashRefillSpringLeft(x::Integer, y::Integer)
8+
9+
const placements = Ahorn.PlacementDict(
10+
"No Dash Refill Spring (Up) (Spring Collab 2020)" => Ahorn.EntityPlacement(
11+
NoDashRefillSpring
12+
),
13+
"No Dash Refill Spring (Left) (Spring Collab 2020)" => Ahorn.EntityPlacement(
14+
NoDashRefillSpringRight
15+
),
16+
"No Dash Refill Spring (Right) (Spring Collab 2020)" => Ahorn.EntityPlacement(
17+
NoDashRefillSpringLeft
18+
),
19+
)
20+
21+
function Ahorn.selection(entity::NoDashRefillSpring)
22+
x, y = Ahorn.position(entity)
23+
24+
return Ahorn.Rectangle(x - 6, y - 3, 12, 5)
25+
end
26+
27+
function Ahorn.selection(entity::NoDashRefillSpringLeft)
28+
x, y = Ahorn.position(entity)
29+
30+
return Ahorn.Rectangle(x - 1, y - 6, 5, 12)
31+
end
32+
33+
function Ahorn.selection(entity::NoDashRefillSpringRight)
34+
x, y = Ahorn.position(entity)
35+
36+
return Ahorn.Rectangle(x - 4, y - 6, 5, 12)
37+
end
38+
39+
sprite = "objects/spring/00.png"
40+
41+
Ahorn.render(ctx::Ahorn.Cairo.CairoContext, entity::NoDashRefillSpring, room::Maple.Room) = Ahorn.drawSprite(ctx, sprite, 0, -8)
42+
Ahorn.render(ctx::Ahorn.Cairo.CairoContext, entity::NoDashRefillSpringLeft, room::Maple.Room) = Ahorn.drawSprite(ctx, sprite, 9, -11, rot=pi / 2)
43+
Ahorn.render(ctx::Ahorn.Cairo.CairoContext, entity::NoDashRefillSpringRight, room::Maple.Room) = Ahorn.drawSprite(ctx, sprite, 3, 1, rot=-pi / 2)
44+
45+
end

Ahorn/lang/en_gb.lang

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,6 @@ placements.entities.SpringCollab2020/MoveBlockCustomSpeed.tooltips.moveSpeed=The
109109

110110
# Disable Ice Physics Trigger
111111
placements.triggers.SpringCollab2020/DisableIcePhysicsTrigger.tooltips.disableIcePhysics=Check to disable ice physics when entering the trigger. Uncheck to enable them again.
112+
113+
# No Dash Refill Spring
114+
placements.entities.SpringCollab2020/NoDashRefillSpring.tooltips.playerCanUse=Determines whether the player is able to interact with the spring.

Entities/NoDashRefillSpring.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using Celeste.Mod.Entities;
2+
using Microsoft.Xna.Framework;
3+
using Monocle;
4+
using System;
5+
using System.Reflection;
6+
7+
namespace Celeste.Mod.SpringCollab2020.Entities {
8+
[CustomEntity("SpringCollab2020/NoDashRefillSpring", "SpringCollab2020/NoDashRefillSpringLeft", "SpringCollab2020/NoDashRefillSpringRight")]
9+
class NoDashRefillSpring : Spring {
10+
private static MethodInfo bounceAnimate = typeof(Spring).GetMethod("BounceAnimate", BindingFlags.NonPublic | BindingFlags.Instance);
11+
private static object[] noParams = new object[0];
12+
13+
public NoDashRefillSpring(EntityData data, Vector2 offset)
14+
: base(data.Position + offset, GetOrientationFromName(data.Name), data.Bool("playerCanUse", true)) {
15+
16+
// remove the vanilla player collider. this is the one thing we want to mod here.
17+
foreach (Component component in this) {
18+
if (component.GetType() == typeof(PlayerCollider)) {
19+
Remove(component);
20+
break;
21+
}
22+
}
23+
24+
// replace it with our own collider.
25+
if (data.Bool("playerCanUse", true)) {
26+
Add(new PlayerCollider(OnCollide));
27+
}
28+
}
29+
30+
private static Orientations GetOrientationFromName(string name) {
31+
switch (name) {
32+
case "SpringCollab2020/NoDashRefillSpring":
33+
return Orientations.Floor;
34+
case "SpringCollab2020/NoDashRefillSpringRight":
35+
return Orientations.WallRight;
36+
case "SpringCollab2020/NoDashRefillSpringLeft":
37+
return Orientations.WallLeft;
38+
default:
39+
throw new Exception("No Dash Refill Spring name doesn't correlate to a valid Orientation!");
40+
}
41+
}
42+
43+
44+
private void OnCollide(Player player) {
45+
if (player.StateMachine.State == 9) {
46+
return;
47+
}
48+
49+
// Save dash count. Dashes are reloaded by SideBounce and SuperBounce.
50+
int originalDashCount = player.Dashes;
51+
52+
if (Orientation == Orientations.Floor) {
53+
if (player.Speed.Y >= 0f) {
54+
bounceAnimate.Invoke(this, noParams);
55+
player.SuperBounce(Top);
56+
}
57+
} else if (Orientation == Orientations.WallLeft) {
58+
if (player.SideBounce(1, Right, CenterY)) {
59+
bounceAnimate.Invoke(this, noParams);
60+
}
61+
} else if (Orientation == Orientations.WallRight) {
62+
if (player.SideBounce(-1, Left, CenterY)) {
63+
bounceAnimate.Invoke(this, noParams);
64+
}
65+
} else {
66+
throw new Exception("Orientation not supported!");
67+
}
68+
69+
// Restore original dash count.
70+
player.Dashes = originalDashCount;
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)