Particle Posted July 29, 2008 Share Posted July 29, 2008 i've been playing around with some code just doing small experiments with window controls. I was seeing if it was possible to give windows kind of a gravity force. This is the source that i've come up with, but for some reason doesn't work properly. Im trying to get it to check to see if the $Pos[1] is higher than the bottem set positions and if it is then it executes the do loop and slowly brings the windows down like gravity until it hits bottem set again. Help please. $Pos = WinGetPos("Ventrilo","") WinMove("Ventrilo","",$Pos[0],@DesktopHeight-$Pos[3],$Pos[2],$Pos[3]) $Pos = WinGetPos("Ventrilo","") $Numb = $Pos[1] While 1 $Pos = WinGetPos("Ventrilo","") If $Pos[1] > $Numb Then Do WinMove("Ventrilo","",$Pos[0],$Pos[1]+10,$Pos[2],$Pos[3]) $Pos = WinGetPos("Ventrilo","") Until $Pos[1] = $Numb EndIf WEnd Link to comment Share on other sites More sharing options...
bogQ Posted July 29, 2008 Share Posted July 29, 2008 can this help? Global $loop = "0" Global $Pos $win = "Calculator" $Pos = WinGetPos($win,"") WinMove($win,"",$Pos[0],@DesktopHeight-$Pos[3]) $Pos = WinGetPos($win,"") While 1 $Pos2 = WinGetPos($win,"") If $Pos[1] <> $Pos2[1] Then Do Sleep(50) $Pos2 = WinGetPos($win,"") Sleep(10) WinMove($win,"",$Pos[0],$Pos2[1]+$loop) $loop = $loop +1 If $Pos2[1]+ $loop > $Pos[1] Then WinMove($win,"",$Pos[0],@DesktopHeight-$Pos[3]) Until $Pos2[1] >= $Pos[1] $loop = "0" EndIf WEnd TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 29, 2008 Share Posted July 29, 2008 More fun: expandcollapse popupHotKeySet("{ESC}", "_Quit") Global $DT_H = @DesktopHeight, $DT_W = @DesktopWidth Global $iPID = Run("Notepad.exe") WinWait("Untitled - Notepad") Global $hWin = WinGetHandle("Untitled - Notepad") Global $avPos, $Dir_X = Random(-2, 2, 1), $Dir_Y = Random(-2, 2, 1) $avPos = WinGetPos($hWin) WinMove($hWin, "", ($DT_W / 2) - ($avPos[2] / 2), ($DT_H / 2) - ($avPos[3] / 2)) While 1 ; [0] = X, [1] = Y, [2] = W, [3] = H $avPos = WinGetPos($hWin) ; Check for contact with sides and pick new directions Select Case $avPos[0] < 2 $Dir_X = Random(0, 2, 1) $Dir_Y = Random(-2, 2, 1) Case ($avPos[0] + $avPos[2]) > $DT_W - 2 $Dir_X = Random(-2, 0, 1) $Dir_Y = Random(-2, 2, 1) EndSelect Select Case $avPos[1] < 2 $Dir_Y = Random(0, 2, 1) $Dir_X = Random(-2, 2, 1) Case ($avPos[1] + $avPos[3]) > $DT_H - 2 $Dir_Y = Random(-2, 0, 1) $Dir_X = Random(-2, 2, 1) EndSelect While ($Dir_X = 0) And ($Dir_Y = 0) $Dir_X = Random(-2, 2, 1) $Dir_Y = Random(-2, 2, 1) WEnd ; Update pos WinMove($hWin, "", $avPos[0] + $Dir_X, $avPos[1] + $Dir_Y) Sleep(20) WEnd Func _Quit() WinClose($hWin) Exit EndFunc You could easily modify this to use WinList() to get an array of all windows, pare it down to only visible ones, normalize all those, move them all to different random offsets... Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Particle Posted July 29, 2008 Author Share Posted July 29, 2008 lol, thanks Link to comment Share on other sites More sharing options...
Glyph Posted July 29, 2008 Share Posted July 29, 2008 >"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /prod /AU3Check /in "C:\Documents and Settings\Glyph\Desktop\grav.au3" +>16:59:09 Starting AutoIt3Wrapper v.1.10.1.4 Environment(Language:0409 Keyboard:00000409 OS:WIN_XP/Service Pack 3 CPU:X86) >Running AU3Check (1.54.13.0) from:C:\Program Files\AutoIt3 C:\Documents and Settings\Glyph\Desktop\grav.au3(11,26) : ERROR: syntax error If $Pos[1] $Pos2[1] Then ~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\Documents and Settings\Glyph\Desktop\grav.au3(21,5) : ERROR: missing Wend. EndIf ~~~~^ C:\Documents and Settings\Glyph\Desktop\grav.au3(8,1) : REF: missing Wend. While ^ C:\Documents and Settings\Glyph\Desktop\grav.au3 - 2 error(s), 0 warning(s) !>16:59:09 AU3Check ended.rc:2 >Exit code: 0 Time: 0.359 tolle indicium Link to comment Share on other sites More sharing options...
TehWhale Posted July 29, 2008 Share Posted July 29, 2008 (edited) It works perfectly for me! Mind if I add this to my examples listing?EDIT: http://h1.ripway.com/AutoIt/bouncingwindow.au3 Edited July 29, 2008 by Alienware Link to comment Share on other sites More sharing options...
Glyph Posted July 29, 2008 Share Posted July 29, 2008 It works perfectly for me! Mind if I add this to my examples listing?EDIT: http://h1.ripway.com/AutoIt/bouncingwindow.au3weired, that works for me.. tolle indicium Link to comment Share on other sites More sharing options...
Particle Posted July 29, 2008 Author Share Posted July 29, 2008 Alright so I tried to toy with it some more so it would grab an array of all the active visible windows. It sets them on the bottem but I can't figure out what i'm doing wrong in the While loop which won't allow any window to work with gravity. expandcollapse popupHotKeySet("{ESC}", "_Quit") Global $loop = "0" Global $Pos, $Array, $win, $BottemX, $BottemY, $var Dim $Array[10000] Dim $BottemY[10000] $var = WinList() For $i = 1 to $var[0][0] ; Only display visble windows that have a title If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then $Array[$i] = $var[$i][0] EndIf $win = $Array[$i] $Pos = WinGetPos($win,"") WinMove($win,"",$Pos[0],@DesktopHeight-$Pos[3]) $Pos = WinGetPos($win,"") $BottemY[$i] = @DesktopHeight-$Pos[3] Next While 1 For $i = 1 to $var[0][0] $win = $Array[$i] $Pos2 = WinGetPos($win,"") If $BottemY[$i] <> $Pos2[1] Then Do Sleep(50) $Pos2 = WinGetPos($win,"") Sleep(10) WinMove($win,"",$Pos2[0],$Pos2[1]+$loop) $loop = $loop +1 If $Pos2[1]+ $loop > $BottemY[$i] Then WinMove($win,"",$Pos2[0],$BottemY[$i]) Until $Pos2[1] >= $BottemY[$i] $loop = "0" EndIf Next WEnd Func IsVisible($handle) If BitAnd( WinGetState($handle), 2 ) Then Return 1 Else Return 0 EndIf EndFunc Func _Quit() Exit EndFunc Link to comment Share on other sites More sharing options...
Particle Posted July 30, 2008 Author Share Posted July 30, 2008 Im not sure the time limit on bumping posts so I apologize if 2 hours isn't enough... ^BumP^ Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 30, 2008 Moderators Share Posted July 30, 2008 Im not sure the time limit on bumping posts so I apologize if 2 hours isn't enough...^BumP^24 hours. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
weaponx Posted July 30, 2008 Share Posted July 30, 2008 (edited) I converted a Flash bouncing ball physics example. It works but its not 100% complete.expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global Const $GUI_Width = 100, $GUI_Height = 100 Global $GUI_X = @DesktopWidth/2, $GUI_Y = 100 Global Const $gravity = 1 Global Const $restitution = 0.6 Global Const $friction = 0.9 GUICreate("My GUI", 100,100) ; will create a dialog box that when displayed is centered GUISetState(@SW_SHOW) ; will display an empty dialog box $vel_x = 0 $vel_y = 0 $pos_x = $GUI_X $pos_y = $GUI_Y $old_x = $GUI_X $old_y = $GUI_Y $radius = $GUI_Width / 2 $movie_width = @DesktopWidth $movie_height = @DesktopHeight $dragging = false ; Run the GUI until the dialog is closed While 1 Update() $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop ;50 fps Sleep(20) WEnd Func Update() If NOT $dragging Then $vel_y += $gravity; $pos_x += $vel_x $pos_y+= $vel_y If ( $pos_y + $radius > $movie_height ) Then $pos_y = $movie_height - $radius $vel_y *= -$restitution $vel_x *= $friction EndIf If( $pos_x + $radius > $movie_width ) Then $pos_x = $movie_width - $radius $vel_x *= -$restitution EndIf If( $pos_x < $radius ) Then $pos_x = $radius $vel_x *= -$restitution EndIf ;WinMove $GUI_X = $pos_x $GUI_Y = $pos_y WinMove ("", "", $GUI_X, $GUI_Y) Else $old_x = $pos_x $old_y = $pos_y ;WinGetPos $pos_x = $GUI_X $pos_y = $GUI_Y $vel_x = ($pos_x- $old_x) / 2 $vel_y = ( $pos_y - $old_y ) / 2 EndIf EndFuncSource:http://www.spoono.com/flash/tutorials/tuto...php?url=gravity Edited July 30, 2008 by weaponx Link to comment Share on other sites More sharing options...
Glyph Posted July 30, 2008 Share Posted July 30, 2008 (edited) I converted a Flash bouncing ball physics example. It works but its not 100% complete. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global Const $GUI_Width = 100, $GUI_Height = 100 Global $GUI_X = @DesktopWidth/2, $GUI_Y = 100 Global Const $gravity = 1 Global Const $restitution = 0.6 Global Const $friction = 0.9 GUICreate("My GUI", 100,100) ; will create a dialog box that when displayed is centered GUISetState(@SW_SHOW) ; will display an empty dialog box $vel_x = 0 $vel_y = 0 $pos_x = $GUI_X $pos_y = $GUI_Y $old_x = $GUI_X $old_y = $GUI_Y $radius = $GUI_Width / 2 $movie_width = @DesktopWidth $movie_height = @DesktopHeight $dragging = false ; Run the GUI until the dialog is closed While 1 Update() $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop ;50 fps Sleep(20) WEnd Func Update() If NOT $dragging Then $vel_y += $gravity; $pos_x += $vel_x $pos_y+= $vel_y If ( $pos_y + $radius > $movie_height ) Then $pos_y = $movie_height - $radius $vel_y *= -$restitution $vel_x *= $friction EndIf If( $pos_x + $radius > $movie_width ) Then $pos_x = $movie_width - $radius $vel_x *= -$restitution EndIf If( $pos_x < $radius ) Then $pos_x = $radius $vel_x *= -$restitution EndIf ;WinMove $GUI_X = $pos_x $GUI_Y = $pos_y WinMove ("", "", $GUI_X, $GUI_Y) Else $old_x = $pos_x $old_y = $pos_y ;WinGetPos $pos_x = $GUI_X $pos_y = $GUI_Y $vel_x = ($pos_x- $old_x) / 2 $vel_y = ( $pos_y - $old_y ) / 2 EndIf EndFunc Source: http://www.spoono.com/flash/tutorials/tuto...php?url=gravity I gotta say, that is realllly cool! <embed width="400" height="300" src="http://chaoticnetworkz.net/wee.swf" border="0" /> Edited July 30, 2008 by BackStabbed tolle indicium Link to comment Share on other sites More sharing options...
Particle Posted July 30, 2008 Author Share Posted July 30, 2008 Very nice! Although when I drag it up it just moves to the bottem position instantly without using Update() Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 30, 2008 Share Posted July 30, 2008 I converted a Flash bouncing ball physics example. It works but its not 100% complete. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global Const $GUI_Width = 100, $GUI_Height = 100 Global $GUI_X = @DesktopWidth/2, $GUI_Y = 100 Global Const $gravity = 1 Global Const $restitution = 0.6 Global Const $friction = 0.9 GUICreate("My GUI", 100,100) ; will create a dialog box that when displayed is centered GUISetState(@SW_SHOW) ; will display an empty dialog box $vel_x = 0 $vel_y = 0 $pos_x = $GUI_X $pos_y = $GUI_Y $old_x = $GUI_X $old_y = $GUI_Y $radius = $GUI_Width / 2 $movie_width = @DesktopWidth $movie_height = @DesktopHeight $dragging = false ; Run the GUI until the dialog is closed While 1 Update() $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop ;50 fps Sleep(20) WEnd Func Update() If NOT $dragging Then $vel_y += $gravity; $pos_x += $vel_x $pos_y+= $vel_y If ( $pos_y + $radius > $movie_height ) Then $pos_y = $movie_height - $radius $vel_y *= -$restitution $vel_x *= $friction EndIf If( $pos_x + $radius > $movie_width ) Then $pos_x = $movie_width - $radius $vel_x *= -$restitution EndIf If( $pos_x < $radius ) Then $pos_x = $radius $vel_x *= -$restitution EndIf ;WinMove $GUI_X = $pos_x $GUI_Y = $pos_y WinMove ("", "", $GUI_X, $GUI_Y) Else $old_x = $pos_x $old_y = $pos_y ;WinGetPos $pos_x = $GUI_X $pos_y = $GUI_Y $vel_x = ($pos_x- $old_x) / 2 $vel_y = ( $pos_y - $old_y ) / 2 EndIf EndFunc Source: http://www.spoono.com/flash/tutorials/tuto...php?url=gravity Some tweaks: 1. Use hWND, or any window active gets moved. 2. Changed $restitution = 1 to keep it going (make it 1.1 for some real fun!). 3. Added delta X. 4. Using WinGetPos() to update current position so drag will work. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global Const $GUI_Width = 100, $GUI_Height = 100 Global $GUI_X = @DesktopWidth/2, $GUI_Y = 100 Global Const $gravity = 1 Global Const $restitution = 1 Global Const $friction = 0.9 $hGUI = GUICreate("My GUI", 100,100) ; will create a dialog box that when displayed is centered GUISetState(@SW_SHOW) ; will display an empty dialog box $vel_x = Random(0, 10, 1) $vel_y = 0 $pos_x = $GUI_X $pos_y = $GUI_Y $old_x = $GUI_X $old_y = $GUI_Y $radius = $GUI_Width / 2 $movie_width = @DesktopWidth $movie_height = @DesktopHeight $dragging = false ; Run the GUI until the dialog is closed While 1 Update() $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop ;50 fps Sleep(20) WEnd Func Update() If NOT $dragging Then $vel_y += $gravity; $avPos = WinGetPos($hGUI) $pos_x = $avPos[0] + $vel_x $pos_y = $avPos[1] + $vel_y If ( $pos_y + $radius > $movie_height ) Then $pos_y = $movie_height - $radius $vel_y *= -$restitution $vel_x *= $friction EndIf If( $pos_x + $radius > $movie_width ) Then $pos_x = $movie_width - $radius $vel_x *= -$restitution EndIf If( $pos_x < $radius ) Then $pos_x = $radius $vel_x *= -$restitution EndIf ;WinMove $GUI_X = $pos_x $GUI_Y = $pos_y WinMove ($hGUI, "", $GUI_X, $GUI_Y) Else $old_x = $pos_x $old_y = $pos_y ;WinGetPos $pos_x = $GUI_X $pos_y = $GUI_Y $vel_x = ($pos_x- $old_x) / 2 $vel_y = ( $pos_y - $old_y ) / 2 EndIf EndFunc Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
weaponx Posted July 30, 2008 Share Posted July 30, 2008 Here is a much cleaner version. I still can't get the position to update after dragging the window though.expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global Const $GUI_Size = 100 ;Start position: Top Middle Global Const $GUI_X = (@DesktopWidth/2)-($GUI_Size/2), $GUI_Y = 0 Global Const $gravity = 1 Global Const $restitution = 0.6 Global Const $friction = 0.9 ;Get taskbar position $Pos = WinGetPos("[CLASS:Shell_TrayWnd]") ;Create square GUI, physics will be applied to this window $GUI = GUICreate("Bouncing Ball", $GUI_Size, $GUI_Size, $GUI_X, $GUI_Y, $WS_POPUP,BitOr($WS_EX_LAYERED,$WS_EX_TOPMOST,$WS_EX_TOOLWINDOW)) GUISetState(@SW_SHOW) $Ball = GUICtrlCreatePic("ball.gif",0,0,$GUI_Size,$GUI_Size,-1,$GUI_WS_EX_PARENTDRAG) ;Velocity Global $vel_x = 0 Global $vel_y = 0 ;New position Global $pos_x = $GUI_X Global $pos_y = $GUI_Y ;Old position Global $old_x = $GUI_X Global $old_y = $GUI_Y ;Define workspace boundaries, account for taskbar height $movie_width = @DesktopWidth $movie_height = @DesktopHeight-$Pos[3] $dragging = false ; Run the GUI until the dialog is closed While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Ball Msgbox(0,"","Ball clicked") $dragging = True $test = WinGetPos($GUI) ConsoleWrite($test[0] & "," & $test[1] & @CRLF) EndSwitch Update() ;50 fps Sleep(20) WEnd Func Update() If NOT $dragging Then $vel_y += $gravity; $pos_x += $vel_x $pos_y += $vel_y If $pos_y + $GUI_Size > $movie_height Then $pos_y = $movie_height - $GUI_Size $vel_y *= -$restitution $vel_x *= $friction EndIf If $pos_x + $GUI_Size > $movie_width Then $pos_x = $movie_width - $GUI_Size $vel_x *= -$restitution EndIf If $pos_x < $GUI_Size Then $pos_x = $GUI_Size $vel_x *= -$restitution EndIf ;Move GUI WinMove($GUI,"",$pos_x,$pos_y) Else $old_x = $pos_x $old_y = $pos_y ;WinGetPos $GUI_Pos = WinGetPos($GUI) $pos_x = $GUI_Pos[0] $pos_y = $GUI_Pos[1] ConsoleWrite("Old position: " & $old_x & "," & $old_y & @CRLF & "New position: " & $pos_x & "," & $pos_y & @CRLF) $vel_x = ($pos_x - $old_x) / 2 $vel_y = ($pos_y - $old_y) / 2 $dragging = False EndIf EndFunc Link to comment Share on other sites More sharing options...
youknowwho4eva Posted July 30, 2008 Share Posted July 30, 2008 Aw man I have a shinny penny for who ever makes an Autoit version of the classic Q-Basic Gorillas. Giggity Link to comment Share on other sites More sharing options...
monoceres Posted July 30, 2008 Share Posted July 30, 2008 Aw man I have a shinny penny for who ever makes an Autoit version of the classic Q-Basic Gorillas.Why not made that your new project, the source is available http://www.xs4all.nl/~hwiegman/other/gorilla.zip Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
youknowwho4eva Posted July 30, 2008 Share Posted July 30, 2008 I'm sure my boss would love that maybe when I have time at home I'll do it, but by that time no one alive will remember the olden days of gorillas and snake... Giggity Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 30, 2008 Share Posted July 30, 2008 Here is a much cleaner version. I still can't get the position to update after dragging the window though. CODE#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global Const $GUI_Size = 100 ;Start position: Top Middle Global Const $GUI_X = (@DesktopWidth/2)-($GUI_Size/2), $GUI_Y = 0 Global Const $gravity = 1 Global Const $restitution = 0.6 Global Const $friction = 0.9 ;Get taskbar position $Pos = WinGetPos("[CLASS:Shell_TrayWnd]") ;Create square GUI, physics will be applied to this window $GUI = GUICreate("Bouncing Ball", $GUI_Size, $GUI_Size, $GUI_X, $GUI_Y, $WS_POPUP,BitOr($WS_EX_LAYERED,$WS_EX_TOPMOST,$WS_EX_TOOLWINDOW)) GUISetState(@SW_SHOW) $Ball = GUICtrlCreatePic("ball.gif",0,0,$GUI_Size,$GUI_Size,-1,$GUI_WS_EX_PARENTDRAG) ;Velocity Global $vel_x = 0 Global $vel_y = 0 ;New position Global $pos_x = $GUI_X Global $pos_y = $GUI_Y ;Old position Global $old_x = $GUI_X Global $old_y = $GUI_Y ;Define workspace boundaries, account for taskbar height $movie_width = @DesktopWidth $movie_height = @DesktopHeight-$Pos[3] $dragging = false ; Run the GUI until the dialog is closed While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Ball Msgbox(0,"","Ball clicked") $dragging = True $test = WinGetPos($GUI) ConsoleWrite($test[0] & "," & $test[1] & @CRLF) EndSwitch Update() ;50 fps Sleep(20) WEnd Func Update() If NOT $dragging Then $vel_y += $gravity; $pos_x += $vel_x $pos_y += $vel_y If $pos_y + $GUI_Size > $movie_height Then $pos_y = $movie_height - $GUI_Size $vel_y *= -$restitution $vel_x *= $friction EndIf If $pos_x + $GUI_Size > $movie_width Then $pos_x = $movie_width - $GUI_Size $vel_x *= -$restitution EndIf If $pos_x < $GUI_Size Then $pos_x = $GUI_Size $vel_x *= -$restitution EndIf ;Move GUI WinMove($GUI,"",$pos_x,$pos_y) Else $old_x = $pos_x $old_y = $pos_y ;WinGetPos $GUI_Pos = WinGetPos($GUI) $pos_x = $GUI_Pos[0] $pos_y = $GUI_Pos[1] ConsoleWrite("Old position: " & $old_x & "," & $old_y & @CRLF & "New position: " & $pos_x & "," & $pos_y & @CRLF) $vel_x = ($pos_x - $old_x) / 2 $vel_y = ($pos_y - $old_y) / 2 $dragging = False EndIf EndFunc Fixed it (requires Ball.gif in @ScriptDir): expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> HotKeySet("{ESC}", "_Quit") HotKeySet("{PAUSE}", "_Pause") Global $fPause = False Global Const $GUI_Size = 100 Global Const $GUI_Width = 100, $GUI_Height = 100 Global $GUI_X = @DesktopWidth/2, $GUI_Y = 100 Global Const $gravity = 1 Global Const $restitution = 1 Global Const $friction = 0.9 $hGUI = GUICreate("Bouncing Ball", $GUI_Size, $GUI_Size, $GUI_X, $GUI_Y, $WS_POPUP,BitOr($WS_EX_LAYERED,$WS_EX_TOPMOST,$WS_EX_TOOLWINDOW)) GUISetState(@SW_SHOW) $Ball = GUICtrlCreatePic("ball.gif",0,0,$GUI_Size,$GUI_Size,-1,$GUI_WS_EX_PARENTDRAG) $vel_x = Random(0, 10, 1) $vel_y = 0 $pos_x = $GUI_X $pos_y = $GUI_Y $old_x = $GUI_X $old_y = $GUI_Y $radius = $GUI_Width / 2 $movie_width = @DesktopWidth $movie_height = @DesktopHeight $dragging = false ; Run the GUI until the dialog is closed While 1 Update() $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop ;50 fps Sleep(20) WEnd Func Update() If $fPause Then Return If NOT $dragging Then $vel_y += $gravity; $avPos = WinGetPos($hGUI) $pos_x = $avPos[0] + $vel_x $pos_y = $avPos[1] + $vel_y If ( $pos_y + $radius > $movie_height ) Then $pos_y = $movie_height - $radius $vel_y *= -$restitution $vel_x *= $friction EndIf If( $pos_x + $radius > $movie_width ) Then $pos_x = $movie_width - $radius $vel_x *= -$restitution EndIf If( $pos_x < $radius ) Then $pos_x = $radius $vel_x *= -$restitution EndIf ;WinMove $GUI_X = $pos_x $GUI_Y = $pos_y WinMove ($hGUI, "", $GUI_X, $GUI_Y) Else $old_x = $pos_x $old_y = $pos_y ;WinGetPos $pos_x = $GUI_X $pos_y = $GUI_Y $vel_x = ($pos_x- $old_x) / 2 $vel_y = ( $pos_y - $old_y ) / 2 EndIf EndFunc Func _Quit() Exit EndFunc Func _Pause() $fPause = Not $fPause EndFunc Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
weaponx Posted July 30, 2008 Share Posted July 30, 2008 Thats teamwork there. I wonder why the velocity isn't affected by moving the ball like in the Flash version? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now