fix: preserve sharp corners during smooth animation

This commit is contained in:
Heller
2026-06-19 10:12:32 +00:00

View File

@@ -376,11 +376,19 @@ public sealed class SnakeRenderer : Control
if (Segments == null)
return (pos.X * CellSize + CellSize * 0.5, pos.Y * CellSize + CellSize * 0.5);
var isHead = segmentIndex == 0;
var isTail = Segments.Count > 1 && segmentIndex == Segments.Count - 1;
// Only interpolate head and tail — middle segments stay grid-snapped
// to preserve sharp corners when the snake bends.
if (!isHead && !isTail)
return (pos.X * CellSize + CellSize * 0.5, pos.Y * CellSize + CellSize * 0.5);
var from = PreviousSegments != null && PreviousSegments.Count > 0
? AnimationHelper.GetPreviousPosition(segmentIndex, Segments, PreviousSegments, SnakeDirection)
: pos;
var useEasing = segmentIndex == 0; // Head gets easing for snappy feel
return AnimationHelper.InterpolatePosition(from, pos, t, CellSize, useEasing);
// Head gets easing for snappy feel; tail uses linear interpolation
return AnimationHelper.InterpolatePosition(from, pos, t, CellSize, useEasing: isHead);
}
}