[Game]Destop Runner Help

  • hi
    ich bin gerade dabei ein spiel zu scripten
    jetzt hab ich aber ein problem

    also in meinem spiel geht es darum von das eine kugel von eimem ort auf dem destop zu anderen rollt
    dabei soll sie auf den fenstern und auf selbst gezeichnetten linien lang rollen können.
    hier mein script:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GDIPlus.au3>
    #include <Misc.au3>
    #include <Array.au3>

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

    HotKeySet("{Esc}", "Ende")
    _GDIPlus_Startup()

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

    Global $Speed = 10

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

    Global $BallPos[4], $ZielPos[4], $Ball

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

    $Main = GUICreate("Destop Runner", 0, 0, -2, -2)
    WinSetTrans("Destop Runner", "", 0)
    GUISetState(@SW_SHOW)

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

    $Background = GUICreate("Background", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_MDICHILD, $WS_EX_LAYERED), $Main)
    GUISetBkColor(0xFFFFFF)
    $Button1 = GUICtrlCreateButton("Start Punkt setzen", 5, 5, 120, 25)
    $Button2 = GUICtrlCreateButton("Ziel Punkt setzen", 5, 35, 120, 25)
    $Button3 = GUICtrlCreateButton("Normale Linie", 5, 70, 120, 25)
    $Button4 = GUICtrlCreateButton("Fahrstuhl", 5, 100, 120, 25)
    $Pic1 = GUICtrlCreatePic("play-button2.jpg", 20, 130, 30, 30)
    $Pic2 = GUICtrlCreatePic("stop-button.jpg", 70, 130, 30, 30)
    GUISetState(@SW_SHOW)

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

    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($Background)
    $hEndCap = _GDIPlus_ArrowCapCreate(1, 2)
    $hPenB = _GDIPlus_PenCreate(0xFF000000, 10, 2)
    $hPenR = _GDIPlus_PenCreate(0xFFFF0000, 10, 2)
    _GDIPlus_PenSetCustomEndCap($hPenR, $hEndCap)

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

    GUIWhile()

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

    Func GUIWhile()
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    Do
    Sleep(100)
    Until _IsPressed(01)
    $Mouse = MouseGetPos()
    $Ball = GUICtrlCreatePic("ball.jpg", $Mouse[0] - 10, $Mouse[1] - 10, 20, 20)
    $BallPos[0] = $Mouse[0] - 10
    $BallPos[1] = $Mouse[1] - 10
    $BallPos[2] = 20
    $BallPos[3] = 20
    GUICtrlSetState($Button1, $GUI_DISABLE)
    Case $Button2
    Do
    Sleep(100)
    Until _IsPressed(01)
    $Mouse = MouseGetPos()
    $Ziel = GUICtrlCreatePic("ziel.jpg", $Mouse[0] - 20, $Mouse[1] - 20, 40, 40)
    $ZielPos[0] = $Mouse[0] - 20
    $ZielPos[1] = $Mouse[1] - 20
    $ZielPos[2] = 40
    $ZielPos[3] = 40
    GUICtrlSetState($Button2, $GUI_DISABLE)
    Case $Button3
    Do
    Sleep(100)
    Until _IsPressed(01)
    $Mouse1 = MouseGetPos()
    Do
    Sleep(100)
    Until _IsPressed(01)
    $Mouse2 = MouseGetPos()
    _GDIPlus_GraphicsDrawLine($hGraphic, $Mouse1[0], $Mouse1[1], $Mouse2[0], $Mouse2[1], $hPenB)
    Case $Button4
    Do
    Sleep(100)
    Until _IsPressed(01)
    $Mouse1 = MouseGetPos()
    Do
    Sleep(100)
    Until _IsPressed(01)
    $Mouse2 = MouseGetPos()
    _GDIPlus_GraphicsDrawLine($hGraphic, $Mouse1[0], $Mouse1[1], $Mouse1[0], $Mouse2[1], $hPenR)
    Case $Pic1
    If GUICtrlGetState($Button1) = 80 Or GUICtrlGetState($Button2) = 80 Then
    MsgBox(0, "Destop Runner", "Sie haben den Start/Ziel Punkt noch nicht gesetzt")
    Else
    GUICtrlSetState($Button1, $GUI_HIDE)
    GUICtrlSetState($Button2, $GUI_HIDE)
    GUICtrlSetState($Button3, $GUI_HIDE)
    GUICtrlSetState($Button4, $GUI_HIDE)
    GUICtrlSetState($Pic1, $GUI_HIDE)
    GUICtrlSetState($Pic2, $GUI_HIDE)
    HotKeySet("{Space}", "Reset")
    Main()
    EndIf
    Case $Pic2
    Exit
    EndSwitch
    WEnd
    EndFunc ;==>GUIWhile

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

    Func Main()
    ;~ $Windows = CheckWindows()
    ;~ _ArrayDisplay($BallPos)
    ;~ _ArrayDisplay($ZielPos)
    ;~ _ArrayDisplay($Windows)

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

    While 1
    Left()
    Right()
    Switch CheckPos()
    Case 0
    FallDown()
    Case 1
    MsgBox(0, "Destop Runner", "Ziel erreicht")
    Exit
    Case 2
    Case 3
    Case 4
    DriveUp()
    EndSwitch
    Sleep($Speed)
    WEnd
    EndFunc ;==>Main

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

    Func Left()
    If _IsPressed(25) Then
    GUICtrlSetPos($Ball, $BallPos[0] - 1, $BallPos[1])
    $BallPos[0] = $BallPos[0] - 1
    EndIf
    EndFunc ;==>Left

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

    Func Right()
    If _IsPressed(27) Then
    GUICtrlSetPos($Ball, $BallPos[0] + 1, $BallPos[1])
    $BallPos[0] = $BallPos[0] + 1
    EndIf
    EndFunc ;==>Right

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

    Func DriveUp()
    GUICtrlSetPos($Ball, $BallPos[0], $BallPos[1] - 1)
    $BallPos[1] = $BallPos[1] - 1
    EndFunc ;==>DriveUp

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

    Func FallDown()
    GUICtrlSetPos($Ball, $BallPos[0], $BallPos[1] + 1)
    $BallPos[1] = $BallPos[1] + 1
    EndFunc ;==>FallDown

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

    Func CheckPos()
    Local $MatchPos = 0

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

    For $i = $ZielPos[0] To $ZielPos[0] + $ZielPos[2]
    If $i = $BallPos[0] And $ZielPos[1] = $BallPos[1] + ($BallPos[3] / 2) Then $MatchPos += 1
    Next
    For $i = $ZielPos[1] To $ZielPos[1] + $ZielPos[3]
    If $i = $BallPos[1] And $ZielPos[0] = $BallPos[0] + ($BallPos[2] / 2) Then $MatchPos += 1
    If $i = $BallPos[1] And $ZielPos[0] = $BallPos[0] - ($BallPos[2] * 1.5) Then $MatchPos += 1
    Next
    If $MatchPos >= 1 Then Return 1
    $MatchPos = 0

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

    $Windows = CheckWindows()
    For $j = 0 To UBound($Windows) - 1
    For $i = $Windows[$j][1] To $Windows[$j][1] + $Windows[$j][3]
    If $i = $BallPos[0] And $Windows[$j][2] = $BallPos[1] + $BallPos[3] Then $MatchPos += 1
    Next
    For $i = $Windows[$j][2] To $Windows[$j][2] + $Windows[$j][4]
    If $i = $BallPos[1] And $Windows[$j][1] = $BallPos[0] - $BallPos[2] Then $MatchPos += 1
    If $i = $BallPos[1] And $Windows[$j][1] = $BallPos[0] + $BallPos[2] Then $MatchPos += 1
    Next
    Next
    If $MatchPos >= 1 Then Return 2
    $MatchPos = 0

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

    If PixelGetColor($BallPos[0] - 1, $BallPos[1] + $BallPos[3] + 1) = 0x000000 Then $MatchPos += 1
    If PixelGetColor($BallPos[0] - 1, $BallPos[1] + ($BallPos[3] / 2) + 1) = 0x000000 Then $MatchPos += 1
    If PixelGetColor($BallPos[0] + $BallPos[2] + 1, $BallPos[1] + $BallPos[3] + 1) = 0x000000 Then $MatchPos += 1
    If PixelGetColor($BallPos[0] + $BallPos[2] + 1, $BallPos[1] + ($BallPos[3] / 2) + 1) = 0x000000 Then $MatchPos += 1
    If $MatchPos >= 1 Then Return 3
    $MatchPos = 0

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

    If PixelGetColor($BallPos[0] - 1, $BallPos[1] + $BallPos[3] + 1) = 0xFF0000 Then $MatchPos += 1
    If PixelGetColor($BallPos[0] - 1, $BallPos[1] + ($BallPos[3] / 2) + 1) = 0xFF0000 Then $MatchPos += 1
    If PixelGetColor($BallPos[0] + $BallPos[2] + 1, $BallPos[1] + $BallPos[3] + 1) = 0xFF0000 Then $MatchPos += 1
    If PixelGetColor($BallPos[0] + $BallPos[2] + 1, $BallPos[1] + ($BallPos[3] / 2) + 1) = 0xFF0000 Then $MatchPos += 1
    If $MatchPos >= 1 Then Return 4
    $MatchPos = 0
    Return 0
    EndFunc ;==>CheckPos

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

    Func CheckWindows()
    $var = WinList()
    Dim $WindowNames[1]
    For $i = 1 To $var[0][0]
    If IsOpen($var[$i][0], $var[$i][1]) Then
    _ArrayAdd($WindowNames, $var[$i][0])
    EndIf
    Next
    Local $iUBound = UBound($WindowNames)
    Dim $Windows[$iUBound - 1][5]
    For $i = 1 To $iUBound - 1
    $pos = WinGetPos($WindowNames[$i])
    $Windows[$i - 1][0] = $WindowNames[$i]
    $Windows[$i - 1][1] = $pos[0]
    $Windows[$i - 1][2] = $pos[1]
    $Windows[$i - 1][3] = $pos[2]
    $Windows[$i - 1][4] = $pos[3]
    Next
    Return $Windows
    EndFunc ;==>CheckWindows

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

    Func Reset()
    HotKeySet("{Space}")
    GUICtrlSetState($Button1, $GUI_SHOW)
    GUICtrlSetState($Button2, $GUI_SHOW)
    GUICtrlSetState($Button3, $GUI_SHOW)
    GUICtrlSetState($Button4, $GUI_SHOW)
    GUICtrlSetState($Pic1, $GUI_SHOW)
    GUICtrlSetState($Pic2, $GUI_SHOW)
    GUIWhile()
    EndFunc ;==>Reset

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

    Func IsOpen($Name, $Handle)
    If BitAND(WinGetState($Handle), 2) And Not BitAND(WinGetState($Handle), 16) _
    And Not BitAND(WinGetState($Handle), 32) And $Name <> "" And $Name <> "Program Manager" _
    And $Name <> "AMD:CCC-AEMCapturingWindow" And $Name <> "Background" _
    And $Name <> "Start" And $Name <> "Destop Runner" Then Return 1
    Return 0
    EndFunc ;==>IsOpen

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

    Func Ende()
    Exit
    EndFunc ;==>Ende

    [/autoit]


    ich hab jetzt das problem das die kugel nicht auf den fenstern hängen bleibt <--Gelöst
    und das mit den linien hab ich noch net drinne das kommt aber noch <--Gelöst auch wenns ein bischen anderst ist
    die bilder und der script sind dan nochmal im anhag

    ich hoffe es kann mir jemand helfen

    2 Mal editiert, zuletzt von HansWurrst (15. August 2009 um 17:09)

  • Ich habe mir das Script nicht genauer angeguckt, aber kannst du den nicht einfach die Koordinaten und die breite des Fenster abfragen, das zusammenrechnen und mit der Position der Kugel vergleichen?

  • wenn die kugel aber ins ziel kommt dann reagiert er aber
    das ist ja das komische
    €dit: oh stimmt geht doch net

  • Hmm irgendwas scheint an deiner Kollisionsabfrage nicht zu stimmen. Evt. solltest du auch noch ein Ende bei @DesktopWidth und @DesktopHeight einbauen (oder zumindest so das dann das spiel vorbei ist)

    MFG FireFlyer

    *Paradox ist, wenn man sich im Handumdrehen den Fuss bricht* :D

  • habs jetzt so weit fertig es geht jetzt auch
    eigentlich wollte ichs anderst machen aber so is au gut