GameMaker [HELP] how to keep snake tail from overlapping in one place

G

Go-a-og

Guest
So I am making a game which is basically a clone of the game 'Spybotics: the nightfall incident"
This is what I am talking about
This is an example of what I have

this is an example of the problem

Now, I have the head object (oTest), create instances of the tail object (tailSeg) when it moves. You should be able to move the head through the tail (without creating new segments of tail) . But when I do this the tail stacks into other parts of the tail and if move between two places, all the tail segments stack into one spot. I do not want this, I want what is in the original game which is that you should be able to move through the tail and when you move out of the tail, the tail follows. I'm trying to explain this as best as possible, if you have any questions please ask.
here is what I think is relevant code:
oTest create event:
Code:
inFol = false
ds = ds_map_create()
ds[? "maxMove"] = 100
ds[? "range"] = ds[? "maxMove"]
ds[? "attRange"] = 1
ds[? "attPower"] = 1
ds[? "tailMax"] = 10
tail = ds_list_create()

xpre = x
ypre = y
step event
Code:
left_right = (keyboard_check_pressed(ord("D"))-keyboard_check_pressed(ord("A"))) * sprite_width
up_down    = (keyboard_check_pressed(ord("S"))-keyboard_check_pressed(ord("W"))) * sprite_height
if ds[? "range"] > 0 && (abs(left_right)||abs(up_down))
{
   xpre = x
   ypre = y
   if ds_list_size(tail)<ds[? "tailMax"] && !inFol
   {
       ds_list_add(tail, instance_create_depth(xpre,ypre,1,tailSeg))
   }
   x += left_right
   y += up_down
   ds[? "range"]--
}
if ds_list_size(tail)>0
{
   tail[| 0].target = id
   tail[| 0].head = id
   for(i = 1; i < ds_list_size(tail); i++)
   {
       tail[| i].target = tail[|i-1]
       tail[| i].head = id
   }   
}
tailSeg step event
Code:
if instance_exists(target)
{
   
   if(x != target.xpre)||(y != target.ypre)
   {
       xpre = x
       ypre = y
   }
   x = target.xpre
   y = target.ypre
   image_angle = point_direction(x,y, target.x,target.y)+270
   
}
tl;dr
snake object tail stacks in one place when snake moves over tail.
 
Top