Kleines Spiel - Kanonenschießen

  • Hab mir ein kleines Spiel gebastelt

    und vielleicht kann ja jemand die Funktion _GDIPlus_GraphicsFillPolygon gebrauchen:

    Spoiler anzeigen
    [autoit]

    Func _GDIPlus_GraphicsFillPolygon($hGraphics, $aPoints, $hBrush = 0)
    Local $iI, $iCount, $pPoints, $tPoints, $aResult, $tmpError, $tmpExError

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

    $iCount = $aPoints[0][0]
    $tPoints = DllStructCreate("int[" & $iCount * 2 & "]")
    $pPoints = DllStructGetPtr($tPoints)
    For $iI = 1 To $iCount
    DllStructSetData($tPoints, 1, $aPoints[$iI][0], (($iI - 1) * 2) + 1)
    DllStructSetData($tPoints, 1, $aPoints[$iI][1], (($iI - 1) * 2) + 2)
    Next

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

    _GDIPlus_BrushDefCreate($hBrush)
    $aResult = DllCall($ghGDIPDll, "int", "GdipFillPolygon2I", "hwnd", $hGraphics, "hwnd", $hBrush, "ptr", $pPoints, "int", $iCount)
    $tmpError = @error
    $tmpExError = @extended
    _GDIPlus_BrushDefDispose()
    If $tmpError Then Return SetError($tmpError, $tmpExError, False)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
    EndFunc

    [/autoit]


    Das Spiel:

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>
    #include <WindowsConstants.au3>
    #include <EditConstants.au3>
    Opt("PixelCoordMode",2)

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

    Global $MainX=800
    Global $MainY=600
    Global $H1,$H2,$H3,$C_Angel,$C_Power,$Wind,$Rem=False
    _SetValues()

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

    _GDIPlus_Startup()

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

    $hGui=GUICreate("Game",$MainX,$MainY)
    GUISetBkColor(0x00FF00)
    GUIRegisterMsg($WM_PAINT, '_Redraw')
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGui)
    GUICtrlCreateLabel("Angle",50,$MainY-23,50,20)
    GUICtrlSetColor(-1,0xFFFFFF)
    $hAngle=GUICtrlCreateInput("45",10,$MainY-25,35,20,$ES_READONLY)
    GUICtrlCreateUpdown(-1)
    GUICtrlSetLimit(-1,80,0)
    GUICtrlCreateLabel("Power",165,$MainY-23,50,20)
    GUICtrlSetColor(-1,0xFFFFFF)
    $hPower=GUICtrlCreateInput("70",120,$MainY-25,40,20,$ES_READONLY)
    GUICtrlCreateUpdown(-1)
    GUICtrlSetLimit(-1,120,40)
    $hFire=GUICtrlCreateButton("Fire",230,$MainY-25,55,20)
    $hNew=GUICtrlCreateButton("New",340,$MainY-25,55,20)

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

    GUISetState()
    _CreateBK($H1,$H2,$H3)

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

    While 1
    $msg=GUIGetMsg()
    If $msg=-3 Then ExitLoop
    If $msg=$hNew Then
    _SetValues()
    _CreateBK($H1,$H2,$H3)
    EndIf
    If $msg=$hFire Then _Fire($H1,$H2)

    Sleep(5)
    WEnd

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

    _GDIPlus_Shutdown()

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

    Func _Fire($H1,$H2)
    Local $pi = 3.14159265358979
    Local $ymax =0
    Local $v = GUICtrlRead($hPower)
    Local $alpha = GUICtrlRead($hAngle)*(-1)
    Local $x_alt=0, $y_alt=0
    Local $Treffer=False
    Local $Gras=False
    $hBrush_Del = _GDIPlus_BrushCreateSolid(0xFF0000FF)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFF222222)
    _ShotSound()
    For $t=0 To 35 Step 0.3
    $x = (cos($pi/180 *$alpha) * ($v-$Wind) * $t)
    $y = (sin($pi/180 *$alpha) * $v * $t) - ( 0.5 * -9.81 * $t * $t )
    PixelSearch(45+$x,$MainY-$H1-60+$y,45+$x+25,$MainY-$H1-60+$y+25,0x887766)
    If Not @error Then $Treffer=True
    If 45+$x>$MainX Then ExitLoop
    If $MainY-$H1-60+$y>=$MainY-50 Then ExitLoop
    PixelSearch(45+$x,$MainY-$H1-60+$y,45+$x+25,$MainY-$H1-60+$y+25,0x00FF00)
    If Not @error Then $Gras=True
    _GDIPlus_GraphicsFillPie($hGraphic,45+$x_alt,$MainY-$H1-60+$y_alt,25,25,0,360,$hBrush_Del)
    _GDIPlus_GraphicsFillPie($hGraphic,45+$x,$MainY-$H1-60+$y,25,25,0,360,$hBrush)
    $x_alt=$x
    $y_alt=$y
    If $Treffer=True Then ExitLoop
    If $Gras=True Then ExitLoop
    Sleep(20)
    Next
    _GDIPlus_GraphicsFillPie($hGraphic,45+$x_alt,$MainY-$H1-60+$y_alt,25,25,0,360,$hBrush_Del)
    If $Treffer=True Then
    $hBrush = _GDIPlus_BrushCreateSolid(0xAA000000)
    _GDIPlus_GraphicsFillPie($hGraphic,$MainX-60,$MainY-$H2-60,60,80,0,360,$hBrush)
    _HitSound()
    MsgBox(0,"Treffer","Hurra, du hast getroffen")
    Else
    ;Computer Anfang
    Sleep(500)
    If $C_Power<20 Then $C_Power=20
    If $C_Power>150 Then $C_Power=150
    If $C_Angel<0 Then $C_Angel=0
    If $C_Angel>80 Then $C_Angel=80
    $v=$C_Power+$Wind
    $alpha=$C_Angel*(-1)
    $x_alt=0
    $y_alt=0
    $Gras=False
    $Treffer=False
    _ShotSound()
    For $t=0 To 35 Step 0.3
    $x = (cos($pi/180 *$alpha) * ($v+$Wind) * $t)
    $y = (sin($pi/180 *$alpha) * $v * $t) - ( 0.5 * -9.81 * $t * $t )
    If ($y*(-1))>$ymax Then $ymax=$y*(-1)
    PixelSearch($MainX-75-$x,$MainY-$H2-60+$y,$MainX-75-$x+25,$MainY-$H2-60+$y+25,0x887766)
    If Not @error Then $Treffer=True
    If $MainX-75-$x<0 Then
    If ($y*(-1))<$ymax Then
    $C_Power-=Random(1,10,1)
    If $Rem=True Then
    $C_Angel+=Random(1,5,1)
    $Rem=False
    EndIf
    Else
    $C_Angel-=Random(3,10,1)
    EndIf
    ExitLoop
    EndIf
    If $MainY-$H2-60+$y>=$MainY-50 Then ExitLoop
    PixelSearch($MainX-75-$x,$MainY-$H2-60+$y,$MainX-75-$x+25,$MainY-$H2-60+$y+25,0x00FF00)
    If Not @error Then
    If $MainX-75-$x < $MainX/2 Then
    $C_Power+=Random(1,10,1)
    Else
    If ($y*(-1))<$ymax Then
    $C_Power+=Random(10,20,1)
    $C_Angel-=Random(1,5,1)
    $Rem=True
    Else
    $C_Angel+=Random(3,10,1)
    EndIf
    EndIf
    $Gras=True
    EndIf
    _GDIPlus_GraphicsFillPie($hGraphic,$MainX-75-$x_alt,$MainY-$H2-60+$y_alt,25,25,0,360,$hBrush_Del)
    _GDIPlus_GraphicsFillPie($hGraphic,$MainX-75-$x,$MainY-$H2-60+$y,25,25,0,360,$hBrush)
    $x_alt=$x
    $y_alt=$y
    If $Treffer=True Then ExitLoop
    If $Gras=True Then ExitLoop
    Sleep(20)
    Next
    _GDIPlus_GraphicsFillPie($hGraphic,$MainX-75-$x_alt,$MainY-$H2-60+$y_alt,25,25,0,360,$hBrush_Del)
    If $Treffer=True Then
    $hBrush = _GDIPlus_BrushCreateSolid(0xAA000000)
    _GDIPlus_GraphicsFillPie($hGraphic,5,$MainY-$H1-60,60,80,0,360,$hBrush)
    _HitSound()
    MsgBox(0,"Treffer","Schade, du bist tot")
    EndIf
    ;Computer Ende
    EndIf

    EndFunc

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

    Func _ShotSound()
    Beep(200,10)
    Beep(100,10)
    Beep(200,10)
    Beep(100,10)
    EndFunc

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

    Func _HitSound()
    For $i=200 to 50 Step -20
    Beep($i,1)
    Beep($i*2,1)
    Beep($i,1)
    Beep($i*2,1)
    Next
    EndFunc

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

    Func _CreateBK($H1,$H2,$H3)
    Local $aPoints[13][2],$W=3
    $hBrush = _GDIPlus_BrushCreateSolid(0xFF0000FF)
    _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $MainX, $MainY-60, $hBrush)
    $hPen = _GDIPlus_PenCreate(0xFFFFFF00)
    _GDIPlus_GraphicsDrawLine($hGraphic, $MainX/2,10,$MainX/2-$Wind*10,10,$hPen)
    If $Wind < 0 Then $W=-3
    _GDIPlus_GraphicsDrawLine($hGraphic, $MainX/2-$Wind*10,10,$MainX/2-$Wind*10+$W,7,$hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $MainX/2-$Wind*10,10,$MainX/2-$Wind*10+$W,13,$hPen)

    $aPoints[0][0] = 12
    $aPoints[1][0] = -50
    $aPoints[1][1] = $MainY-$H1
    $aPoints[2][0] = 50
    $aPoints[2][1] = $MainY-$H1
    $aPoints[3][0] = 180
    $aPoints[3][1] = $MainY-$H1-($H3-$H1)/5
    $aPoints[4][0] = $MainX/2
    $aPoints[4][1] = $MainY-$H3
    $aPoints[5][0] = $MainX-180
    $aPoints[5][1] = $MainY-$H2-($H3-$H2)/5
    $aPoints[6][0] = $MainX-50
    $aPoints[6][1] = $MainY-$H2
    $aPoints[7][0] = $MainX+50
    $aPoints[7][1] = $MainY-$H2
    $aPoints[8][0] = $MainX+51
    $aPoints[8][1] = $MainY-$H2-1
    $aPoints[9][0] = $MainX+50
    $aPoints[9][1] = $MainY-55
    $aPoints[10][0] = $MainX/2
    $aPoints[10][1] = $MainY-55
    $aPoints[11][0] = -50
    $aPoints[11][1] = $MainY-55
    $aPoints[12][0] = -51
    $aPoints[12][1] = $MainY-$H1-1
    $hBrush = _GDIPlus_BrushCreateSolid(0xFF00FF00)
    _GDIPlus_GraphicsFillClosedCurve($hGraphic, $aPoints, $hBrush)

    $hBrush = _GDIPlus_BrushCreateSolid(0xFF887766)
    _GDIPlus_GraphicsFillPie($hGraphic,11,$MainY-$H1-30,28,28,0,360,$hBrush)
    $aPoints[0][0] = 4
    $aPoints[1][0] = 15
    $aPoints[1][1] = $MainY-$H1-25
    $aPoints[2][0] = 35
    $aPoints[2][1] = $MainY-$H1-45
    $aPoints[3][0] = 55
    $aPoints[3][1] = $MainY-$H1-25
    $aPoints[4][0] = 35
    $aPoints[4][1] = $MainY-$H1-5
    _GDIPlus_GraphicsFillPolygon($hGraphic, $aPoints, $hBrush)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFF443322)
    _GDIPlus_GraphicsFillPie($hGraphic,15,$MainY-$H1-20,28,28,0,360,$hBrush)

    $hBrush = _GDIPlus_BrushCreateSolid(0xFF887766)
    _GDIPlus_GraphicsFillPie($hGraphic,$MainX-40,$MainY-$H2-30,28,28,0,360,$hBrush)
    $aPoints[0][0] = 4
    $aPoints[1][0] = $MainX-15
    $aPoints[1][1] = $MainY-$H2-25
    $aPoints[2][0] = $MainX-35
    $aPoints[2][1] = $MainY-$H2-45
    $aPoints[3][0] = $MainX-55
    $aPoints[3][1] = $MainY-$H2-25
    $aPoints[4][0] = $MainX-35
    $aPoints[4][1] = $MainY-$H2-5
    _GDIPlus_GraphicsFillPolygon($hGraphic, $aPoints, $hBrush)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFF443322)
    _GDIPlus_GraphicsFillPie($hGraphic,$MainX-43,$MainY-$H2-20,28,28,0,360,$hBrush)
    EndFunc

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

    Func _SetValues()
    $H1=Random(65,$MainY-180,1)
    $H2=Random(65,$MainY-180,1)
    $H3=Random(120,$MainY-50,1)
    $C_Angel=Round((($H3-$H2)*100)/500+Random(-5,5,1),0)
    If $C_Angel<40 Then $C_Angel=40
    If $C_Angel>80 Then $C_Angel=80
    $Wind=Random(-20,20,1)
    $C_Power=40-$Wind+$C_Angel+Random(-5,5,1)
    EndFunc

    Func _Redraw()
    _CreateBK($H1,$H2,$H3)
    EndFunc

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

    Func _GDIPlus_GraphicsFillPolygon($hGraphics, $aPoints, $hBrush = 0)
    Local $iI, $iCount, $pPoints, $tPoints, $aResult, $tmpError, $tmpExError

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

    $iCount = $aPoints[0][0]
    $tPoints = DllStructCreate("int[" & $iCount * 2 & "]")
    $pPoints = DllStructGetPtr($tPoints)
    For $iI = 1 To $iCount
    DllStructSetData($tPoints, 1, $aPoints[$iI][0], (($iI - 1) * 2) + 1)
    DllStructSetData($tPoints, 1, $aPoints[$iI][1], (($iI - 1) * 2) + 2)
    Next

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

    _GDIPlus_BrushDefCreate($hBrush)
    $aResult = DllCall($ghGDIPDll, "int", "GdipFillPolygon2I", "hwnd", $hGraphics, "hwnd", $hBrush, "ptr", $pPoints, "int", $iCount)
    $tmpError = @error
    $tmpExError = @extended
    _GDIPlus_BrushDefDispose()
    If $tmpError Then Return SetError($tmpError, $tmpExError, False)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
    EndFunc

    [/autoit]

    Viel Spaß ;)

  • So, habs wieder etwas erweitert:
    größeres Spielfeld, Kanonen stehen jetzt immer am Boden, es gibt Gegen/Mit-Wind, KI etwas besser usw...

    Natürlich ist da nichts perfekt, ich wollte eigentlich nur etwas mit Parabelflugbahnen experimentieren.
    Und bei der Gelegenheit gleich mal etwas in GDI+ reinschnuppern...

    Übrigens hab ich grad im englischen Forum gelesen, daß die _GDIPlus_GraphicsFillPolygon Funktion in der aktuellen Beta enthalten ist (hätte mir Arbeit erspart) ;)

  • hi,

    ich hab mir den code mal rauskopiert,

    der funk überhaupt net da sind echt viele fehler drin

    wo ich bei manchen net weis wie ich sie beheben soll xD

    so gut kann ich dann auch noch nicht coden...

    wäre nett wenn du diese behebn könntest

    mfg: sandex

  • Hi

    eigentlich war mir die Spielfunktion relativ egal.
    um mich mal selber zu zitieren: :P

    Code
    Natürlich ist da nichts perfekt, ich wollte eigentlich nur etwas mit Parabelflugbahnen experimentieren.
     Und bei der Gelegenheit gleich mal etwas in GDI+ reinschnuppern...

    Meine Spiele entstehen fast immer aus Langeweile, oder weil ich was ausprobieren will ;)
    (Oda weil Autoit einfach Spaß macht!!!)
    3D - Mensch ärgere dich nicht
    Kleines Spiel : SNAKE

    würd mich aber freuen, wenn jemand meine rudimentären Scripte zu einem "vollwertigen" Spiel erweitert :D