gottygolly 6 Posted April 4, 2014 (edited) I started to play around with the _IsPressed function and it's a lot of fun. I made this script below for fun and I want to stop the Gray box from going through the Red box any ideas? expandcollapse popup#include<misc.au3> #include<windowsconstants.au3> #include<guiconstants.au3> $gui = GUICreate("Gui",300,300,-1,-1,BitOR($WS_EX_WINDOWEDGE,$WS_POPUP)) $pic = GUICtrlCreateInput("",50,50,36,36) GUICtrlSetState($pic,$GUI_DISABLE) GUICtrlSetBkColor($pic,0xFF0000) GUISetBkColor(0x000000) $inp = GUICtrlCreateInput("",200,200,50,50) GUICtrlSetState($inp,$GUI_DISABLE) GUISetState() while 1 If _IsPressed("25") Then $cp = ControlGetPos($gui,"",$pic) $cpx = $cp[0] - 1 GUICtrlSetPos($pic,$cpx,$cp[1]) EndIf If _IsPressed("28") Then $cp = ControlGetPos($gui,"",$pic) $cpy = $cp[1] + 1 GUICtrlSetPos($pic,$cp[0],$cpy) EndIf If _IsPressed("27") Then $cp = ControlGetPos($gui,"",$pic) $cpx = $cp[0] + 1 GUICtrlSetPos($pic,$cpx,$cp[1]) EndIf If _IsPressed("26") Then $cp = ControlGetPos($gui,"",$pic) $cpy = $cp[1] - 1 GUICtrlSetPos($pic,$cp[0],$cpy) EndIf $msg = GUIGetMsg(1) Switch $msg[1] Case $gui Switch $msg[0] Case -3 Exit EndSwitch EndSwitch WEnd Thanks. Edited April 4, 2014 by gottygolly Share this post Link to post Share on other sites
Palestinian 13 Posted April 4, 2014 (edited) You could try putting the x,y of $pic in a variable and then set an If...Then condition, if $x = xx then reset. EDIT: you already got the $cpy and $cpx so no need for $x,$y, you could try something like this: $cp = ControlGetPos($gui,"",$pic) $cpx = $cp[0] + 1 If $cpx > 150 Then $cpx = 150 GUICtrlSetPos($pic,$cpx,$cp[1]) Edited April 5, 2014 by Palestinian Share this post Link to post Share on other sites
gottygolly 6 Posted April 5, 2014 Thanks Palestinian. I'm not able to get try this oout on a computer at the moment but I'll check it soon and let you know. Share this post Link to post Share on other sites
JohnOne 1,603 Posted April 5, 2014 (edited) What you really want to do is create an _Is_collision() function in which all edges are calculated to see if any are overlapped. For example if the bottom of red is equal to top of grey and (right of red is equal to left of grey or left of red is equal to right of grey) then red cannot move down. A whole lot of calculations but a decent exercise for beginner. EDIT: Example to control a down movement. expandcollapse popup#include<misc.au3> #include<windowsconstants.au3> #include<guiconstants.au3> $gui = GUICreate("Gui", 300, 300, -1, -1, BitOR($WS_EX_WINDOWEDGE, $WS_POPUP)) $pic = GUICtrlCreateInput("", 50, 50, 36, 36) GUICtrlSetState($pic, $GUI_DISABLE) GUICtrlSetBkColor($pic, 0xFF0000) GUISetBkColor(0x000000) $inp = GUICtrlCreateInput("", 200, 200, 50, 50) GUICtrlSetState($inp, $GUI_DISABLE) GUISetState() While 1 If _IsPressed("25") Then $cp = ControlGetPos($gui, "", $pic) $cpx = $cp[0] - 1 GUICtrlSetPos($pic, $cpx, $cp[1]) EndIf If _IsPressed("28") Then $cp = ControlGetPos($gui, "", $pic) If _CanMoveDown($cp) Then $cpy = $cp[1] + 1 GUICtrlSetPos($pic, $cp[0], $cpy) EndIf EndIf If _IsPressed("27") Then $cp = ControlGetPos($gui, "", $pic) $cpx = $cp[0] + 1 GUICtrlSetPos($pic, $cpx, $cp[1]) EndIf If _IsPressed("26") Then $cp = ControlGetPos($gui, "", $pic) $cpy = $cp[1] - 1 GUICtrlSetPos($pic, $cp[0], $cpy) EndIf $msg = GUIGetMsg(1) Switch $msg[1] Case $gui Switch $msg[0] Case -3 Exit EndSwitch EndSwitch WEnd Func _CanMoveDown($cp) $red_B = $cp[1] + $cp[3] $red_R = $cp[0] + $cp[2] $red_L = $cp[0] If $red_B >= 200 And ($red_R >= 200 And $red_L <= 250) Then Return False EndIf Return True EndFunc ;==>_CanMoveDown Just need to repeat with left right and up. Edited April 5, 2014 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Share this post Link to post Share on other sites
gottygolly 6 Posted April 5, 2014 (edited) Thanks JohnOne it works like a charm And Palestinian it works but it wasn't what I was looking for thanks for the info though I'll probably end up using it in the future. Edit: JohnOne I ran into a problem with the code you provided me...When ever the blocks touch each other it disables all the other arrow keys. (I probably did something wrong but could you enlighten me on what I did wrong?) expandcollapse popup#include<misc.au3> #include<windowsconstants.au3> #include<guiconstants.au3> $gui = GUICreate("Gui", 300, 300, -1, -1, BitOR($WS_EX_WINDOWEDGE, $WS_POPUP)) $pic = GUICtrlCreateInput("", 50, 50, 36, 36) GUICtrlSetState($pic, $GUI_DISABLE) GUICtrlSetBkColor($pic, 0xFF0000) GUISetBkColor(0x000000) $inp = GUICtrlCreateInput("", 200, 200, 50, 50) GUICtrlSetState($inp, $GUI_DISABLE) GUISetState() While 1 If _IsPressed("25") Then $cp = ControlGetPos($gui, "", $pic) If _CanMoveLeft($cp) Then $cpx = $cp[0] - 1 GUICtrlSetPos($pic, $cpx, $cp[1]) EndIf EndIf If _IsPressed("28") Then $cp = ControlGetPos($gui, "", $pic) If _CanMoveDown($cp) Then $cpy = $cp[1] + 1 GUICtrlSetPos($pic, $cp[0], $cpy) EndIf EndIf If _IsPressed("27") Then $cp = ControlGetPos($gui, "", $pic) If _CanMoveRight($cp) Then $cpx = $cp[0] + 1 GUICtrlSetPos($pic, $cpx, $cp[1]) EndIf EndIf If _IsPressed("26") Then $cp = ControlGetPos($gui, "", $pic) If _CanMoveUp($cp) Then $cpy = $cp[1] - 1 GUICtrlSetPos($pic, $cp[0], $cpy) EndIf EndIf $msg = GUIGetMsg(1) Switch $msg[1] Case $gui Switch $msg[0] Case -3 Exit EndSwitch EndSwitch WEnd Func _CanMoveDown($cp) $red_B = $cp[1] + $cp[3] $red_R = $cp[0] + $cp[2] $red_L = $cp[0] If $red_B >= 200 And ($red_R >= 200 And $red_L <= 250) Then Return False EndIf Return True EndFunc ;==>_CanMoveDown Func _CanMoveLeft($cp) $red_B = $cp[1] + $cp[3] $red_R = $cp[0] + $cp[2] $red_L = $cp[0] If $red_B >= 200 And ($red_R >= 200 And $red_L <= 250) Then Return False EndIf Return True EndFunc Func _CanMoveRight($cp) $red_B = $cp[1] + $cp[3] $red_R = $cp[0] + $cp[2] `$red_L = $cp[0] If $red_B >= 200 And ($red_R >= 200 And $red_L <= 250) Then Return False EndIf Return True EndFunc Func _CanMoveUp($cp) $red_B = $cp[1] + $cp[3] $red_R = $cp[0] + $cp[2] $red_L = $cp[0] If $red_B >= 200 And ($red_R >= 200 And $red_L <= 250) Then Return False EndIf Return True EndFunc Sorry for the inconvenience. Edited April 5, 2014 by gottygolly Share this post Link to post Share on other sites
JohnOne 1,603 Posted April 5, 2014 JohnOne I ran into a problem with the code you provided me...When ever the blocks touch each other it disables all the other arrow keys. I probably did something wrong but could you enlighten me on what I did wrong? You simply renamed the function for checking the down movement for other directions. You need different logic for each direction. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Share this post Link to post Share on other sites