Hier ein kleines GDI+ Script mit Punkten die von den Wänden abprallen
Kollisionen unter den Punkten zu überwachen war mir leider noch zu kompliziert. Ich glaube kaum das das irgendjemand wirklich gebrauchen kann. Und ich weiß auch nicht, ob es das hier schon gibt. Und dennoch musste ich das einfach mal loswerden...
Spoiler anzeigen
#include <GDIPlus.au3>
#include <GUIConstants.au3>
Global $GUIWidth = 400 ;Breite GUI
Global $GUIHeight = 400 ;Höhe GUI
Global $BallWidth = 20 ;Breite Punkte
Global $BallHeight = 20 ;Höhe Punkte
Global $BallCount = 10 ;Anzahl Punkte
Global $GUIColorBG = 0xFF000000 ;Farbe GUI
Global $BallColor = 0xFFFFFFFF ;Farbe Punkte
Global $Title = 1
Global $iX[$BallCount]
Global $iY[$BallCount]
Global $StepX[$BallCount]
Global $StepY[$BallCount]
For $i = 0 To $BallCount - 1
$iX[$i] = Random($BallWidth + 10, $GUIWidth - $BallWidth - 10)
$iY[$i] = Random($BallHeight + 10, $GUIHeight - $BallHeight - 10)
Do
$StepX[$i] = Random(-5, 5, 1)
$StepY[$i] = Random(-5, 5, 1)
Until Not ($StepX[$i] = 0 And $StepY[$i] = 0)
Next
$hWnd = GUICreate("Punkteanzahl: " & $BallCount, $GUIWidth, $GUIHeight)
GUISetState(@SW_SHOW)
_GDIPlus_Startup()
[/autoit] [autoit][/autoit] [autoit]Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($GUIWidth, $GUIHeight, $hGraphic)
Global $Buffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($Buffer, 2)
_GDIPlus_GraphicsClear($Buffer, $GUIColorBG)
Global $hBrush = _GDIPlus_BrushCreateSolid($BallColor)
AdlibRegister("_Draw", 20)
AdlibRegister("_ChangeTitle", 4000)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
AdlibUnRegister()
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($Buffer)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
Exit
EndSwitch
WEnd
Func _Draw()
_GDIPlus_GraphicsClear($Buffer, $GUIColorBG)
For $i = 0 To $BallCount - 1
_GDIPlus_GraphicsFillEllipse($Buffer, $iX[$i], $iY[$i], $BallWidth, $BallHeight, $hBrush)
$iX[$i] += $StepX[$i]
$iY[$i] += $StepY[$i]
If $iX[$i] >= $GUIWidth - $BallWidth Then $StepX[$i] = $StepX[$i] * - 1
If $iY[$i] >= $GUIWidth - $BallHeight Then $StepY[$i] = $StepY[$i] * - 1
If $iX[$i] <= 0 Then $StepX[$i] = $StepX[$i] * - 1
If $iY[$i] <= 0 Then $StepY[$i] = $StepY[$i] * - 1
Next
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $GUIWidth, $GUIHeight)
EndFunc ;==>_Draw
Func _ChangeTitle()
If $Title = 1 Then
WinSetTitle($hWnd,"", "Punkteanzahl: " & $BallCount)
$Title += 1
ElseIf $Title = 2 Then
WinSetTitle($hWnd, "", "Punktefarbe: 0x" & Hex($BallColor, 8))
$Title += 1
Else
WinSetTitle($hWnd, "", "GUI Hintergrundfarbe: 0x" & Hex($GUIColorBG, 8))
$Title = 1
EndIf
EndFunc