 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Zed Gecko
Joined: 23 Sep 2006 Posts: 98
|
Posted: Thu Jun 19, 2008 9:16 pm Post subject: Windoquarium - a useless distraction |
|
|
Inspired by Rajats aquarium, I have made a little toy/ game/screensaver/something, the Windoquarium.
Small Windows "EGGS" drift around and sometimes become bigger Windows,
those drift around, too, and consume EGGS or fight against each other.
Simply launch and watch!
To Interact,
you can draw the windows around and/or
click the EGGS and then press space, to force the breeding of a new Window.
| Code: | ;----------------Windoquarium--------------------------------------------------
;----------- a toy / game / screensaver / something ---------------------------
;----- simply launsch and watch -----------------------------------------------
;----- Small Windows "EGGS" drift around and grow bigger Windows,
;----- those drift around, too, and consume EGGS or fight against each other
;----- To Interact: Draw the windows around and/or
;----- click the little checkbox-windows and then press space
;------------------------------------------------------------------------------
maxwindows = 20 ; more than two and not more than 40
minwindows = 10 ; at least one and not more than %maxwindows%
maxeggs = 40 ; more than two and not more than 49
AUTOReSeed = 20000 ; the time in ms between two auto-pollinations
TimingA := 50 ; waiting time after each set of movements in ms
TimingB := 0 ; waiting time after each set of fights in ms
TimingC := 25 ; waiting time after each fight in ms
;--------------no edit needed below this line :-)-------
CoordMode, ToolTip, Screen
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
CoordMode, Caret, Screen
CoordMode, Menu, Screen
SetBatchLines -1
WM_NCLBUTTONDOWN := 0x00A1
HTCAPTION := 2
SysGet, VirtualScreenWidth, 78
SysGet, VirtualScreenHeight, 79
StartTime := A_TickCount
loop, %maxwindows%
{
Gui, %A_Index%: -Caption +Border +LastFound +AlwaysOnTop +ToolWindow
Gui, %A_Index%: Font, s39, Wingdings
Gui, %A_Index%: Add, Text, x0 y0 w50 h50 center gMoveWindow vGWIN%A_Index%,
WinSet, Transparent, 160
WinHWND%A_Index% := WinExist()
WinSTAT%A_Index% := 4
GuiControl,%A_Index%: , GWIN%A_Index%, % Chr(165 + WinSTAT%A_Index%)
WinHEAL%A_Index% := 1
Gui, %A_Index%: Color, % healthcolor(WinHEAL%A_Index%)
WinLIVE%A_Index% := "OFF"
WinDIR%A_Index% := 0
WinFIGHT%A_Index% := 0
WinVICTORY%A_Index% := 0
}
loop, %maxeggs%
{
E_Index := A_Index + 50
Gui, %E_Index%: Color, 0xF0F0F0
Gui, %E_Index%: -Caption +Border +LastFound +AlwaysOnTop +ToolWindow
Gui, %E_Index%: Add, Text, x0 y0 w20 h20 gMoveWindow
Gui, %E_Index%: Add, Checkbox, x4 y4 vEggCHK%E_Index%
WinSet, Transparent, 100
EggHWND%E_Index% := WinExist()
EggLIVE%E_Index% := "OFF"
}
CurrSec := A_Sec
loop
{
GoSub, IterateEggs
GoSub, IterateWindows
if ( ((A_Sec - CurrSec) * (A_Sec - CurrSec)) >= 4 )
{
Gosub, ProcreateEgg
Gosub, ProcreateWin
Gosub, CheckEggEat
Gosub, CheckWinFight
CurrSec := A_Sec
sleep, %TimingB%
}
else
sleep, %TimingA%
}
return
IterateEggs:
TEMPBoundary := VirtualScreenWidth - 20
loop, %maxeggs%
{
E_Index := A_Index + 50
if ( EggLIVE%E_Index% = "ON" )
{
TEMPEGG := EggHWND%E_Index%
WinGetPos, TEMPX, TEMPY, , , ahk_id %TEMPEGG%
if ((TEMPX > 0) && (TEMPX < TEMPBoundary))
{
Random, TEMPNewDir, 1, 5
if (TEMPNewDir = 1)
{
TEMPX -= 1
}
if (TEMPNewDir = 2)
{
TEMPX -= 1
TEMPY += 1
}
if (TEMPNewDir = 3)
{
TEMPY += 1
}
if (TEMPNewDir = 4)
{
TEMPX += 1
TEMPY += 1
}
if (TEMPNewDir = 5)
{
TEMPX += 1
}
}
else
{
if (TEMPX <= 0)
TEMPX += 1
if (TEMPX >= TEMPBoundary)
TEMPX -= 1
}
if (TEMPY >= VirtualScreenHeight)
KillEgg(E_Index)
else
Gui, %E_Index%: Show, X%TEMPX% Y%TEMPY% W20 H20 NoActivate
}
}
return
IterateWindows:
TEMPBoundaryX := VirtualScreenWidth - 50
TEMPBoundaryY := VirtualScreenHeight - 50
loop, %maxwindows%
{
if ( WinLIVE%A_Index% = "ON" )
{
TEMPWIN := WinHWND%A_Index%
WinGetPos, TEMPX, TEMPY, , , ahk_id %TEMPWIN%
if (((TEMPX > 0) && (TEMPX < TEMPBoundaryX)) && ((TEMPY > 0) && (TEMPY < TEMPBoundaryY)))
{
if ( WinDIR%A_Index% = 0 )
Random, WinDIR%A_Index%, 1, 6
Random, TEMPDir, 1, 8
if ( TEMPDir = 1 )
WinDIR%A_Index% -= 1
if ( TEMPDir = 8 )
WinDIR%A_Index% += 1
if (WinDIR%A_Index% > 6)
WinDIR%A_Index% := 1
if (WinDIR%A_Index% < 1)
WinDIR%A_Index% := 6
if (WinDIR%A_Index% = 1)
{
TEMPX -=1
TEMPY -=1
}
if (WinDIR%A_Index% = 2)
{
TEMPX -=1
}
if (WinDIR%A_Index% = 3)
{
TEMPX -=1
TEMPY +=1
}
if (WinDIR%A_Index% = 4)
{
TEMPX +=1
TEMPY +=1
}
if (WinDIR%A_Index% = 5)
{
TEMPX +=1
}
if (WinDIR%A_Index% = 6)
{
TEMPX +=1
TEMPY -=1
}
Gui, %A_Index%: Show, X%TEMPX% Y%TEMPY% W50 H50 NoActivate
}
else
{
WinDIR%A_Index% := 0
if (TEMPX <= 0)
TEMPX += 1
if (TEMPX >= TEMPBoundaryX)
TEMPX -= 1
if (TEMPY <= 0)
TEMPY += 1
if (TEMPY >= TEMPBoundaryY)
TEMPY -= 1
Gui, %A_Index%: Show, X%TEMPX% Y%TEMPY% W50 H50 NoActivate
}
}
}
return
ProcreateEgg:
if ( checklivingeggs() < maxeggs )
{
TEMPNewEgg := getnextfreeegg()
TEMPBoundary := VirtualScreenWidth - 20
Random, TEMPNewEggPos, 1, %TEMPBoundary%
Gui, %TEMPNewEgg%: Show, X%TEMPNewEggPos% Y1 W20 H20 NoActivate
EggLIVE%TEMPNewEgg% := "ON"
}
return
ProcreateWin:
if ( checklivingwin() < maxwindows)
{
loop, %maxeggs%
{
E_Index := A_Index + 50
if ( EggLIVE%E_Index% = "ON" )
{
Gui, %E_Index%: Submit, NoHide
if ( EggCHK%E_Index% = 1 )
{
GuiControl, %E_Index%:, EggCHK%E_Index% , 0
TEMPEGG := EggHWND%E_Index%
WinGetPos, TEMPX, TEMPY, , , ahk_id %TEMPEGG%
KillEgg(E_Index)
TEMPNewWin := getnextfreewin()
WinSTAT%TEMPNewWin% := 4
GuiControl,%TEMPNewWin%: , GWIN%TEMPNewWin%, % Chr(165 + WinSTAT%TEMPNewWin%)
WinHEAL%TEMPNewWin% := 1
Gui, %TEMPNewWin%: Color, % healthcolor(WinHEAL%TEMPNewWin%)
WinLIVE%TEMPNewWin% := "ON"
Gui, %TEMPNewWin%: Show, X%TEMPX% Y%TEMPY% W50 H50 NoActivate
WinDIR%TEMPNewWin% := 0
break
}
}
}
}
if ( checklivingwin() < minwindows)
{
TEMPReSeed := A_TickCount - StartTime
if ( TEMPReSeed > AUTOReSeed )
{
StartTime := A_TickCount
loop
{
Random, TEMPSeed, 50, % ( 50 + maxeggs )
if ( EggLIVE%TEMPSeed% = "ON" )
break
}
GuiControl, %TEMPSeed%:, EggCHK%TEMPSeed% , 1
}
}
return
CheckEggEat:
loop, %maxwindows%
{
if ( WinLIVE%A_Index% = "ON" )
{
TEMPWINB := WinHWND%A_Index%
TEMPWinGUI := A_Index
WinGetPos, TEMPXB, TEMPYB, , , ahk_id %TEMPWINB%
loop, %maxeggs%
{
E_Index := A_Index + 50
if ( EggLIVE%E_Index% = "ON" )
{
TEMPEGG := EggHWND%E_Index%
WinGetPos, TEMPX, TEMPY, , , ahk_id %TEMPEGG%
if ((((TEMPX + 20) >= TEMPXB) && (TEMPX <= (TEMPXB + 50))) && (((TEMPY + 20) >= TEMPYB) && (TEMPY <= (TEMPYB + 50))))
{
Gui, %TEMPWinGUI%: Color, Blue
Tooltip, Yummie!, %TEMPXB%, %TEMPYB%, 2
sleep, %TimingC%
WinHEAL%TEMPWinGUI% += 1
KillEgg(E_Index)
UpdateWin(TEMPWinGUI)
ToolTip,,,, 2
}
}
}
}
}
return
CheckWinFight:
loop, %maxwindows%
{
if ( WinLIVE%A_Index% = "ON" )
{
TEMPWINB := WinHWND%A_Index%
TEMPWinGUI := A_Index
WinGetPos, TEMPXB, TEMPYB, , , ahk_id %TEMPWINB%
loop, %maxwindows%
{
if (( WinLIVE%A_Index% = "ON" ) && (A_Index != TEMPWinGUI))
{
TEMPWINA := WinHWND%A_Index%
TEMPWinGUIA := A_Index
WinGetPos, TEMPXA, TEMPYA, , , ahk_id %TEMPWINA%
if ((((TEMPXA + 50) >= TEMPXB) && (TEMPXA <= (TEMPXB + 50))) && (((TEMPYA + 50) >= TEMPYB) && (TEMPYA <= (TEMPYB + 50))))
{
Gui, %TEMPWinGUI%: Color, Red
Gui, %TEMPWinGUIA%: Color, Red
ToolTip, # %TEMPWinGUI% vs. # %TEMPWinGUIA%, %TEMPXB%, %TEMPYB%, 3
sleep, %TimingC%
Random, TEMPFight, 0, WinSTAT%TEMPWinGUI%
Random, TEMPFightA, 0, WinSTAT%TEMPWinGUIA%
WinFIGHT%TEMPWinGUI% += 1
WinFIGHT%TEMPWinGUIA% += 1
if (TEMPFight > TEMPFightA)
{
TEMPDamage := TEMPFight - TEMPFightA
WinVICTORY%TEMPWinGUI% += 1
WinHEAL%TEMPWinGUIA% -= TEMPDamage
if (WinHEAL%TEMPWinGUIA% <= 0)
{
WinHEAL%TEMPWinGUI% += WinSTAT%TEMPWinGUIA%
UpdateWin(TEMPWinGUI)
KillWin(TEMPWinGUIA)
}
else
{
UpdateWin(TEMPWinGUI)
UpdateWin(TEMPWinGUIA)
}
ToolTip,# %TEMPWinGUI% WON! , %TEMPXB%, %TEMPYB%, 3
}
if (TEMPFightA > TEMPFight)
{
TEMPDamage := TEMPFightA - TEMPFight
WinVICTORY%TEMPWinGUIA% += 1
WinHEAL%TEMPWinGUI% -= TEMPDamage
if (WinHEAL%TEMPWinGUI% <= 0)
{
WinHEAL%TEMPWinGUIA% += WinSTAT%TEMPWinGUI%
UpdateWin(TEMPWinGUIA)
KillWin(TEMPWinGUI)
}
else
{
UpdateWin(TEMPWinGUIA)
UpdateWin(TEMPWinGUI)
}
ToolTip,# %TEMPWinGUIA% WON! , %TEMPXB%, %TEMPYB%, 3
}
if (TEMPFightA = TEMPFight)
{
UpdateWin(TEMPWinGUIA)
UpdateWin(TEMPWinGUI)
ToolTip,# DRAW! , %TEMPXB%, %TEMPYB%, 3
}
SetTimer, RemoveToolTip3, 500
}
}
}
}
}
return
KillEgg(GUI)
{
global
EggLIVE%GUI% := "OFF"
GuiControl, %GUI%:, EggCHK%GUI% , 0
Gui, %GUI%: Hide
return
}
getnextfreeegg()
{
global
loop, %maxeggs%
{
E_Index := A_Index + 50
if ( EggLIVE%E_Index% = "OFF" )
return %E_Index%
}
return "FULL"
}
checklivingeggs()
{
global
local eggcount
loop, %maxeggs%
{
E_Index := A_Index + 50
if ( EggLIVE%E_Index% = "ON" )
eggcount += 1
}
return %eggcount%
}
UpdateWin(GUI)
{
global
if ((WinHEAL%GUI% > WinSTAT%GUI%) && (WinSTAT%GUI% < 9))
{
WinSTAT%GUI% += 1
WinHEAL%GUI% := 1
}
if (WinHEAL%GUI% > WinSTAT%GUI%)
WinHEAL%GUI% := WinSTAT%GUI%
GuiControl,%GUI%: , GWIN%GUI%, % Chr(165 + WinSTAT%GUI%)
Gui, %GUI%: Color, % healthcolor(WinHEAL%GUI%)
Gui, %GUI%: Show, NoActivate
return
}
KillWin(GUI)
{
global
WinLIVE%GUI% := "OFF"
WinSTAT%GUI% := 4
GuiControl,%GUI%: , GWIN%A_Index%, % Chr(165 + WinSTAT%GUI%)
WinHEAL%GUI% := 1
WinDIR%GUI% := 0
WinFIGHT%GUI% := 0
WinVICTORY%GUI% := 0
Gui, %GUI%: Color, % healthcolor(WinHEAL%GUI%)
Gui, %GUI%: Hide
return
}
getnextfreewin()
{
global
loop, %maxwindows%
{
if ( WinLIVE%A_Index% = "OFF" )
return %A_Index%
}
return "FULL"
}
checklivingwin()
{
global
local wincount
loop, %maxwindows%
{
if ( WinLIVE%A_Index% = "ON" )
wincount += 1
}
return %wincount%
}
MoveWindow:
if ( A_GUI <= maxwindows )
{
Tooltip, % "# " . A_GUI . "`n-----------`n Rank: " . (WinSTAT%A_GUI% - 3) . "`nHealth: " . WinHEAL%A_GUI% . "`n-----------`nFights: " . WinFIGHT%A_GUI% . "`n Wins: " . WinVICTORY%A_GUI%
SetTimer, RemoveToolTip, 2000
}
if ( A_GUI > 50 )
{
Tooltip, Egg # %A_GUI%`nPress Space to pollinate!
SetTimer, RemoveToolTip, 1000
}
PostMessage, WM_NCLBUTTONDOWN, HTCAPTION, , , a
return
RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return
RemoveToolTip3:
SetTimer, RemoveToolTip3, Off
ToolTip,,,,3
return
healthcolor(heal)
{
if (heal = 0)
return 0x010101
if (heal = 1)
return 0x252525
if (heal = 2)
return 0x383838
if (heal = 3)
return 0x4F4F4F
if (heal = 4)
return 0x707070
if (heal = 5)
return 0x808080
if (heal = 6)
return 0x999999
if (heal = 7)
return 0xB2B2B2
if (heal = 8)
return 0xD2D2D2
if (heal = 9)
return 0xE5E5E5
if (heal = 10)
return 0xFFFFFF
return 0x010101
} |
 _________________ 1) All my code can be reused in ANY way. 2) Please check the help and the forum-search, before posting questions; the answer is out there...
Last edited by Zed Gecko on Thu Jun 19, 2008 11:10 pm; edited 3 times in total |
|
| Back to top |
|
 |
SoggyDog
Joined: 02 May 2006 Posts: 214 Location: Greeley, CO
|
Posted: Thu Jun 19, 2008 9:26 pm Post subject: |
|
|
Fun. Thanks.
Not diggin' all the task bar entries, though.  _________________
SoggyDog
Download AutoHotKey Wallpaper
Does 'Fuzzy Logic' tickle? |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5814
|
Posted: Thu Jun 19, 2008 9:30 pm Post subject: |
|
|
C L _________________ SKAN - Suresh Kumar A N |
|
| Back to top |
|
 |
Zed Gecko
Joined: 23 Sep 2006 Posts: 98
|
Posted: Thu Jun 19, 2008 10:55 pm Post subject: |
|
|
glad you like it
I made some minor corrections in the code above. _________________ 1) All my code can be reused in ANY way. 2) Please check the help and the forum-search, before posting questions; the answer is out there... |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 853 Location: The Interwebs
|
Posted: Thu Jun 19, 2008 11:29 pm Post subject: |
|
|
| That, I must say, is pretty damn awesome o_o |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|