Jex Posted October 24, 2007 Share Posted October 24, 2007 I'm bored and tryied create little game. Left and right sides (22 and 24 lines) working good but up and down sides move button randomly? (26 and 28 lines) I can't figure out what is problem, maybe im doing small mistake #include <GUIConstants.au3> Opt("MouseCoordMode", 2) $Width = 500 $Height = 500 $Gui = GuiCreate("Test",$Width,$Height) $Button = GUICtrlCreateButton("",250,250,50,50) GUISetState() While 1 $msg = GUIGetMsg() If $msg = -3 Then Exit $Pos = MouseGetPos() $ControlPos = ControlGetPos("","",$Button) If $Pos[0] >= 0 And $Pos[0] <= $Width And $Pos[1] >= 0 And $Pos[1] <= $Height Then ;If mouse inside window ToolTip("Mouse X: " & $Pos[0] & " Y: " & $Pos[1] & " Button X: " & $ControlPos[0] & " Y: " & $ControlPos[1]) $x1 = $ControlPos[0] - 20 $x2 = $ControlPos[0] + $ControlPos[2] + 20 $y1 = $ControlPos[1] - 20 $y2 = $ControlPos[1] + $ControlPos[3] + 20 If $Pos[0] > $x1 And $Pos[0] < $x1 + 20 And $Pos[1] > $y1 + 20 And $Pos[1] < $y2 - 20 Then ;Left GUICtrlSetPos($Button, $Pos[0] + 20, $ControlPos[1]) ElseIf $Pos[0] < $x2 And $Pos[0] > $x2 - 20 And $Pos[1] > $y1 + 20 And $Pos[1] < $y2 - 20 Then ;Right GUICtrlSetPos($Button, ($Pos[0] - $ControlPos[2]) - 20, $ControlPos[1]) ElseIf $Pos[1] > $y1 And $Pos[1] < $y1 + 20 And $Pos[0] > $x1 + 20 And $Pos[0] < $x2 - 20 Then ;Up GUICtrlSetPos($Button, $Pos[1] + 20, $ControlPos[0]) ElseIf $Pos[1] < $y2 And $Pos[1] > $y2 - 20 And $Pos[0] > $x1 + 20 And $Pos[0] < $x2 - 20 Then ;Down GUICtrlSetPos($Button, ($Pos[1] - $ControlPos[3]) - 20, $ControlPos[0]) EndIf EndIf WEnd My scripts : Immediate Window , My Web Browser , Travian , Text Effect , Characters & Words per minute or second , Image Editor (ImageMagick) , Matrix style background effect ( Screensaver ) , Mail Sender , Protectlinks decoder and Rapidshare links checker , Fonts Fetcher , Region determine , Compare pictures , Gradient color box , Mouse Coordinates, Colors, Pixel Search things , Encrypt/Decrypt and embeding file in jpeg thing , Hard disk space monitor , Reflex game , Multiplayer Tic Tac Toe , WLM ( MSN ) personal message changer Link to comment Share on other sites More sharing options...
Nahuel Posted October 24, 2007 Share Posted October 24, 2007 #include <GUIConstants.au3> Opt("MouseCoordMode", 2) $Width = 500 $Height = 500 $Gui = GuiCreate("Test",$Width,$Height) $Button = GUICtrlCreateButton("",250,250,50,50) GUISetState() While 1 $msg = GUIGetMsg() If $msg = -3 Then Exit $Pos = MouseGetPos() $ControlPos = ControlGetPos("","",$Button) If $Pos[0] >= 0 And $Pos[0] <= $Width And $Pos[1] >= 0 And $Pos[1] <= $Height Then ;If mouse inside window ToolTip("Mouse X: " & $Pos[0] & " Y: " & $Pos[1] & " Button X: " & $ControlPos[0] & " Y: " & $ControlPos[1]) $x1 = $ControlPos[0] - 20 $x2 = $ControlPos[0] + $ControlPos[2] + 20 $y1 = $ControlPos[1] - 20 $y2 = $ControlPos[1] + $ControlPos[3] + 20 If $Pos[0] > $x1 And $Pos[0] < $x1 + 20 And $Pos[1] > $y1 + 20 And $Pos[1] < $y2 - 20 Then ;Left GUICtrlSetPos($Button, $Pos[0] + 20, $ControlPos[1]) ElseIf $Pos[0] < $x2 And $Pos[0] > $x2 - 20 And $Pos[1] > $y1 + 20 And $Pos[1] < $y2 - 20 Then ;Right GUICtrlSetPos($Button, ($Pos[0] - $ControlPos[2]) - 20, $ControlPos[1]) ElseIf $Pos[1] > $y1 And $Pos[1] < $y1 + 20 And $Pos[0] > $x1 And $Pos[0] < $x2 -20 Then ;Down GUICtrlSetPos($Button,$ControlPos[0] , $Pos[1] + 20) ElseIf $Pos[1] < $y2 And $Pos[1] > $y2 - 20 And $Pos[0] > $x1 + 20 And $Pos[0] < $x2 - 20 Then ;Up GUICtrlSetPos($Button,$ControlPos[0] ,($Pos[1] - $ControlPos[3]) - 20 ) EndIf EndIf WEnd Link to comment Share on other sites More sharing options...
Jex Posted October 24, 2007 Author Share Posted October 24, 2007 Thanks My scripts : Immediate Window , My Web Browser , Travian , Text Effect , Characters & Words per minute or second , Image Editor (ImageMagick) , Matrix style background effect ( Screensaver ) , Mail Sender , Protectlinks decoder and Rapidshare links checker , Fonts Fetcher , Region determine , Compare pictures , Gradient color box , Mouse Coordinates, Colors, Pixel Search things , Encrypt/Decrypt and embeding file in jpeg thing , Hard disk space monitor , Reflex game , Multiplayer Tic Tac Toe , WLM ( MSN ) personal message changer 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