Files
CalamityModPublic/DataStructures/DoGCartSegment.cs
T
tomat 67bceff6e7 Initial dotnet format pass.
This commit formats the entire codebase according to `dotnet format` and its limited understanding of our provided `.editorconfig`.
2024-02-28 21:49:50 -08:00

32 lines
1.1 KiB
C#

using Microsoft.Xna.Framework;
using Terraria;
namespace CalamityMod.DataStructures
{
public class DoGCartSegment
{
public Vector2 Center;
public float Rotation;
public int OldDirection;
public void Update(Player player, Vector2 aheadPosition, float idealRotation)
{
int direction = (player.velocity.SafeNormalize(Vector2.UnitX * player.direction).X > 0f).ToDirectionInt();
if (player.velocity.X == 0f)
direction = player.direction;
if (OldDirection != direction)
{
// Flip the segments if the player flips their direction.
if (OldDirection != 0)
Center = player.Center - Center + player.Center;
OldDirection = direction;
}
Vector2 offsetDirection = (aheadPosition - Center).SafeNormalize(Vector2.Zero);
offsetDirection = offsetDirection.ToRotation().AngleTowards(idealRotation, 0.2f).ToRotationVector2();
Rotation = offsetDirection.ToRotation();
Center = aheadPosition - offsetDirection * 20f;
}
}
}