pieeater Posted April 15, 2011 Share Posted April 15, 2011 im trying to make a program where you press the arrow keys and it moves a lable and once it gets to a certain point it opens a msg box telling you you hit the goal and closes the windows. but i have no clue how to make the program wait until the x and y cordanates are within where the goal lable is. so far ive gotten this expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEX.au3> $left=50 $top=70 HotKeySet("{esc}", "terminate") HotKeySet("{left}", "left") HotKeySet("{right}", "right") HotKeySet("{up}", "up") HotKeySet("{down}", "down") GUICreate("lol123",1000,700,10,10) $lable = GUICtrlCreateLabel("use the arrow keys to move the arrow into the goal",50,50) $lable2 = GUICtrlCreateLabel("~~>",$left,$top) $lable3 = GUICtrlCreateLabel("GAOL",300,300) GUISetState() Do $msg=GUIGetMsg() Until $msg=$GUI_EVENT_CLOSE Func terminate() Exit EndFunc Func left() $left=$left-1 ControlMove("lol123","","[CLASS:Static; INSTANCE:2]", $left,$top) EndFunc Func right() $left=$left+1 ControlMove("lol123","","[CLASS:Static; INSTANCE:2]", $left,$top) EndFunc Func up() $top=$top-1 ControlMove("lol123","","[CLASS:Static; INSTANCE:2]", $left,$top) EndFunc Func down() $top=$top+1 ControlMove("lol123","","[CLASS:Static; INSTANCE:2]", $left,$top) EndFunc [spoiler]My UDFs: Login UDF[/spoiler] Link to comment Share on other sites More sharing options...
taietel Posted April 15, 2011 Share Posted April 15, 2011 Something like this? expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Misc.au3> $left=50 $top=70 $iXGoal = 300 $iYGoal = 300 HotKeySet("{esc}", "terminate") HotKeySet("{left}", "left") HotKeySet("{right}", "right") HotKeySet("{up}", "up") HotKeySet("{down}", "down") $hGui = GUICreate("lol123",1000,700,10,10) $lable = GUICtrlCreateLabel("use the arrow keys to move the arrow into the goal",50,50) $lable2 = GUICtrlCreateLabel("~~>",$left,$top,25,18) GUICtrlSetBkColor(-1,0xff0000);just to see $lable3 = GUICtrlCreateLabel("GAOL",$iXGoal,$iYGoal,30,18) GUICtrlSetBkColor(-1,0xff0000);just to see GUISetState() AdlibRegister("_Win") While 1 Sleep(10) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func terminate() Exit EndFunc Func _Win() If $iXGoal-25<=$left And $left<=$iXGoal+30 And $iYGoal-18<=$top And $top<=$iYGoal+18 Then MsgBox(64,"Congratulation!","We have a winner!") Exit EndIf EndFunc Func left() $left=$left-1 ControlMove($hGui,"",$lable2, $left,$top) EndFunc Func right() $left=$left+1 ControlMove($hGui,"",$lable2, $left,$top) EndFunc Func up() $top=$top-1 ControlMove($hGui,"",$lable2, $left,$top) EndFunc Func down() $top=$top+1 ControlMove($hGui,"",$lable2, $left,$top) EndFunc Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text Link to comment Share on other sites More sharing options...
pieeater Posted April 15, 2011 Author Share Posted April 15, 2011 yah thats exactly what i was looking for thanks [spoiler]My UDFs: Login UDF[/spoiler] Link to comment Share on other sites More sharing options...
jaberwacky Posted April 16, 2011 Share Posted April 16, 2011 (edited) Try this too... #include <GUIConstantsEx.au3> Global Const $hGUI = GUICreate( "Button Demon -- Hours of Fun!" , 600 , 400 , 10 , 10 ) Global Const $hButton = GUICtrlCreateButton( "Click Me! }:>" , 50 , 100 , 100 , 90 ) GUISetState() Opt( "MouseCoordMode" , 2 ) Global $MouseNFO , $1 , $2 While 1 $MouseNFO = GUIGetCursorInfo() If $MouseNFO[ 4 ] = $hButton Then $1 = Random( 0 , 500 ) $2 = Random( 0 , 310 ) GUICtrlSetPos( $hButton , $1 , $2 ) EndIf If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit WEnd Edited April 16, 2011 by LaCastiglione Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
pieeater Posted April 16, 2011 Author Share Posted April 16, 2011 thanks LaCastiglione thts closer to what i wanted [spoiler]My UDFs: Login UDF[/spoiler] Link to comment Share on other sites More sharing options...
jaberwacky Posted April 17, 2011 Share Posted April 17, 2011 thanks LaCastiglione thts closer to what i wanted Hah, I just reread your original post and I realized that I misunderstood your request. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
bwochinski Posted April 17, 2011 Share Posted April 17, 2011 (edited) This sounded like a bit of a fun one, so here's my contribution: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Misc.au3> $speed = 3 $winW = 800 $winH = 600 $winMargin = 5 $bLeft = 50 $bTop = 300 $bWidth = 25 $bHeight = 33 $goalX = 700 $goalY = 275 $goalW = 75 $goalH = 75 $winMain = GUICreate("Form Game",$winW,$winH) $lbl = GUICtrlCreateLabel("use the arrow keys to move the X into the goal",50,50) $label1 = GUICtrlCreateLabel("X",$bLeft,$bTop,$bWidth,$bHeight) GUICtrlSetFont($label1, 24, 1600) GUICtrlSetBkColor($label1,0x00bb00) $label2 = GUICtrlCreateLabel(" GOAL ",$goalX,$goalY,$goalW,$goalH) GUICtrlSetFont($label2, 12, 800) GUICtrlSetBkColor($label2,0xcc9999) GUISetState() While 1 If GUIGetMsg() == $GUI_EVENT_CLOSE Then Exit If _IsPressed(25) Then _LEFT() If _IsPressed(26) Then _UP() If _IsPressed(27) Then _RIGHT() If _IsPressed(28) Then _DOWN() ControlMove($winMain,"",$label1,$bLeft,$bTop) _check_goal() WEnd Func _LEFT() $bLeft -= $speed If $bLeft < $winMargin Then $bLeft = $winMargin EndFunc Func _UP() $bTop -= $speed If $bTop < $winMargin Then $bTop = $winMargin EndFunc Func _RIGHT() $bLeft += $speed If $bLeft > $winW - ($bWidth + $winMargin) Then $bLeft = $winW - ($bWidth + $winMargin) EndFunc Func _DOWN() $bTop += $speed If $bTop > $winH - ($bHeight + $winMargin) Then $bTop = $winH - ($bHeight + $winMargin) EndFunc Func _check_goal() If $bTop > $goalY And $bLeft > $goalX Then If $bTop + $bHeight < $goalY + $goalH And $bLeft + $bWidth < $goalX + $goalW Then MsgBox(0,"Goal", "GOOOOOOOAAAAAAAAAAAAAAAAAAAAAAAAAL!!!") $bLeft = 100 $bTop = 100 EndIf EndIf EndFunc Made the main loop watch for key presses instead of using hotkeys to get better smoothness and also allow for diagonal movement. (up + right, etc) Sped up the movement a bit to save my sanity and added checks to prevent the ball from leaving the visible area. Goal is only scored when the ball is completely within the goal area. (EDIT: cleaned up a little / got rid of hard-coded formulas, use variables at top to modify now) Edited April 17, 2011 by bwochinski Link to comment Share on other sites More sharing options...
pieeater Posted April 17, 2011 Author Share Posted April 17, 2011 @ bwochinski thanks that script is helping me on another script alot and making it much easyer. also im going to try and use it to make a 2 player game:) [spoiler]My UDFs: Login UDF[/spoiler] 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