fix: smooth tail interpolation for non-growing snake
When snake doesn't grow, the last segment (new tail) should interpolate from the old tail's position (previous[segmentIndex]), not from the second-to-last segment (previous[segmentIndex-1]) which didn't move.
This commit is contained in:
@@ -75,9 +75,11 @@ public static class AnimationHelper
|
||||
else
|
||||
{
|
||||
// When not growing: tail removed, new head added.
|
||||
// current[0] = new head, current[1] = old head, etc.
|
||||
// current[i] (i>=1) was at old[i-1]
|
||||
var prevIdx = segmentIndex - 1;
|
||||
// current[0] = new head, current[1] = old head, … current[N-2] = old[N-3]
|
||||
// BUT the last segment (tail): it was old[N-1] (the removed tail's position)
|
||||
// because visually it slides from where the old tail was.
|
||||
var isLast = segmentIndex == currentSegments.Count - 1;
|
||||
var prevIdx = isLast ? segmentIndex : segmentIndex - 1;
|
||||
if (prevIdx < previousSegments.Count)
|
||||
return previousSegments[prevIdx];
|
||||
}
|
||||
|
||||
BIN
publish/Snake.Avalonia
Executable file
BIN
publish/Snake.Avalonia
Executable file
Binary file not shown.
Reference in New Issue
Block a user