Skip to content

Commit 9b5170b

Browse files
authored
Merge pull request #83 from aridai-shi/lightning_dash_switch
Lightning Dash Switch
2 parents 546c5f3 + 6057b97 commit 9b5170b

File tree

2 files changed

+199
-0
lines changed

2 files changed

+199
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
module SpringCollabLightningDashSwitch
2+
3+
using ..Ahorn, Maple
4+
5+
sides = String[
6+
"left",
7+
"right",
8+
"up",
9+
"down"
10+
]
11+
12+
textures = String[
13+
"default",
14+
"mirror"
15+
]
16+
17+
@mapdef Entity "SpringCollab2020/LightningDashSwitch" LDashSwitch(x::Integer, y::Integer, side::String="up", persistent::Bool=false, sprite::String="default")
18+
19+
const placements = Ahorn.PlacementDict(
20+
"Lightning Dash Switch ($(uppercasefirst(side))) (Spring Collab 2020)" => Ahorn.EntityPlacement(
21+
LDashSwitch,
22+
"rectangle",
23+
Dict{String, Any}(
24+
"side" => side
25+
)
26+
) for side in sides
27+
)
28+
29+
Ahorn.editingOptions(entity::LDashSwitch) = Dict{String, Any}(
30+
"side" => sides
31+
)
32+
33+
function Ahorn.selection(entity::LDashSwitch)
34+
x, y = Ahorn.position(entity)
35+
side = get(entity.data, "side", false)
36+
37+
if side == "left"
38+
return Ahorn.Rectangle(x, y - 1, 10, 16)
39+
elseif side == "right"
40+
return Ahorn.Rectangle(x - 2, y, 10, 16)
41+
elseif side == "down"
42+
return Ahorn.Rectangle(x, y, 16, 12)
43+
elseif side == "up"
44+
return Ahorn.Rectangle(x, y - 4, 16, 12)
45+
end
46+
end
47+
48+
function Ahorn.render(ctx::Ahorn.Cairo.CairoContext, entity::LDashSwitch, room::Maple.Room)
49+
sprite = get(entity.data, "sprite", "default")
50+
side = get(entity.data, "side", "up")
51+
texture = sprite == "default" ? "objects/temple/dashButton00.png" : "objects/temple/dashButtonMirror00.png"
52+
53+
if side == "left"
54+
Ahorn.drawSprite(ctx, texture, 20, 25, rot=pi)
55+
elseif side == "right"
56+
Ahorn.drawSprite(ctx, texture, 8, 8)
57+
elseif side == "up"
58+
Ahorn.drawSprite(ctx, texture, 9, 20, rot=-pi / 2)
59+
elseif side == "down"
60+
Ahorn.drawSprite(ctx, texture, 27, 7, rot=pi / 2)
61+
end
62+
end
63+
64+
end

Entities/LightningDashSwitch.cs

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
using Celeste.Mod.Entities;
2+
using Microsoft.Xna.Framework;
3+
using Monocle;
4+
using System;
5+
namespace Celeste.Mod.SpringCollab2020.Entities {
6+
[CustomEntity("SpringCollab2020/LightningDashSwitch")]
7+
8+
public class LDashSwitch : Solid {
9+
public LDashSwitch(EntityData data, Vector2 offset) : this(data.Position + offset, data.Enum("side", Sides.Up), data.Bool("persistent", false), new EntityID(data.Level.Name, data.ID), data.Attr("sprite", "default")) { }
10+
11+
public LDashSwitch(Vector2 position, Sides side, bool persistent, EntityID id, string spriteName) : base(position, 0f, 0f, true) {
12+
this.side = side;
13+
this.persistent = persistent;
14+
this.id = id;
15+
mirrorMode = (spriteName != "default");
16+
Add(sprite = GFX.SpriteBank.Create("DashSwitch_" + spriteName));
17+
sprite.Play("idle", false, false);
18+
if (side == Sides.Up || side == Sides.Down) {
19+
Collider.Width = 16f;
20+
Collider.Height = 8f;
21+
} else {
22+
Collider.Width = 8f;
23+
Collider.Height = 16f;
24+
}
25+
switch (side) {
26+
case Sides.Up:
27+
sprite.Position = new Vector2(8f, 0f);
28+
sprite.Rotation = -1.5707964f;
29+
pressedTarget = Position + Vector2.UnitY * -8f;
30+
pressDirection = -Vector2.UnitY;
31+
break;
32+
case Sides.Down:
33+
sprite.Position = new Vector2(8f, 8f);
34+
sprite.Rotation = 1.5707964f;
35+
pressedTarget = Position + Vector2.UnitY * 8f;
36+
pressDirection = Vector2.UnitY;
37+
startY = Y;
38+
break;
39+
case Sides.Left:
40+
sprite.Position = new Vector2(0f, 8f);
41+
sprite.Rotation = 3.1415927f;
42+
pressedTarget = Position + Vector2.UnitX * -8f;
43+
pressDirection = -Vector2.UnitX;
44+
break;
45+
case Sides.Right:
46+
sprite.Position = new Vector2(8f, 8f);
47+
sprite.Rotation = 0f;
48+
pressedTarget = Position + Vector2.UnitX * 8f;
49+
pressDirection = Vector2.UnitX;
50+
break;
51+
}
52+
OnDashCollide = new DashCollision(OnDashed);
53+
}
54+
55+
public override void Awake(Scene scene) {
56+
base.Awake(scene);
57+
if (persistent && SceneAs<Level>().Session.GetFlag(FlagName)) {
58+
sprite.Play("pushed", false, false);
59+
Position = pressedTarget - pressDirection * 2f;
60+
pressed = true;
61+
Collidable = false;
62+
Add(new Coroutine(Lightning.RemoveRoutine(SceneAs<Level>()), true));
63+
}
64+
}
65+
66+
public override void Update() {
67+
base.Update();
68+
if (!pressed && side == Sides.Down) {
69+
Player playerOnTop = GetPlayerOnTop();
70+
if (playerOnTop != null) {
71+
if (playerOnTop.Holding != null) {
72+
OnDashed(playerOnTop, Vector2.UnitY);
73+
} else {
74+
if (speedY < 0f) {
75+
speedY = 0f;
76+
}
77+
speedY = Calc.Approach(speedY, 70f, 200f * Engine.DeltaTime);
78+
MoveTowardsY(startY + 2f, speedY * Engine.DeltaTime);
79+
if (!playerWasOn) {
80+
Audio.Play("event:/game/05_mirror_temple/button_depress", Position);
81+
}
82+
}
83+
} else {
84+
if (speedY > 0f) {
85+
speedY = 0f;
86+
}
87+
speedY = Calc.Approach(speedY, -150f, 200f * Engine.DeltaTime);
88+
MoveTowardsY(startY, -speedY * Engine.DeltaTime);
89+
if (playerWasOn) {
90+
Audio.Play("event:/game/05_mirror_temple/button_return", Position);
91+
}
92+
}
93+
playerWasOn = (playerOnTop != null);
94+
}
95+
}
96+
97+
public DashCollisionResults OnDashed(Player player, Vector2 direction) {
98+
if (!pressed && direction == pressDirection) {
99+
Input.Rumble(RumbleStrength.Medium, RumbleLength.Medium);
100+
Audio.Play("event:/game/05_mirror_temple/button_activate", Position);
101+
sprite.Play("push", false, false);
102+
pressed = true;
103+
MoveTo(pressedTarget);
104+
Collidable = false;
105+
Position -= pressDirection * 2f;
106+
Add(new Coroutine(Lightning.RemoveRoutine(SceneAs<Level>()), true));
107+
}
108+
return DashCollisionResults.NormalCollision;
109+
}
110+
111+
private string FlagName {
112+
get {
113+
return "LDashSwitch_" + id.Key;
114+
}
115+
}
116+
117+
private Sides side;
118+
private Vector2 pressedTarget;
119+
private bool pressed;
120+
private Vector2 pressDirection;
121+
private float speedY;
122+
private float startY;
123+
private bool persistent;
124+
private EntityID id;
125+
private bool mirrorMode;
126+
private bool playerWasOn;
127+
private Sprite sprite;
128+
public enum Sides {
129+
Up,
130+
Down,
131+
Left,
132+
Right
133+
}
134+
}
135+
}

0 commit comments

Comments
 (0)