# Ice Hockey Game

## Recommended Posts

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.

```#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)

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

\$iMoveX *= 0.99
\$iMoveY *= 0.99

\$aPos[1] += \$iMoveX
\$aPos[2] += \$iMoveY

\$m1 = MouseGetPos()

GUICtrlSetGraphic(\$hGraphic,\$GUI_GR_REFRESH)

_Clear()

Sleep(10)

Until Abs(\$iMoveX) < 0.3 And Abs(\$iMoveY) < 0.3

EndIf

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!

##### Share on other sites

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

## Create an account

Register a new account

×

• Wiki

• Back

• Git