This program works well and has plenty of room for enhancment, project folder available from the download button.
Set Display Mode 800, 600, 16
Sync On; Sync Rate 0; Sync; Sync
Type Snake_Type
X As Integer
Y As Integer
Angle As Float
Spr As Integer
Img As Integer
EndType
Global Dim Snake(0) As Snake_Type
Global SnakeImage As Integer
SnakeImage = Free_Image()
Load Image "Element01.bmp", SnakeImage, 1
For Count = 1 to 100
Array Insert At Bottom Snake(0)
Snake(Count - 1).X = 400 - (5 * Count)
Snake(Count - 1).Y = 300
Snake(Count - 1).Spr = Free_Sprite()
Snake(Count - 1).Img = SnakeImage
Sprite Snake(Count - 1).Spr, Snake(Count - 1).X, Snake(Count - 1).Y, Snake(Count - 1).Img
Offset Sprite Snake(Count - 1).Spr, 7, 7
Next Count
repeat
For Count = 100 to 1 Step -1
If Count = 1
X = Sprite X(Snake(Count-1).Spr)
Y = Sprite Y(Snake(Count-1).Spr)
If X = MouseX() and Y = MouseY()
Else
Snake(Count-1).X = X
Snake(Count-1).Y = Y
Ang# = NewAngle#(X,Y,MouseX(),MouseY())
Rotate Sprite Snake(Count - 1).Spr, Ang#
Move Sprite Snake(Count - 1).Spr, 5
EndIf
Else
Snake(Count - 1).X = Snake(Count - 2).X
Snake(Count - 1).Y = Snake(Count - 2).Y
Sprite Snake(Count - 1).Spr, Snake(Count-1).X, Snake(Count-1).Y, Snake(Count-1).Img
EndIf
Next Count
Sync
until keystate(1)
Function Free_Image()
Count = 1
While Image Exist(Count)
Inc Count, 1
EndWhile
EndFunction Count
Function Free_Sprite()
Count = 1
While Sprite Exist(Count)
Inc Count, 1
EndWhile
EndFunction Count
Function NewAngle#(x, y, xx, yy)
`x=cos
`y=sin
if xx >= x and yy < y
a# = x - xx
b# = yy - y
c# = a# / b#
ang# = atan(c#)
endif
If xx > x and yy >= y
a# = x - xx
b# = y - yy
c# = b# / a#
ang# = atan(c#) + 90
endif
If xx <= x and yy > y
a# = xx - x
b# = y - yy
c# = a# / b#
ang# = atan(c#) + 180
endif
if xx < x and yy <= y
a# = xx - x
b# = yy - y
c# = b# / a#
ang# = atan(c#)+ 270
endif
EndFunction ang#
Function Distance#(x, y, xx, yy)
if xx => x
a# = xx - x
else
a# = x - xx
endif
if yy => y
b# = yy - y
else
b# = y- yy
endif
a# = a# * a#
b# = b# * b#
c# = a# + b#
c# = SQRT(c#)
endfunction c#
Also can my two maths functions be made better, thanks.