Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
swoolcock committed Aug 24, 2024
2 parents f58b0b5 + 34e05c9 commit a92b204
Show file tree
Hide file tree
Showing 15 changed files with 197 additions and 50 deletions.
2 changes: 1 addition & 1 deletion Loenn/consts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ local function makeOptions(options, defaults, ...)
end

local consts = {
modVersion = "1.2.18",
modVersion = "1.2.19",
ignoredFields = {
"modVersion",
"pluginVersion",
Expand Down
1 change: 1 addition & 0 deletions Loenn/entities/gravityDreamBlock.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ local placementData = helpers.createPlacementData('1', {
fallType = 0,
climbFall = true,
endFallOnSolidTiles = true,
invertFallingDirFlag = "",
})

local gravityDreamBlock = {
Expand Down
1 change: 1 addition & 0 deletions Loenn/entities/inversionBlock.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ local placementData = helpers.createPlacementData('2', {
fallType = 0,
climbFall = true,
endFallOnSolidTiles = true,
invertFallingDirFlag = "",
sound = "event:/char/badeline/disappear",
autotile = false,
tiletype = fakeTilesHelper.getPlacementMaterial(),
Expand Down
1 change: 1 addition & 0 deletions Loenn/entities/upsideDownJumpThru.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ local placementData = helpers.createPlacementData('1', {
texture = "wood",
attached = false,
triggerStaticMovers = true,
invisible = false,
})

local upsideDownJumpThru = {
Expand Down
3 changes: 3 additions & 0 deletions Loenn/lang/en_gb.lang
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ entities.GravityHelper/GravityDreamBlock.attributes.description.particleColor=Th
entities.GravityHelper/GravityDreamBlock.attributes.description.fallType=The type of fall that should be triggered if the dream block is stepped on or dashed through. Defaults to None.
entities.GravityHelper/GravityDreamBlock.attributes.description.climbFall=Whether the dream block should fall if climbed. Requires "fallType" to be something other than None. Defaults to true.
entities.GravityHelper/GravityDreamBlock.attributes.description.endFallOnSolidTiles=Whether the dream block should stop falling once it hits foreground tiles.\nDefaults to true, but you may want to set this to false if "fallType" is dependent on the player's gravity.
entities.GravityHelper/GravityDreamBlock.attributes.description.invertFallingDirFlag=Flag which, when enabled, inverts the current falling direction. The original falling direction is restored when the flag is disabled.\nHas no effect if left empty or if "fallType" is set to None.

# Gravity Field
entities.GravityHelper/GravityField.placements.name.normal=Gravity Field (Normal)
Expand Down Expand Up @@ -217,6 +218,7 @@ entities.GravityHelper/UpsideDownJumpThru.attributes.description.texture=The spr
entities.GravityHelper/UpsideDownJumpThru.attributes.description.surfaceIndex=The sound to use for the jump through. Defaults to -1, which uses the expected sound for the texture.
entities.GravityHelper/UpsideDownJumpThru.attributes.description.attached=Whether the upside down jump through should attach to solids. Defaults to false.
entities.GravityHelper/UpsideDownJumpThru.attributes.description.triggerStaticMovers=Whether an attached upside down jump through should trigger static movers. Defaults to true.
entities.GravityHelper/UpsideDownJumpThru.attributes.description.invisible=Whether the upside down jump through should be hidden. Defaults to false.

# Upside Down Watch Tower
entities.GravityHelper/UpsideDownWatchTower.placements.name.normal=Upside Down Watch Tower
Expand Down Expand Up @@ -348,6 +350,7 @@ entities.GravityHelper/InversionBlock.attributes.description.rightEnabled=Whethe
entities.GravityHelper/InversionBlock.attributes.description.fallType=The type of fall that should be triggered if the inversion block is stepped on. Defaults to None.
entities.GravityHelper/InversionBlock.attributes.description.climbFall=Whether the inversion block should fall if climbed. Requires "fallType" to be something other than None. Defaults to true.
entities.GravityHelper/InversionBlock.attributes.description.endFallOnSolidTiles=Whether the inversion block should stop falling once it hits foreground tiles.\nDefaults to true, but you may want to set this to false if "fallType" is dependent on the player's gravity.
entities.GravityHelper/InversionBlock.attributes.description.invertFallingDirFlag=Flag which, when enabled, inverts the current falling direction. The original falling direction is restored when the flag is disabled.\nHas no effect if left empty or if "fallType" is set to None.
entities.GravityHelper/InversionBlock.attributes.description.defaultToController=If true (default), supported properties for this entity will use the value from the active controller.
entities.GravityHelper/InversionBlock.attributes.description.sound=The sound to play when travelling through this inversion block. Defaults to event:/char/badeline/disappear (the sound when the final Badeline chaser disappears in 2A), or the active controller.
entities.GravityHelper/InversionBlock.attributes.description.autotile=Whether this block should be rendered as a tile entity, similar to a falling block. Defaults to false.
Expand Down
45 changes: 28 additions & 17 deletions Source/Components/FallingComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ internal class FallingComponent : Component
public bool ShouldManageSafe = true;
public FallingType FallType = FallingType.Down;
public bool EndOnSolidTiles = true;
public string InvertFallingDirFlag = "";

// coroutine properties
public bool Triggered;
Expand All @@ -36,8 +37,11 @@ internal class FallingComponent : Component
// ReSharper disable once NotAccessedField.Local
private Coroutine _coroutine;
private float _fallDelayRemaining;

private bool _fallingUp;

private bool shouldFallUp() => _fallingUp ^ (!string.IsNullOrWhiteSpace(InvertFallingDirFlag) && Entity.SceneAs<Level>().Session.GetFlag(InvertFallingDirFlag));

public new Solid Entity => base.Entity as Solid;

public FallingComponent() : base(false, false)
Expand Down Expand Up @@ -93,15 +97,17 @@ private void fallParticles()
{
if (Entity == null) return;
var level = Entity.SceneAs<Level>();
var fallingUp = shouldFallUp();

for (int x = 2; x < Entity.Width; x += 4)
{
var position = new Vector2(Entity.X + x, Entity.Y);
var range = Vector2.One * 4f;
var direction = (float)Math.PI / 2f;
var offset = new Vector2(x, -2f);
var check = _fallingUp ? Entity.BottomLeft - offset : Entity.TopLeft + offset;
var check = fallingUp ? Entity.BottomLeft - offset : Entity.TopLeft + offset;
if (level.CollideCheck<Solid>(check))
level.Particles.Emit(FallingBlock.P_FallDustA, 2, position, range, _fallingUp ? -direction : direction);
level.Particles.Emit(FallingBlock.P_FallDustA, 2, position, range, fallingUp ? -direction : direction);
level.Particles.Emit(FallingBlock.P_FallDustB, 2, position, range);
}
}
Expand All @@ -110,18 +116,20 @@ private void landParticles()
{
if (Entity == null) return;
var level = Entity.SceneAs<Level>();
var fallingUp = shouldFallUp();

for (int x = 2; x <= Entity.Width; x += 4)
{
var offset = new Vector2(x, 3f);
var checkPosition = _fallingUp ? Entity.TopLeft - offset : Entity.BottomLeft + offset;
var checkPosition = fallingUp ? Entity.TopLeft - offset : Entity.BottomLeft + offset;
if (level.CollideCheck<Solid>(checkPosition))
{
var position = new Vector2(Entity.X + x, _fallingUp ? Entity.Top : Entity.Bottom);
var position = new Vector2(Entity.X + x, fallingUp ? Entity.Top : Entity.Bottom);
var range = Vector2.One * 4f;
var fallDustDirection = -(float)Math.PI / 2f;
level.ParticlesFG.Emit(FallingBlock.P_FallDustA, 1, position, range, _fallingUp ? -fallDustDirection : fallDustDirection);
level.ParticlesFG.Emit(FallingBlock.P_FallDustA, 1, position, range, fallingUp ? -fallDustDirection : fallDustDirection);
var landDustDirection = x >= Entity.Width / 2f ? 0f : (float)Math.PI;
level.ParticlesFG.Emit(FallingBlock.P_LandDust, 1, position, range, _fallingUp ? -landDustDirection : landDustDirection);
level.ParticlesFG.Emit(FallingBlock.P_LandDust, 1, position, range, fallingUp ? -landDustDirection : landDustDirection);
}
}
}
Expand Down Expand Up @@ -177,26 +185,29 @@ private IEnumerator fallingSequence()
self.FallParticles?.Invoke();

// fall
float speed = 0f;
float vel = 0f;
float maxSpeed = self.FallSpeed;
while (true)
{
// update the speed
speed = Calc.Approach(speed, maxSpeed, 500f * Engine.DeltaTime);
// see if we're falling up on this frame
var fallingUp = shouldFallUp();
// update the velocity
vel = Calc.Approach(vel, maxSpeed * (fallingUp ? -1 : 1), 500f * Engine.DeltaTime);
// try to move
if (!entity.MoveVCollideSolids(speed * Engine.DeltaTime * (_fallingUp ? -1 : 1), true))
if (!entity.MoveVCollideSolids(vel * Engine.DeltaTime, true))
{
// if we've fallen out the bottom of the screen, we should remove the entity
// otherwise yield for a frame and loop
if (!_fallingUp && entity.Top <= level.Bounds.Bottom + 16 && (entity.Top <= level.Bounds.Bottom - 1 || !entity.CollideCheck<Solid>(entity.Position + Vector2.UnitY)) ||
_fallingUp && entity.Bottom >= level.Bounds.Top - 16 && (entity.Bottom >= level.Bounds.Top + 1 || !entity.CollideCheck<Solid>(entity.Position - Vector2.UnitY)))
if (!fallingUp && entity.Top <= level.Bounds.Bottom + 16 && (entity.Top <= level.Bounds.Bottom - 1 || !entity.CollideCheck<Solid>(entity.Position + Vector2.UnitY)) ||
fallingUp && entity.Bottom >= level.Bounds.Top - 16 && (entity.Bottom >= level.Bounds.Top + 1 || !entity.CollideCheck<Solid>(entity.Position - Vector2.UnitY)))
yield return null;
else
{
// we've fallen out of the screen and should remove the entity
entity.Collidable = entity.Visible = false;
yield return 0.2f;
if (level.Session.MapData.CanTransitionTo(level, new Vector2(entity.Center.X, _fallingUp ? (entity.Top - 12f) : (entity.Bottom + 12f))))
// note: make sure we use the same snapshot fallingUp that triggered this code path
if (level.Session.MapData.CanTransitionTo(level, new Vector2(entity.Center.X, fallingUp ? (entity.Top - 12f) : (entity.Bottom + 12f))))
{
yield return 0.2f;
level.Shake();
Expand All @@ -218,21 +229,21 @@ private IEnumerator fallingSequence()
// impact effects
self.ImpactSfx?.Invoke();
if (self.ShouldRumble) Input.Rumble(RumbleStrength.Strong, RumbleLength.Medium);
level.DirectionalShake(_fallingUp ? -Vector2.UnitY : Vector2.UnitY);
level.DirectionalShake(shouldFallUp() ? -Vector2.UnitY : Vector2.UnitY);
entity.StartShaking();
self.LandParticles?.Invoke();
yield return 0.2f;
entity.StopShaking();

// if it's hit the fg tiles then make it safe and end
if (EndOnSolidTiles && entity.CollideCheck<SolidTiles>(entity.Position + (_fallingUp ? -Vector2.UnitY : Vector2.UnitY)))
// if it's hit the fg tiles and the falling dir cannot be changed then make it safe and end
if (EndOnSolidTiles && entity.CollideCheck<SolidTiles>(entity.Position + (shouldFallUp() ? -Vector2.UnitY : Vector2.UnitY)) && InvertFallingDirFlag == "")
{
entity.Safe |= self.ShouldManageSafe;
yield break;
}

// wait until we can fall again
while (entity.CollideCheck<Platform>(entity.Position + (_fallingUp ? -Vector2.UnitY : Vector2.UnitY)))
while (entity.CollideCheck<Platform>(entity.Position + (shouldFallUp() ? -Vector2.UnitY : Vector2.UnitY)))
{
yield return 0.1f;
// if the block is dependent on the player's gravity and the player is able to trigger it, update _fallingUp
Expand Down
1 change: 1 addition & 0 deletions Source/Components/GravityComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public override void Update()
var isInverted = CurrentGravity == GravityType.Inverted;
if (flagValue != isInverted)
{
// TODO: might want to prevent flips if in an opposing gravity field, similar to dash-to-toggle
SetGravity(flagValue ? GravityType.Inverted : GravityType.Normal);
}
}
Expand Down
3 changes: 3 additions & 0 deletions Source/Entities/GravityBumper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public GravityBumper(EntityData data, Vector2 offset)
sine.Active = false;
}

// update the position manually since the sine may have changed since base()
UpdatePosition();

var spriteName = _spriteName;
if (string.IsNullOrWhiteSpace(spriteName))
{
Expand Down
1 change: 1 addition & 0 deletions Source/Entities/GravityDreamBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public GravityDreamBlock(EntityData data, Vector2 offset)
ClimbFall = data.Bool("climbFall", true),
FallType = fallType,
EndOnSolidTiles = data.Bool("endFallOnSolidTiles", true),
InvertFallingDirFlag = data.Attr("invertFallingDirFlag", ""),
});
}

Expand Down
1 change: 1 addition & 0 deletions Source/Entities/InversionBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ public InversionBlock(EntityData data, Vector2 offset)
ClimbFall = data.Bool("climbFall", true),
FallType = fallType,
EndOnSolidTiles = data.Bool("endFallOnSolidTiles", true),
InvertFallingDirFlag = data.Attr("invertFallingDirFlag", ""),
});
}
}
Expand Down
90 changes: 60 additions & 30 deletions Source/Entities/UpsideDownJumpThru.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,28 @@ public class UpsideDownJumpThru : JumpThru
private readonly int _overrideSoundIndex;
private readonly bool _attached;
private readonly bool _triggerStaticMovers;
private readonly bool _invisible;

private Vector2 shakeOffset;
private Vector2 _shakeOffset;
private Platform _attachedPlatform;
private readonly StaticMover _staticMover;
private StaticMover _staticMover;

public UpsideDownJumpThru(Vector2 position, int width, string overrideTexture, int overrideSoundIndex = -1,
bool safe = true, bool attached = false, bool triggerStaticMovers = true, bool invisible = false)
: base(position, width, safe)
{
_modVersion = default;
_pluginVersion = default;

_columns = width / 8;
_overrideTexture = overrideTexture;
_overrideSoundIndex = overrideSoundIndex;
_attached = attached;
_triggerStaticMovers = triggerStaticMovers;
_invisible = invisible;

init();
}

public UpsideDownJumpThru(EntityData data, Vector2 offset)
: base(data.Position + offset, data.Width, true)
Expand All @@ -39,7 +57,13 @@ public UpsideDownJumpThru(EntityData data, Vector2 offset)
_overrideSoundIndex = data.Int("surfaceIndex", -1);
_attached = data.Bool("attached", false);
_triggerStaticMovers = data.Bool("triggerStaticMovers", true);
_invisible = data.Bool("invisible", false);

init();
}

private void init()
{
if (_attached)
{
List<Actor> sharedRiders = new();
Expand Down Expand Up @@ -80,7 +104,7 @@ solid is not FloatySpaceBlock && // moon blocks handle attached jumpthrus automa
OnShake = amount =>
{
ShakeStaticMovers(amount);
shakeOffset += amount;
_shakeOffset += amount;
},
OnAttach = p =>
{
Expand All @@ -106,9 +130,9 @@ solid is not FloatySpaceBlock && // moon blocks handle attached jumpthrus automa

public override void Render()
{
Position += shakeOffset;
Position += _shakeOffset;
base.Render();
Position -= shakeOffset;
Position -= _shakeOffset;
}

public override void Update()
Expand Down Expand Up @@ -143,34 +167,40 @@ public override void Awake(Scene scene)
};

using var _ = new PushRandomDisposable(scene);
var mtexture = GFX.Game[$"objects/jumpthru/{str}"];
int textureWidthInTiles = mtexture.Width / 8;
for (int i = 0; i < _columns; ++i)

// "invisible" determines whether we add image components to the entity
// this allows us to leave Visible = true so that subclasses can inherit the shake offset functionality
if (!_invisible)
{
int xOffset;
int yOffset;
if (i == 0)
{
xOffset = 0;
yOffset = CollideCheck<Solid, SwapBlock, ExitBlock>(Position + new Vector2(-1f, 0.0f)) ? 0 : 1;
}
else if (i == _columns - 1)
{
xOffset = textureWidthInTiles - 1;
yOffset = CollideCheck<Solid, SwapBlock, ExitBlock>(Position + new Vector2(1f, 0.0f)) ? 0 : 1;
}
else
var mtexture = GFX.Game[$"objects/jumpthru/{str}"];
int textureWidthInTiles = mtexture.Width / 8;
for (int i = 0; i < _columns; ++i)
{
xOffset = 1 + Calc.Random.Next(textureWidthInTiles - 2);
yOffset = Calc.Random.Choose(0, 1);
}
int xOffset;
int yOffset;
if (i == 0)
{
xOffset = 0;
yOffset = CollideCheck<Solid, SwapBlock, ExitBlock>(Position + new Vector2(-1f, 0.0f)) ? 0 : 1;
}
else if (i == _columns - 1)
{
xOffset = textureWidthInTiles - 1;
yOffset = CollideCheck<Solid, SwapBlock, ExitBlock>(Position + new Vector2(1f, 0.0f)) ? 0 : 1;
}
else
{
xOffset = 1 + Calc.Random.Next(textureWidthInTiles - 2);
yOffset = Calc.Random.Choose(0, 1);
}

Add(new Image(mtexture.GetSubtexture(xOffset * 8, yOffset * 8, 8, 8))
{
X = i * 8,
Y = 8,
Scale = {Y = -1},
});
Add(new Image(mtexture.GetSubtexture(xOffset * 8, yOffset * 8, 8, 8))
{
X = i * 8,
Y = 8,
Scale = {Y = -1},
});
}
}

foreach (StaticMover mover in scene.Tracker.GetComponents<StaticMover>())
Expand Down
Loading

0 comments on commit a92b204

Please sign in to comment.