Sign in to follow this  
Followers 0
Paulie

Box that dodges the mouse

4 posts in this topic

#1 ·  Posted (edited)

Try to click the box as it runs away, i need help on the 'Wintrap' (Crappy mod of '_Mousetrap') so it is less glitchy

#include <GuiConstants.au3>
$time = TimerInit()
Global $Box = GUICreate("Click Me!", 100, 100, -1, -1, $WS_POPUP, BitOr($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
    $WIN = GUICtrlCreateButton("OK", 25, 25, 50,50)
    GUISetState()
Global $speed = 5   
While 1
    Global $window = WinGetPos("Click Me!")
    Global $mouse = MouseGetPos()
    $msg = GuiGetMsg()
    If $msg = $WIN Then
        GuiSetState(@SW_HIDE, $Box)
        $time2 = TimerDiff($time)
        $sec = Round($time2/1000,2)
        MsgBox(0,"Congratulations!", "Congratulations! You Won!"&@CRLF&"And it only took you "&$sec&" Seconds.")
            Exit
        Endif
    
    If $Msg = $GUI_EVENT_CLOSE then Exit

    If $mouse[0] > $window[0]-5 And $mouse[0]<$window[0]+200 Then
        MoveRight()
    EndIf
    
    If $mouse[0] < $window[0]+205 And $mouse[0]>$window[0] Then
        MoveLeft()
    EndIf
    
    If $mouse[1] > $window[1]-5 And $mouse[1] < $window[1]+200 Then
        MoveDown()
    EndIf
    
    If $mouse[1] < $window[1]+205 And $mouse[1] > $window[1] Then
        MoveUp()
    EndIf
    WinTrap(2,2, @desktopwidth-100, @desktopheight-100)

WEnd

Func MoveRight()
    WinMove("Click Me!","", $window[0]+$speed, $window[1])
EndFunc

Func MoveLeft()
    WinMove("Click Me!","", $window[0]-$speed, $window[1])
EndFunc

Func MoveDown()
    WinMove("Click Me!","", $window[0], $window[1]+$speed)
EndFunc

Func MoveUp()
    WinMove("Click Me!","", $window[0], $window[1]-$speed)
EndFunc


Func WinTrap($iLeft, $iTop, $iWidth, $iHeight)
  Local $aPos, $iRight, $iBottom

  $iRight = $iLeft + $iWidth
  $iBottom = $iTop + $iHeight
  
  If $iLeft < 0 Or $iTop < 0 Or $iRight > @DesktopWidth Or $iBottom > @DesktopHeight Then
     SetError (1)
     Return 0
  EndIf
  $aPos = WinGetPos("Click Me!")
  
  Select
     Case $aPos[0] > $iRight
        WinMove("Click Me!","",$iLeft, $aPos[1])
     Case $aPos[0] < $iLeft
        WinMove("Click Me!","",$iRight, $aPos[1])
     Case $aPos[1] > $iBottom
        WinMove("Click Me!","",$aPos[0], $iTop)
     Case $aPos[1] < $iTop
        WinMove("Click Me!","",$aPos[0], $iBottom)
        
  EndSelect
  
EndFunc
Edited by Paulie

Share this post


Link to post
Share on other sites



set desktop height width. it gets hidden


[s]Autoit[/s]

Share this post


Link to post
Share on other sites

set desktop height width. it gets hidden

ya i figured it out how not to make it hide, but it is REALLY hard to click because it like teleports from side to side, i wish there was a better way that was more smooth, but thats all i can think of

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

0.88 ms ^^ really easy :whistle:

but nice game

edit :

0.47

Edited by Busti

My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0