subr fruit rx = (random 0 19) * 5 + 2.5 ry = (random 0 19) * 5 + 2.5 . subr start fruit game = 1 sx[] = [ 52.5 0 0 0 0 ] sy[] = [ 52.5 0 0 0 0 ] dir = random 1 4 timer 0 . gbackground 242 gclear gcolor 997 gtext 30 70 "SNAKE" gtextsize 5 gtext 6 40 "Keys or mouse for controlling" gtext 6 30 "Space or click to start" # on key_down if game = 0 and keybkey = " " start return . if dir mod 2 = 1 if keybkey = "ArrowRight" dir = 2 elif keybkey = "ArrowLeft" dir = 4 . else if keybkey = "ArrowUp" dir = 1 elif keybkey = "ArrowDown" dir = 3 . . . on mouse_down if game = 0 start return . if dir mod 2 = 1 if mouse_x < sx dir = 4 else dir = 2 . else if mouse_y < sy dir = 3 else dir = 1 . . . proc over . gcolor 997 gtext 10 10 "Space or click for new game" game = 2 timer 1 . on timer if game = 2 game = 0 return . sx = sx[1] sy = sy[1] if dir = 1 sy += 5 elif dir = 2 sx += 5 elif dir = 3 sy -= 5 elif dir = 4 sx -= 5 . if sx < 0 or sx > 100 or sy < 0 or sy > 100 over return . for i = len sx[] downto 2 if sx = sx[i] and sy = sy[i] over return . . gclear gcolor 997 gtext 2 95 "Score: " & 10 * len sx[] - 50 gcolor 966 gcircle rx ry 1.5 # gcolor 494 for i = len sx[] downto 2 sx[i] = sx[i - 1] sy[i] = sy[i - 1] if sx[i] > 0 gcircle sx[i] sy[i] 2.5 . . gcircle sx sy 2.5 gcolor 000 if dir = 2 or dir = 4 gcircle sx sy + 1 0.5 gcircle sx sy - 1 0.5 else gcircle sx + 1 sy 0.5 gcircle sx - 1 sy 0.5 . if sx = rx and sy = ry len sx[] len sx[] + 3 len sy[] len sy[] + 3 fruit . sx[1] = sx sy[1] = sy timer 0.15 .