GDI+ Punkte drücken

  • Hallo.
    Hier ist mal mein erstes GDI+ - Skript von mir, bei dem wenigstens Ansatzweise etwas rausgekommen ist. Es geht dort um schlichtes Punkte drücken und um möglichst viele Punkte zu erreichen. Aber mir ging es eher um die Übung mit GDI+.
    Hier ist der Code:

    Spoiler anzeigen
    [autoit]

    #cs ----------------------------------------------------------------------------

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

    AutoIt Version: 3.3.6.1
    Author: myName

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

    Script Function:
    Template AutoIt script.

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

    #ce ----------------------------------------------------------------------------
    #include <GDIPlus.au3>
    #include <WindowsConstants.au3>
    #include <GUIConstantsEx.au3>

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

    Global $iWidth = 400
    Global $iHeight = 400
    Global $sTitle = "GDI+ Spiel - by Bakku (http://www.autoit.de)"
    Global $GUIBkColor = 0xFF000000 + 0xF0F0F0
    Global $iPosition1[3] = [0,0,0]
    Global $iPosition2[3] = [0,0,0]
    Global $iPosition3[3] = [0,0,0]
    Global $iPosition4[3] = [0,0,0]
    Global $iPosition5[3] = [0,0,0]
    Global $iPosition6[3] = [0,0,0]
    Global $iPosition7[3] = [0,0,0]
    Global $iPosition8[3] = [0,0,0]
    Global $iPosition9[3] = [0,0,0]
    Global $iPosition10[3] = [0,0,0]
    Global $Points = 0
    Global $oldPoints = 0
    Global $PositionFree = True
    Global $counter = 60
    Global $schwierigkeit = 0

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

    $zahl = InputBox("Schwierigkeit", "Bitte die Schwierigkeit eingeben. Zahl von 1-3. 1: Leicht, 2: Mittel, 3: Schwer")
    If $zahl = 1 Then
    $schwierigkeit = 1000
    ElseIf $zahl = 2 Then
    $schwierigkeit = 500
    ElseIf $zahl = 3 Then
    $schwierigkeit = 200
    Else
    MsgBox(0, "Falsch", "Falsche Eingabe. Wer lesen kann hat Vorteile :-)")
    Exit
    EndIf

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

    _GDIPlus_Startup()

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

    $hGUI = GUICreate($sTitle, $iWidth, $iHeight)

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

    GUICtrlCreateLabel("Punkte:", 10, 10)
    GUICtrlSetFont(-1, 9, -1, -1, "Comic Sans MS")
    $hLabel = GUICtrlCreateLabel("", 55, 10, 20, 20)
    GUICtrlSetFont(-1, 9, -1, -1, "Comic Sans MS")

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

    GUICtrlCreateLabel("Zeit:", 300, 10)
    GUICtrlSetFont(-1, 9, -1, -1, "Comic Sans MS")
    $hLabelCountdown = GUICtrlCreateLabel("", 350, 10, 20, 20)
    GUICtrlSetFont(-1, 9, -1, -1, "Comic Sans MS")

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

    $hWnd = WinGetHandle($sTitle)

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

    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphic)
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)

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

    $hBrush = _GDIPlus_BrushCreateSolid(0xFFFF0000)
    $hBrushBk = _GDIPlus_BrushCreateSolid($GUIBkColor)

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

    GUIRegisterMsg($WM_PAINT, "WM_PAINT")

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

    GUISetState(@SW_SHOW)

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

    AdlibRegister("Countdown", 1000)

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

    $Timer = TimerInit()

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

    While 1
    $nMsg = GUIGetMsg(1)

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

    Switch $nMsg[0]
    Case $GUI_EVENT_CLOSE
    _Exit()
    Case $GUI_EVENT_PRIMARYDOWN
    Switch $nMsg[3]
    Case $iPosition1[0] to $iPosition1[0] + $iPosition1[2]
    Switch $nMsg[4]
    Case $iPosition1[1] to $iPosition1[1] + $iPosition1[2]
    _GDIPlus_GraphicsFillEllipse($hBuffer, $iPosition1[0], $iPosition1[1], $iPosition1[2], $iPosition1[2], $hBrushBk)
    For $i = 0 to 2
    $iPosition1[$i] = 0
    Next
    $Points += 1
    $PositionFree = True
    EndSwitch
    Case $iPosition2[0] to $iPosition2[0] + $iPosition2[2]
    Switch $nMsg[4]
    Case $iPosition2[1] to $iPosition2[1] + $iPosition2[2]
    _GDIPlus_GraphicsFillEllipse($hBuffer, $iPosition2[0], $iPosition2[1], $iPosition2[2], $iPosition2[2], $hBrushBk)
    For $i = 0 to 2
    $iPosition2[$i] = 0
    Next
    $Points += 1
    $PositionFree = True
    EndSwitch
    Case $iPosition3[0] to $iPosition3[0] + $iPosition3[2]
    Switch $nMsg[4]
    Case $iPosition3[1] to $iPosition3[1] + $iPosition3[2]
    _GDIPlus_GraphicsFillEllipse($hBuffer, $iPosition3[0], $iPosition3[1], $iPosition3[2], $iPosition3[2], $hBrushBk)
    For $i = 0 to 2
    $iPosition3[$i] = 0
    Next
    $Points += 1
    $PositionFree = True
    EndSwitch
    Case $iPosition4[0] to $iPosition4[0] + $iPosition4[2]
    Switch $nMsg[4]
    Case $iPosition4[1] to $iPosition4[1] + $iPosition4[2]
    _GDIPlus_GraphicsFillEllipse($hBuffer, $iPosition4[0], $iPosition4[1], $iPosition4[2], $iPosition4[2], $hBrushBk)
    For $i = 0 to 2
    $iPosition4[$i] = 0
    Next
    $Points += 1
    $PositionFree = True
    EndSwitch
    Case $iPosition5[0] to $iPosition5[0] + $iPosition5[2]
    Switch $nMsg[4]
    Case $iPosition5[1] to $iPosition5[1] + $iPosition5[2]
    _GDIPlus_GraphicsFillEllipse($hBuffer, $iPosition5[0], $iPosition5[1], $iPosition5[2], $iPosition5[2], $hBrushBk)
    For $i = 0 to 2
    $iPosition5[$i] = 0
    Next
    $Points += 1
    $PositionFree = True
    EndSwitch
    Case $iPosition6[0] to $iPosition6[0] + $iPosition6[2]
    Switch $nMsg[4]
    Case $iPosition6[1] to $iPosition6[1] + $iPosition6[2]
    _GDIPlus_GraphicsFillEllipse($hBuffer, $iPosition6[0], $iPosition6[1], $iPosition6[2], $iPosition6[2], $hBrushBk)
    For $i = 0 to 2
    $iPosition6[$i] = 0
    Next
    $Points += 1
    $PositionFree = True
    EndSwitch
    Case $iPosition7[0] to $iPosition7[0] + $iPosition7[2]
    Switch $nMsg[4]
    Case $iPosition7[1] to $iPosition7[1] + $iPosition7[2]
    _GDIPlus_GraphicsFillEllipse($hBuffer, $iPosition7[0], $iPosition7[1], $iPosition7[2], $iPosition7[2], $hBrushBk)
    For $i = 0 to 2
    $iPosition7[$i] = 0
    Next
    $Points += 1
    $PositionFree = True
    EndSwitch
    Case $iPosition8[0] to $iPosition8[0] + $iPosition8[2]
    Switch $nMsg[4]
    Case $iPosition8[1] to $iPosition8[1] + $iPosition8[2]
    _GDIPlus_GraphicsFillEllipse($hBuffer, $iPosition8[0], $iPosition8[1], $iPosition8[2], $iPosition8[2], $hBrushBk)
    For $i = 0 to 2
    $iPosition8[$i] = 0
    Next
    $Points += 1
    $PositionFree = True
    EndSwitch
    Case $iPosition9[0] to $iPosition9[0] + $iPosition9[2]
    Switch $nMsg[4]
    Case $iPosition9[1] to $iPosition9[1] + $iPosition9[2]
    _GDIPlus_GraphicsFillEllipse($hBuffer, $iPosition9[0], $iPosition9[1], $iPosition9[2], $iPosition9[2], $hBrushBk)
    For $i = 0 to 2
    $iPosition9[$i] = 0
    Next
    $Points += 1
    $PositionFree = True
    EndSwitch
    Case $iPosition10[0] to $iPosition10[0] + $iPosition10[2]
    Switch $nMsg[4]
    Case $iPosition10[1] to $iPosition10[1] + $iPosition10[2]
    _GDIPlus_GraphicsFillEllipse($hBuffer, $iPosition10[0], $iPosition10[1], $iPosition10[2], $iPosition10[2], $hBrushBk)
    For $i = 0 to 2
    $iPosition10[$i] = 0
    Next
    $Points += 1
    $PositionFree = True
    EndSwitch
    EndSwitch
    EndSwitch

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

    If TimerDiff($Timer) > $schwierigkeit Then
    If $PositionFree = True Then
    _DrawCircle()
    EndIf
    $Timer = TimerInit()
    EndIf

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

    If $oldPoints <> $Points Then
    GUICtrlSetData($hLabel, $Points)
    $oldPoints = $Points
    EndIf
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_INTERNALPAINT)
    WEnd

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

    Func WM_PAINT()
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iWidth, $iHeight)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
    EndFunc ;===> WM_PAINT()

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

    Func _DrawCircle()
    If $iPosition1[0] = 0 And $iPosition1[1] = 0 Then
    $RandomLeft1 = Random(10, 350, 1)
    $RandomHeight1 = Random(30, 350, 1)
    $RandomSize1 = Random(5, 30, 1)
    _GDIPlus_GraphicsFillEllipse($hBuffer, $RandomLeft1, $RandomHeight1, $RandomSize1, $RandomSize1, $hBrush)
    $iPosition1[0] = $RandomLeft1
    $iPosition1[1] = $RandomHeight1
    $iPosition1[2] = $RandomSize1
    Return 0
    ElseIf $iPosition2[0] = 0 And $iPosition2[1] = 0 Then
    $RandomLeft2 = Random(10, 350, 1)
    $RandomHeight2 = Random(30, 350, 1)
    $RandomSize2 = Random(5, 30, 1)
    _GDIPlus_GraphicsFillEllipse($hBuffer, $RandomLeft2, $RandomHeight2, $RandomSize2, $RandomSize2, $hBrush)
    $iPosition2[0] = $RandomLeft2
    $iPosition2[1] = $RandomHeight2
    $iPosition2[2] = $RandomSize2
    Return 0
    ElseIf $iPosition3[0] = 0 And $iPosition3[1] = 0 Then
    $RandomLeft3 = Random(10, 350, 1)
    $RandomHeight3 = Random(30, 350, 1)
    $RandomSize3 = Random(5, 30, 1)
    _GDIPlus_GraphicsFillEllipse($hBuffer, $RandomLeft3, $RandomHeight3, $RandomSize3, $RandomSize3, $hBrush)
    $iPosition3[0] = $RandomLeft3
    $iPosition3[1] = $RandomHeight3
    $iPosition3[2] = $RandomSize3
    Return 0
    ElseIf $iPosition4[0] = 0 And $iPosition4[1] = 0 Then
    $RandomLeft4 = Random(10, 350, 1)
    $RandomHeight4 = Random(30, 350, 1)
    $RandomSize4 = Random(5, 30, 1)
    _GDIPlus_GraphicsFillEllipse($hBuffer, $RandomLeft4, $RandomHeight4, $RandomSize4, $RandomSize4, $hBrush)
    $iPosition4[0] = $RandomLeft4
    $iPosition4[1] = $RandomHeight4
    $iPosition4[2] = $RandomSize4
    Return 0
    ElseIf $iPosition5[0] = 0 And $iPosition5[1] = 0 Then
    $RandomLeft5 = Random(10, 350, 1)
    $RandomHeight5 = Random(30, 350, 1)
    $RandomSize5 = Random(5, 30, 1)
    _GDIPlus_GraphicsFillEllipse($hBuffer, $RandomLeft5, $RandomHeight5, $RandomSize5, $RandomSize5, $hBrush)
    $iPosition5[0] = $RandomLeft5
    $iPosition5[1] = $RandomHeight5
    $iPosition5[2] = $RandomSize5
    Return 0
    ElseIf $iPosition6[0] = 0 And $iPosition6[1] = 0 Then
    $RandomLeft6 = Random(10, 350, 1)
    $RandomHeight6 = Random(30, 350, 1)
    $RandomSize6 = Random(5, 30, 1)
    _GDIPlus_GraphicsFillEllipse($hBuffer, $RandomLeft6, $RandomHeight6, $RandomSize6, $RandomSize6, $hBrush)
    $iPosition6[0] = $RandomLeft6
    $iPosition6[1] = $RandomHeight6
    $iPosition6[2] = $RandomSize6
    Return 0
    ElseIf $iPosition7[0] = 0 And $iPosition7[1] = 0 Then
    $RandomLeft7 = Random(10, 350, 1)
    $RandomHeight7 = Random(30, 350, 1)
    $RandomSize7 = Random(5, 30, 1)
    _GDIPlus_GraphicsFillEllipse($hBuffer, $RandomLeft7, $RandomHeight7, $RandomSize7, $RandomSize7, $hBrush)
    $iPosition7[0] = $RandomLeft7
    $iPosition7[1] = $RandomHeight7
    $iPosition7[2] = $RandomSize7
    Return 0
    ElseIf $iPosition8[0] = 0 And $iPosition8[1] = 0 Then
    $RandomLeft8 = Random(10, 350, 1)
    $RandomHeight8 = Random(30, 350, 1)
    $RandomSize8 = Random(5, 30, 1)
    _GDIPlus_GraphicsFillEllipse($hBuffer, $RandomLeft8, $RandomHeight8, $RandomSize8, $RandomSize8, $hBrush)
    $iPosition8[0] = $RandomLeft8
    $iPosition8[1] = $RandomHeight8
    $iPosition8[2] = $RandomSize8
    Return 0
    ElseIf $iPosition9[0] = 0 And $iPosition9[1] = 0 Then
    $RandomLeft9 = Random(10, 350, 1)
    $RandomHeight9 = Random(30, 350, 1)
    $RandomSize9 = Random(5, 30, 1)
    _GDIPlus_GraphicsFillEllipse($hBuffer, $RandomLeft9, $RandomHeight9, $RandomSize9, $RandomSize9, $hBrush)
    $iPosition9[0] = $RandomLeft9
    $iPosition9[1] = $RandomHeight9
    $iPosition9[2] = $RandomSize9
    Return 0
    ElseIf $iPosition10[0] = 0 And $iPosition10[1] = 0 Then
    $RandomLeft10 = Random(10, 350, 1)
    $RandomHeight10 = Random(30, 350, 1)
    $RandomSize10 = Random(5, 30, 1)
    _GDIPlus_GraphicsFillEllipse($hBuffer, $RandomLeft10, $RandomHeight10, $RandomSize10, $RandomSize10, $hBrush)
    $iPosition10[0] = $RandomLeft10
    $iPosition10[1] = $RandomHeight10
    $iPosition10[2] = $RandomSize10
    Return 0
    Else
    $PositionFree = False
    EndIf

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

    EndFunc ;===> _DrawCircle()

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

    Func Countdown()
    $counter -= 1
    GUICtrlSetData($hLabelCountdown, $counter)
    If $counter = 0 Then
    $spielen = MsgBox(0, "Spiel Zuende", "Ende. Punktestand:" & $Points)
    _Exit()
    EndIf
    EndFunc

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

    Func _Exit()
    _GDIPlus_BrushDispose($hBrushBk)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_ImageDispose($hBuffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    Exit
    EndFunc ;===> _Exit()

    [/autoit]

    Edit: Hier noch zum downloaden.

  • gute idee, aber es bugt bei mir sodass ich manchmal die punkte nicht andruecken kann und sie verschwinden oder dass wenn sich zwei punkte ueberlagern und man einen wegmacht der darunter abgeschnitten bzw. halbiert ist

    [autoit]


    Func Ulam($n)
    Return 1
    EndFunc

    [/autoit]


    Rekursion FTW :D

  • Stimmt.
    Das mit den überlagerten Punkten könnte ich nur wegmachen, wenn ich nochmals die Array-Positionen vergleichen würde.
    Das mit dem hängen ist bei mir bei Schwer auch so, obwohl ich nicht weiß wieso. Hab schon viel ausprobiert, hat aber alles nichts geändert.

  • Nett, aber das überlagern solltest du wegbekommen
    du könntest ja die punkte in bilder austauschen und einen hintergrund machen