Ejoc Posted April 23, 2005 Posted April 23, 2005 (edited) Joystick game soo coool You are the @ X is the exit Use the joystick Beat the game and feel special about your self expandcollapse popupOpt("MustDeclareVars",1) #include <DllMem.au3> #include <GUIConstants.au3> #include <File.au3> Local $joy,$coor,$h,$s="",$msg Dim $map[1],$lastpos[2],$pos[2] $joy = _JoyInit() _FileReadToArray("map.txt",$map) For $i = 1 To 16 $s = $s & $map[$i] Next $pos[0] = 2 $pos[1] = 15;starting pos GUICreate("The worlds lamest joystick game",300,300) GuiSetFont(9,400,0,"Lucida Console") $h= GuiCtrlCreatelabel($s,10,10,290,290) GUISetState() while 1 $msg = GUIGetMSG() $coor = _GetJoy($joy,0) ;$pos = $lastpos if $coor[1] < 3000 Or $coor[6] = 0 Then $pos[1] = $pos[1] - 1 if $coor[1] > 63000 Or $coor[6] = 18000 Then $pos[1] = $pos[1] + 1 if $coor[0] < 3000 or $coor[6] = 27000 Then $pos[0] = $pos[0] - 1 if $coor[0] > 63000 Or $coor[6] = 9000 Then $pos[0] = $pos[0] + 1 if $pos[0] <> $lastpos[0] Or $pos[1] <> $lastpos[1] Then $s = _MoveMe($map,$pos) if Not @error Then GUICtrlSetData($h,$s,1) $lastpos = $pos Else $pos = $lastpos EndIf Endif If Not $msg Then sleep(500) if $msg = $GUI_EVENT_CLOSE Then Exitloop WEnd Func _MoveMe($map,$pos) Local $s="",$i SetError(0) if $pos[0] < 2 or $pos[0] > 15 Then; bad x SetError(1) return "" Endif if $pos[1] < 2 or $pos[1] > 15 Then; bad y SetError(1) return "" Endif if stringmid($map[$pos[1]],$pos[0],1) = "#" Then SetError(1) return "" Endif if stringmid($map[$pos[1]],$pos[0],1) = "X" Then MsgBox(0,"You Win","You beat the stupid game, woohoo") exit Endif For $i = 1 To $pos[1]-1 $s = $s & $map[$i] Next $s = $s & StringLeft($map[$pos[1]],$pos[0]-1) & "@" & stringtrimleft($map[$pos[1]],$pos[0]) For $i = $pos[1]+1 To 16 $s = $s & $map[$i] Next return $s EndFunc ;====================================== ; _JoyInit() ;====================================== Func _JoyInit() Local $joy Global $JOYINFOEX_struct = "dword(13)" $joy = _DllMemCreate($JOYINFOEX_struct) if Not $joy Then Return 0 _DllMemSet($joy,$JOYINFOEX_struct,0,_DllMemStructSize($JOYINFOEX_struct),0) _DllMemSet($joy,$JOYINFOEX_struct,0,255,1) return $joy EndFunc ;====================================== ; _GetJoy($lpJoy,$iJoy) ; $lpJoy Return from _JoyInit() ; $iJoy Joystick # 0-15 ; Return Array containing X-Pos, Y-Pos, Z-Pos, R-Pos, U-Pos, V-Pos,POV ; Buttons down ; ; *POV This is a digital game pad, not analog joystick ; 65535 = Not pressed ; 0 = U ; 4500 = UR ; 9000 = R ; Goes around clockwise increasing 4500 for each position ;====================================== Func _GetJoy($lpJoy,$iJoy) Local $coor,$ret Dim $coor[8] $ret = DllCall("Winmm.dll","int","joyGetPosEx",_ "int",$iJoy,_ "ptr",$lpJoy) if Not @error Then $coor[0] = _DllMemGet($lpJoy,$JOYINFOEX_struct,0,2) $coor[1] = _DllMemGet($lpJoy,$JOYINFOEX_struct,0,3) $coor[2] = _DllMemGet($lpJoy,$JOYINFOEX_struct,0,4) $coor[3] = _DllMemGet($lpJoy,$JOYINFOEX_struct,0,5) $coor[4] = _DllMemGet($lpJoy,$JOYINFOEX_struct,0,6) $coor[5] = _DllMemGet($lpJoy,$JOYINFOEX_struct,0,7) $coor[6] = _DllMemGet($lpJoy,$JOYINFOEX_struct,0,10) $coor[7] = _DllMemGet($lpJoy,$JOYINFOEX_struct,0,8) EndIf return $coor EndFuncJoystickGame.zip Edited April 23, 2005 by Ejoc Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs
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