Skip to content

Commit 1f5ad40

Browse files
committed
Basic functionality of Move Block Barriers
1 parent a3e0c95 commit 1f5ad40

File tree

3 files changed

+148
-0
lines changed

3 files changed

+148
-0
lines changed

Ahorn/entities/moveBlockBarrier.jl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module SpringCollab2020MoveBlockBarrier
2+
3+
using ..Ahorn, Maple
4+
5+
@mapdef Entity "SpringCollab2020/moveBlockBarrier" MoveBlockBarrier(x::Integer, y::Integer, width::Integer=Maple.defaultBlockWidth, height::Integer=Maple.defaultBlockHeight)
6+
7+
const placements = Ahorn.PlacementDict(
8+
"Move Block Barrier (Spring Collab 2020)" => Ahorn.EntityPlacement(
9+
MoveBlockBarrier,
10+
"rectangle"
11+
),
12+
)
13+
14+
Ahorn.minimumSize(entity::MoveBlockBarrier) = 8, 8
15+
Ahorn.resizable(entity::MoveBlockBarrier) = true, true
16+
17+
function Ahorn.selection(entity::MoveBlockBarrier)
18+
x, y = Ahorn.position(entity)
19+
20+
width = Int(get(entity.data, "width", 8))
21+
height = Int(get(entity.data, "height", 8))
22+
23+
return Ahorn.Rectangle(x, y, width, height)
24+
end
25+
26+
function Ahorn.render(ctx::Ahorn.Cairo.CairoContext, entity::MoveBlockBarrier, room::Maple.Room)
27+
width = Int(get(entity.data, "width", 32))
28+
height = Int(get(entity.data, "height", 32))
29+
30+
# Slightly darker than seeker barriers, design unfinalized
31+
Ahorn.drawRectangle(ctx, 0, 0, width, height, (0.45, 0.45, 0.45, 0.8), (0.0, 0.0, 0.0, 0.0))
32+
end
33+
34+
end

Entities/MoveBlockBarrier.cs

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
using System;
2+
using Celeste.Mod.Entities;
3+
using Microsoft.Xna.Framework;
4+
using Monocle;
5+
6+
namespace Celeste.Mod.SpringCollab2020.Entities {
7+
[CustomEntity("SpringCollab2020/moveBlockBarrier")]
8+
[Tracked(false)]
9+
public class MoveBlockBarrier : SeekerBarrier {
10+
public MoveBlockBarrier(EntityData data, Vector2 offset) : base(data, offset) {
11+
}
12+
13+
public static void Load() {
14+
On.Celeste.MoveBlock.MoveCheck += MoveBlock_MoveCheck;
15+
On.Celeste.Platform.MoveHCollideSolids += Platform_MoveHCollideSolids;
16+
On.Celeste.Platform.MoveVCollideSolids += Platform_MoveVCollideSolids;
17+
On.Celeste.Actor.MoveHExact += Actor_MoveHExact;
18+
On.Celeste.Actor.MoveVExact += Actor_MoveVExact;
19+
}
20+
21+
public static void Unload() {
22+
On.Celeste.MoveBlock.MoveCheck -= MoveBlock_MoveCheck;
23+
On.Celeste.Platform.MoveHCollideSolids -= Platform_MoveHCollideSolids;
24+
On.Celeste.Platform.MoveVCollideSolids -= Platform_MoveVCollideSolids;
25+
On.Celeste.Actor.MoveHExact -= Actor_MoveHExact;
26+
On.Celeste.Actor.MoveVExact -= Actor_MoveVExact;
27+
}
28+
29+
static bool Platform_MoveHCollideSolids(On.Celeste.Platform.orig_MoveHCollideSolids orig, Platform self, float moveH, bool thruDashBlocks, Action<Vector2, Vector2, Platform> onCollide) {
30+
bool barrierWasCollidable = self.Scene.Tracker.GetEntity<MoveBlockBarrier>()?.Collidable ?? false;
31+
if (self is MoveBlock) {
32+
foreach (Entity barrier in self.Scene.Tracker.GetEntities<MoveBlockBarrier>()) {
33+
barrier.Collidable = true;
34+
}
35+
36+
bool result = orig(self, moveH, thruDashBlocks, onCollide);
37+
38+
foreach (Entity barrier in self.Scene.Tracker.GetEntities<MoveBlockBarrier>()) {
39+
barrier.Collidable = barrierWasCollidable;
40+
}
41+
42+
return result;
43+
}
44+
return orig(self, moveH, thruDashBlocks, onCollide);
45+
}
46+
47+
static bool Platform_MoveVCollideSolids(On.Celeste.Platform.orig_MoveVCollideSolids orig, Platform self, float moveV, bool thruDashBlocks, Action<Vector2, Vector2, Platform> onCollide) {
48+
bool barrierWasCollidable = self.Scene.Tracker.GetEntity<MoveBlockBarrier>()?.Collidable ?? false;
49+
if (self is MoveBlock) {
50+
foreach (Entity barrier in self.Scene.Tracker.GetEntities<MoveBlockBarrier>()) {
51+
barrier.Collidable = true;
52+
}
53+
54+
bool result = orig(self, moveV, thruDashBlocks, onCollide);
55+
56+
foreach (Entity barrier in self.Scene.Tracker.GetEntities<MoveBlockBarrier>()) {
57+
barrier.Collidable = barrierWasCollidable;
58+
}
59+
60+
return result;
61+
}
62+
return orig(self, moveV, thruDashBlocks, onCollide);
63+
}
64+
65+
66+
static bool Actor_MoveHExact(On.Celeste.Actor.orig_MoveHExact orig, Actor self, int moveH, Collision onCollide, Solid pusher) {
67+
bool barrierWasCollidable = self.Scene.Tracker.GetEntity<MoveBlockBarrier>()?.Collidable ?? false;
68+
foreach (Entity barrier in self.Scene.Tracker.GetEntities<MoveBlockBarrier>()) {
69+
barrier.Collidable = false;
70+
}
71+
72+
bool result = orig(self, moveH, onCollide, pusher);
73+
74+
foreach (Entity barrier in self.Scene.Tracker.GetEntities<MoveBlockBarrier>()) {
75+
barrier.Collidable = barrierWasCollidable;
76+
}
77+
78+
return result;
79+
}
80+
81+
static bool Actor_MoveVExact(On.Celeste.Actor.orig_MoveVExact orig, Actor self, int moveV, Collision onCollide, Solid pusher) {
82+
bool barrierWasCollidable = self.Scene.Tracker.GetEntity<MoveBlockBarrier>()?.Collidable ?? false;
83+
foreach (Entity barrier in self.Scene.Tracker.GetEntities<MoveBlockBarrier>()) {
84+
barrier.Collidable = false;
85+
}
86+
87+
bool result = orig(self, moveV, onCollide, pusher);
88+
89+
foreach (Entity barrier in self.Scene.Tracker.GetEntities<MoveBlockBarrier>()) {
90+
barrier.Collidable = barrierWasCollidable;
91+
}
92+
93+
return result;
94+
}
95+
96+
// Make the barrier temporarily collidable while checking MoveBlock collisions
97+
static bool MoveBlock_MoveCheck(On.Celeste.MoveBlock.orig_MoveCheck orig, MoveBlock self, Vector2 speed) {
98+
foreach (Entity barrier in self.Scene.Tracker.GetEntities<MoveBlockBarrier>()) {
99+
barrier.Collidable = true;
100+
}
101+
102+
bool result = orig(self, speed);
103+
104+
foreach (Entity barrier in self.Scene.Tracker.GetEntities<MoveBlockBarrier>()) {
105+
barrier.Collidable = false;
106+
}
107+
108+
return result;
109+
}
110+
111+
}
112+
}

SpringCollab2020Module.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ public SpringCollab2020Module() {
1313
public override void Load() {
1414
NoRefillField.Load();
1515
FloatierSpaceBlock.Load();
16+
MoveBlockBarrier.Load();
1617
}
1718

1819
public override void Unload() {
1920
NoRefillField.Unload();
2021
FloatierSpaceBlock.Unload();
22+
MoveBlockBarrier.Unload();
2123
}
2224
}
2325
}

0 commit comments

Comments
 (0)