In my first attempt, I simply created the segments of the snake and ordered each one to walk_towards the one in front of it. This kinda worked, but the segments didn't follow the original path of the head. If they were arranged vertically, and the head stepped southeast, they would all step southeast.
So I am trying to devise a way to do it manually, and I'm having a little trouble. Here's the system I have right now:
if(text == "<FONT COLOR=#0A0>@</FONT>" && back)
var/oldloc = loc
if(oldloc != loc)
oldloc2 = back.loc
var/check = 0
var/swix = 0
newback = back.back
check = 1
check = 0
oldloc2 = newback.loc
newback.loc = oldloc
oldloc = newback.loc
newback.loc = oldloc2
check = 1
newback = newback.back
swix = ~ swix
And it's bad, man. Real bad. In case you didn't guess, "back" is a variable that stores the next segment in the snake. So why is it bad?
1. It's laggy. When the heads run into obstacles they start using pathfinding, and it seems to lag out when multiple snakes get tangled up with each other and the map.
2. It's buggy. I think I got one of the snakes to move all segments to the same space as the head mob.
3. It's crappy. I just feel terrible about this code, I want it to be sleek and sexy but instead it is fat and sassy.
I was toying with the idea of somehow keeping track of the moves done by the head mob, and using that in conjunction with each segment's position in the snake, to step() them all in the right direction. But I haven't really thought that one out yet...maybe you think it's a good idea? Or should I take a different approach altogether?