Skip to content

Commit 433844f

Browse files
committed
Added Underwater Switch Controller
1 parent 004c60a commit 433844f

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module SpringCollab2020UnderwaterSwitchController
2+
3+
using ..Ahorn, Maple
4+
5+
@mapdef Entity "SpringCollab2020/UnderwaterSwitchController" UnderwaterSwitchController(x::Integer, y::Integer, flag::String="underwater_switch")
6+
7+
const placements = Ahorn.PlacementDict(
8+
"Underwater Switch Controller (Spring Collab 2020)" => Ahorn.EntityPlacement(
9+
UnderwaterSwitchController
10+
)
11+
)
12+
13+
function Ahorn.selection(entity::UnderwaterSwitchController)
14+
x, y = Ahorn.position(entity)
15+
16+
return Ahorn.Rectangle(x - 12, y - 12, 24, 24)
17+
end
18+
19+
Ahorn.render(ctx::Ahorn.Cairo.CairoContext, entity::UnderwaterSwitchController, room::Maple.Room) = Ahorn.drawImage(ctx, Ahorn.Assets.northernLights, -12, -12)
20+
21+
end

Ahorn/lang/en_gb.lang

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,7 @@ placements.entities.SpringCollab2020/FlagSwitchGate.tooltips.persistent=If enabl
8989
placements.entities.SpringCollab2020/FlagSwitchGate.tooltips.inactiveColor=The gate icon colour when not triggered yet.
9090
placements.entities.SpringCollab2020/FlagSwitchGate.tooltips.activeColor=The gate icon colour when triggered, but the group is not complete yet.
9191
placements.entities.SpringCollab2020/FlagSwitchGate.tooltips.finishColor=The gate icon colour when the group is complete.
92-
placements.entities.SpringCollab2020/FlagSwitchGate.tooltips.sprite=The texture for the gate block.
92+
placements.entities.SpringCollab2020/FlagSwitchGate.tooltips.sprite=The texture for the gate block.
93+
94+
# Underwater Switch Controller
95+
placements.entities.SpringCollab2020/UnderwaterSwitchController.tooltips.flag=When this session flag is set, the whole room will be covered with water.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using Celeste.Mod.Entities;
2+
using Microsoft.Xna.Framework;
3+
using Monocle;
4+
using System.Collections;
5+
using System.Reflection;
6+
7+
namespace Celeste.Mod.SpringCollab2020.Entities {
8+
[CustomEntity("SpringCollab2020/UnderwaterSwitchController")]
9+
class UnderwaterSwitchController : Entity {
10+
private static FieldInfo waterFill = typeof(Water).GetField("fill", BindingFlags.NonPublic | BindingFlags.Instance);
11+
12+
private string flag;
13+
private Water water;
14+
15+
public UnderwaterSwitchController(EntityData data, Vector2 offset) : base(data.Position + offset) {
16+
flag = data.Attr("flag");
17+
18+
Add(new Coroutine(Routine()));
19+
20+
Add(new TransitionListener() {
21+
OnInBegin = () => {
22+
// when transitioning in a room with a controller and the flag is already set, spawn water right away
23+
Session session = SceneAs<Level>().Session;
24+
if (session.GetFlag(flag)) {
25+
spawnWater(session.LevelData.Bounds);
26+
}
27+
}
28+
});
29+
}
30+
31+
public IEnumerator Routine() {
32+
Session session = SceneAs<Level>().Session;
33+
while (true) {
34+
// wait until the flag is set.
35+
while (!session.GetFlag(flag)) {
36+
yield return null;
37+
}
38+
39+
// spawn water.
40+
if (water == null) {
41+
spawnWater(session.LevelData.Bounds);
42+
}
43+
44+
// wait until the flag is set.
45+
while (session.GetFlag(flag)) {
46+
yield return null;
47+
}
48+
49+
// make water go away.
50+
Scene.Remove(water);
51+
water = null;
52+
}
53+
}
54+
55+
private void spawnWater(Rectangle levelBounds) {
56+
// flood the room with water, make the water 10 pixels over the top to prevent a "splash" effect when going in a room above.
57+
water = new Water(new Vector2(levelBounds.Left, levelBounds.Top - 10),
58+
false, false, levelBounds.Width, levelBounds.Height + 10);
59+
60+
// but we don't want the water to render off-screen, because it is visible on upwards transitions.
61+
Rectangle fill = (Rectangle) waterFill.GetValue(water);
62+
fill.Y += 10;
63+
fill.Height -= 10;
64+
waterFill.SetValue(water, fill);
65+
66+
Scene.Add(water);
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)