Skip to content

Commit 776ec4b

Browse files
authored
Merge pull request #46 from EverestAPI/move_block_barrier
Move block barrier
2 parents 4add9a7 + 16a0d4f commit 776ec4b

File tree

4 files changed

+419
-0
lines changed

4 files changed

+419
-0
lines changed

Ahorn/entities/moveBlockBarrier.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
Ahorn.drawRectangle(ctx, 0, 0, width, height, (0.45, 0.0, 0.45, 0.8), (0.0, 0.0, 0.0, 0.0))
31+
end
32+
33+
end

Entities/MoveBlockBarrier.cs

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Reflection;
4+
using Celeste.Mod.Entities;
5+
using Microsoft.Xna.Framework;
6+
using Monocle;
7+
8+
namespace Celeste.Mod.SpringCollab2020.Entities {
9+
[CustomEntity("SpringCollab2020/moveBlockBarrier")]
10+
[Tracked(false)]
11+
public class MoveBlockBarrier : SeekerBarrier {
12+
13+
private static FieldInfo particlesInfo = typeof(SeekerBarrier).GetField("particles", BindingFlags.GetField | BindingFlags.Instance | BindingFlags.NonPublic);
14+
15+
public MoveBlockBarrier(EntityData data, Vector2 offset) : base(data, offset) {
16+
}
17+
18+
public override void Added(Scene scene) {
19+
base.Added(scene);
20+
scene.Tracker.GetEntity<SeekerBarrierRenderer>().Untrack(this);
21+
scene.Tracker.GetEntity<MoveBlockBarrierRenderer>().Track(this);
22+
}
23+
24+
public override void Removed(Scene scene) {
25+
base.Removed(scene);
26+
scene.Tracker.GetEntity<MoveBlockBarrierRenderer>().Untrack(this);
27+
}
28+
29+
public override void Render() {
30+
List<Vector2> particles = (List<Vector2>) particlesInfo.GetValue(this);
31+
Color color = Color.Pink * 0.5f;
32+
foreach (Vector2 particle in particles) {
33+
Draw.Pixel.Draw(Position + particle, Vector2.Zero, color);
34+
}
35+
if (Flashing) {
36+
Draw.Rect(base.Collider, Color.Pink * Flash * 0.5f);
37+
}
38+
}
39+
40+
public static void Load() {
41+
On.Celeste.MoveBlock.MoveCheck += MoveBlock_MoveCheck;
42+
On.Celeste.Platform.MoveHCollideSolids += Platform_MoveHCollideSolids;
43+
On.Celeste.Platform.MoveVCollideSolids += Platform_MoveVCollideSolids;
44+
On.Celeste.Actor.MoveHExact += Actor_MoveHExact;
45+
On.Celeste.Actor.MoveVExact += Actor_MoveVExact;
46+
}
47+
48+
public static void Unload() {
49+
On.Celeste.MoveBlock.MoveCheck -= MoveBlock_MoveCheck;
50+
On.Celeste.Platform.MoveHCollideSolids -= Platform_MoveHCollideSolids;
51+
On.Celeste.Platform.MoveVCollideSolids -= Platform_MoveVCollideSolids;
52+
On.Celeste.Actor.MoveHExact -= Actor_MoveHExact;
53+
On.Celeste.Actor.MoveVExact -= Actor_MoveVExact;
54+
}
55+
56+
static bool Platform_MoveHCollideSolids(On.Celeste.Platform.orig_MoveHCollideSolids orig, Platform self, float moveH, bool thruDashBlocks, Action<Vector2, Vector2, Platform> onCollide) {
57+
bool barrierWasCollidable = self.Scene.Tracker.GetEntity<MoveBlockBarrier>()?.Collidable ?? false;
58+
if (self is MoveBlock) {
59+
foreach (Entity barrier in self.Scene.Tracker.GetEntities<MoveBlockBarrier>()) {
60+
barrier.Collidable = true;
61+
}
62+
63+
bool result = orig(self, moveH, thruDashBlocks, onCollide);
64+
65+
foreach (Entity barrier in self.Scene.Tracker.GetEntities<MoveBlockBarrier>()) {
66+
barrier.Collidable = barrierWasCollidable;
67+
}
68+
69+
return result;
70+
}
71+
return orig(self, moveH, thruDashBlocks, onCollide);
72+
}
73+
74+
static bool Platform_MoveVCollideSolids(On.Celeste.Platform.orig_MoveVCollideSolids orig, Platform self, float moveV, bool thruDashBlocks, Action<Vector2, Vector2, Platform> onCollide) {
75+
bool barrierWasCollidable = self.Scene.Tracker.GetEntity<MoveBlockBarrier>()?.Collidable ?? false;
76+
if (self is MoveBlock) {
77+
foreach (Entity barrier in self.Scene.Tracker.GetEntities<MoveBlockBarrier>()) {
78+
barrier.Collidable = true;
79+
}
80+
81+
bool result = orig(self, moveV, thruDashBlocks, onCollide);
82+
83+
foreach (Entity barrier in self.Scene.Tracker.GetEntities<MoveBlockBarrier>()) {
84+
barrier.Collidable = barrierWasCollidable;
85+
}
86+
87+
return result;
88+
}
89+
return orig(self, moveV, thruDashBlocks, onCollide);
90+
}
91+
92+
93+
static bool Actor_MoveHExact(On.Celeste.Actor.orig_MoveHExact orig, Actor self, int moveH, Collision onCollide, Solid pusher) {
94+
bool barrierWasCollidable = self.Scene.Tracker.GetEntity<MoveBlockBarrier>()?.Collidable ?? false;
95+
foreach (Entity barrier in self.Scene.Tracker.GetEntities<MoveBlockBarrier>()) {
96+
barrier.Collidable = false;
97+
}
98+
99+
bool result = orig(self, moveH, onCollide, pusher);
100+
101+
foreach (Entity barrier in self.Scene.Tracker.GetEntities<MoveBlockBarrier>()) {
102+
barrier.Collidable = barrierWasCollidable;
103+
}
104+
105+
return result;
106+
}
107+
108+
static bool Actor_MoveVExact(On.Celeste.Actor.orig_MoveVExact orig, Actor self, int moveV, Collision onCollide, Solid pusher) {
109+
bool barrierWasCollidable = self.Scene.Tracker.GetEntity<MoveBlockBarrier>()?.Collidable ?? false;
110+
foreach (Entity barrier in self.Scene.Tracker.GetEntities<MoveBlockBarrier>()) {
111+
barrier.Collidable = false;
112+
}
113+
114+
bool result = orig(self, moveV, onCollide, pusher);
115+
116+
foreach (Entity barrier in self.Scene.Tracker.GetEntities<MoveBlockBarrier>()) {
117+
barrier.Collidable = barrierWasCollidable;
118+
}
119+
120+
return result;
121+
}
122+
123+
// Make the barrier temporarily collidable while checking MoveBlock collisions
124+
static bool MoveBlock_MoveCheck(On.Celeste.MoveBlock.orig_MoveCheck orig, MoveBlock self, Vector2 speed) {
125+
foreach (Entity barrier in self.Scene.Tracker.GetEntities<MoveBlockBarrier>()) {
126+
barrier.Collidable = true;
127+
}
128+
129+
bool result = orig(self, speed);
130+
131+
foreach (Entity barrier in self.Scene.Tracker.GetEntities<MoveBlockBarrier>()) {
132+
barrier.Collidable = false;
133+
}
134+
135+
return result;
136+
}
137+
138+
}
139+
}

0 commit comments

Comments
 (0)