GDI+: PacMan

  • Hallo Leute,

    der ein odere andere hat bestimmt schon gemerkt das ich mich auch mal an PacMan versuche. Um einfach bei GDI+ einzusteigen. Hab ja auch schon mehrere Threads erstellt bei H&U.
    Deswegen wollte ich jetzt mal den aktuellen Stand bekannt geben, und natürlich immer das Neuste updaten. Und natürlich will ich von auch Verbesserungen und Kritiken hören (natürlich auch Lob :P).
    Gesteuert wird das ganze über die Pfeiltasten, so wie ihr es kennt. Und sagt mal was ob und wie doll es bei euch laggt. Weil das ist noch ein großer Punkt, den ich versuche wegzubekommen. Übrigens wenn ich während des Spiels die Pause-Taste drückt kommt ein Menü. Dieses muss ich aber auch noch ein bissl bearbeiten (siehe Threads von mir bei H&U).

    Spoiler anzeigen
    [autoit]

    #include <Array.au3>
    #include <Date.au3>
    #include <GDIPlus.au3>
    #include <GDIP.au3>
    #include <GUIConstants.au3>
    #include <Misc.au3>
    #Include <WinAPI.au3>
    #include <WindowsConstants.au3>
    #include <StructureConstants.au3>

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

    Opt("GUIOnEventMode", 1)

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

    Global $iMenuReturn, $aTimer[7], $Hold[4], $iCountPoints, $iCountCurrPoints, $iX, $iY, $aPoints, $aBG[1][1], $sMap, $aSquarePos[4]
    Global $aEnableForGo[4] ; [links, oben, rechts, unten]
    Global $iGuiWidth = 600
    Global $iGuiHeight = 700
    Global $iAngleStart = 20
    Global $iAngleEnd = 320
    Global $piewidth = 0
    Global $pieheight = 320

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

    HotKeySet("{PAUSE}", "_MenuShow")

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

    $hDLL = DllOpen("user32.dll")

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

    $hGuiGame = GUICreate("PacMan made by m-obi", $iGuiWidth, $iGuiHeight)
    GUISetBkColor(0x696969)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    GUISetState()

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

    _GDIPlus_Startup ()

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

    $hGraphicGame = _GDIPlus_GraphicsCreateFromHWND($hGuiGame)
    $hBitmapGame = _GDIPlus_BitmapCreateFromGraphics($iGuiWidth, $iGuiHeight, $hGraphicGame)
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmapGame)

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

    $hPen_Line = _GDIPlus_PenCreate(0xFF000000, 5)
    $hBrush_Pac = _GDIPlus_BrushCreateSolid(0xFFFFFF00)
    $hBrush_Way = _GDIPlus_BrushCreateSolid(0xFFEEEEEE)
    $hBrush_Start = _GDIPlus_BrushCreateSolid(0xFF00FF00)
    $hBrush_End = _GDIPlus_BrushCreateSolid(0xFFFF0000)
    $Brush2 = _GDIPlus_BrushCreateSolid(0xFF000000)
    $Brush3 = _GDIPlus_BrushCreateSolid(0xFF636363)
    $Brush_Red = _GDIPlus_BrushCreateSolid(0xFFFF0000)
    $Brush_Green = _GDIPlus_BrushCreateSolid(0xFF00FF00)

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

    _NewGame()

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

    While 1
    Switch $iMenuReturn
    Case 0
    Opt("MouseCoordMode", 1)
    Opt("GUIOnEventMode", 1)
    HotKeySet("{PAUSE}", "_MenuShow")
    _Time("start")
    Case 1
    _Exit()
    EndSwitch

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

    _SquarePos()

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

    If $aBG[Int($aSquarePos[1])][Int($aSquarePos[0])] = 3 And StringRight($aSquarePos[0], 1) = 5 And StringRight($aSquarePos[1], 1) = 5 Then
    _Time("reset")
    AdlibUnRegister("_SquarePos")
    AdlibUnRegister("_AniPacMan")
    MsgBox(0, "Test", "Test")
    _NewGame()
    EndIf

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

    If TimerDiff($aTimer[1]) > 200 Then _Draw(1)

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

    ;ToolTip($aSquarePos[0] & @CRLF & $aSquarePos[1] & @CRLF & $aSquarePos[2] & @CRLF & $aSquarePos[3])

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

    If $aSquarePos[0] > 0.9 Then $aEnableForGo[0] = $aBG[Int($aSquarePos[1])][Int($aSquarePos[0]) - 1]
    If $aSquarePos[1] > 0.9 Then $aEnableForGo[1] = $aBG[Int($aSquarePos[1]) - 1][Int($aSquarePos[0])]
    If $aSquarePos[0] < 11 Then $aEnableForGo[2] = $aBG[Int($aSquarePos[1])][Int($aSquarePos[0]) + 1]
    If $aSquarePos[1] < 11 Then $aEnableForGo[3] = $aBG[Int($aSquarePos[1]) + 1][Int($aSquarePos[0])]

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

    _SquarePos()

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

    $aEnableForGo[0] = _Iif($aSquarePos[0] = 0.5 Or (Not $aEnableForGo[0] And StringRight($aSquarePos[0], 1) = 5), 0, 1)
    $aEnableForGo[1] = _Iif($aSquarePos[1] = 0.5 Or (Not $aEnableForGo[1] And StringRight($aSquarePos[1], 1) = 5), 0, 1)
    $aEnableForGo[2] = _Iif($aSquarePos[0] = 11.5 Or (Not $aEnableForGo[2] And StringRight($aSquarePos[0], 1) = 5), 0, 1)
    $aEnableForGo[3] = _Iif($aSquarePos[1] = 11.5 Or (Not $aEnableForGo[3] And StringRight($aSquarePos[1], 1) = 5), 0, 1)

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

    If Not _IsPressed("25", $hDLL) Then $Hold[0] = 0
    If Not _IsPressed("26", $hDLL) Then $Hold[1] = 0
    If Not _IsPressed("27", $hDLL) Then $Hold[2] = 0
    If Not _IsPressed("28", $hDLL) Then $Hold[3] = 0

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

    If WinActive($hGuiGame) And StringRight($aSquarePos[0], 1) = 5 Then
    Select
    Case _IsPressed("26", $hDLL) And $aEnableForGo[1] ;oben
    _Time("start")
    If Not $Hold[1] Then $aTimer[3] = TimerInit()
    $Hold[1] = 1
    $iAngleStart = 290
    $iY -= 10
    _Draw()
    While _IsPressed("26", $hDLL) And TimerDiff($aTimer[3]) < 300
    Sleep(10)
    WEnd
    Case _IsPressed("28", $hDLL) And $aEnableForGo[3] ;unten
    _Time("start")
    If Not $Hold[3] Then $aTimer[5] = TimerInit()
    $Hold[3] = 1
    $iAngleStart = 110
    $iY += 10
    _Draw()
    While _IsPressed("28", $hDLL) And TimerDiff($aTimer[5]) < 300
    Sleep(10)
    WEnd
    EndSelect
    EndIf

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

    _SquarePos()

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

    If WinActive($hGuiGame) And StringRight($aSquarePos[1], 1) = 5 Then
    Select
    Case _IsPressed("25", $hDLL) And $aEnableForGo[0] ;links
    _Time("start")
    If Not $Hold[0] Then $aTimer[2] = TimerInit()
    $Hold[0] = 1
    $iAngleStart = 200
    $iX -= 10
    _Draw()
    While _IsPressed("25", $hDLL) And TimerDiff($aTimer[2]) < 300
    Sleep(10)
    WEnd
    Case _IsPressed("27", $hDLL) And $aEnableForGo[2] ;rechts
    _Time("start")
    If Not $Hold[2] Then $aTimer[4] = TimerInit()
    $Hold[2] = 1
    $iAngleStart = 20
    $iX += 10
    _Draw()
    While _IsPressed("27", $hDLL) And TimerDiff($aTimer[4]) < 300
    Sleep(10)
    WEnd
    EndSelect
    EndIf
    WEnd

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

    Func _NewGame()
    $iAngleStart = 20
    $iAngleEnd = 320
    $iCheckFinish = 0
    $iCountPoints = 0
    $iCountCurrPoints = 0
    $iX = 0
    $iY = 0
    ReDim $aBG[12][12]
    $sMap = "2,1,1,1,1,1,1,1,0,1,1,1;" & _
    "0,1,0,1,0,0,0,1,0,1,0,0;" & _
    "0,0,0,1,0,1,0,1,0,1,0,1;" & _
    "1,1,1,1,1,1,1,1,0,1,0,1;" & _
    "1,0,0,0,0,0,1,0,0,1,1,1;" & _
    "1,0,1,1,1,0,1,1,1,1,0,0;" & _
    "1,0,1,0,1,0,1,0,0,1,0,1;" & _
    "1,1,1,1,1,1,1,0,1,1,0,1;" & _
    "0,0,1,0,0,0,0,0,0,1,1,1;" & _
    "1,0,1,1,1,1,1,1,1,1,0,0;" & _
    "1,0,1,0,0,1,0,0,0,1,0,3;" & _
    "1,1,1,1,1,1,0,1,1,1,1,1"
    $sSplit_1 = StringSplit($sMap, ";")
    For $y = 1 To $sSplit_1[0]
    $sSplit_2 = StringSplit($sSplit_1[$y], ",")
    For $x = 1 To $sSplit_2[0]
    $aBG[$y - 1][$x - 1] = Int($sSplit_2[$x])
    Next
    Next
    _ArrayDisplay($aBG)
    $aPoints = $aBG
    _DrawLabel($hBuffer, "Zeit: 00:00:00.0", 20, 650, 140, -1, "Arial", 14)
    _SquarePos()
    _BG()
    _DrawPoints()

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

    AdlibRegister("_SquarePos", 50)
    AdlibRegister("_AniPacMan", 400)

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

    $aTimer[6] = TimerInit()
    Do
    Until TimerDiff($aTimer[6]) > 1000

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

    $iMsgBox = MsgBox(36, "Frage", "Wollen sie das Spiel starten?" & @CRLF & @CRLF & "(Dient als Platzhalter, hier kommt noch ein mit GDI+ erstelltes Fenster hin.)")
    If $iMsgBox = 7 Then _Exit()
    EndFunc

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

    Func _Draw($iTyp = 0)
    Local $iTime, $iHour, $iMin, $iSec, $iMsec
    If WinActive($hGuiGame) Then
    AdlibUnRegister("_SquarePos")
    _GDIPlus_GraphicsSetSmoothingMode_New($hBuffer, 3)
    For $i = 0 To 2 Step 2
    Switch $aBG[Int($aSquarePos[$i + 1])][Int($aSquarePos[$i])]
    Case 1
    _GDIPlus_GraphicsFillRect($hBuffer, Int($aSquarePos[$i]) * 50, Int($aSquarePos[$i + 1]) * 50, 50, 50, $hBrush_Way)
    Case 2
    _GDIPlus_GraphicsFillRect($hBuffer, Int($aSquarePos[$i]) * 50, Int($aSquarePos[$i + 1]) * 50, 50, 50, $hBrush_Start)
    Case 3
    _GDIPlus_GraphicsFillRect($hBuffer, Int($aSquarePos[$i]) * 50, Int($aSquarePos[$i + 1]) * 50, 50, 50, $hBrush_End)
    EndSwitch
    Next
    If StringRight($aSquarePos[0], 1) = 5 And StringRight($aSquarePos[1], 1) = 5 And $aPoints[Int($aSquarePos[1])][Int($aSquarePos[0])] = 1 Then
    $aPoints[Int($aSquarePos[1])][Int($aSquarePos[0])] = 0
    $iCountCurrPoints += 1
    EndIf
    _GDIPlus_GraphicsSetSmoothingMode_New($hBuffer, 4)
    If $aPoints[Int($aSquarePos[1])][Int($aSquarePos[0])] = 1 Then _GDIPlus_GraphicsFillEllipse($hBuffer, Int($aSquarePos[0]) * 50 + 15, Int($aSquarePos[1]) * 50 + 15, 20, 20, $Brush3)
    If $aPoints[Int($aSquarePos[3])][Int($aSquarePos[2])] = 1 Then _GDIPlus_GraphicsFillEllipse($hBuffer, Int($aSquarePos[2]) * 50 + 15, Int($aSquarePos[3]) * 50 + 15, 20, 20, $Brush3)
    AdlibRegister("_SquarePos", 50)
    While 1
    Switch $iTyp
    Case 0
    $iTyp = _Iif(TimerDiff($aTimer[1]) > 200, 1, 2)
    Case 1
    _GDIPlus_GraphicsFillPie($hBuffer, $iX + 2, $iY + 2, 46, 46, $iAngleStart, $iAngleEnd, $hBrush_Pac)
    ExitLoop
    Case 2
    _GDIPlus_GraphicsFillPie($hBuffer, $iX + 2, $iY + 2, 46, 46, $iAngleStart - 15, $iAngleEnd + 30, $hBrush_Pac)
    ExitLoop
    EndSwitch
    WEnd
    _GDIPlus_GraphicsSetSmoothingMode_New($hBuffer, 3)
    _GDIPlus_GraphicsDrawLine($hBuffer, 0, 602, $iGuiWidth, 602, $hPen_Line)
    _DrawLabel($hBuffer, "Punkte: " & $iCountCurrPoints, 20, 620, 100, -1, "Arial", 14)
    $iTime = _Time("read")
    ;ConsoleWrite(@CRLF & $iTime)
    If $iTime <> 0 Then
    _TicksToTime(Int($iTime), $iHour, $iMin, $iSec)
    $sTime = StringFormat("%02i:%02i:%02i.%1i", $iHour, $iMin, $iSec, StringTrimRight(StringRight(Int($iTime), 3), 2))
    _DrawLabel($hBuffer, "Zeit: " & $sTime, 20, 650, 140, -1, "Arial", 14)
    EndIf
    _GDIPlus_GraphicsDrawImageRect($hGraphicGame, $hBitmapGame, 0, 0, $iGuiWidth, $iGuiHeight)
    EndIf
    EndFunc

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

    Func _DrawPoints()
    _GDIPlus_GraphicsSetSmoothingMode_New($hBuffer, 4)
    If StringRight($aSquarePos[0], 1) = 5 And StringRight($aSquarePos[1], 1) = 5 Then $aPoints[Int($aSquarePos[1])][Int($aSquarePos[0])] = 0
    For $y = 0 To UBound($aPoints) - 1
    For $x = 0 To UBound($aPoints, 2) - 1
    If $aPoints[$y][$x] = 1 Then
    _GDIPlus_GraphicsFillEllipse($hBuffer, $x * 50 + 15, $y * 50 + 15, 20, 20, $Brush3)
    $iCountPoints += 1
    EndIf
    Next
    Next
    _GDIPlus_GraphicsSetSmoothingMode_New($hBuffer, 3)
    EndFunc

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

    Func _AniPacMan()
    _Draw(2)
    $aTimer[1] = TimerInit()
    EndFunc

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

    Func _BG()
    ;ConsoleWrite(@CRLF & "_BG")
    _GDIPlus_GraphicsFillRect($hBuffer, 0, 0, 600, 600, $Brush2)
    For $y = 0 To UBound($aBG) - 1
    For $x = 0 To UBound($aBG, 2) - 1
    Switch $aBG[$y][$x]
    Case 1
    _GDIPlus_GraphicsFillRect($hBuffer, $x * 50, $y * 50, 50, 50, $hBrush_Way)
    Case 2
    _GDIPlus_GraphicsFillRect($hBuffer, $x * 50, $y * 50, 50, 50, $hBrush_Start)
    Case 3
    _GDIPlus_GraphicsFillRect($hBuffer, $x * 50, $y * 50, 50, 50, $hBrush_End)
    EndSwitch
    Next
    Next
    EndFunc

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

    Func _SquarePos()
    ;ConsoleWrite(@CRLF & "_SquarePos")
    $aSquarePos[0] = ($iX / 50) + 0.5
    $aSquarePos[1] = ($iY / 50) + 0.5
    Select
    Case StringRight($aSquarePos[0], 1) = 5 And StringRight($aSquarePos[1], 1) = 5
    $aSquarePos[2] = $aSquarePos[0]
    $aSquarePos[3] = $aSquarePos[1]
    Case StringRight($aSquarePos[0], 1) < 5 And StringRight($aSquarePos[1], 1) = 5
    $aSquarePos[2] = $aSquarePos[0] - 1
    $aSquarePos[3] = $aSquarePos[1]
    Case StringRight($aSquarePos[0], 1) = 5 And StringRight($aSquarePos[1], 1) < 5
    $aSquarePos[2] = $aSquarePos[0]
    $aSquarePos[3] = $aSquarePos[1] - 1
    Case StringRight($aSquarePos[0], 1) > 5 And StringRight($aSquarePos[1], 1) = 5
    $aSquarePos[2] = $aSquarePos[0] + 1
    $aSquarePos[3] = $aSquarePos[1]
    Case StringRight($aSquarePos[0], 1) = 5 And StringRight($aSquarePos[1], 1) > 5
    $aSquarePos[2] = $aSquarePos[0]
    $aSquarePos[3] = $aSquarePos[1] + 1
    EndSelect
    EndFunc

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

    Func _Time($sCommand)
    Local Static $iTime
    Switch $sCommand
    Case "start"
    If $aTimer[0] = "" Then $aTimer[0] = TimerInit()
    Case "stop"
    If $aTimer[0] <> "" Then
    $iTime += TimerDiff($aTimer[0])
    $aTimer[0] = ""
    Return $iTime
    Else
    SetError(-1, 0, 0)
    EndIf
    Case "read"
    If $aTimer[0] <> "" Then
    $iTime += TimerDiff($aTimer[0])
    $aTimer[0] = TimerInit()
    Return $iTime
    EndIf
    Case "reset"
    $iTime = 0
    $aTimer[0] = ""
    EndSwitch
    EndFunc

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

    Func _MenuShow()
    _Time("stop")

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

    Local $iWidth = 200
    Local $iHeight = 300
    Local $iRadius = 30
    Local $iOffset = 3
    Local $aButton[3]
    Local $aHover[3] = [0, 0, 0]
    Local $aPress[3] = [0, 0, 0]
    Local $aPressed[3] = [0, 0, 0]
    Local $aPressBefore[3] = [0, 0, 0]

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

    HotKeySet("{PAUSE}")
    GUISetState(@SW_DISABLE, $hGuiGame)
    Opt("GUIOnEventMode", 0)

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

    $hGuiMenu = GUICreate("Menü", $iWidth + 6, $iHeight + 6, -1, -1, 0, $WS_EX_LAYERED)
    ;~ $hGuiMenu1 = GUICreate("", 80, 25, -1, -1, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOPMOST, $hGuiMenu)
    ;~ GUISetBkColor(0xF0F0F0)
    ;~ _WinAPI_SetLayeredWindowAttributes($hGuiMenu1, 0xF0F0F0)
    ;~ $hContinue = GUICtrlCreateButton("Weiter", 0, 0, 80, 25)
    ;~ WinSetTrans($hGuiMenu1, "", 180)

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

    $hGraphicMenu = _GDIPlus_GraphicsCreateFromHWND($hGuiMenu)
    $hBitmapMenu = _GDIPlus_BitmapCreateFromGraphics($iWidth + 6, $iHeight + 6, $hGraphicMenu)
    $hBufferMenu = _GDIPlus_ImageGetGraphicsContext($hBitmapMenu)
    $hScreenDC = _WinAPI_GetDC($hGuiMenu)
    $hHBitmapMenu = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmapMenu)
    $hDC = _WinAPI_CreateCompatibleDC($hScreenDC)
    _WinAPI_SelectObject($hDC, $hHBitmapMenu)
    ; _WinAPI_UpdateLayeredWindow parameters
    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", $iWidth + 6)
    DllStructSetData($tSize, "Y", $iHeight + 6)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", 0xFF)
    DllStructSetData($tBlend, "Format", 1)
    $tPoint = DllStructCreate($tagPOINT)
    $pPoint = DllStructGetPtr($tPoint)
    DllStructSetData($tPoint, "X", 0)
    DllStructSetData($tPoint, "Y", 0)

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

    $hBrush_BG = _GDIPlus_BrushCreateSolid(0xAAFFA500)
    $hPen_BG = _GDIPlus_PenCreate(0xFF000000, 3)
    _GDIPlus_GraphicsFillRect($hBufferMenu, $iOffset, $iRadius + $iOffset, $iRadius, $iHeight - $iRadius * 2, $hBrush_BG)
    _GDIPlus_GraphicsFillPie($hBufferMenu, $iOffset, $iOffset, $iRadius * 2, $iRadius * 2, 180, 90, $hBrush_BG)
    _GDIPlus_GraphicsFillRect($hBufferMenu, $iRadius + $iOffset, $iOffset, $iWidth - $iRadius * 2, $iRadius, $hBrush_BG)
    _GDIPlus_GraphicsFillPie($hBufferMenu, $iWidth - $iRadius * 2 + $iOffset, $iOffset, $iRadius * 2, $iRadius * 2, 270, 90, $hBrush_BG)
    _GDIPlus_GraphicsFillRect($hBufferMenu, $iWidth - $iRadius + $iOffset, $iRadius + $iOffset, $iRadius, $iHeight - $iRadius * 2, $hBrush_BG)
    _GDIPlus_GraphicsFillPie($hBufferMenu, $iWidth - $iRadius * 2 + $iOffset, $iHeight - $iRadius * 2 + $iOffset, $iRadius * 2, $iRadius * 2, 0, 90, $hBrush_BG)
    _GDIPlus_GraphicsFillRect($hBufferMenu, $iRadius + $iOffset, $iHeight - $iRadius + $iOffset, $iWidth - $iRadius * 2, $iRadius, $hBrush_BG)
    _GDIPlus_GraphicsFillPie($hBufferMenu, $iOffset, $iHeight - $iRadius * 2 + $iOffset, $iRadius * 2, $iRadius * 2, 90, 90, $hBrush_BG)
    _GDIPlus_GraphicsFillRect($hBufferMenu, $iRadius + $iOffset, $iRadius + $iOffset, $iWidth - $iRadius * 2, $iHeight - $iRadius * 2, $hBrush_BG)
    _GDIPlus_GraphicsSetSmoothingMode_New($hBufferMenu, 4)
    _GDIPlus_GraphicsDrawLine($hBufferMenu, $iOffset, $iHeight - $iRadius + $iOffset, $iOffset, $iRadius + $iOffset, $hPen_BG)
    _GDIPlus_GraphicsDrawArc($hBufferMenu, $iOffset, $iOffset, $iRadius * 2, $iRadius * 2, 180, 90, $hPen_BG)
    _GDIPlus_GraphicsDrawLine($hBufferMenu, $iRadius + $iOffset, $iOffset, $iWidth - $iRadius + $iOffset, $iOffset, $hPen_BG)
    _GDIPlus_GraphicsDrawArc($hBufferMenu, $iWidth - $iRadius * 2 + $iOffset, $iOffset, $iRadius * 2, $iRadius * 2, 270, 90, $hPen_BG)
    _GDIPlus_GraphicsDrawLine($hBufferMenu, $iWidth + $iOffset, $iRadius + $iOffset, $iWidth + $iOffset, $iHeight - $iRadius + $iOffset, $hPen_BG)
    _GDIPlus_GraphicsDrawArc($hBufferMenu, $iWidth - $iRadius * 2 + $iOffset, $iHeight - $iRadius * 2 + $iOffset, $iRadius * 2, $iRadius * 2, 0, 90, $hPen_BG)
    _GDIPlus_GraphicsDrawLine($hBufferMenu, $iRadius + $iOffset, $iHeight + $iOffset, $iWidth - $iRadius + $iOffset, $iHeight + $iOffset, $hPen_BG)
    _GDIPlus_GraphicsDrawArc($hBufferMenu, $iOffset, $iHeight - $iRadius * 2 + $iOffset, $iRadius * 2, $iRadius * 2, 90, 90, $hPen_BG)
    _GDIPlus_GraphicsSetSmoothingMode_New($hBufferMenu, 3)

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

    $aButton[0] = _DrawButton($hBufferMenu, $hBitmapMenu, "Weiter", -1, 30, 120, 30, "Arial", 12)
    $aButton[1] = _DrawButton($hBufferMenu, $hBitmapMenu, "Hilfe", -1, 80, 120, 30, "Arial", 12)
    $aButton[2] = _DrawButton($hBufferMenu, $hBitmapMenu, "Beenden", -1, 150, 120, 30, "Arial", 12)

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

    $hHBitmapMenu = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmapMenu)
    _WinAPI_SelectObject($hDC, $hHBitmapMenu)
    _WinAPI_UpdateLayeredWindow($hGuiMenu, $hScreenDC, 0, $pSize, $hDC, $pSource, 0, $pBlend, 2)

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

    GUISetState(@SW_SHOW, $hGuiMenu)

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

    Opt("MouseCoordMode", 0)

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

    While 1
    For $i = 0 To UBound($aButton) - 1
    $sTextButton = DllStructGetData($aButton[$i], "Text")
    $iLeftButton = DllStructGetData($aButton[$i], "Left")
    $iTopButton = DllStructGetData($aButton[$i], "Top")
    $iWidthButton = DllStructGetData($aButton[$i], "Width")
    $iHeightButton = DllStructGetData($aButton[$i], "Height")
    $iRadiusButton = DllStructGetData($aButton[$i], "Radius")
    $aPos = MouseGetPos()
    ;ToolTip($aPos[0] & "|" & $aPos[1])
    If ($aPos[0] - $iLeftButton - $iRadiusButton) ^ 2 / $iRadiusButton ^ 2 + ($aPos[1] - $iTopButton - $iRadiusButton) ^ 2 / $iRadiusButton ^ 2 <= 1 _
    Or ($aPos[0] - $iLeftButton - $iWidthButton + $iRadiusButton) ^ 2 / $iRadiusButton ^ 2 + ($aPos[1] - $iTopButton - $iRadiusButton) ^ 2 / $iRadiusButton ^ 2 <= 1 _
    Or ($aPos[0] - $iLeftButton - $iWidthButton + $iRadiusButton) ^ 2 / $iRadiusButton ^ 2 + ($aPos[1] - $iTopButton - $iHeightButton + $iRadiusButton) ^ 2 / $iRadiusButton ^ 2 <= 1 _
    Or ($aPos[0] - $iLeftButton - $iRadiusButton) ^ 2 / $iRadiusButton ^ 2 + ($aPos[1] - $iTopButton - $iHeightButton + $iRadiusButton) ^ 2 / $iRadiusButton ^ 2 <= 1 _
    Or ($aPos[0] > $iLeftButton And $aPos[0] < ($iLeftButton + $iWidthButton) And $aPos[1] > ($iTopButton + $iRadiusButton) And $aPos[1] < ($iTopButton + $iHeightButton - $iRadiusButton)) _
    Or ($aPos[0] > ($iLeftButton + $iRadiusButton) And $aPos[0] < ($iLeftButton + $iWidthButton - $iRadiusButton) And $aPos[1] > $iTopButton And $aPos[1] < ($iTopButton + $iHeightButton)) Then

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

    If _IsPressed("01") And Not $aPress[$i] And Not $aPressBefore[$i] Then
    _DrawButton($hBufferMenu, $hBitmapMenu, $sTextButton, $iLeftButton, $iTopButton, $iWidthButton, $iHeightButton, "Arial", 12, 3)
    $aPress[$i] = 1
    $aPressed[$i] = 1
    EndIf
    If Not _IsPressed("01") Then
    $aPressed[$i] = 0
    $aPressBefore[$i] = 0
    If $aPress[$i] Then
    $aHover[$i] = 0
    $aPress[$i] = 0
    Switch $sTextButton
    Case "Weiter", "Beenden"
    _WinAPI_DeleteObject($hHBitmapMenu)
    _GDIPlus_PenDispose($hPen_BG)
    _GDIPlus_BrushDispose($hBrush_BG)
    _WinAPI_DeleteDC($hDC)
    _WinAPI_ReleaseDC($hGuiMenu, $hScreenDC)
    _GDIPlus_GraphicsDispose($hBufferMenu)
    _GDIPlus_BitmapDispose($hBitmapMenu)
    $tSize = ""
    $tSource = ""
    $tBlend = ""
    $tPoint = ""
    Switch $sTextButton
    Case "Weiter"
    ;ConsoleWrite(@CRLF & "-- Weiter --")
    $iMenuReturn = 0
    Case "Beenden"
    ;ConsoleWrite(@CRLF & "-- Beenden --")
    $iMenuReturn = 1
    EndSwitch
    GUISetState(@SW_ENABLE, $hGuiGame)
    GUIDelete($hGuiMenu)
    Return
    Case "Hilfe"
    ;ConsoleWrite(@CRLF & "-- Hilfe --")
    EndSwitch
    EndIf
    EndIf
    If Not $aHover[$i] And Not $aPress[$i] Then
    _DrawButton($hBufferMenu, $hBitmapMenu, $sTextButton, $iLeftButton, $iTopButton, $iWidthButton, $iHeightButton, "Arial", 12, 2)
    $aHover[$i] = 1
    EndIf
    Else
    $aPressBefore[$i] = 0
    If _IsPressed("01") Then
    If Not $aPressed[$i] Then $aPressBefore[$i] = 1
    Else
    $aPressed[$i] = 0
    EndIf
    If $aHover[$i] Or $aPress[$i] Then
    _DrawButton($hBufferMenu, $hBitmapMenu, $sTextButton, $iLeftButton, $iTopButton, $iWidthButton, $iHeightButton, "Arial", 12)
    $aPress[$i] = 0
    $aHover[$i] = 0
    EndIf
    EndIf
    $hHBitmapMenu = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmapMenu)
    _WinAPI_SelectObject($hDC, $hHBitmapMenu)
    _WinAPI_UpdateLayeredWindow($hGuiMenu, $hScreenDC, 0, $pSize, $hDC, $pSource, 0, $pBlend, 2)
    Next
    Sleep(50)
    WEnd
    EndFunc

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

    Func _DrawLabel($hGraphic, $sText, $iLeft, $iTop, $iWidth = -1, $iHeight = -1, $sFont = "Arial", $iFontSize = 10)
    If WinActive($hGuiGame) Then
    Opt("PixelCoordMode", 2)
    Local $iGuiColor = PixelGetColor($iLeft - 2, $iTop - 2, $hGuiGame)
    ;ConsoleWrite(@CRLF & Hex($iGuiColor, 6))
    Local $hBrush_BG = _GDIPlus_BrushCreateSolid("0xFF" & Hex($iGuiColor, 6))
    Local $hBrush_Text = _GDIPlus_BrushCreateSolid(0xFF000000)
    Local $hFormat = _GDIPlus_StringFormatCreate()
    Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
    Local $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, 0)
    Local $tLayout = _GDIPlus_RectFCreate($iLeft, $iTop, 0, 0)
    Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sText, $hFont, $tLayout, $hFormat)
    Local $iWidthText = Int(DllStructGetData($aInfo[0], "Width"))
    Local $iHeightText = Int(DllStructGetData($aInfo[0], "Height"))

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

    If $iWidth = -1 Then $iWidth = $iWidthText
    If $iHeight = -1 Then $iHeight = $iHeightText
    If $iWidth < $iWidthText Or $iHeight < $iHeightText Then Return SetError(-1, 0, 0)

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

    _GDIPlus_GraphicsFillRect($hGraphic, $iLeft, $iTop, $iWidth, $iHeight, $hBrush_BG)
    _GDIPlus_GraphicsDrawStringEx($hGraphic, $sText, $hFont, $tLayout, $hFormat, $hBrush_Text)

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

    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush_Text)
    Opt("PixelCoordMode", 1)
    EndIf
    EndFunc

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

    Func _DrawButton($hGraphic, $hBitmap, $sText, $iLeft, $iTop, $iWidth, $iHeight, $sFont = "Arial", $iFontSize = 10, $iState = 1)
    Local $iRadius = 10
    Local $iWidthBitmap = _GDIPlus_ImageGetWidth($hBitmap)
    Switch $iState
    Case 1 ; normal
    ;ConsoleWrite(@CRLF & $sText & " nicht hover")
    Local $hBrush_BG = _GDIPlus_BrushCreateSolid(0xC8FFA500)
    Case 2 ; hover
    ;ConsoleWrite(@CRLF & $sText & " hover")
    Local $hBrush_BG = _GDIPlus_BrushCreateSolid(0xC800FF00)
    Case 3 ; pressed
    ;ConsoleWrite(@CRLF & $sText & " gedrückt")
    Local $hBrush_BG = _GDIPlus_BrushCreateSolid(0xC8FF0000)
    EndSwitch
    Local $hBrush_Text = _GDIPlus_BrushCreateSolid(0xFF000000)
    Local $hPen = _GDIPlus_PenCreate(0xFF000000, 2)
    Local $hFormat = _GDIPlus_StringFormatCreate()
    Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
    Local $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, 0)
    Local $tLayout = _GDIPlus_RectFCreate($iLeft, $iTop, 0, 0)
    Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sText, $hFont, $tLayout, $hFormat)
    Local $iWidthText = Int(DllStructGetData($aInfo[0], "Width"))
    Local $iHeightText = Int(DllStructGetData($aInfo[0], "Height"))

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

    If $iLeft = -1 Then $iLeft = ($iWidthBitmap - $iWidth) / 2

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

    _GDIPlus_GraphicsFillRect($hGraphic, $iLeft, $iRadius + $iTop, $iRadius, $iHeight - $iRadius * 2, $hBrush_BG)
    _GDIPlus_GraphicsFillPie($hGraphic, $iLeft, $iTop, $iRadius * 2, $iRadius * 2, 180, 90, $hBrush_BG)
    _GDIPlus_GraphicsFillRect($hGraphic, $iRadius + $iLeft, $iTop, $iWidth - $iRadius * 2, $iRadius, $hBrush_BG)
    _GDIPlus_GraphicsFillPie($hGraphic, $iWidth - $iRadius * 2 + $iLeft, $iTop, $iRadius * 2, $iRadius * 2, 270, 90, $hBrush_BG)
    _GDIPlus_GraphicsFillRect($hGraphic, $iWidth - $iRadius + $iLeft, $iRadius + $iTop, $iRadius, $iHeight - $iRadius * 2, $hBrush_BG)
    _GDIPlus_GraphicsFillPie($hGraphic, $iWidth - $iRadius * 2 + $iLeft, $iHeight - $iRadius * 2 + $iTop, $iRadius * 2, $iRadius * 2, 0, 90, $hBrush_BG)
    _GDIPlus_GraphicsFillRect($hGraphic, $iRadius + $iLeft, $iHeight - $iRadius + $iTop, $iWidth - $iRadius * 2, $iRadius, $hBrush_BG)
    _GDIPlus_GraphicsFillPie($hGraphic, $iLeft, $iHeight - $iRadius * 2 + $iTop, $iRadius * 2, $iRadius * 2, 90, 90, $hBrush_BG)
    _GDIPlus_GraphicsFillRect($hGraphic, $iRadius + $iLeft, $iRadius + $iTop, $iWidth - $iRadius * 2, $iHeight - $iRadius * 2, $hBrush_BG)
    _GDIPlus_GraphicsSetSmoothingMode_New($hGraphic, 4)
    _GDIPlus_GraphicsDrawLine($hGraphic, $iLeft, $iHeight - $iRadius + $iTop, $iLeft, $iRadius + $iTop, $hPen)
    _GDIPlus_GraphicsDrawArc($hGraphic, $iLeft, $iTop, $iRadius * 2, $iRadius * 2, 180, 90, $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $iRadius + $iLeft, $iTop, $iWidth - $iRadius + $iLeft, $iTop, $hPen)
    _GDIPlus_GraphicsDrawArc($hGraphic, $iWidth - $iRadius * 2 + $iLeft, $iTop, $iRadius * 2, $iRadius * 2, 270, 90, $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $iWidth + $iLeft, $iRadius + $iTop, $iWidth + $iLeft, $iHeight - $iRadius + $iTop, $hPen)
    _GDIPlus_GraphicsDrawArc($hGraphic, $iWidth - $iRadius * 2 + $iLeft, $iHeight - $iRadius * 2 + $iTop, $iRadius * 2, $iRadius * 2, 0, 90, $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $iRadius + $iLeft, $iHeight + $iTop, $iWidth - $iRadius + $iLeft, $iHeight + $iTop, $hPen)
    _GDIPlus_GraphicsDrawArc($hGraphic, $iLeft, $iHeight - $iRadius * 2 + $iTop, $iRadius * 2, $iRadius * 2, 90, 90, $hPen)
    _GDIPlus_GraphicsSetSmoothingMode_New($hGraphic, 3)

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

    $tLayout = _GDIPlus_RectFCreate($iLeft + (($iWidth - $iWidthText) / 2), $iTop + (($iHeight - $iHeightText) / 2), 0, 0)
    _GDIPlus_GraphicsDrawStringEx($hGraphic, $sText, $hFont, $tLayout, $hFormat, $hBrush_Text)

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

    $hStruct = DllStructCreate("char Text[10]; int Left; int Top; int Width; int Height; int Radius")
    DllStructSetData($hStruct, "Text", $sText)
    DllStructSetData($hStruct, "Left", $iLeft)
    DllStructSetData($hStruct, "Top", $iTop)
    DllStructSetData($hStruct, "Width", $iWidth)
    DllStructSetData($hStruct, "Height", $iHeight)
    DllStructSetData($hStruct, "Radius", $iRadius)

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

    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BrushDispose($hBrush_Text)
    _GDIPlus_BrushDispose($hBrush_BG)

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

    Return $hStruct
    EndFunc

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

    Func _Exit()
    _GDIPlus_PenDispose($hPen_Line)
    _GDIPlus_BrushDispose($hBrush_Pac)
    _GDIPlus_BrushDispose($hBrush_Way)
    _GDIPlus_BrushDispose($Brush2)
    _GDIPlus_BrushDispose($Brush3)
    _GDIPlus_GraphicsDispose($hBuffer)
    _GDIPlus_BitmapDispose($hBitmapGame)
    _GDIPlus_GraphicsDispose($hGraphicGame)
    _GDIPlus_Shutdown()
    DllClose($hDLL)
    Exit
    EndFunc

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

    Func _GDIPlus_GraphicsGetSmoothingMode_New($hGraphic)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipGetSmoothingMode", "handle", $hGraphic, "int*", 0)
    If @error Then Return SetError(@error, @extended, -1)
    Return $aResult[2]
    EndFunc ;==>_GDIPlus_GraphicsGetSmoothingMode_New

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

    Func _GDIPlus_GraphicsSetSmoothingMode_New($hGraphic, $iSmooth)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipSetSmoothingMode", "handle", $hGraphic, "int", $iSmooth)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
    EndFunc ;==>_GDIPlus_GraphicsSetSmoothingMode_New

    [/autoit]
  • Also bei mir hängt das noch ein bisschen(kaum merkbar), und ich kann einfach so durch Wände fahren ?(
    Aber ansonsten gefällt es mir :thumbup:
    (PS.: Bedenke, dass Pacman nicht stehen bleibt, sobald er mal läuft, es sei denn er fähr gegen Wände.)

  • Ja ich hatte was geändert beim erstellen der Map, davor hats geklappt danach nicht mehr, wusste ich aber nicht. Kleine Änderung in Zeile 169.
    Da muss folgendes stehen:

    [autoit]

    $aBG[$y - 1][$x - 1] = Int($sSplit_2[$x])

    [/autoit]


    Hab ich oben auch geändert im ersten Post.
    ;)

    Achja und die GDIP.au3 hab ich oben angehängt.

  • Genial, aber es fehlen halt noch die Monster, und Pacman sollte nicht stehen bleiben, aber ich denke die änderungen kommen noch :D

    Ich weiß nicht wie es bei den anderen ist, aber bei mir ist das etwas am laggen, da kommt der spielspaß nicht so rüber, vllt. könnte sich Paci auch etwas mehr bewegen :D

    Aber echt Genial, gute arbeit :thumbup:

  • Du meinst sobald man in eine Richtung tippt geht er die ganze Zeit in die Richtung, auch wenn man loslässt?

  • Nein wenn ich eine Teaste gedrückt halte dann geht er ein paar mal ruckartig in die gewünschte Richtung und dann wird Pacman sehr schnell.
    Wenn ich die Taste loslasse stopt er aber wieder.

    mfg Ubuntu

  • Achso ok, ja das Problem kenn ich, das hängt mit den Timern zusammen und der Verriegelung, dass wenn man nur einmal tastet er auch nur einen chritt geht und nicht mal eins oder mal zweo oder drei. Und wenn man dann gedrückt hält geht er dann die ganze Zeit. Aber ich überleg noch ob ich die Steuerung auch so mache wie bei dem Originalpacman, das er die ganze zeit geht, sobald man eine Richtung tastet. Die Frage gebe ich aber an euch weiter :).

    Also welche Steuerung soll ich nehmen?
    1. Solange man gedrückt hält geht er auch und sobald man loslässt stoppt er und wenn man nur einmal kurz tastet, macht er soviele Schritte wie er schafft während des kurzen Tasten.
    2. Solange man gedrückt hält geht er auch und sobald man loslässt stoppt er und wenn man nur einmal kurz tastet, macht er auch nur einen Schritt.
    3. Man drückt einmal eine Richtung lässt dann sofort wieder los (also einmal tasten) und dann geht er die ganze Zeit in die Richtung bis er halt auf eine Wand trifft oder man die entgegengesetzte Richtung drückt.

  • Zu 1. so ist es jetzt oder?
    Finde ich nicht so gut.

    Zu 2
    So ist es beim orginal oder?
    Die würde ich bevorzugen

    Zu 3
    Dann funktioniert zumindest dein aktuelles Labyrinth nicht.

    mfg Ubuntu

  • Also momentan ist es 2. Das Original ist 3.. Aber warum sollte das bei mir nicht funktionieren?

  • Du hast 3 aber nicht richtig beschrieben wenn es wie beim orginal
    heissen soll

    Zitat

    3. Man drückt einmal eine Richtung lässt dann sofort wieder los (also einmal tasten) und dann geht er die ganze Zeit in die Richtung bis er halt auf eine Wand trifft oder man die entgegengesetzte Richtung drückt.

    Das bedeutet wenn ich einmal drücke geht pacman solage weiter bis irgendwann eine Mauer kommt.
    Er kann nicht unterwegs anhalten.
    Folglich würde man aus dem Rechteck in der mitte nicht mehr rauskommen.

    mfg Ubuntu