• GDI+ Pong:
    Steuerung:
    - linkes Pad: W und S
    - rechtes Pad: Pfeiltaste Oben und Pfeiltaste Unten

    (Am Anfang des Scripts sind ein paar globale Variablen mit Beschreibungen was sie bewirken)

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>
    #include <GUIConstants.au3>
    #include <Misc.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $GUIWidth = 600 ;Breite GUI
    Global $GUIHeight = 400 ;Höhe GUI
    Global $BallWidth = 10 ;Breite Punkt
    Global $BallHeight = 10 ;Höhe Punkt
    Global $PadHeight1 = 60 ;Höhe des linken Pads
    Global $PadHeight2 = 60 ;Höhe des rechten Pads
    Global $PadWidth1 = 10 ;Breite des linken Pads
    Global $PadWidth2 = 10 ;Breite des rechten Pads
    Global $GUIColorBG = 0xFF000000 ;Farbe GUI
    Global $BallColor = 0xFFFFFFFF ;Farbe Punkt
    Global $Pad1Color = 0xFFFFFFFF ;Farbe des linken Pads
    Global $Pad2Color = 0xFFFFFFFF ;Farbe des rechten Pads
    Global $LineColor = 0xFFFFFFFF ;Farbe der Mittellinie

    [/autoit] [autoit][/autoit] [autoit]

    Global $Score1 = 0
    Global $Score2 = 0
    Global $iXBall = $GUIWidth / 2 - $BallWidth / 2
    Global $iYBall = Random($BallHeight + 10, $GUIHeight - $BallHeight - 10)
    Global $iXPad1 = 10
    Global $iYPad1 = $GUIHeight / 2 - $PadHeight1 / 2
    Global $iXPad2 = $GUIWidth - $PadWidth2 - 10
    Global $iYPad2 = $GUIHeight / 2 - $PadHeight2 / 2
    Global $StepYBall

    [/autoit] [autoit][/autoit] [autoit]

    If Random(1, 2, 1) = 1 Then
    Global $StepXBall = 5
    Else
    Global $StepXBall = -5
    EndIf
    Do
    $StepYBall = Random(-5, 5, 1)
    Until Not $StepYBall = 0

    [/autoit] [autoit][/autoit] [autoit]

    $hWnd = GUICreate("GDI+ Pong by Name22", $GUIWidth, $GUIHeight)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    _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 $hBrush1 = _GDIPlus_BrushCreateSolid($BallColor)
    Global $hBrush2 = _GDIPlus_BrushCreateSolid($Pad1Color)
    Global $hBrush3 = _GDIPlus_BrushCreateSolid($Pad2Color)
    Global $hBrush4 = _GDIPlus_BrushCreateSolid($LineColor)

    [/autoit] [autoit][/autoit] [autoit]

    AdlibRegister("_Draw", 20)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    AdlibUnRegister()
    _GDIPlus_BrushDispose($hBrush1)
    _GDIPlus_BrushDispose($hBrush2)
    _GDIPlus_BrushDispose($hBrush3)
    _GDIPlus_BrushDispose($hBrush4)
    _GDIPlus_GraphicsDispose($Buffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    Exit
    EndSwitch
    If Not WinActive($hWnd) = 0 Then
    If _IsPressed("57") And $iYPad1 >= 0 Then $iYPad1 -= 2
    If _IsPressed("53") And $iYPad1 <= $GUIHeight - $PadHeight1 Then $iYPad1 += 2
    If _IsPressed("26") And $iYPad2 >= 0 Then $iYPad2 -= 2
    If _IsPressed("28") And $iYPad2 <= $GUIHeight - $PadHeight2 Then $iYPad2 += 2
    EndIf
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _Draw()
    _GDIPlus_GraphicsClear($Buffer, $GUIColorBG)
    _GDIPlus_GraphicsFillRect($Buffer, $iXPad1, $iYPad1, $PadWidth1, $PadHeight1, $hBrush2)
    _GDIPlus_GraphicsFillRect($Buffer, $iXPad2, $iYPad2, $PadWidth2, $PadHeight2, $hBrush3)
    For $i = 0 To Round($GUIHeight / 30) - 1
    _GDIPlus_GraphicsFillRect($Buffer, $GUIWidth / 2 - 15, $i * 60, 10, 30, $hBrush4)
    Next
    _GDIPlus_GraphicsFillEllipse($Buffer, $iXBall, $iYBall, $BallWidth, $BallHeight, $hBrush1)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $GUIWidth, $GUIHeight)
    $iXBall += $StepXBall
    $iYBall += $StepYBall
    Switch $iXBall
    Case $iXPad1 + $PadWidth1 - 5 To $iXPad1 + $PadWidth1
    If $iYBall >= $iYPad1 - $BallHeight / 2 And $iYBall <= $iYPad1 + $PadHeight1 + $BallHeight / 2 Then $StepXBall = $StepXBall * - 1
    Case $iXPad2 - $PadWidth2 To $iXPad2 - $PadWidth2 + 5
    If $iYBall >= $iYPad2 - $BallHeight / 2 And $iYBall <= $iYPad2 + $PadHeight2 + $BallHeight / 2 Then $StepXBall = $StepXBall * - 1
    EndSwitch
    If $iYBall >= $GUIHeight - $BallHeight Then $StepYBall = $StepYBall * - 1
    If $iYBall <= 0 Then $StepYBall = $StepYBall * - 1
    If $iXBall <= 0 Then
    $Score2 += 1
    WinSetTitle($hWnd, "", "Player 1: " & $Score1 & " | Player 2: " & $Score2)
    Sleep(1000)
    $iXBall = $GUIWidth / 2 - $BallWidth / 2
    $iYBall = Random($BallHeight + 10, $GUIHeight - $BallHeight - 10)
    $iYPad1 = $GUIHeight / 2 - $PadHeight1 / 2
    $iYPad2 = $GUIHeight / 2 - $PadHeight2 / 2
    If Random(1, 2, 1) = 1 Then
    $StepXBall = 5
    Else
    $StepXBall = -5
    EndIf
    Do
    $StepYBall = Random(-5, 5, 1)
    Until Not $StepYBall = 0
    EndIf
    If $iXBall >= $GUIWidth - $BallWidth Then
    $Score1 += 1
    WinSetTitle($hWnd, "", "Player 1: " & $Score1 & " | Player 2: " & $Score2)
    Sleep(1000)
    $iXBall = $GUIWidth / 2 - $BallWidth / 2
    $iYBall = Random($BallHeight + 10, $GUIHeight - $BallHeight - 10)
    $iYPad1 = $GUIHeight / 2 - $PadHeight1 / 2
    $iYPad2 = $GUIHeight / 2 - $PadHeight2 / 2
    If Random(1, 2, 1) = 1 Then
    $StepXBall = 5
    Else
    $StepXBall = -5
    EndIf
    Do
    $StepYBall = Random(-5, 5, 1)
    Until Not $StepYBall = 0
    EndIf
    EndFunc ;==>_Draw

    [/autoit]