GDI+ Spiel

  • Hallo habe demletzt von Hauke ein Spiel gesehen das meine interesse geweckt hat :) . Jetzt habe ich versucht so was (ähnliches) auch zu machen ,aber es funktioniert nicht richtig ... ich möchte in einer while schleife die Position des Zeigers auslesen lassen und überprüfe ob der zeiger auf einem Rechteck ist..... soweit so gut.. es funktioniert auch ABER nur einmal nachdem das 2. Rechteck gezeichnet worden ist passiert nichts mehr

    [autoit]

    #include
    #include
    #include

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

    _GDIPlus_Startup()

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

    #region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("GDI + Spiel", 617, 694, 194, 122)
    GUISetBkColor(0x000077)
    $graphik = _GDIPlus_GraphicsCreateFromHWND($Form1)
    $starten = GUICtrlCreateButton("Starten", 100, 100, 400, 400)
    GUISetState(@SW_SHOW)

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

    #endregion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    _GDIPlus_GraphicsDispose($graphik)
    _GDIPlus_Shutdown()

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

    Exit
    Case $starten
    GUICtrlDelete($starten)
    GUISetBkColor(0x999900, $Form1)
    $rand_x = 10
    $rand_y = 10
    _GDIPlus_GraphicsFillRect($graphik, $rand_x, $rand_y, 80, 80)
    While 1
    $nMsg2 = GUIGetMsg()
    If $nMsg2 = -3 Then
    _GDIPlus_GraphicsDispose($graphik)
    _GDIPlus_Shutdown()
    Exit
    EndIf

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

    $getpos = GUIGetCursorInfo()
    If $getpos[0] > $rand_x And $getpos[0] < 80 And $getpos[1] > $rand_y And $getpos[1] < 80 Then
    $rand_x = Random(1, 600, 1)
    $rand_y = Random(1, 600, 1)
    _GDIPlus_GraphicsFillRect($graphik, $rand_x, $rand_y, 80, 80)

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

    EndIf

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

    WEnd

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

    EndSwitch

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

    WEnd

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

    Einmal editiert, zuletzt von Silvester (29. Januar 2012 um 19:00)

  • Also das versteh ich net.
    Wieso diese Zeile? was bringt das/was SOLL es bringen?

    [autoit]

    If $getpos[0] > $rand_x And $getpos[0] < 80 And $getpos[1] > $rand_y And $getpos[1] < 80 Then

    [/autoit]


    Wenn $getpos[0] also z.B. 100 und $rand_x z.B. 70 ist, dann kann ja nix passieren.

    mfg
    Hauke

  • ja aber

    [autoit]

    $rand_x

    [/autoit]

    ändert sich doch immer, oder nicht, wenn $rand_x also mal kleiner als die Mausposition ist, dann kann schonmal nichts passieren.

    mfg
    Hauke

    Ja die koordinaten sollen sich ja auch jedes mal ändern wenn ich auf das (in das ) rechteck "zeige" , also wenn ich im Rechteck bin sollen $rand_x und $rand_y irgenwelche zufallszahlen zwischen 1 und 600 sein und mit den Koordinaten wird dann das neue Rechteck gezeichnet ... dann soll wieder abgefragt werden ob ich mit dem Zeiger auf dem NEUEM Rechteck bin dann wieder neue Zahlen und neues Rechteck zeichnen usw. usw.

  • Meinst du es so?

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include<GDIPLUS.au3>

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

    _GDIPlus_Startup()

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

    #region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("GDI + Spiel", 617, 694, 194, 122)
    GUISetBkColor(0x000077)
    $graphik = _GDIPlus_GraphicsCreateFromHWND($Form1)
    $starten = GUICtrlCreateButton("Starten", 100, 100, 400, 400)
    GUISetState(@SW_SHOW)

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

    #endregion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    _GDIPlus_GraphicsDispose($graphik)
    _GDIPlus_Shutdown()

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

    Exit
    Case $starten
    GUICtrlDelete($starten)
    GUISetBkColor(0x999900, $Form1)
    $rand_x = 10
    $rand_y = 10
    _GDIPlus_GraphicsFillRect($graphik, $rand_x, $rand_y, 80, 80)
    While 1
    $nMsg2 = GUIGetMsg()
    If $nMsg2 = -3 Then
    _GDIPlus_GraphicsDispose($graphik)
    _GDIPlus_Shutdown()
    Exit
    EndIf

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

    $getpos = GUIGetCursorInfo()
    If $getpos[0] > $rand_x And $getpos[0] < $rand_x + 80 And $getpos[1] > $rand_y And $getpos[1] < $rand_y + 80 Then
    $rand_x = Random(1, 600, 1)
    $rand_y = Random(1, 600, 1)
    _GDIPlus_GraphicsFillRect($graphik, $rand_x, $rand_y, 80, 80)
    EndIf

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

    WEnd

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

    EndSwitch

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

    WEnd

    [/autoit]

    Ich habe dort die If Abfrage geändert, du hast abgefragt ob sich der Mauszeiger über der Position des Rechtecks ist aber
    unter den Wert 80, es muss aber so sein das der Mauszeiger über die Position des Rechtecks ist und der Mauszeiger unter die
    Position des Rechteck + 80.

  • Perfekt :rock: :rock:
    das wars :)