Skip to content

Commit 82a5c5a

Browse files
committed
Added No Dash Refill Springs
1 parent 004c60a commit 82a5c5a

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
module SpringCollab2020DashSpring
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

Entities/NoDashRefillSpring.cs

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

0 commit comments

Comments
 (0)