GDI+ Kometenschweif

  • Und zu den Berechnungen, du musst im Grunde nur das, was du bei _IsPressed() stehen hast, ohne das _IsPressed() schreiben^^

    [autoit]

    If 25 Then $iX -= $bewegung
    If 26 Then $iY -= $bewegung
    If 27 Then $iX += $bewegung
    If 28 Then $iY += $bewegung

    [/autoit]

    Passiert recht wenig so :rolleyes:

    Spoiler anzeigen

    Grundkenntnisse in: C++, JavaScript
    Sehr gute Kenntnisse: PHP, JAVA, C und näturlich AutoIt


    Klaviatur, Anhang UDF, GDI+ Mühle

    Zitat

    "Wenn einen um 20h der Pizzadienst anruft und fragt, ob man's nur vergessen hat und ob man das gleiche
    möchte wie immer -- dann sollte man sein Bestellverhalten evtl überdenken"

  • Im Grunde!!!!!

    Des ist aber nicht dein ernst, oder? 8|

  • Sorry, habs falsch rübergebracht...
    Sollte nen Scherz werden :rofl:

    Spoiler anzeigen

    Grundkenntnisse in: C++, JavaScript
    Sehr gute Kenntnisse: PHP, JAVA, C und näturlich AutoIt


    Klaviatur, Anhang UDF, GDI+ Mühle

    Zitat

    "Wenn einen um 20h der Pizzadienst anruft und fragt, ob man's nur vergessen hat und ob man das gleiche
    möchte wie immer -- dann sollte man sein Bestellverhalten evtl überdenken"

  • doch!
    ich blicke das einfach nicht :cursing: ;(
    ich bin einfach schlecht in berechnungen/formeln/mathe
    meine anfänge taten nichts (bewegten nur in eine richtung egal was ich tat

  • Zitat

    doch!
    ich blicke das einfach nicht :cursing: ;(
    ich bin einfach schlecht in berechnungen/formeln/mathe
    meine anfänge taten nichts (bewegten nur in eine richtung egal was ich tat


    Im Forum gab es schon 2 Umsetzungen von Pong mit GDI+ (eine ist von mir) 8) , guck die mal an. Es ist wirklich viel einfacher als du dir vorstellst ;).

  • Ich bin auch nicht sehr bewandert in GDI+ (sprich: so gut wie null Erfahrung :( )
    Würd mich also auch mal interessieren, wie das funzt...

    Spoiler anzeigen

    Grundkenntnisse in: C++, JavaScript
    Sehr gute Kenntnisse: PHP, JAVA, C und näturlich AutoIt


    Klaviatur, Anhang UDF, GDI+ Mühle

    Zitat

    "Wenn einen um 20h der Pizzadienst anruft und fragt, ob man's nur vergessen hat und ob man das gleiche
    möchte wie immer -- dann sollte man sein Bestellverhalten evtl überdenken"

  • Zitat

    names pong = nur variablen und 0 sinn für mich


    Und dabei war das mein wohl einfachstes GDI+ Script (Beispiele ausgeschlossen)... 8|
    Ignorier doch mal alle Variablen die nichts mit dem Ball zu tun haben.

    Also... :D
    Ich habe nicht nur die Position des Balls sondern auch die Entfernung in Pixeln um die er bei jeder Frame bewegt wird in Variablen gespeichert. D.h. Ich kann einfach das Vorzeichen der Variablen für die "Geschwindigkeit" ändern (Multiplikation mit -1) um den Ball in die exakt gegenüberliegende Richtung fliegen zu lassen.
    Tut mir leid ich bin leider schlecht im erklären... :(

  • name22: So, hab dein Pong mal etwas "benutzerfreundlich" gemacht ^^

    Spoiler anzeigen
    [autoit]

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

    [/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

    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

    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

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

    _GDIPlus_Startup()

    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)

    AdlibRegister("_Draw", 20)

    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

    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

    [autoit]



    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]
    Spoiler anzeigen

    Grundkenntnisse in: C++, JavaScript
    Sehr gute Kenntnisse: PHP, JAVA, C und näturlich AutoIt


    Klaviatur, Anhang UDF, GDI+ Mühle

    Zitat

    "Wenn einen um 20h der Pizzadienst anruft und fragt, ob man's nur vergessen hat und ob man das gleiche
    möchte wie immer -- dann sollte man sein Bestellverhalten evtl überdenken"

  • hmmm..
    es macht nachm 3. mal abprallen nen fehler, kreige den aber irgendwie nicht weg!

    Spoiler anzeigen
    [autoit]

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

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

    AutoIt Version: 3.3.5.6 (beta)
    Author: Alizame

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

    Script Function:
    It make a kometenschweif

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

    #ce ----------------------------------------------------------------------------

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

    ; Script Start - Add your code below here
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GDIPlus.au3>
    #include <Misc.au3>

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

    ;###
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Kometenschweif by Alizame", 800, 600)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    ;###

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

    $farbewei = 0xFFFFFFFF
    $farbeschwar = 0xFFFFFFFF
    $Ball = 40
    $iX = 400
    $iY = 300
    $iXold = 400
    $iYold = 300
    $bewegung = 5
    $richtung = 1

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

    _GDIPlus_Startup()
    $hGraphics = _GDIPlus_GraphicsCreateFromHWND($Form1)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics(800,600,$hGraphics)
    $Buffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    $bWei = _GDIPlus_BrushCreateSolid($farbewei)
    $bSch = _GDIPlus_BrushCreateSolid($farbeschwar)
    $smooth = _GDIPlus_GraphicsSetSmoothingMode($hGraphics,2)
    _ReDraw ()

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    _GDIPlus_ImageDispose($Buffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_BrushDispose($bWei)
    _GDIPlus_BrushDispose($bSch)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    Exit
    EndSwitch
    ;~ If _IsPressed("25") Then $iX -= $bewegung
    If $richtung = 1 Then
    $iX -= $bewegung
    $iY -= $bewegung
    ElseIf $richtung = 2 Then
    $iX -= $bewegung
    $iY += $bewegung
    ElseIf $richtung = 3 Then
    $iX += $bewegung
    $iY -= $bewegung
    ElseIf $richtung = 4 Then
    $iX += $bewegung
    $iY += $bewegung
    EndIf
    ;~ If _IsPressed("26") Then $iY -= $bewegung
    ;~ If _IsPressed("27") Then $iX += $bewegung
    ;~ If _IsPressed("28") Then $iY += $bewegung
    If $iX <> $iXold Or $iY <> $iYold Then _ReDraw ()
    WEnd

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

    Func _ReDraw ()
    _PosCorrect ()
    _GDIPlus_GraphicsClear($Buffer,$bSch)
    _GDIPlus_GraphicsFillEllipse($Buffer,$iX,$iY,$Ball,$Ball,$bWei)
    _GDIPlus_GraphicsDrawImageRect($hGraphics,$hBitmap,0,0,800,600)
    $iXold = $iX
    $iYold = $iY
    EndFunc

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

    Func _PosCorrect()
    If $iX < 0 Then $richtung = 4
    If $iY < 0 Then $richtung = 2
    If $iX > 760 Then $richtung = 1
    If $iY > 560 Then $richtung = 3
    ToolTip("x="&$iX&@CRLF&"y="&$iY&@CRLF&$richtung,0,0)
    EndFunc

    [/autoit]