Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gravity Helper support + other fixes #43

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion Code/Entities/BowlPuffer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Celeste.Mod.Entities;
using Celeste.Mod.VortexHelper.Misc;
using Microsoft.Xna.Framework;
using Monocle;
using System;
Expand Down Expand Up @@ -341,7 +342,7 @@ private void OnRelease(Vector2 force)

#endregion

#region Explosiong
#region Explosion

private void Explode(bool playsound = true)
{
Expand Down Expand Up @@ -764,6 +765,21 @@ public override void Render()
{
this.puffer.Scale = this.scale * (1f + this.inflateWiggler.Value * 0.4f);
this.puffer.FlipX = false;

// gravity helper forces a scale change on the default Sprite
if (Get<Sprite>() is { } sprite) sprite.Scale.Y = Math.Abs(sprite.Scale.Y);
bigkahuna443 marked this conversation as resolved.
Show resolved Hide resolved

// invert sprites if required
var inverted = GravityHelperInterop.IsActorInverted(this);
if (inverted)
{
this.puffer.Y *= -1;
this.pufferBowlTop.Y *= -1;
this.pufferBowlBottom.Y *= -1;
this.pufferBowlTop.Scale.Y *= -1;
this.pufferBowlBottom.Scale.Y *= -1;
this.puffer.Scale.Y *= -1;
}

Vector2 position = this.Position;
this.Position.Y -= 6.0f;
Expand Down Expand Up @@ -792,6 +808,16 @@ public override void Render()
Draw.Point(p, Color.Lerp(Color.OrangeRed, Color.LawnGreen, a / (float) Math.PI));
}
}

if (inverted)
{
this.puffer.Y *= -1;
this.pufferBowlTop.Y *= -1;
this.pufferBowlBottom.Y *= -1;
this.pufferBowlTop.Scale.Y *= -1;
this.pufferBowlBottom.Scale.Y *= -1;
this.puffer.Scale.Y *= -1;
}
}

public static void InitializeParticles()
Expand Down
49 changes: 36 additions & 13 deletions Code/Entities/FloorBooster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ private enum DisableMode

public bool IceMode;
public bool NoRefillsOnIce;
public bool Ceiling;

private DisableMode disableMode;

Expand All @@ -41,9 +42,12 @@ private enum DisableMode
public int MoveSpeed;

public FloorBooster(EntityData data, Vector2 offset)
: this(data.Position + offset, data.Width, data.Bool("left"), data.Int("speed"), data.Bool("iceMode"), data.Bool("noRefillOnIce"), data.Bool("notAttached")) { }
: this(data.Position + offset, data.Width, data.Bool("left"), data.Int("speed"), data.Bool("iceMode"), data.Bool("noRefillOnIce"), data.Bool("notAttached"), data.Bool("ceiling")) { }

public FloorBooster(Vector2 position, int width, bool left, int speed, bool iceMode, bool noRefillOnIce, bool notAttached)
: this(position, width, left, speed, iceMode, noRefillOnIce, notAttached, false) { }
bigkahuna443 marked this conversation as resolved.
Show resolved Hide resolved

public FloorBooster(Vector2 position, int width, bool left, int speed, bool iceMode, bool noRefillOnIce, bool notAttached, bool ceiling)
: base(position)
{
this.Tag = Tags.TransitionUpdate;
Expand All @@ -54,8 +58,9 @@ public FloorBooster(Vector2 position, int width, bool left, int speed, bool iceM
this.IceMode = iceMode;
this.MoveSpeed = (int) Calc.Max(0, speed);
this.Facing = left ? Facings.Left : Facings.Right;
this.Ceiling = ceiling;

this.Collider = new Hitbox(width, 3, 0, 5);
this.Collider = new Hitbox(width, 3, 0, ceiling ? 0 : 5);
if (!this.notCoreMode)
Add(new CoreModeListener(OnChangeMode));

Expand All @@ -74,7 +79,7 @@ public FloorBooster(Vector2 position, int width, bool left, int speed, bool iceM
});
}

this.tiles = BuildSprite(left);
this.tiles = BuildSprite(left, ceiling);
}

public void SetColor(Color color)
Expand Down Expand Up @@ -109,7 +114,7 @@ private void OnDisable()
this.Visible = false;
}

private List<Sprite> BuildSprite(bool left)
private List<Sprite> BuildSprite(bool left, bool ceiling)
{
var list = new List<Sprite>();
for (int i = 0; i < this.Width; i += 8)
Expand All @@ -128,6 +133,8 @@ private List<Sprite> BuildSprite(bool left)
Sprite sprite = VortexHelperModule.FloorBoosterSpriteBank.Create("FloorBooster" + id);
if (!left)
sprite.FlipX = true;
if (ceiling)
sprite.FlipY = true;

sprite.Position = new Vector2(i, 0);
list.Add(sprite);
Expand All @@ -151,11 +158,11 @@ private void OnChangeMode(Session.CoreModes mode)
this.idleSfx.Play(SFX.env_loc_09_conveyer_idle);
}

private bool IsRiding(JumpThru jumpThru) => CollideCheckOutside(jumpThru, this.Position + Vector2.UnitY);
private bool IsRiding(JumpThru jumpThru) => CollideCheckOutside(jumpThru, this.Position + (this.Ceiling ? -Vector2.UnitY : Vector2.UnitY));

private bool IsRiding(Solid solid)
{
if (CollideCheckOutside(solid, this.Position + Vector2.UnitY))
if (CollideCheckOutside(solid, this.Position + (this.Ceiling ? -Vector2.UnitY : Vector2.UnitY)))
{
this.disableMode = (solid is CassetteBlock or SwitchBlock) ? DisableMode.ColorFade : DisableMode.Disappear;
return true;
Expand Down Expand Up @@ -192,8 +199,10 @@ public override void Update()
bool isUsed = false;
base.Update();

if (player is not null && CollideCheck(player) && player.OnGround() && player.Bottom <= this.Bottom)
isUsed = true;
var matchGravity = this.Ceiling == GravityHelperInterop.IsPlayerInverted();

if (matchGravity && player is not null && CollideCheck(player) && player.OnGround())
isUsed = this.Ceiling ? player.Top >= this.Top : player.Bottom <= this.Bottom;

PlayActivateSfx(this.IceMode || !isUsed);
}
Expand Down Expand Up @@ -224,7 +233,7 @@ private void PositionSfx(Player entity)
return;

this.idleSfx.Position = Calc.ClosestPointOnLine(this.Position, this.Position + new Vector2(this.Width, 0f), entity.Center) - this.Position;
this.idleSfx.Position.Y += 7;
if (!this.Ceiling) this.idleSfx.Position.Y += 7;
this.activateSfx.Position = this.idleSfx.Position;
this.idleSfx.UpdateSfxPosition(); this.activateSfx.UpdateSfxPosition();
}
Expand Down Expand Up @@ -258,13 +267,18 @@ private static bool Player_RefillDash(On.Celeste.Player.orig_RefillDash orig, Pl
if (level.Transitioning)
return orig(self);

var playerInverted = GravityHelperInterop.IsPlayerInverted();

foreach (FloorBooster entity in self.Scene.Tracker.GetEntities<FloorBooster>())
{
if (!entity.IceMode)
continue;

if (entity.Ceiling != playerInverted)
continue;

if (self.CollideCheck(entity) && self.OnGround()
&& self.Bottom <= entity.Bottom
&& (entity.Ceiling ? self.Top >= entity.Top : self.Bottom <= entity.Bottom)
&& entity.NoRefillsOnIce)
return false;
}
Expand All @@ -289,8 +303,9 @@ private static int Player_NormalUpdate(On.Celeste.Player.orig_NormalUpdate orig,
playerData.Set("lastFloorBooster", null);

FloorBooster lastFloorBooster = playerData.Get<FloorBooster>("lastFloorBooster");
var playerInverted = GravityHelperInterop.IsPlayerInverted();

if (lastFloorBooster is not null && !self.CollideCheck(lastFloorBooster))
if (lastFloorBooster is not null && (lastFloorBooster.Ceiling != playerInverted || !self.CollideCheck(lastFloorBooster)))
{
Vector2 vec = Vector2.UnitX
* playerData.Get<float>("floorBoosterSpeed")
Expand All @@ -310,8 +325,11 @@ private static int Player_NormalUpdate(On.Celeste.Player.orig_NormalUpdate orig,
{
if (entity.IceMode)
continue;

if (entity.Ceiling != playerInverted)
continue;

if (self.CollideCheck(entity) && self.OnGround() && self.StateMachine != Player.StClimb && self.Bottom <= entity.Bottom)
if (self.CollideCheck(entity) && self.OnGround() && self.StateMachine != Player.StClimb && (entity.Ceiling ? self.Top >= entity.Top : self.Bottom <= entity.Bottom))
{
if (!touchedFloorBooster)
{
Expand Down Expand Up @@ -349,14 +367,19 @@ private static float GetPlayerFriction()
{
if (!Util.TryGetPlayer(out Player player))
return 1.0f;

var playerInverted = GravityHelperInterop.IsPlayerInverted();

foreach (FloorBooster entity in player.Scene.Tracker.GetEntities<FloorBooster>())
{
if (!entity.IceMode)
continue;

if (entity.Ceiling != playerInverted)
continue;

if (player.CollideCheck(entity) && player.OnGround() && player.StateMachine != Player.StClimb
&& player.Bottom <= entity.Bottom)
&& (entity.Ceiling ? player.Top >= entity.Top : player.Bottom <= entity.Bottom))
return player.SceneAs<Level>().CoreMode is Session.CoreModes.Cold ? 0.4f : 0.2f;
}

Expand Down
27 changes: 21 additions & 6 deletions Code/Entities/PurpleBooster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ public override void Update()
{
base.Update();

var inverted = GravityHelperInterop.IsPlayerInverted();

this.actualLinkPercent = Calc.Approach(this.actualLinkPercent, this.linkPercent, 5f * Engine.DeltaTime);

if (this.cannotUseTimer > 0f)
Expand All @@ -271,7 +273,10 @@ public override void Update()
Vector2 target = Vector2.Zero;
Player entity = this.Scene.Tracker.GetEntity<Player>();
if (entity is not null && CollideCheck(entity))
target = entity.Center + Booster.playerOffset - this.Position;
{
var playerOffset = new Vector2(Booster.playerOffset.X, inverted ? -Booster.playerOffset.Y : Booster.playerOffset.Y);
target = entity.Center + playerOffset - this.Position;
}
this.sprite.Position = Calc.Approach(this.sprite.Position, target, 80f * Engine.DeltaTime);
}

Expand Down Expand Up @@ -377,8 +382,10 @@ public static int PurpleBoostUpdate(Player player)
Vector2 value = Input.Aim.Value * 3f;
Vector2 vector = Calc.Approach(player.ExactPosition, boostTarget - player.Collider.Center + value, 80f * Engine.DeltaTime);

GravityHelperInterop.BeginOverride();
player.MoveToX(vector.X, null);
player.MoveToY(vector.Y, null);
GravityHelperInterop.EndOverride();

if (Vector2.DistanceSquared(player.Center, boostTarget) >= 275f)
{
Expand All @@ -403,9 +410,11 @@ public static int PurpleBoostUpdate(Player player)

public static void PurpleBoostEnd(Player player)
{
GravityHelperInterop.BeginOverride();
Vector2 vector = (player.boostTarget - player.Collider.Center).Floor();
player.MoveToX(vector.X, null);
player.MoveToY(vector.Y, null);
GravityHelperInterop.EndOverride();
}

public static IEnumerator PurpleBoostCoroutine(Player player)
Expand All @@ -414,12 +423,12 @@ public static IEnumerator PurpleBoostCoroutine(Player player)
player.StateMachine.State = VortexHelperModule.PurpleBoosterDashState;
}

// Arc Motion
// Arc Motion
public static void PurpleDashingBegin(Player player)
{
Celeste.Freeze(0.05f); // this freeze makes fastbubbling much more lenient
DynamicData playerData = DynamicData.For(player);
player.DashDir = Input.GetAimVector(player.Facing);
player.DashDir = GravityHelperInterop.InvertIfRequired(Input.GetAimVector(player.Facing));
playerData.Set(POSSIBLE_EARLY_DASHSPEED, Vector2.Zero);

foreach (PurpleBooster b in player.Scene.Tracker.GetEntities<PurpleBooster>())
Expand Down Expand Up @@ -469,22 +478,24 @@ public static IEnumerator PurpleDashingCoroutine(Player player)
Vector2 origin = player.boostTarget;
if(VortexHelperModule.SessionProperties.BoosterQoL) {
yield return null;
player.DashDir = player.lastAim;
player.DashDir = GravityHelperInterop.InvertIfRequired(player.lastAim);
}

Vector2 earlyExitBoost = Vector2.Zero;
while (t < 1f)
{
t = Calc.Approach(t, 1.0f, Engine.DeltaTime * 1.5f);
Vector2 vec = origin + Vector2.UnitY * 6f + player.DashDir * 60f * (float) Math.Sin(t * Math.PI);
float offset = GravityHelperInterop.IsPlayerInverted() ? -6f : 6f;
Vector2 vec = origin + Vector2.UnitY * offset + player.DashDir * 60f * (float) Math.Sin(t * Math.PI);

if(VortexHelperModule.SessionProperties.BoosterQoL)
{
if(t == 1f)
{
// frame 0: mimics speed at launch exit exactly, Input.MoveX.Value == -Math.Sign(player.DashDir) ? 300 : 250
earlyExitBoost = 250f * -player.DashDir;
Vector2 aim = Input.GetAimVector(player.Facing).EightWayNormal().Sign();
Vector2 aim = GravityHelperInterop.InvertIfRequired(Input.GetAimVector(player.Facing));
aim = aim.EightWayNormal().Sign();
if (aim.X == Math.Sign(earlyExitBoost.X)) earlyExitBoost.X *= 1.2f;
if (aim.Y == Math.Sign(earlyExitBoost.Y)) earlyExitBoost.Y *= 1.2f;
} else if(t > 0.93f)
Expand All @@ -505,7 +516,9 @@ public static IEnumerator PurpleDashingCoroutine(Player player)
player.StateMachine.State = Player.StNormal;
yield break;
}
GravityHelperInterop.BeginOverride();
player.MoveToX(vec.X); player.MoveToY(vec.Y);
GravityHelperInterop.EndOverride();
yield return null;
}

Expand All @@ -531,6 +544,8 @@ public static void PurpleBoosterExplodeLaunch(Player player, Vector2 from, Vecto
level.Shake(0.15f);

Vector2 vector = (player.Center - from).SafeNormalize(-Vector2.UnitY);
vector = GravityHelperInterop.InvertIfRequired(vector);

if (Math.Abs(vector.X) < 1f && Math.Abs(vector.Y) < 1f)
vector *= 1.1f;

Expand Down
23 changes: 23 additions & 0 deletions Code/Misc/GravityHelperInterop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Microsoft.Xna.Framework;
using MonoMod.ModInterop;
using System;

namespace Celeste.Mod.VortexHelper.Misc;

internal static class GravityHelperInterop
{
[ModImportName("GravityHelper")]
internal static class Imports
{
public static Func<bool> IsPlayerInverted;

Check warning on line 12 in Code/Misc/GravityHelperInterop.cs

View workflow job for this annotation

GitHub Actions / build

Field 'GravityHelperInterop.Imports.IsPlayerInverted' is never assigned to, and will always have its default value null

Check warning on line 12 in Code/Misc/GravityHelperInterop.cs

View workflow job for this annotation

GitHub Actions / build

Field 'GravityHelperInterop.Imports.IsPlayerInverted' is never assigned to, and will always have its default value null
public static Func<Actor, bool> IsActorInverted;

Check warning on line 13 in Code/Misc/GravityHelperInterop.cs

View workflow job for this annotation

GitHub Actions / build

Field 'GravityHelperInterop.Imports.IsActorInverted' is never assigned to, and will always have its default value null

Check warning on line 13 in Code/Misc/GravityHelperInterop.cs

View workflow job for this annotation

GitHub Actions / build

Field 'GravityHelperInterop.Imports.IsActorInverted' is never assigned to, and will always have its default value null
public static Action BeginOverride;

Check warning on line 14 in Code/Misc/GravityHelperInterop.cs

View workflow job for this annotation

GitHub Actions / build

Field 'GravityHelperInterop.Imports.BeginOverride' is never assigned to, and will always have its default value null

Check warning on line 14 in Code/Misc/GravityHelperInterop.cs

View workflow job for this annotation

GitHub Actions / build

Field 'GravityHelperInterop.Imports.BeginOverride' is never assigned to, and will always have its default value null
public static Action EndOverride;

Check warning on line 15 in Code/Misc/GravityHelperInterop.cs

View workflow job for this annotation

GitHub Actions / build

Field 'GravityHelperInterop.Imports.EndOverride' is never assigned to, and will always have its default value null

Check warning on line 15 in Code/Misc/GravityHelperInterop.cs

View workflow job for this annotation

GitHub Actions / build

Field 'GravityHelperInterop.Imports.EndOverride' is never assigned to, and will always have its default value null
}

public static bool IsPlayerInverted() => Imports.IsPlayerInverted?.Invoke() ?? false;
public static bool IsActorInverted(Actor actor) => Imports.IsActorInverted?.Invoke(actor) ?? false;
public static void BeginOverride() => Imports.BeginOverride?.Invoke();
public static void EndOverride() => Imports.EndOverride?.Invoke();
public static Vector2 InvertIfRequired(Vector2 v) => IsPlayerInverted() ? new Vector2(v.X, -v.Y) : v;
}
3 changes: 3 additions & 0 deletions Code/VortexHelperModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Celeste.Mod.VortexHelper.Misc;
using Microsoft.Xna.Framework;
using Monocle;
using MonoMod.ModInterop;
using System;
using System.Reflection;

Expand Down Expand Up @@ -69,6 +70,8 @@ public override void Load()
MiscHooks.Hook();

Util.LoadDelegates();

typeof(GravityHelperInterop.Imports).ModInterop();
}

public override void Unload()
Expand Down
2 changes: 1 addition & 1 deletion Loenn/entities/bowl_puffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ bowlPuffer.placements = {
}

bowlPuffer.texture = "objects/VortexHelper/pufferBowl/idle00"
bowlPuffer.offset = {32, 35}
bowlPuffer.offset = {0, 3}
swoolcock marked this conversation as resolved.
Show resolved Hide resolved

function bowlPuffer.selection(room, entity)
return utils.rectangle((entity.x or 0) - 11, (entity.y or 0) - 11, 21, 19)
Expand Down
Loading
Loading