Skip to content

Commit 135b00b

Browse files
authored
Return Berry Improvements (#64)
Return Berry Improvements
2 parents 48e87fa + 561c04f commit 135b00b

File tree

3 files changed

+65
-8
lines changed

3 files changed

+65
-8
lines changed

Ahorn/entities/bubbleReturnBerry.jl

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,25 @@
22

33
using ..Ahorn, Maple
44

5-
@mapdef Entity "SpringCollab2020/returnBerry" ReturnBerry(x::Integer, y::Integer, order::Integer=-1, checkpointID::Integer=-1, winged::Bool=false)
5+
@mapdef Entity "SpringCollab2020/returnBerry" ReturnBerry(x::Integer, y::Integer, order::Integer=-1, checkpointID::Integer=-1, winged::Bool=false, nodes::Array{Tuple{Integer, Integer}, 1}=Tuple{Integer, Integer}[])
66

77
const placements = Ahorn.PlacementDict(
8-
"Strawberry With Return (Spring Collab 2020)" => Ahorn.EntityPlacement(
8+
"Strawberry (With Return) (Spring Collab 2020)" => Ahorn.EntityPlacement(
99
ReturnBerry
10+
),
11+
"Strawberry (Winged, With Return) (Spring Collab 2020)" => Ahorn.EntityPlacement(
12+
ReturnBerry,
13+
"point",
14+
Dict{String,Any}(
15+
"winged" => true
16+
)
1017
)
1118
)
1219

20+
seedSprite = "collectables/strawberry/seed00"
21+
22+
Ahorn.nodeLimits(entity::ReturnBerry) = 0, -1
23+
1324
function getSpriteName(entity::ReturnBerry)
1425
winged = get(entity.data, "winged", false)
1526

@@ -22,12 +33,37 @@ end
2233

2334
function Ahorn.selection(entity::ReturnBerry)
2435
x, y = Ahorn.position(entity)
36+
nodes = get(entity.data, "nodes", ())
37+
38+
res = Ahorn.Rectangle[Ahorn.getSpriteRectangle(getSpriteName(entity), x, y)]
39+
40+
for node in nodes
41+
nx, ny = node
42+
push!(res, Ahorn.getSpriteRectangle(seedSprite, nx, ny))
43+
end
44+
45+
return res
46+
end
47+
48+
function Ahorn.renderSelectedAbs(ctx::Ahorn.Cairo.CairoContext, entity::ReturnBerry)
49+
x, y = Ahorn.position(entity)
2550

26-
return Ahorn.getSpriteRectangle(getSpriteName(entity), x, y)
51+
for node in get(entity.data, "nodes", ())
52+
nx, ny = node
53+
54+
Ahorn.drawLines(ctx, Tuple{Number, Number}[(x, y), (nx, ny)], Ahorn.colors.selection_selected_fc)
55+
end
2756
end
2857

2958
function Ahorn.renderAbs(ctx::Ahorn.Cairo.CairoContext, entity::ReturnBerry, room::Maple.Room)
3059
x, y = Ahorn.position(entity)
60+
nodes = get(entity.data, "nodes", ())
61+
62+
for node in nodes
63+
nx, ny = node
64+
65+
Ahorn.drawSprite(ctx, seedSprite, nx, ny)
66+
end
3167

3268
Ahorn.drawSprite(ctx, getSpriteName(entity), x, y)
3369
end

Entities/BubbleReturnBerry.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,41 @@
1-
using Celeste;
2-
using Celeste.Mod.Entities;
1+
using Celeste.Mod.Entities;
32
using Microsoft.Xna.Framework;
43
using Monocle;
54
using System;
65
using System.Collections;
76

87
namespace Celeste.Mod.SpringCollab2020.Entities {
9-
[CustomEntity("SpringCollab2020/returnBerry")]
108
[RegisterStrawberry(true, false)]
9+
[CustomEntity("SpringCollab2020/returnBerry")]
1110
class BubbleReturnBerry : Strawberry {
1211
public BubbleReturnBerry(EntityData data, Vector2 position, EntityID gid) : base(data, position, gid) {
1312
Add(collider = new PlayerCollider(new Action<Player>(OnPlayer)));
1413
}
1514

15+
public static void Load() {
16+
On.Celeste.Player.OnSquish += ModOnSquish;
17+
}
18+
19+
public static void Unload() {
20+
On.Celeste.Player.OnSquish -= ModOnSquish;
21+
}
22+
1623
public new void OnPlayer(Player player) {
17-
Add(new Coroutine(Return(player), true));
24+
base.OnPlayer(player);
25+
26+
if (!WaitingOnSeeds) {
27+
Add(new Coroutine(Return(player), true));
28+
Collidable = false;
29+
}
30+
}
31+
32+
private static void ModOnSquish(On.Celeste.Player.orig_OnSquish orig, Player player, CollisionData data) {
33+
// State 21 is the state where the player is located within the Cassette Bubble.
34+
// They shouldn't be squished by moving blocks inside of it, so we prevent that.
35+
if (player.StateMachine.State == 21)
36+
return;
1837

19-
Collidable = false;
38+
orig(player, data);
2039
}
2140

2241
private IEnumerator Return(Player player) {

SpringCollab2020Module.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public override void Load() {
1818
RemoveLightSourcesTrigger.Load();
1919
SafeRespawnCrumble.Load();
2020
UpsideDownJumpThru.Load();
21+
BubbleReturnBerry.Load();
2122
SidewaysJumpThru.Load();
2223
}
2324

@@ -35,6 +36,7 @@ public override void Unload() {
3536
SafeRespawnCrumble.Unload();
3637
GlassBerry.Unload();
3738
UpsideDownJumpThru.Unload();
39+
BubbleReturnBerry.Unload();
3840
SidewaysJumpThru.Unload();
3941
}
4042
}

0 commit comments

Comments
 (0)