fix: only interpolate head and tail, keep middle segments grid-snapped
Prevents diagonal shortcuts when snake bends — middle segments stay at exact cell centers so L-shaped corners render correctly.
This commit is contained in:
@@ -376,11 +376,19 @@ public sealed class SnakeRenderer : Control
|
|||||||
if (Segments == null)
|
if (Segments == null)
|
||||||
return (pos.X * CellSize + CellSize * 0.5, pos.Y * CellSize + CellSize * 0.5);
|
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
|
var from = PreviousSegments != null && PreviousSegments.Count > 0
|
||||||
? AnimationHelper.GetPreviousPosition(segmentIndex, Segments, PreviousSegments, SnakeDirection)
|
? AnimationHelper.GetPreviousPosition(segmentIndex, Segments, PreviousSegments, SnakeDirection)
|
||||||
: pos;
|
: pos;
|
||||||
|
|
||||||
var useEasing = segmentIndex == 0; // Head gets easing for snappy feel
|
// Head gets easing for snappy feel; tail uses linear interpolation
|
||||||
return AnimationHelper.InterpolatePosition(from, pos, t, CellSize, useEasing);
|
return AnimationHelper.InterpolatePosition(from, pos, t, CellSize, useEasing: isHead);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user