I'm having a problem with a game I'm trying to make (I may even end up coming close to finishing this one!). It's basically a Snake clone, or Nibbles for all you QBasic fans. You know, you steer a constantly moving snake around eating things until it grows so large you die.

The problem currently is figuring out a movement routine. I thought it'd be good enough to just make a procedure that gives each segment of the snake the co-ords of the previous segment (except the head which is given new co-ords in the loop). That way the body of the snake would more or less follow where the head leads (that's my theory anyway).

Here's what I've come up with:
I think it's pretty self explanitary, Snake1 is an open array of a record
containing X, Y values. I tried just Snake1[i].X := Snake1[i - 1].X but
that just puts all of the segments on top of the head.
So I tried making another 2 arrays to store all of the co-ords and then
assign the X/Y all at once from those. But I get an invalid pointer error
if I do that. I've been up for too long to try think of another way (except
maybe 2 X/Y variables for each segment and alternating them each tick,
bleh).

[pascal]
procedure CalcSnakes;
var i: Integer;
PrevX, PrevY: array of Integer;
begin
SetLength(PrevX, High(Snake1));
SetLength(PrevY, High(Snake1));
for i := 1 to High(Snake1) do begin
PrevX[i] := Snake1[i - 1].X;
PrevY[i] := Snake1[i - 1].Y;
end;
for i := 1 to High(Snake1) do begin
Snake1[i].X := PrevX[i];
Snake1[i].Y := PrevY[i];
end;
end;
[/pascal]

There's probably a heaps easier way, there always is.