Skruge Posted July 30, 2008 Posted July 30, 2008 Thats teamwork there. I wonder why the velocity isn't affected by moving the ball like in the Flash version? The dragging code was essentially there, but not implemented.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() Switch $msg Case - 7 $dragging = True Case $GUI_EVENT_CLOSE ExitLoop EndSwitch ;50 fps Sleep(20) WEnd Func Update() If $fPause Then Return If Not $dragging Then $old_x = $pos_x $old_y = $pos_y $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 ;WinGetPos $pos_x = $GUI_X $pos_y = $GUI_Y $vel_x = ($pos_x - $old_x) / 2 $vel_y = ($pos_y - $old_y) / 2 $dragging = False EndIf EndFunc ;==>Update Func _Quit() Exit EndFunc ;==>_Quit Func _Pause() $fPause = Not $fPause EndFunc ;==>_Pause Next up, better bounds-checking and multi-monitor support! [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]
weaponx Posted July 30, 2008 Posted July 30, 2008 (edited) Here, the bounds checking is perfect.If anyone was wondering, I got the idea for this from a program called mProjector which converts Flash files to EXE.http://www.screentime.com/software/mprojector/There is a Red Bouncing Ball example on their homepage:http://www.screentime.com/downloads/mp/win/RedBall.exeexpandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> HotKeySet("{ESC}", "_Quit") HotKeySet("{PAUSE}", "_Pause") Global $fPause = False Global Const $GUI_Size = 100 Global $GUI_X = @DesktopWidth / 2, $GUI_Y = 100 Global Const $gravity = 1 Global Const $restitution = .6 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 ;Get taskbar height $Pos = WinGetPos("[CLASS:Shell_TrayWnd]") $movie_width = @DesktopWidth ;Bottom = absolute bottom ;$movie_height = @DesktopHeight ;Bottom = account for taskbar $movie_height = @DesktopHeight-$Pos[3] $dragging = False ; Run the GUI until the dialog is closed While 1 Update() $msg = GUIGetMsg() Switch $msg Case - 7 $dragging = True Case $GUI_EVENT_CLOSE ExitLoop EndSwitch ;50 fps Sleep(20) WEnd Func Update() If $fPause Then Return If Not $dragging Then $old_x = $pos_x $old_y = $pos_y $vel_y += $gravity; $avPos = WinGetPos($hGUI) $pos_x = $avPos[0] + $vel_x $pos_y = $avPos[1] + $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 < 0) Then $pos_x = 0 $vel_x *= -$restitution EndIf ;WinMove $GUI_X = $pos_x $GUI_Y = $pos_y WinMove($hGUI, "", $GUI_X, $GUI_Y) Else ;WinGetPos $pos_x = $GUI_X $pos_y = $GUI_Y $vel_x = ($pos_x - $old_x) / 2 $vel_y = ($pos_y - $old_y) / 2 $dragging = False EndIf EndFunc ;==>Update Func _Quit() Exit EndFunc ;==>_Quit Func _Pause() $fPause = Not $fPause EndFunc ;==>_Pause Edited July 30, 2008 by weaponx
Particle Posted July 30, 2008 Author Posted July 30, 2008 lol wow thats pretty tight, when i click and drag the ball though it acts as if im throwing it full speed and it just flys off the screen, eventually returns
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