Geschicklichkeitsspiel: Spaceship

  • Guten Morgen ;)

    Ich habe mir mal aus Langeweile ein kleines Spiel gescriptet:
    Spaceship :
    Ziel ist es solange zu Überleben wie möglich; aber vorsicht, das Raumschiff wird immer schneller!
    Man muss die Wände ausweichen, man kann 10 mal getroffen werden
    Steuerung:
    Pfeiltasten :rolleyes:
    Esc Beendet man
    Es ist mein ersten Spiel was ich hier veröffentliche und ich weis das man noch 100 tsd. sachen verbessern könnte,
    deswegen erwartet euch nicht zu viel.

    Download Spaceship.rar
    Inhalt:
    Spaceship.exe
    Spaceship.au3
    \Data\ die ganzen Bilder und Sounds

    Script:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GUIConstants.au3>
    #include <GDIPlus.au3>
    #include <Misc.au3>
    #include <Sound.au3>
    #include <array.au3>

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

    $Speed = 12
    $iX = 50
    $iY = 110
    $vX = 1 * $Speed
    $vY = 1 * $Speed
    $iSleep = 50
    $wand = 10
    $zwischenstellen = 190
    Global $t = 2, $y = 140, $Zeit, $TextOver = "Game Over", $Score[6][2], $Zeit = 0
    Global $waende[4 + 1][$t + 1], $name
    $waende[0][0] = 4
    Global $fortschritt = 0, $fortschritt2 = 800, $fortschritt3 = -800, $Highscore = @ScriptDir & "\Data\Highscore.ini"
    Global $SchiffX = 80, $SchiffY = 40, $tp = 100, $farbe[4], $col, $down = 0, $sound2 = 178
    $Sound_1 = _SoundOpen(@ScriptDir & "\Data\BGM.mp3");Portal 2 - An Accent Beyond
    $w = 1
    $MitteX = @DesktopWidth / 2
    $MitteY = @DesktopHeight / 2
    If FileExists(@ScriptDir & "\Data\Name.ini") Then
    $name = FileRead(@ScriptDir & "\Data\Name.ini")
    Else
    $name = "IhrName"
    EndIf

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

    If Not FileExists($Highscore) Then
    FileWrite($Highscore, "Hans|35000#Peter|50000#Günter|200000#Otto|140000#Werner|170000")
    EndIf

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

    #region ### START Koda GUI section ### Form=
    $MainGUI = GUICreate("Spaceship", 163, 50, Default, Default, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE))
    $Run = GUICtrlCreateButton("Spiel Start", 0, 24, 81, 25)
    $Exit = GUICtrlCreateButton("Exit", 80, 24, 81, 25)
    $NameI = GUICtrlCreateInput($name, 0, 0, 161, 21)
    GUISetState(@SW_SHOW, $MainGUI)
    #endregion ### END Koda GUI section ###

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

    While $w
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

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

    Case $Run
    FileDelete(@ScriptDir & "\Data\Name.ini")
    FileWrite(@ScriptDir & "\Data\Name.ini", GUICtrlRead($NameI))
    $name = GUICtrlRead($NameI)
    $w = 0
    GUISetState(@SW_HIDE, $MainGUI)
    Case $Exit
    Exit
    EndSwitch
    WEnd
    _SoundPlay($Sound_1)
    #region ### START Koda GUI section ### Form=
    $Form_1 = GUICreate("Form1", 100, 300, $MitteX - 400, $MitteY - 150, $WS_POPUP, BitOR($WS_EX_TOPMOST, 0x00000080))
    $pic1 = GUICtrlCreatePic(@ScriptDir & "\Data\1.jpg", 0, 0, 100, 300)
    Sleep(000)
    GUISetState(@SW_SHOW)
    $Form_2 = GUICreate("Form1", 100, 300, $MitteX - 300, $MitteY - 150, $WS_POPUP, BitOR($WS_EX_TOPMOST, 0x00000080))
    $pic2 = GUICtrlCreatePic(@ScriptDir & "\Data\2.jpg", 0, 0, 100, 300)
    Sleep(200)
    GUISetState(@SW_SHOW)
    $Form_3 = GUICreate("Form1", 100, 300, $MitteX - 200, $MitteY - 150, $WS_POPUP, BitOR($WS_EX_TOPMOST, 0x00000080))
    $pic3 = GUICtrlCreatePic(@ScriptDir & "\Data\3.jpg", 0, 0, 100, 300)
    Sleep(200)
    GUISetState(@SW_SHOW)
    $Form_4 = GUICreate("Form1", 100, 300, $MitteX - 100, $MitteY - 150, $WS_POPUP, BitOR($WS_EX_TOPMOST, 0x00000080))
    $pic4 = GUICtrlCreatePic(@ScriptDir & "\Data\4.jpg", 0, 0, 100, 300)
    Sleep(200)
    GUISetState(@SW_SHOW)
    $Form_5 = GUICreate("Form1", 100, 300, $MitteX, $MitteY - 150, $WS_POPUP, BitOR($WS_EX_TOPMOST, 0x00000080))
    $pic5 = GUICtrlCreatePic(@ScriptDir & "\Data\5.jpg", 0, 0, 100, 300)
    Sleep(400)
    GUISetState(@SW_SHOW)
    $Form_6 = GUICreate("Form1", 100, 300, $MitteX + 100, $MitteY - 150, $WS_POPUP, BitOR($WS_EX_TOPMOST, 0x00000080))
    $pic6 = GUICtrlCreatePic(@ScriptDir & "\Data\6.jpg", 0, 0, 100, 300)
    Sleep(400)
    GUISetState(@SW_SHOW)
    $Form_7 = GUICreate("Form1", 100, 300, $MitteX + 200, $MitteY - 150, $WS_POPUP, BitOR($WS_EX_TOPMOST, 0x00000080))
    $pic7 = GUICtrlCreatePic(@ScriptDir & "\Data\7.jpg", 0, 0, 100, 300)
    Sleep(300)
    GUISetState(@SW_SHOW)
    $Form_8 = GUICreate("Form1", 100, 300, $MitteX + 300, $MitteY - 150, $WS_POPUP, BitOR($WS_EX_TOPMOST, 0x00000080))
    $pic8 = GUICtrlCreatePic(@ScriptDir & "\Data\8.jpg", 0, 0, 100, 300)
    Sleep(300)
    GUISetState(@SW_SHOW)
    Sleep(800)
    #endregion ### END Koda GUI section ###
    $hWnd = GUICreate("", 800, 300, $MitteX - 400, $MitteY - 150, $WS_POPUP, BitOR($WS_EX_TOPMOST, 0x00000080))
    GUISetState()

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

    _GDIPlus_Startup()
    $farbe[1] = _GDIPlus_BrushCreateSolid(0xFFFF0000)
    $farbe[2] = _GDIPlus_BrushCreateSolid(0xFFFFFF00)
    $farbe[3] = _GDIPlus_BrushCreateSolid(0xFFFF00FF)
    $Gamer = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Data\Ship.png")
    $HG = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Data\BG.png")
    $HG2 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Data\BG.png")
    $HG3 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Data\BG.png")
    $i = Round(Random(0, 1))

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

    $waende[1][0] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Data\Wand.png")
    $waende[2][0] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Data\Wand.png")
    $waende[3][0] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Data\Wand.png")
    $waende[4][0] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Data\Wand.png")

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

    $waende[1][1] = 800 + (1 * $zwischenstellen)
    $waende[2][1] = 800 + (2 * $zwischenstellen)
    $waende[3][1] = 800 + (3 * $zwischenstellen)
    $waende[4][1] = 800 + (4 * $zwischenstellen)

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

    $waende[1][2] = 0
    $waende[2][2] = 160
    $waende[3][2] = 0
    $waende[4][2] = 160

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

    $hLayoutZeit = _GDIPlus_RectFCreate(30, 270)
    $Text2 = _GDIPlus_RectFCreate(300, 140)
    $farbe[0] = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    $hFontFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFontTime = _GDIPlus_FontCreate($hFontFamily, 10)
    $hFontTime2 = _GDIPlus_FontCreate($hFontFamily, 20)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics(800, 300, $hGraphic)
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
    _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)
    GUISetState(@SW_HIDE, $Form_1)
    GUISetState(@SW_HIDE, $Form_2)
    GUISetState(@SW_HIDE, $Form_3)
    GUISetState(@SW_HIDE, $Form_4)
    GUISetState(@SW_HIDE, $Form_5)
    GUISetState(@SW_HIDE, $Form_6)
    GUISetState(@SW_HIDE, $Form_7)
    GUISetState(@SW_HIDE, $Form_8)

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

    $Timer = TimerInit()
    $1 = -1
    While 1
    If $down = 1 And _IsPressed("0D") Then
    If @Compiled = 1 Then
    Run(@ScriptFullPath)
    Else
    Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @ScriptFullPath & '"')
    EndIf
    Exit
    EndIf
    $tt = TimerInit()
    If TimerDiff($Timer) > $sound2 * 1000 Then
    $sound2 += 178
    _SoundPlay($Sound_1)
    EndIf
    If $down = 0 Then
    If TimerDiff($Timer) > 15000 And $1 = -1 Then
    $iSleep -= 1
    $wand += 2
    $1 = 0
    $vY += 1
    $vX += 1
    EndIf
    If TimerDiff($Timer) > 30000 And $1 = 0 Then
    $iSleep -= 1
    $wand += 1
    $1 = 1
    $vY += 1
    $vX += 1
    EndIf
    If TimerDiff($Timer) > 40000 And $1 = 1 Then
    $iSleep -= 1
    $wand += 2
    $1 = 2
    $vY += 1
    $vX += 1
    EndIf
    If TimerDiff($Timer) > 92000 And $1 = 2 Then
    $wand += 2
    $1 = 3
    $vY += 2
    $vX += 2
    EndIf
    If TimerDiff($Timer) > 120000 And $1 = 3 Then
    $wand += 2
    $1 = 4
    $vY += 2
    $vX += 2
    EndIf
    If TimerDiff($Timer) > 130000 And $1 = 4 Then
    $wand += 1
    $1 = 5
    $vY += 1
    $vX += 1
    EndIf
    If TimerDiff($Timer) > 140000 And $1 = 5 Then
    $wand += 2
    $1 = 6
    $vY += 2
    $vX += 2
    EndIf
    If TimerDiff($Timer) > 150000 And $1 = 6 Then
    $wand += 1
    $1 = 7
    $vY += 1
    $vX += 1
    EndIf
    If TimerDiff($Timer) > 200000 And $1 = 7 Then
    $wand += 2
    $1 = 8
    $vY += 2
    $vX += 2
    EndIf
    If _IsPressed("25") And $iX >= 0 Then ;links
    $iX -= $vX
    EndIf
    If _IsPressed("26") And $iY >= 0 Then ;hoch
    $iY -= $vY
    EndIf
    If _IsPressed("27") And $iX <= 700 Then ;rechts
    $iX += $vX
    EndIf
    If _IsPressed("28") And $iY <= 240 Then ;unten
    $iY += $vY
    EndIf
    If $iY <= 0 Then
    $iY = 1
    EndIf
    If $iX <= 0 Then
    $iX = 0
    EndIf
    If $iY >= 240 Then
    $iY = 240
    EndIf
    EndIf
    $fortschritt -= 9
    $fortschritt2 -= 9
    If $fortschritt <= -800 Then
    $fortschritt = 800
    EndIf
    If $fortschritt2 <= -800 Then
    $fortschritt2 = 800
    EndIf
    If $down = 0 Then
    $i = Round(Random(0, 1))
    For $wd = 1 To $waende[0][0]
    $waende[$wd][1] -= $wand
    If $waende[$wd][1] <= -20 Then
    $waende[$wd][1] = 800 + $zwischenstellen
    If $i = 1 Then
    $waende[$wd][2] = 0
    $i = 0
    Else
    $waende[$wd][2] = 160
    $i = 1
    EndIf
    EndIf
    Next
    EndIf
    _GDIPlus_GraphicsDrawImageRect($hBuffer, $HG, $fortschritt, 0, 800, 300)
    _GDIPlus_GraphicsDrawImageRect($hBuffer, $HG2, $fortschritt2, 0, 800, 300)
    _GDIPlus_GraphicsDrawImageRect($hBuffer, $HG3, $fortschritt3, 0, 800, 300)
    $kolision = 0
    If $down = 0 Then
    For $wd = 1 To $waende[0][0]
    _GDIPlus_GraphicsDrawImageRect($hBuffer, $waende[$wd][0], $waende[$wd][1], $waende[$wd][2], 30, 170)
    If $iY > $waende[$wd][2] And $iY < $waende[$wd][2] + 170 And $waende[$wd][1] < $iX And $waende[$wd][1] + 30 > $iX Then $kolision = $wd
    If $iY > $waende[$wd][2] - $SchiffY And $iY < $waende[$wd][2] + 170 And $waende[$wd][1] < $iX And $waende[$wd][1] + 30 > $iX Then $kolision = $wd
    If $iY + $SchiffY / 2 > $waende[$wd][2] And $iY + $SchiffY / 2 < $waende[$wd][2] + 170 And $waende[$wd][1] < $iX + $SchiffX And $waende[$wd][1] + 30 > $iX + $SchiffX Then $kolision = $wd
    Next
    If $kolision > 0 Then
    $t = SoundPlay(@ScriptDir & "\Data\Bom.wav")
    $waende[$kolision][2] = 301
    $tp -= 10
    EndIf
    EndIf
    If $tp >= 60 Then
    $col = 1
    EndIf
    If $tp >= 30 And $tp < 60 Then
    $col = 2
    EndIf
    If $tp <= 30 Then
    $col = 3
    EndIf
    If $tp <= 1 And $down = 0 Then
    $Zeit = TimerDiff($Timer)
    $down = 1
    $vY = 801
    $vX = 301
    $wand = 2
    $iX = 801
    $iY = 301
    For $wd = 1 To $waende[0][0]
    $waende[$wd][1] = 801
    $waende[$wd][2] = 301
    Next
    EndIf
    If $down = 1 Then
    If $Zeit + 5000 < TimerDiff($Timer) And $y > 0 Then
    $y -= 4
    $Text2 = _GDIPlus_RectFCreate(300, $y)
    EndIf
    If $y = 0 Then
    $y += 1
    Dim $TmArray[2]
    $TmArray[0] = $name
    $TmArray[1] = Round($Zeit)
    $Score = _Highscore($Highscore, $TmArray)
    $TextOver = "Highscore:" & @CRLF & "1. " & $Score[0][0] & " " & Round($Score[0][1] / 1000) & @CRLF & "2. " & $Score[1][0] & " " & Round($Score[1][1] / 1000) & @CRLF & "3. " & $Score[2][0] & " " & Round($Score[2][1] / 1000) & @CRLF & "4. " & $Score[3][0] & " " & Round($Score[3][1] / 1000) & @CRLF & "5. " & $Score[4][0] & " " & Round($Score[4][1] / 1000) & @CRLF & @CRLF & "You. " & $name & " " & Round($Zeit / 1000) & @CRLF & "PRESS ENTER"
    EndIf
    _GDIPlus_GraphicsDrawStringEx($hBuffer, $TextOver, $hFontTime2, $Text2, Default, $farbe[1])
    EndIf
    _GDIPlus_GraphicsDrawImageRect($hBuffer, $Gamer, $iX, $iY, $SchiffX, $SchiffY)
    _GDIPlus_GraphicsDrawStringEx($hBuffer, Round(TimerDiff($Timer) / 1000) & " Sek", $hFontTime, $hLayoutZeit, Default, $farbe[0])
    _GDIPlus_GraphicsFillRect($hBuffer, 150, 10, $tp * 5, 5, $farbe[$col])
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, 800, 300)
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    _Exit()
    EndSwitch
    Sleep($iSleep - TimerDiff($tt))
    WEnd

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

    Func _Highscore($ScoreData, $NewArray = -1)
    If Not FileExists($ScoreData) And $NewArray = -1 Then Return -1
    If Not $NewArray = -1 And Not FileExists($ScoreData) Then
    FileWrite($ScoreData, $NewArray[0] & "|" & $NewArray[1])
    ElseIf Not $NewArray = -1 Then
    FileWrite($ScoreData, "#" & $NewArray[0] & "|" & $NewArray[1])
    EndIf
    $File = FileRead($ScoreData)
    $Sco = StringSplit($File, "#")
    Dim $NsG[$Sco[0] + 1][2]
    For $i = 1 To $Sco[0]
    $Data = StringSplit($Sco[$i], "|")
    $NsG[$i][0] = $Data[1]
    $NsG[$i][1] = Int($Data[$Data[0]])
    Next
    _ArraySort($NsG, 1, 0, 0, 1)
    Return $NsG
    EndFunc ;==>_Highscore

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

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

    [/autoit]

    Bild:
    [Blockierte Grafik: http://666kb.com/i/c2knlv7ki8xveuhw7.jpg]

    Viel Spaß ;)

    Sind TV-Quizfragen zu einfach? A) Ja B) Harry Potter

    Spoiler anzeigen

    Ich gebe zu dieser Post hat wahrscheinlich nicht viel geholfen,
    aber ich versuche wenigstens zu helfen :rolleyes:

  • Danke^^

    Sind TV-Quizfragen zu einfach? A) Ja B) Harry Potter

    Spoiler anzeigen

    Ich gebe zu dieser Post hat wahrscheinlich nicht viel geholfen,
    aber ich versuche wenigstens zu helfen :rolleyes:

  • das versteh ich nicht, bei mir geht alles und es sollte alles gehen...

    Sind TV-Quizfragen zu einfach? A) Ja B) Harry Potter

    Spoiler anzeigen

    Ich gebe zu dieser Post hat wahrscheinlich nicht viel geholfen,
    aber ich versuche wenigstens zu helfen :rolleyes:

  • Gute Arbeit mit GDI+ (für den Anfang)
    Ist zwar ein riesen Paket mit 7MB, aber das ist ja der Musik geschuldet. (dachte beim Download schon: ohje, was ist da bloß alles drin...).
    Grafikmäßig ist es schon ganz schön :)

    Natürlich lässt sich der ganze Spaß noch stark optimieren.
    Versuche in Zukunft evtl mehr mit Arrays zu arbeiten, das schafft Übersicht.

    lg
    M

  • Okay danke^^

    Sind TV-Quizfragen zu einfach? A) Ja B) Harry Potter

    Spoiler anzeigen

    Ich gebe zu dieser Post hat wahrscheinlich nicht viel geholfen,
    aber ich versuche wenigstens zu helfen :rolleyes:

  • Hallo,
    ich weiß, dass die letzte Antwort auf dieses Thema mehr als 68 Tage zurück liegt, aber du solltest am Ende deines Skriptes ebenfalls u. a. alle brushes und geladenen Bilder disponieren.