• Hallo zusammen

    Ich habe mal ein kleine Spiel gemacht um mich ein wenig mit GDI+ zu beschäftigen. Es ist eigentlich selbsterklärend. Steuern kann man mit WASD oder den Pfeiltasten.
    Ich hoffe es gefällt euch.

    Anleitung:

    Spoiler anzeigen

    WASD, Pfeiltasten oder Linke Maustaste: Bewegen
    Maus: Blickrichtung ändern
    Leertaste: Superwaffe
    Esc: Beenden
    Enter: Zwischen mit und ohne Rand wechseln/Neustart wenn man verloren hat
    Alt: Pause


    Änderungen:

    Spoiler anzeigen

    Version 1.5
    - Das Raumschiff wird erst langsamer bevor es stillsteht
    - Superwaffe wird jetzt mit der Leertaste gezündet
    - Wenn man die linke Maustaste drückt, fliegt das Raumschiff jetzt in Blickrichtung
    - Diverse Bugfixes

    Version 1.4
    - Wenn man verliert, kann man es mit Enter noch mal versuchen
    - Man hat 3 Leben
    - Das Raumschiff bewegt sich jetzt selber (Noch im Teststadium)
    - Einige Bugfixes

    Version 1.3
    - Es können PowerUps eingesammelt werden (kleine, Dunkelgrüne Rechtecke). Dadurch wird man für kurze Zeit unverwundbar.
    - Verbesserte Kollisionserkennung
    - Diverse Bugfixes

    Version 1.2
    - Superwaffe kann mit Enter gezündet werden
    - Statusbalken für die Superwaffe am unteren Rand (Gelb = Noch nicht einsatzfähig, Violett = Einsatzfähig)
    - Diverse Bugfixes

    Version 1.1
    - Pause mit Alt möglich
    - Mit der Leertaste kann zwischen Popup-Fenster und Grössenveränderbarem Fenster gewechselt werden.
    - Einige Bugfixes


    Code:

    Spoiler anzeigen
    [autoit]


    #region Includes
    #include <GDIPlus.au3>
    #include <GUIConstants.au3>
    #include <ButtonConstants.au3>
    #include <WindowsConstants.au3>
    #include <Misc.au3>
    #endregion Includes

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

    #region Options
    _GDIPlus_Startup()
    OnAutoItExitRegister("_exit")
    Opt("MustDeclareVars", 1)
    #endregion Options

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

    ;--- Changeable Constants ---------------------------------------------------------------------
    Global Const $PlayerRadius = 40
    Global Const $nPlayerSpeed = 2
    Global Const $nPlayerSmoothing = 20
    Global Const $nPlayerSmoothingSpeed = 1
    Global Const $nInvincibleTime = 50

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

    Global Const $SHOOTING_SPEED = 2
    Global Const $nSpeedEnemys = 5
    Global Const $nSpeeedNewEnemy = 15

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

    Global Const $nEnemyMaxSize = 200
    Global Const $nEnemyMinSize = 90
    Global Const $nEnemyDestroySize = 50
    Global Const $nEnemySmallingSpeed = 30

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

    Global Const $nPowerUpPlayerRadius = 60
    Global Const $nPowerUpRadius = 30
    Global Const $nPowerUpMinTime = 400
    Global Const $nPowerUpMaxTime = 800
    Global Const $nPowerUpDuration = 200
    ;----------------------------------------------------------------------------------------------

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

    #region Global Variabels
    Global Const $pi = 3.14159265358979
    Global Const $HalfPi = $pi / 2
    Global Const $Cos08 = Cos(0.8), $Sin08 = Sin(0.8), $Cosn08 = Cos(-0.8), $Sinn08 = Sin(-0.8)
    Global Const $MAX_ENEMYS = 40, $MAX_SHOTS = 40

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

    Global Const $nEnemyX = 0, $nEnemyY = 1, $nEnemySize = 2, $nEnemyDir = 3
    Global Const $nShotXFront = 0, $nShotYFront = 1, $nShotXBack = 2, $nShotYBack = 3

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

    Global $hGraphic, $hBrushPlayer, $hBrushEnemy, $hPen, $xPlayer, $yPlayer, $rotationPlayer, $xGUI, $yGUI, $hBitmap, $hBuffer
    Global $nPlayerFrontX, $nPlayerFrontY, $nPlayerBack1X, $nPlayerBack1Y, $nPlayerBack2X, $nPlayerBack2Y, $hBrushWhite, $hLayoutOver
    Global $hFontFamily, $hFontPoints, $hLayoutPoints, $hFontOver, $nPoints, $hPenMenu, $hBrushSuper1, $hBrushSuper2
    Global $fWeaponShooting, $nWeaponRadius, $xWeapon, $yWeapon, $hBrushPowerUp, $hBrushPowerUpPlayer, $fPowerUp
    Global $fPowerUpReady, $nPowerUpTimer, $xPowerUp, $yPowerUp, $nPowerUpActiveTime, $nLives, $fWeaponReady
    Global $fWeaponReloading, $nLine, $nNewEnemy, $nlSpeedNewEnemys, $nNewShot, $nSmooth
    Global $aShots[$MAX_SHOTS][4] ; [x1][y1][x2][y2]
    Global $aEnemys[$MAX_ENEMYS][4] ; [x][y][Size][Direction]
    Global $afCollided[$MAX_ENEMYS]
    Global $anPointsPowerUp[5][2]
    Global $widhtGUI = 800
    Global $heightGUI = 800
    Global $hDLL = DllOpen("Kernel32.dll")
    #endregion Global Variables

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

    #region Variable Initialisations
    $xGUI = (@DesktopWidth - $widhtGUI) / 2
    $yGUI = (@DesktopHeight - $heightGUI) / 2
    _InitVars()
    #endregion Variable Initialisations

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

    #region GUI
    Local $GUI_Border = False
    Local $hGUI = GUICreate("PolyShoot", $widhtGUI, $heightGUI, $xGUI, $yGUI, $WS_POPUP)
    GUISetBkColor(0x000000, $hGUI)
    #endregion GUI

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

    #region GDI+
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hBrushPlayer = _GDIPlus_BrushCreateSolid(0xFF00FF00) ; Grün
    $hBrushEnemy = _GDIPlus_BrushCreateSolid(0xFFFF0000) ; Rot
    $hBrushWhite = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) ; Weiss
    $hBrushSuper1 = _GDIPlus_BrushCreateSolid(0xFFFFFF00) ; Gelb
    $hBrushSuper2 = _GDIPlus_BrushCreateSolid(0xFF551A8B) ; Violett
    $hBrushPowerUpPlayer = _GDIPlus_BrushCreateSolid(0x7FFFFF00) ; Blasses Gelb
    $hBrushPowerUp = _GDIPlus_BrushCreateSolid(0xFF006400) ; Dunkelgrün
    $hPen = _GDIPlus_PenCreate(0xFF0000FF, 5) ; Blau
    $hPenMenu = _GDIPlus_PenCreate(0xFFFFFFFF, 3) ; Weiss
    $hLayoutOver = _GDIPlus_RectFCreate(($widhtGUI / 2) - 280, ($heightGUI / 2) - 70, 800, 100)
    $hLayoutPoints = _GDIPlus_RectFCreate(($widhtGUI / 2) - 50, $heightGUI - 80, 200, 50)
    $hFontFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFontOver = _GDIPlus_FontCreate($hFontFamily, 60)
    $hFontPoints = _GDIPlus_FontCreate($hFontFamily, 10)

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

    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($widhtGUI, $heightGUI, $hGraphic)
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)

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

    _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
    _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)

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

    _GDIPlus_GraphicsFillRect($hBuffer, ($widhtGUI / 2) + 50, $heightGUI - 60, ($widhtGUI / 2) + 100, $heightGUI - 30, $hBrushSuper2)

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

    #endregion GDI+

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

    GUISetState(@SW_SHOW, $hGUI)

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

    #region Main Loop
    While 1

    _LoopDelay()

    Switch GUIGetMsg()

    Case $GUI_EVENT_CLOSE
    Exit

    Case $GUI_EVENT_RESIZED
    _Resized()

    EndSwitch

    _SpecialKeys()
    _UpdatePlayer()
    If _IsPressed("01") Then _Move($nPlayerSpeed, $nPlayerFrontX, $nPlayerFrontY)
    _UpdateShots()
    _PowerUp()
    _UpdateEnemys()
    _SuperWeapon()
    _CheckCollisions()
    _DrawPoints()
    _UpdateScreen()

    WEnd
    #endregion Main Loop

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

    #region Functions

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

    Func _LoopDelay()

    Local Static $nTimer = 0

    If $nTimer = 0 Then
    $nTimer = TimerInit()
    Return
    EndIf

    While TimerDiff($nTimer) < 50
    Sleep(1)
    WEnd

    $nTimer = TimerInit()

    EndFunc

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

    Func _SpecialKeys()

    If _IsPressed("0D") Then
    If $GUI_Border Then
    GUISetStyle($WS_POPUP)
    Else
    GUISetStyle($WS_OVERLAPPEDWINDOW)
    EndIf
    $GUI_Border = Not $GUI_Border
    While _IsPressed("0D")
    Sleep(10)
    WEnd
    EndIf

    If _IsPressed("12") Then
    While _IsPressed("12")
    Sleep(10)
    WEnd
    _GDIPlus_GraphicsDrawStringEx($hGraphic, " Paused", $hFontOver, $hLayoutOver, Default, $hBrushWhite)
    While Not _IsPressed("12")
    Sleep(10)
    WEnd
    While _IsPressed("12")
    Sleep(10)
    WEnd
    EndIf

    EndFunc

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

    Func _UpdatePlayer()

    Dim $posMouse, $aPolygon[4][2]
    Local $tmpRotation, $xTmp, $yTmp, $fLeft, $fRight, $fUp, $fDown
    Local Static $fLeftTmp, $fRightTmp, $fUpTmp, $fDownTmp, $fMouseDown = False, $nMouseXTmp, $nMouseYTmp

    If Not _IsPressed("01") Then
    $fUp = _IsPressed("57") Or _IsPressed("26")
    $fDown = _IsPressed("53") Or _IsPressed("28")
    $fRight = _IsPressed("44") Or _IsPressed("27")
    $fLeft = _IsPressed("41") Or _IsPressed("25")

    _MovePlayer($nPlayerSpeed, $fLeft, $fRight, $fUp, $fDown)

    If $fUp Or $fDown Or $fRight Or $fLeft Then
    $nSmooth = $nPlayerSmoothing
    $fLeftTmp = $fLeft
    $fRightTmp = $fRight
    $fUpTmp = $fUp
    $fDownTmp = $fDown
    $fMouseDown = False
    ElseIf $nSmooth > $nPlayerSmoothingSpeed Then
    If $fMouseDown Then
    _Move($nSmooth / 10, $nMouseXTmp, $nMouseYTmp)
    Else
    _MovePlayer($nSmooth / 10, $fLeftTmp, $fRightTmp, $fUpTmp, $fDownTmp)
    EndIf
    $nSmooth -= $nPlayerSmoothingSpeed
    Else
    $fMouseDown = False
    EndIf
    Else
    $nSmooth = $nPlayerSmoothing
    $fMouseDown = True
    $nMouseXTmp = $nPlayerFrontX
    $nMouseYTmp = $nPlayerFrontY
    EndIf

    Do
    $posMouse = GUIGetCursorInfo()
    Sleep(10)
    Until IsArray($posMouse)

    $rotationPlayer = ATan(($posMouse[0] - $xPlayer) / ($yPlayer - $posMouse[1]))

    If $posMouse[1] > $yPlayer Then $rotationPlayer *= -1

    $tmpRotation = $rotationPlayer
    If $tmpRotation < 0 Then $tmpRotation *= -1
    $nPlayerFrontX = $PlayerRadius * Sin($tmpRotation)

    $tmpRotation = $HalfPi - $tmpRotation
    $nPlayerFrontY = $nPlayerFrontX * Tan($tmpRotation)
    If $posMouse[1] > $yPlayer Then
    $nPlayerFrontY = $yPlayer + $nPlayerFrontY
    Else
    $nPlayerFrontY = $yPlayer - $nPlayerFrontY
    EndIf

    If $posMouse[0] < $xPlayer Then
    $nPlayerFrontX = $xPlayer - $nPlayerFrontX
    Else
    $nPlayerFrontX = $xPlayer + $nPlayerFrontX
    EndIf

    $yTmp = ($yPlayer - $nPlayerFrontY) / 1.5
    $xTmp = ($xPlayer - $nPlayerFrontX) / 1.5

    $nPlayerBack1X = $xTmp * $Cos08 - $yTmp * $Sin08 + $xPlayer
    $nPlayerBack1Y = $xTmp * $Sin08 + $yTmp * $Cos08 + $yPlayer

    $nPlayerBack2X = $xTmp * $Cosn08 - $yTmp * $Sinn08 + $xPlayer
    $nPlayerBack2Y = $xTmp * $Sinn08 + $yTmp * $Cosn08 + $yPlayer

    $aPolygon[0][0] = 3
    $aPolygon[1][0] = $nPlayerFrontX
    $aPolygon[1][1] = $nPlayerFrontY
    $aPolygon[2][0] = $nPlayerBack1X
    $aPolygon[2][1] = $nPlayerBack1Y
    $aPolygon[3][0] = $nPlayerBack2X
    $aPolygon[3][1] = $nPlayerBack2Y

    _GDIPlus_GraphicsClear($hBuffer, 0xFF000000)
    _GDIPlus_GraphicsFillPolygon($hBuffer, $aPolygon, $hBrushPlayer)

    EndFunc

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

    Func _MovePlayer($nSpeed, $fLeft, $fRight, $fUp, $fDown)

    If $fUp Then
    $yPlayer -= 3 * $nSpeed
    If $fRight Then
    $xPlayer += 3 * $nSpeed
    ElseIf $fLeft Then
    $xPlayer -= 3 * $nSpeed
    Else
    $yPlayer -= $nSpeed
    EndIf
    ElseIf $fDown Then
    $yPlayer += 3 * $nSpeed
    If $fRight Then
    $xPlayer += 3 * $nSpeed
    ElseIf $fLeft Then
    $xPlayer -= 3 * $nSpeed
    Else
    $yPlayer += $nSpeed
    EndIf
    ElseIf $fLeft Then
    $xPlayer -= 4 * $nSpeed
    ElseIf $fRight Then
    $xPlayer += 4 * $nSpeed
    EndIf

    EndFunc

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

    Func _Move($nValue, ByRef $x, ByRef $y)

    $x -= ($xPlayer - $x) * $nValue / 10
    $xPlayer -= ($xPlayer - $x) * $nValue / 10
    $y -= ($yPlayer - $y) * $nValue / 10
    $yPlayer -= ($yPlayer - $y) * $nValue / 10

    EndFunc

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

    Func _UpdateShots()

    Local $xTmp, $yTmp, $k

    If Mod($nNewEnemy, $SHOOTING_SPEED) = 0 Then
    $k = $nNewShot / $SHOOTING_SPEED
    $aShots[$k][$nShotXFront] = $nPlayerFrontX
    $aShots[$k][$nShotYFront] = $nPlayerFrontY
    $aShots[$k][$nShotXBack] = $xPlayer - (($xPlayer - $nPlayerFrontX) * 1.2)
    $aShots[$k][$nShotYBack] = $yPlayer - (($yPlayer - $nPlayerFrontY) * 1.2)
    If $k > ($MAX_SHOTS - 2) Then $nNewShot = 0
    EndIf

    For $j = 0 To $MAX_SHOTS - 1
    $xTmp = $aShots[$j][$nShotXFront]
    $yTmp = $aShots[$j][$nShotYFront]
    $aShots[$j][$nShotXFront] = $aShots[$j][$nShotXBack] - ($xTmp - $aShots[$j][$nShotXBack])
    $aShots[$j][$nShotYFront] = $aShots[$j][$nShotYBack] - ($yTmp - $aShots[$j][$nShotYBack])
    $aShots[$j][$nShotXBack] = $aShots[$j][$nShotXFront] - ($aShots[$j][$nShotXBack] - $aShots[$j][$nShotXFront])
    $aShots[$j][$nShotYBack] = $aShots[$j][$nShotYFront] - ($aShots[$j][$nShotYBack] - $aShots[$j][$nShotYFront])

    _GDIPlus_GraphicsDrawLine($hBuffer, $aShots[$j][$nShotXFront], $aShots[$j][$nShotYFront], $aShots[$j][$nShotXBack], $aShots[$j][$nShotYBack], $hPen)
    Next

    $nNewShot += 1

    EndFunc

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

    Func _SuperWeapon()

    If _IsPressed("20") And $fWeaponReady Then
    $fWeaponReady = False
    $fWeaponShooting = True
    $fWeaponReloading = True
    $xWeapon = $xPlayer
    $yWeapon = $yPlayer
    EndIf

    If $fWeaponShooting Then
    _GDIPlus_GraphicsDrawArc($hBuffer, $xWeapon - $nWeaponRadius, $yWeapon - $nWeaponRadius, $nWeaponRadius * 2, $nWeaponRadius * 2, 0, 360, $hPen)
    $nWeaponRadius += 10
    If $nWeaponRadius > ($widhtGUI * 3) And $nWeaponRadius > ($heightGUI * 4) Then
    $fWeaponShooting = False
    $nWeaponRadius = 0
    _ClearCollisionArray()
    EndIf
    EndIf

    If $fWeaponReloading Then
    _GDIPlus_GraphicsFillRect($hBuffer, ($widhtGUI / 2) + 100, $heightGUI - 80, $nLine, 20, $hBrushSuper1)
    $nLine += 0.1
    If $nLine > 50 Then
    $fWeaponReady = True
    $fWeaponReloading = False
    $nLine = 0
    EndIf
    Else
    _GDIPlus_GraphicsFillRect($hBuffer, ($widhtGUI / 2) + 100, $heightGUI - 80, 50, 20, $hBrushSuper2)
    EndIf

    EndFunc

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

    Func _PowerUp()

    If $nPowerUpTimer < 1 And Not $fPowerUpReady And Not $fPowerUp Then
    $fPowerUpReady = True
    $xPowerUp = Random($nPowerUpRadius, $widhtGUI - $nPowerUpRadius, 1)
    $yPowerUp = Random($nPowerUpRadius, $heightGUI - $nPowerUpRadius, 1)
    $anPointsPowerUp[1][0] = $xPowerUp - $nPowerUpRadius
    $anPointsPowerUp[1][1] = $yPowerUp
    $anPointsPowerUp[2][0] = $xPowerUp
    $anPointsPowerUp[2][1] = $yPowerUp - $nPowerUpRadius
    $anPointsPowerUp[3][0] = $xPowerUp + $nPowerUpRadius
    $anPointsPowerUp[3][1] = $yPowerUp
    $anPointsPowerUp[4][0] = $xPowerUp
    $anPointsPowerUp[4][1] = $yPowerUp + $nPowerUpRadius
    _GDIPlus_BrushSetSolidColor($hBrushPowerUpPlayer, 0x7FFFFF00)
    ElseIf $fPowerUpReady Then
    _GDIPlus_GraphicsFillPolygon($hBuffer, $anPointsPowerUp, $hBrushPowerUp)
    ElseIf Not $fPowerUp Then
    $nPowerUpTimer -= 1
    EndIf

    If $fPowerUp Then
    If $nPowerUpActiveTime = 10 Or $nPowerUpActiveTime = 20 Or $nPowerUpActiveTime = 30 Then _GDIPlus_BrushSetSolidColor($hBrushPowerUpPlayer, 0x7FFFFF00)
    If $nPowerUpActiveTime = 5 Or $nPowerUpActiveTime = 15 Or $nPowerUpActiveTime = 25 Or $nPowerUpActiveTime = 35 Then _GDIPlus_BrushSetSolidColor($hBrushPowerUpPlayer, 0x00FFFF00)
    _GDIPlus_GraphicsFillEllipse($hBuffer, $xPlayer - $nPowerUpPlayerRadius, $yPlayer - $nPowerUpPlayerRadius, $nPowerUpPlayerRadius * 2, $nPowerUpPlayerRadius * 2, $hBrushPowerUpPlayer)
    $nPowerUpActiveTime -= 1
    If $nPowerUpActiveTime < 1 Then
    $fPowerUp = False
    $nPowerUpTimer = Random($nPowerUpMinTime, $nPowerUpMaxTime, 1)
    EndIf
    EndIf

    EndFunc

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

    Func _UpdateEnemys()

    Local $j

    If Mod($nNewEnemy + 1, $nlSpeedNewEnemys) = 0 Then

    $j = Round($nNewEnemy / $nlSpeedNewEnemys)
    $aEnemys[$j][$nEnemySize] = Random($nEnemyMinSize, $nEnemyMaxSize, 1)
    $aEnemys[$j][$nEnemyDir] = Random(0, 3, 1) ; 0 = Left, 1 = Top, 2 = Right, 3 = Down

    Switch $aEnemys[$j][$nEnemyDir]

    Case 0

    $aEnemys[$j][$nEnemyX] = - $aEnemys[$j][$nEnemySize]
    $aEnemys[$j][$nEnemyY] = Random(0, $heightGUI - $aEnemys[$j][$nEnemySize], 1)

    Case 1

    $aEnemys[$j][$nEnemyX] = Random(0, $widhtGUI - $aEnemys[$j][$nEnemySize], 1)
    $aEnemys[$j][$nEnemyY] = - $aEnemys[$j][$nEnemySize]

    Case 2

    $aEnemys[$j][$nEnemyX] = $widhtGUI + $aEnemys[$j][$nEnemySize]
    $aEnemys[$j][$nEnemyY] = Random(0, $heightGUI - $aEnemys[$j][$nEnemySize], 1)

    Case 3

    $aEnemys[$j][$nEnemyX] = Random(0, $widhtGUI - $aEnemys[$j][$nEnemySize], 1)
    $aEnemys[$j][$nEnemyY] = $heightGUI + $aEnemys[$j][$nEnemySize]

    EndSwitch

    If $j > $MAX_ENEMYS - 2 Then
    $nNewEnemy = 0
    $nlSpeedNewEnemys -= 2
    EndIf
    EndIf

    For $j = 0 To $MAX_ENEMYS - 1
    Switch $aEnemys[$j][$nEnemyDir]

    Case 0
    $aEnemys[$j][$nEnemyX] += $nSpeedEnemys

    Case 1
    $aEnemys[$j][$nEnemyY] += $nSpeedEnemys

    Case 2
    $aEnemys[$j][$nEnemyX] -= $nSpeedEnemys

    Case 3
    $aEnemys[$j][$nEnemyY] -= $nSpeedEnemys

    EndSwitch

    _GDIPlus_GraphicsFillRect($hBuffer, $aEnemys[$j][$nEnemyX], $aEnemys[$j][$nEnemyY], $aEnemys[$j][$nEnemySize], $aEnemys[$j][$nEnemySize], $hBrushEnemy)
    Next

    $nNewEnemy += 1

    EndFunc

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

    Func _CheckCollisions()

    For $i = 0 To $MAX_ENEMYS - 1
    For $j = 0 To $MAX_SHOTS - 1
    If ($aShots[$j][$nShotXFront] > $aEnemys[$i][$nEnemyX]) And ($aShots[$j][$nShotXFront] < ($aEnemys[$i][$nEnemyX] + $aEnemys[$i][$nEnemySize])) And ($aShots[$j][$nShotYFront] > $aEnemys[$i][$nEnemyY]) And ($aShots[$j][$nShotYFront] < ($aEnemys[$i][$nEnemyY] + $aEnemys[$i][$nEnemySize])) Then
    $aShots[$j][$nShotXFront] = 0
    $aShots[$j][$nShotYFront] = 0
    $aShots[$j][$nShotXBack] = -1
    $aShots[$j][$nShotYBack] = -1
    _DamageEnemy($i)
    EndIf
    Next

    If _LineEnemyIntersects($nPlayerFrontX, $nPlayerFrontY, $nPlayerBack1X, $nPlayerBack1Y, $i) _
    Or _LineEnemyIntersects($nPlayerBack1X, $nPlayerBack1Y, $nPlayerBack2X, $nPlayerBack2Y, $i) _
    Or _LineEnemyIntersects($nPlayerBack2X, $nPlayerBack2Y, $nPlayerFrontX, $nPlayerFrontY, $i) Then
    $nLives -= 1
    If $nLives = 0 Then
    _GDIPlus_GraphicsDrawStringEx($hBuffer, "Game Over", $hFontOver, $hLayoutOver, Default, $hBrushWhite)
    _DrawPoints()
    _UpdateScreen()
    _InitVars()
    While Not _IsPressed("0D")
    Sleep(10)
    If _IsPressed("1B") Then Exit
    WEnd
    While _IsPressed("0D")
    Sleep(10)
    WEnd
    Else
    _DamageEnemy($i)
    $fPowerUp = True
    $nPowerUpActiveTime = $nInvincibleTime
    _GDIPlus_BrushSetSolidColor($hBrushPowerUpPlayer, 0x7FFFFF00)
    EndIf
    EndIf

    If $fWeaponShooting And Not $afCollided[$i] Then
    If _ArcEnemyIntersects($i, $xWeapon, $yWeapon, $nWeaponRadius) Then
    _DamageEnemy($i)
    $afCollided[$i] = True
    EndIf
    EndIf

    If $fPowerUpReady Then
    If (Sqrt(($xPlayer - $xPowerUp) ^ 2 + ($yPlayer - $yPowerUp) ^ 2) < $nPowerUpRadius) Then
    $fPowerUp = True
    $fPowerUpReady = False
    $nPowerUpActiveTime = $nPowerUpDuration
    EndIf
    EndIf

    If $fPowerUp Then
    If _ArcEnemyIntersects($i, $xPlayer, $yPlayer, $nPowerUpPlayerRadius) Then
    _DamageEnemy($i)
    EndIf
    EndIf
    Next

    EndFunc

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

    Func _DrawPoints()

    If $nLives > 2 Then _GDIPlus_GraphicsFillEllipse($hBuffer, ($widhtGUI / 2) - 250, $heightGUI - 90, 30, 40, $hBrushWhite)

    If $nLives > 1 Then _GDIPlus_GraphicsFillEllipse($hBuffer, ($widhtGUI / 2) - 200, $heightGUI - 90, 30, 40, $hBrushWhite)

    If $nLives > 0 Then _GDIPlus_GraphicsFillEllipse($hBuffer, ($widhtGUI / 2) - 150, $heightGUI - 90, 30, 40, $hBrushWhite)

    _GDIPlus_GraphicsDrawStringEx($hBuffer, "Punkte: " & $nPoints, $hFontPoints, $hLayoutPoints, Default, $hBrushWhite)

    EndFunc

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

    Func _UpdateScreen()

    _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0)

    EndFunc

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

    Func _exit()

    _GDIPlus_BrushDispose($hBrushPlayer)
    _GDIPlus_BrushDispose($hBrushEnemy)
    _GDIPlus_BrushDispose($hBrushWhite)
    _GDIPlus_BrushDispose($hBrushSuper1)
    _GDIPlus_BrushDispose($hBrushSuper2)
    _GDIPlus_BrushDispose($hBrushPowerUpPlayer)
    _GDIPlus_BrushDispose($hBrushPowerUp)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_PenDispose($hPenMenu)
    _GDIPlus_FontFamilyDispose($hFontFamily)
    _GDIPlus_FontDispose($hFontOver)
    _GDIPlus_FontDispose($hFontPoints)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_GraphicsDispose($hBuffer)
    _GDIPlus_Shutdown()

    EndFunc

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

    Func _Resized()

    Local $nGUI_Pos = WinGetPos("PolyShoot")
    $widhtGUI = $nGUI_Pos[2]
    $heightGUI = $nGUI_Pos[3]
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_GraphicsDispose($hBuffer)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($widhtGUI, $heightGUI, $hGraphic)
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    $hLayoutOver = _GDIPlus_RectFCreate(($widhtGUI / 2) - 280, ($heightGUI / 2) - 70, 800, 100)
    $hLayoutPoints = _GDIPlus_RectFCreate(($widhtGUI / 2) - 50, $heightGUI - 80, 200, 50)

    EndFunc

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

    Func _DamageEnemy($nEnemy)

    If $aEnemys[$nEnemy][$nEnemySize] < $nEnemyDestroySize Then
    $aEnemys[$nEnemy][$nEnemySize] = 0
    Else
    $aEnemys[$nEnemy][$nEnemySize] -= $nEnemySmallingSpeed
    $aEnemys[$nEnemy][$nEnemyX] += $nEnemySmallingSpeed / 2
    $aEnemys[$nEnemy][$nEnemyY] += $nEnemySmallingSpeed / 2
    EndIf
    $nPoints += 100

    EndFunc

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

    Func _LineEnemyIntersects($x0, $y0, $x1, $y1, $i)

    Local $m, $c, $topoverlap, $botoverlap, $top_intersection, $bottom_intersection, $toptrianglepoint, $bottomtrianglepoint, $l, $r, $t, $b

    $l = $aEnemys[$i][$nEnemyX]
    $r = $aEnemys[$i][$nEnemyX] + $aEnemys[$i][$nEnemySize]
    $t = $aEnemys[$i][$nEnemyY]
    $b = $aEnemys[$i][$nEnemyY] + $aEnemys[$i][$nEnemySize]

    $m = ($y1 - $y0) / ($x1 - $x0)
    $c = $y0 - ($m * $x0)

    if ($m > 0) Then
    $top_intersection = ($m * $l + $c)
    $bottom_intersection = ($m * $r + $c)
    else
    $top_intersection = ($m * $r + $c)
    $bottom_intersection = ($m * $l + $c)
    EndIf

    if ($y0 < $y1) Then
    $toptrianglepoint = $y0
    $bottomtrianglepoint = $y1
    else
    $toptrianglepoint = $y1
    $bottomtrianglepoint = $y0
    EndIf

    If $top_intersection > $toptrianglepoint Then
    $topoverlap = $top_intersection
    Else
    $topoverlap = $toptrianglepoint
    EndIf

    If $bottom_intersection < $bottomtrianglepoint Then
    $botoverlap = $bottom_intersection
    Else
    $botoverlap = $bottomtrianglepoint
    EndIf

    return($topoverlap < $botoverlap) And (Not (($botoverlap < $t) Or ($topoverlap > $b)))

    EndFunc

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

    Func _ArcEnemyIntersects($nEnemy, $nArcX, $nArcY, $nArcRadius)

    Return(Sqrt(($nArcX - $aEnemys[$nEnemy][$nEnemyX]) ^ 2 + ($nArcY - $aEnemys[$nEnemy][$nEnemyY]) ^ 2) < $nArcRadius) _
    Or (Sqrt(($nArcX - $aEnemys[$nEnemy][$nEnemyX] - $aEnemys[$nEnemy][$nEnemySize]) ^ 2 + ($nArcY - $aEnemys[$nEnemy][$nEnemyY]) ^ 2) < $nArcRadius) _
    Or (Sqrt(($nArcX - $aEnemys[$nEnemy][$nEnemyX]) ^ 2 + ($nArcY - $aEnemys[$nEnemy][$nEnemyY] - $aEnemys[$nEnemy][$nEnemySize]) ^ 2) < $nArcRadius) _
    Or (Sqrt(($nArcX - $aEnemys[$nEnemy][$nEnemyX] - $aEnemys[$nEnemy][$nEnemySize]) ^ 2 + ($nArcY - $aEnemys[$nEnemy][$nEnemyY] - $aEnemys[$nEnemy][$nEnemySize]) ^ 2) < $nArcRadius) _
    Or ((($nArcX + $nArcRadius) > $aEnemys[$nEnemy][$nEnemyX]) And (($nArcX + $nArcRadius) < $aEnemys[$nEnemy][$nEnemyX] + $aEnemys[$nEnemy][$nEnemySize]) _
    And ($nArcY > $aEnemys[$nEnemy][$nEnemyY]) And ($nArcY < ($aEnemys[$nEnemy][$nEnemyY] + $aEnemys[$nEnemy][$nEnemySize]))) _
    Or ((($nArcY + $nArcRadius) > $aEnemys[$nEnemy][$nEnemyY]) And (($nArcY + $nArcRadius) < $aEnemys[$nEnemy][$nEnemyY] + $aEnemys[$nEnemy][$nEnemySize]) _
    And ($nArcX > $aEnemys[$nEnemy][$nEnemyX]) And ($nArcX < ($aEnemys[$nEnemy][$nEnemyX] + $aEnemys[$nEnemy][$nEnemySize]))) _
    Or ((($nArcX - $nArcRadius) > $aEnemys[$nEnemy][$nEnemyX]) And (($nArcX - $nArcRadius) < $aEnemys[$nEnemy][$nEnemyX] + $aEnemys[$nEnemy][$nEnemySize]) _
    And ($nArcY > $aEnemys[$nEnemy][$nEnemyY]) And ($nArcY < ($aEnemys[$nEnemy][$nEnemyY] + $aEnemys[$nEnemy][$nEnemySize]))) _
    Or ((($nArcY - $nArcRadius) > $aEnemys[$nEnemy][$nEnemyY]) And (($nArcY - $nArcRadius) < $aEnemys[$nEnemy][$nEnemyY] + $aEnemys[$nEnemy][$nEnemySize]) _
    And ($nArcX > $aEnemys[$nEnemy][$nEnemyX]) And ($nArcX < ($aEnemys[$nEnemy][$nEnemyX] + $aEnemys[$nEnemy][$nEnemySize])))

    EndFunc

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

    Func _InitVars()

    $xPlayer = 400
    $yPlayer = 400
    $rotationPlayer = 0
    $nPoints = 0
    $nLives = 3
    $anPointsPowerUp[0][0] = 4
    $nPowerUpTimer = Random($nPowerUpMinTime, $nPowerUpMaxTime, 1)
    $fWeaponReady = True
    $fWeaponReloading = False
    $fWeaponShooting = False
    $nWeaponRadius = 0
    $nLine = 0
    $nNewEnemy = 0
    $nlSpeedNewEnemys = $nSpeeedNewEnemy
    $nNewShot = 0
    $xWeapon = 0
    $yWeapon = 0
    $fPowerUp = False
    $fPowerUpReady = False
    $nPowerUpActiveTime = $nPowerUpDuration
    $nSmooth = 0
    _GDIPlus_BrushSetSolidColor($hBrushPowerUpPlayer, 0x7FFFFF00)
    For $i = 0 To $MAX_ENEMYS - 1
    $afCollided[$i] = False
    $aEnemys[$i][$nEnemyX] = 0
    $aEnemys[$i][$nEnemyY] = 0
    $aEnemys[$i][$nEnemySize] = 0
    Next
    For $i = 0 To $MAX_SHOTS - 1
    $aShots[$i][$nShotXFront] = 0
    $aShots[$i][$nShotYFront] = 0
    $aShots[$i][$nShotXBack] = 0
    $aShots[$i][$nShotYBack] = 0
    Next

    EndFunc

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

    Func _ClearCollisionArray()

    For $i = 0 To $MAX_ENEMYS - 1
    $afCollided[$i] = False
    Next

    EndFunc

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

    #endregion Functions

    [/autoit]


    Gruss Shadowigor

  • Das ist dein erstes Spiel mit GDI+? Respekt. Ist wirklich gut geworden. Ruckelt nicht und die Idee ist auch mal was anderes^^ (Ähnelt ein wenig AuoItRoids, du musst nurnoch "Trägheit" vom Raumschiff machen^^)
    Weiter so :thumbup:

    mfg BB

    "IF YOU'RE GOING TO KILL IT
    OPEN SOURCE IT!"

    by Phillip Torrone

    Zitat von Shoutbox

    [Heute, 11:16] Andy: ....böseböseböseböse....da erinnere ich mich daran, dass man den Puschelschwanz eines KaRnickels auch "Blume" nennt....ob da eins zum anderen passt? :rofl: :rofl: :rofl: :rofl:

    https://autoit.de/index.php?page…leIt#post251138

    Neon Snake

  • Danke vielmals.
    L3viathan: Also den Punktestand zeigt es ja schon an (ganz unten in der mitte. ist vielleicht ein wenig klein). Das mit der Höhe und Breite lässt sich machen.
    Hat sonst noch jemand Verbesserungsvorschläge?

  • schussgeschwindigkeit runterschrauben aber dafür eine "superwaffe" die man alle 30 sek einsätzen kann oder so ;D

    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:

  • Sehr schön :)
    In Zeile 115 (in die While Schleife) aber bitte ein Sleep(10) einsetzen.
    Dann geht die CPU Last herunter und die Wartezeit verändert sich nicht.

    lg
    M

  • Erstmal danke für die vielen Rückmeldungen.

    @Marsi: Stimmt. Hab ich vergessen. Mache ich noch.
    @xXxProGamerxXx und chesstiger: Gute Idee. Das werde ich sicher auch noch machen. Das dauert aber wohl noch ein wenig...

    Ich hab jetzt mal eine neue Version hochgeladen (siehe Post #1).

    PS: Kann mir jemand sagen weshalb er erst so nach dem 3. Leertastendruck beginnt umzuschalten? Das versteh ich irgendwie nicht ganz.

  • Noch ein Paar Kleinigkeiten habe ich entdeckt.

    In Zeile 79 setzt du den Smoothingmode für das Fenster, aber nicht für den Puffer auf den du eigentlich zeichnest.
    einfach ein _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2) daraus machen, und schon ist alles ganz glatt ;)

    In Zeile 192 wird auch ein Sleep(10) benötigt. Sonst überprüft das Skript im Eiltempo alle paar ns die Mausposition.

    Sleep(1) ist in AutoIt das gleiche wie Sleep(10).
    Der Sleep Befehl funktioniert leider nur in 10er schritten. (10, 20, ...)

    lg
    M

  • So, die neueste Version ist Online.

    @Marsi: Danke für die Hinweise. Ich habe jetzt alles geändert. Und das mit Sleep wusste ich gar nicht. Tja, man lernt nie aus.
    @xXxProGamerxXx: So, eine Superwaffe gibts jezt auch. Hoffentlich gefällt sie dir ^^

  • Es freut mich wikrich das es euch gefällt.
    WASD geht eigentlich schon immer. An dem habe ich nichts geändert.
    Ich hoffe ihr habt noch ein paar Ideen um es noch ein wenig aufzumotzen. Dann kann daraus ja mal noch etwas anständiges werden. ;)

  • So, es gibt wieder mal eine neue Version. Für die Änderungen siehe Post #1. Viel Spass damit.

    PS: Verbesserungsvorschläge sind natürlich nach wie vor erwünscht :thumbup:

  • Nice^^
    ne Idee:
    Das "Raumschiff" soll immer in bewegung sein.
    also das immer in die Richtung fliegt wo das Raumschiff hinguckt. (auch wenns sehr langsam ist) sons kann man campen^^
    und
    man soll 3 Leben haben^^ ;)

    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:

  • So, und wieder mal gibt es eine neue Version.

    @xXxProGamerxXx: Ich hoffe es ist so wie du es dir gedacht hast. Ich bin mir aber noch nicht so sicher ob ich es so lasse soll.
    hellboy3: Das wäre eh gekommen. Hab mich selber genervt, dass ichs immer wieder neu starten musste :rolleyes:

    An Alle: Ich würde mich freuen wenn ihr mir eure Meinung zum selber Bewegen des Raumschiffs sagt. Und fleissig neue Ideen posten :thumbup: