Sounds cool, feel free to post your modified version.
I haven't done much more on this myself. I've written code for the bug to follow (or flee from) a point on the screen, but I haven't put it to good use yet. Here's a sample that makes it follow the mouse pointer, but I don't really like the effect, at least not for all the time. It conflicts with the behavior where it runs when you point at it, so I disbaled that in this example.
Code:
#SingleInstance Force
#NoEnv
CoordMode Mouse, Screen
SetBatchLines -1
SetWinDelay -1
IfNotExist bug
{
FileCreateDir bug
Loop 17
UrlDownloadToFile http://www.autohotkey.net/~ManaUser/bugs/bug%A_Index%.png, bug\bug%A_Index%.png
}
SetWorkingDir bug
Gui Color, White
Loop 16
{
Gui Add, Picture, x0 y0 gGrab, bug%A_Index%.png
GuiControl Hide, bug%A_Index%.png
}
Gui Add, Picture, x0 y0 gWipe, bug17.png
GuiControl Hide, bug17.png
Gui -Caption +ToolWindow +AlwaysOnTop +LastFound
WinSet, TransColor, White
TheBug := WinExist()
Gui Show, w16 h16 y0, NA
WinGetPos X, Y
XSpeeds := "0:1:2:3:3:3:2:1:0:-1:-2:-3:-3:-3:-2:-1"
YSpeeds := "-3:-3:-2:-1:0:1:2:3:3:3:2:1:0:-1:-2:-3"
StringSplit XSpeed, XSpeeds, :
StringSplit YSpeed, YSpeeds, :
Speed := 1
Random Dir, 1, 9
SetTimer Move, 50
GoSub Move
Return
Move:
MouseGetPos, Mx, My, UnderMouse
;If (TheBug = UnderMouse)
;{
; Speed := 3
; SetTimer SlowDown, -525
; SetTimer SlowMore, -1525
;}
X += XSpeed%Dir% * Speed
Y += YSpeed%Dir% * Speed
If (X < -16)
X := -16
Else If (X > A_ScreenWidth)
X := A_ScreenWidth
If (Y < -16)
Y := -16
Else If (Y > A_ScreenHeight)
Y := A_ScreenHeight
GuiControl Hide, bug%Dir%.png
;Dir := NewDirRnd()
Dir := NewDirChase(Mx, My, 50) ;<-- (X, Y, Influence), also try NewDirFlee
GuiControl Show, bug%Dir%.png
Gui +LastFound
WinMove, X, Y
Gui Show, NA
Return
NewDirRnd()
{
Global Dir
Random Rand, 0, 1
Rand := Rand & !GetKeyState("Left") | GetKeyState("Right")
NewDir := WrapDir(Dir + (Rand ? 1 : -1))
Return NewDir
}
NewDirChase(TargetX, TargetY, Influence = 50, Flee = False)
{
Global Dir, X, Y
Random Rand, 1, 100
If (Influence < Rand)
Return NewDirRnd()
Random Rand, 0, 1
NewDir := WrapDir(Dir + (Rand ? 1 : -1))
AltDir := WrapDir(Dir + (!Rand ? 1 : -1))
NewDist := Distance(X+8+XSpeed%NewDir%, Y+8+YSpeed%NewDir%, TargetX, TargetY)
AltDist := Distance(X+8+XSpeed%AltDir%, Y+8+YSpeed%AltDir%, TargetX, TargetY)
Return (AltDist < NewDist) ^ Flee ? AltDir : NewDir
}
NewDirFlee(TargetX, TargetY, Influence = 50)
{
Return NewDirChase(TargetX, TargetY, Influence, True)
}
WrapDir(wDir)
{
If (wDir = 0)
Return 16
If (wDir = 17)
Return 1
Return wDir
}
Distance(X1, Y1, X2, Y2)
{
Return Sqrt(Abs( (X1-X2)**2 + (Y1-Y2)**2 ))
}
SlowDown:
Speed := 2
Return
SlowMore:
Speed := 1
Return
Grab:
SetTimer Move, Off
SetTimer SlowDown, Off
SetTimer SlowMore, Off
SetTimer Hold, 50
Wiggle := 1
If (Dir = 16)
Dir := 1
Return
Hold:
MouseGetPos X, Y
X -= 8, Y -= 8
Random Rand, 0, 1
If Rand
{
GuiControl Hide, bug%Dir%.png
Dir += Wiggle
GuiControl Show, bug%Dir%.png
Wiggle *= -1
}
Gui +LastFound
WinMove, X, Y
If GetKeyState("LButton") = 0
{
SetTimer Hold, Off
SetTimer Move, 50
}
Return
GuiContextMenu: ;Squish
SetTimer Move, Off
SetTimer Hold, Off
Gui Show, Hide
GuiControl Hide, bug%Dir%.png
GuiControl Show, bug17.png
Gui Show, NA
Sleep 60000
Wipe:
ExitApp
Return
Edit: Thanks for pointing out that goof with UrlDownloadToFile. (Fixed now.)