andybiochem Posted February 11, 2009 Posted February 11, 2009 Hi, Here are my first attempts to code the collision dynamics of a table-hockey game in AutoIt, trying to maintain as much pure AI as possible (no GDI etc) Still lots to do yet!!! Click and drag to make contact. expandcollapse popup#include <GUIConstantsEx.au3> #include <Misc.au3> Opt("GUIOnEventMode", 1) Opt("MouseCoordMode",2) Global $iGraphCount = 0 Global $iMoveUnit = 4 Global $m1[2] Global $m2[2] Global $aPos[3] = ["",200,200] Global $dll = DllOpen("user32.dll") GUICreate("",600,600,Default,Default,Default,0x2000000) GUISetOnEvent($GUI_EVENT_CLOSE,"_Close") $hGraphic = GUICtrlCreateGraphic(0,0,600,600) GUICtrlSetBkColor(-1,0xFFFFFF) $iRad = 40 GUICtrlSetGraphic($hGraphic,$GUI_GR_ELLIPSE,40,40,$iRad*2,$iRad*2) GUICtrlSetGraphic($hGraphic,$GUI_GR_ELLIPSE,$aPos[1],$aPos[2],$iRad*2,$iRad*2) GUISetState(@SW_SHOW) While 1 $m2 = $m1 Sleep(10) $m1 = MouseGetPos() If _IsPressed("01",$dll) Then _Clear() If Sqrt(((($aPos[1] + $iRad) - $m1[0])^2) + ((($aPos[2] + $iRad) - $m1[1])^2)) < ($iRad * 2) - 1 Then $iMoveX = $m1[0] - $m2[0] $iMoveY = $m1[1] - $m2[1] Do If $aPos[1] +$iRad <= $iRad Or $aPos[1] + $iRad >= 600 - $iRad Then $iMoveX = - $iMoveX If $aPos[2] +$iRad <= $iRad Or $aPos[2] + $iRad >= 600 - $iRad Then $iMoveY = - $iMoveY $iMoveX *= 0.99 $iMoveY *= 0.99 $aPos[1] += $iMoveX $aPos[2] += $iMoveY $m1 = MouseGetPos() GUICtrlSetGraphic($hGraphic,$GUI_GR_ELLIPSE,$m1[0] - $iRad,$m1[1] - $iRad,$iRad*2,$iRad*2) GUICtrlSetGraphic($hGraphic,$GUI_GR_ELLIPSE,$aPos[1],$aPos[2],$iRad*2,$iRad*2) GUICtrlSetGraphic($hGraphic,$GUI_GR_REFRESH) _Clear() Sleep(10) Until Abs($iMoveX) < 0.3 And Abs($iMoveY) < 0.3 EndIf GUICtrlSetGraphic($hGraphic,$GUI_GR_ELLIPSE,$m1[0] - $iRad,$m1[1] - $iRad,$iRad*2,$iRad*2) GUICtrlSetGraphic($hGraphic,$GUI_GR_ELLIPSE,$aPos[1],$aPos[2],$iRad*2,$iRad*2) GUICtrlSetGraphic($hGraphic,$GUI_GR_REFRESH) EndIf WEnd Func _Clear() $iGraphCount += 1 GUICtrlSetGraphic($hGraphic,$GUI_GR_COLOR,0xFFFFFF,0xFFFFFF) GUICtrlSetGraphic($hGraphic,$GUI_GR_RECT,0,0,600,600) GUICtrlSetGraphic($hGraphic,$GUI_GR_COLOR,0x000000,$GUI_GR_NOBKCOLOR) If $iGraphCount > 10 Then GUISetState(@SW_LOCK) GUICtrlDelete($hGraphic) $hGraphic = GUICtrlCreateGraphic(0,0,600,600) GUICtrlSetBkColor(-1,0xFFFFFF) GUISetState(@SW_UNLOCK) $iGraphCount = 0 EndIf EndFunc Func _Close() Exit EndFunc - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
WideBoyDixon Posted February 11, 2009 Posted February 11, 2009 Nice physics going on there. I think you're always going to struggle against the flicker though. I did try adapting this so that there were two graphic controls and the updates were drawn on a hidden one which was then shown just before the current one was hidden. However, it didn't work too well as you got kind of a trail effect. WBD [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center]
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