Xonix - Ein kleines Spielchen

  • Hi Forum
    RapIt, ein Freund und ich haben zusammen das Minispiel Xonix entwickelt.
    Vielleicht kennen ein paar von euch das Spiel von alten Nokia-Handys :D

    Naja, eigentlich wollten wir das Spiel komplett mit Standard GUI controls machen (wird demnächst veröffentlicht), ich habe das auch mal mit meinen geringen GDI+ Kenntnissen aus der Tutorial
    umgeschrieben, um einen direkten (Performance-)Vergleich zu haben.

    Im Spiel geht es darum, mit den Pfeiltasten den Bereich für den Ball einzugrenzen. Erst wenn man den Rand erreicht hat, wird er gefüllt. Der Ball darf die rote Linie nicht berühren, sonst verliert man eins von drei Leben.
    Ein Level hat man geschafft, wenn mehr als 70% des Spielfelds ausgefüllt sind.
    Viel Spaß!


    Bekannte Bugs:

    Spoiler anzeigen

    -Wenn es mehr als einen Bereich mit Bällen gibt, wird dieser manchmal nicht korrekt gefüllt.
    -Bei neuem Level stürzt es manchmal ab

    Code:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <array.au3>
    #include <gdiplus.au3>
    HotKeySet("{LEFT}", "_left")
    HotKeySet("{UP}", "_up")
    HotKeySet("{RIGHT}", "_right")
    HotKeySet("{DOWN}", "_down")

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

    Global $game_scale = 40
    Global $ballpos[2][8]
    Global $direction[8]
    Global $array[$game_scale][$game_scale]
    Global $background_control[$game_scale][$game_scale]
    Global $level = 1

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

    Global $player_direction = -1
    Global $player_pos[2] = [0, 0]
    Global $grenze = 0.7
    Global $lives = 3
    Global $rpcounter = 0
    Global $newdirdirection[4][8][4] = [[[0, 1, 2, 2], [0, 1, 2, 1], [0, 1, 2, 2], [0, 1, 2, 0], [0, 1, 2, 3], [0, 1, 2, 2], [0, 1, 2, 0], [0, 1, 2, 0]], [[2, 3, 4, 3], [2, 3, 4, 2], [2, 3, 4, 3], [2, 3, 4, 1], [2, 3, 4, 0], [2, 3, 4, 3], [2, 3, 4, 1], [2, 3, 4, 1]], [[4, 5, 6, 0], [4, 5, 6, 3], [4, 5, 6, 0], [4, 5, 6, 2], [4, 5, 6, 1], [4, 5, 6, 0], [4, 5, 6, 2], [4, 5, 6, 2]], [[6, 7, 0, 1], [6, 7, 0, 0], [6, 7, 0, 1], [6, 7, 0, 3], [6, 7, 0, 2], [6, 7, 0, 1], [6, 7, 0, 3], [6, 7, 0, 3]]]
    Global $pen[3]
    _GDIPlus_Startup()

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

    $MainGui = GUICreate("Xonix -by Alex & RapIt & Fresapore", $game_scale*10+1, $game_scale*10+30, 192, 124)
    $percentlabel = guictrlcreatelabel("Prozent: 0", 0, $game_scale*10, $game_scale*10/3, 30)
    guictrlsetfont(-1, 20)
    $lifelabel = guictrlcreatelabel("Leben: 3", $game_scale*10/3*2, $game_scale*10, $game_scale*10/3, 30)
    guictrlsetfont(-1, 20)
    $levellabel = guictrlcreatelabel("Level: ", $game_scale*10/3, $game_scale*10, $game_scale*10/3, 30)
    guictrlsetfont(-1, 20)
    GUISetState(@SW_SHOW)
    $graphic = _GDIPlus_GraphicsCreateFromHWND($MainGui)
    $bitmap = _GDIPlus_BitmapCreateFromGraphics($game_scale*10, $game_scale*10, $graphic)
    $buffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
    $pen[1] = _GDIPlus_BrushCreateSolid(0xFF000000)
    $pen[0] = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    $pen[2] = _GDIPlus_BrushCreateSolid(0xFFFF0000)
    For $x = 0 To ($game_scale-1)
    For $y = 0 To ($game_scale-1)
    $array[$x][$y] = 0
    Next
    Next

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

    For $x = 0 To ($game_scale-1)
    $array[0][$x] = 1
    $array[($game_scale-1)][$x] = 1
    $array[$x][0] = 1
    $array[$x][($game_scale-1)] = 1
    Next

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

    ;------------Main----------------

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

    _newlevel()
    AdlibRegister("_ballmove", 100)
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    _GDIPlus_GraphicsDispose($graphic);Grafik Objekt freigeben
    _GDIPlus_GraphicsDispose($buffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_Shutdown();Ressourcen freigeben
    Exit
    EndSwitch
    Sleep(10)
    WEnd

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

    ;---------------------------------

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

    Func _left()
    If $player_direction <> 2 Or $array[$player_pos[0]][$player_pos[1]] = 1 Then $player_direction = 0
    EndFunc ;==>_left

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

    Func _up()
    If $player_direction <> 3 Or $array[$player_pos[0]][$player_pos[1]] = 1 Then $player_direction = 1
    EndFunc ;==>_up

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

    Func _right()
    If $player_direction <> 0 Or $array[$player_pos[0]][$player_pos[1]] = 1 Then $player_direction = 2
    EndFunc ;==>_right

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

    Func _down()
    If $player_direction <> 1 Or $array[$player_pos[0]][$player_pos[1]] = 1 Then $player_direction = 3
    EndFunc ;==>_down

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

    Func _newlevel()
    guictrlsetdata($percentlabel, "Prozent: 0")
    For $x = 1 to ($game_scale-2)
    For $y = 1 to ($game_scale-2)
    $array[$x][$y] = 0
    Next
    Next
    GUICtrlSetData($levellabel, "Level: "&$level)
    $player_direction = -1
    $player_pos[0] = 0
    $player_pos[1] = 0
    For $i = 0 To $level - 1
    $direction[$i] = Random(0, 3, 1)
    $ballpos[0][$i] = Random(2, $game_scale-3, 1)
    $ballpos[1][$i] = Random(2, $game_scale-3, 1)
    Next
    $level += 1
    EndFunc ;==>_newlevel

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

    Func _ballmove()
    Local $newdir
    Local $collision[7]
    Local $number_red = 0
    Switch $player_direction
    Case 0
    If $player_pos[0] > 0 Then
    If $array[$player_pos[0] - 1][$player_pos[1]] = 0 Then
    $array[$player_pos[0] - 1][$player_pos[1]] = 2
    ElseIf $array[$player_pos[0] - 1][$player_pos[1]] = 2 Then
    If $lives > 0 Then
    $player_direction = -1
    $player_pos[0] = 0
    $player_pos[1] = 0
    $lives -= 1
    GUICtrlSetData($lifelabel, "Leben: "&$lives)
    For $x = 1 to $game_scale-2
    For $y = 1 to $game_scale-2
    If $array[$x][$y] = 2 then $array[$x][$y] = 0
    Next
    Next
    Else
    MsgBox(0, "Game Over", "Du hast bei Level "&$level-1&" verloren.")
    $level = 1
    $lives = 3
    GUICtrlSetData($lifelabel, "Leben: "&$lives)
    _newlevel()
    EndIf
    Else
    If $array[$player_pos[0]][$player_pos[1]] <> 1 Then
    _fill(0, 0)
    EndIf
    EndIf
    If $player_pos[0] > 0 Then $player_pos[0] -= 1
    Else
    $player_direction = -1
    EndIf
    Case 1
    If $player_pos[1] > 0 Then
    If $array[$player_pos[0]][$player_pos[1] - 1] = 0 Then
    $array[$player_pos[0]][$player_pos[1] - 1] = 2
    ElseIf $array[$player_pos[0]][$player_pos[1] - 1] = 2 Then
    If $lives > 0 Then
    $player_direction = -1
    $player_pos[0] = 0
    $player_pos[1] = 0
    $lives -= 1
    GUICtrlSetData($lifelabel, "Leben: "&$lives)
    For $x = 1 to $game_scale-2
    For $y = 1 to $game_scale-2
    If $array[$x][$y] = 2 then $array[$x][$y] = 0
    Next
    Next
    Else
    MsgBox(0, "Game Over", "Du hast bei Level "&$level-1&" verloren.")
    $level = 1
    $lives = 3
    GUICtrlSetData($lifelabel, "Leben: "&$lives)
    _newlevel()
    EndIf
    Else
    If $array[$player_pos[0]][$player_pos[1]] <> 1 Then
    _fill(0, 0)
    EndIf
    EndIf
    If $player_pos[1] > 0 Then $player_pos[1] -= 1
    Else
    $player_direction = -1
    EndIf
    Case 2
    If $player_pos[0] < ($game_scale-1) Then
    If $array[$player_pos[0] + 1][$player_pos[1]] = 0 Then
    $array[$player_pos[0] + 1][$player_pos[1]] = 2
    ElseIf $array[$player_pos[0] + 1][$player_pos[1]] = 2 Then
    If $lives > 0 Then
    $player_direction = -1
    $player_pos[0] = 0
    $player_pos[1] = 0
    $lives -= 1
    GUICtrlSetData($lifelabel, "Leben: "&$lives)
    For $x = 1 to $game_scale-2
    For $y = 1 to $game_scale-2
    If $array[$x][$y] = 2 then $array[$x][$y] = 0
    Next
    Next
    Else
    MsgBox(0, "Game Over", "Du hast bei Level "&$level-1&" verloren.")
    $level = 1
    $lives = 3
    GUICtrlSetData($lifelabel, "Leben: "&$lives)
    _newlevel()
    EndIf
    Else
    If $array[$player_pos[0]][$player_pos[1]] <> 1 Then
    _fill(0, 0)
    EndIf
    EndIf
    If $player_pos[0] < $game_scale Then $player_pos[0] += 1
    Else
    $player_direction = -1
    EndIf
    Case 3
    If $player_pos[1] < ($game_scale-1) Then
    If $array[$player_pos[0]][$player_pos[1] + 1] = 0 Then
    $array[$player_pos[0]][$player_pos[1] + 1] = 2
    ElseIf $array[$player_pos[0]][$player_pos[1] + 1] = 2 Then
    If $lives > 0 Then
    $player_direction = -1
    $player_pos[0] = 0
    $player_pos[1] = 0
    $lives -= 1
    GUICtrlSetData($lifelabel, "Leben: "&$lives)
    For $x = 1 to $game_scale-2
    For $y = 1 to $game_scale-2
    If $array[$x][$y] = 2 then $array[$x][$y] = 0
    Next
    Next
    Else
    MsgBox(0, "Game Over", "Du hast bei Level "&$level-1&" verloren.")
    $level = 1
    $lives = 3
    GUICtrlSetData($lifelabel, "Leben: "&$lives)
    _newlevel()
    EndIf
    Else
    If $array[$player_pos[0]][$player_pos[1]] <> 1 Then
    _fill(0, 0)
    EndIf
    EndIf
    If $player_pos[1] < $game_scale Then $player_pos[1] += 1
    Else
    $player_direction = -1
    EndIf
    EndSwitch
    For $i = 0 To $level - 2
    $collision = _Check($i)
    If $collision[$newdirdirection[$direction[$i]][0][0]] = 1 And $collision[$newdirdirection[$direction[$i]][0][1]] = 1 And $collision[$newdirdirection[$direction[$i]][0][2]] = 1 Then $newdir = $newdirdirection[$direction[$i]][0][3]
    If $collision[$newdirdirection[$direction[$i]][1][0]] = 1 And $collision[$newdirdirection[$direction[$i]][1][1]] = 1 And $collision[$newdirdirection[$direction[$i]][1][2]] <> 1 Then $newdir = $newdirdirection[$direction[$i]][1][3]
    If $collision[$newdirdirection[$direction[$i]][2][0]] = 1 And $collision[$newdirdirection[$direction[$i]][2][1]] <> 1 And $collision[$newdirdirection[$direction[$i]][2][2]] = 1 Then $newdir = $newdirdirection[$direction[$i]][2][3]
    If $collision[$newdirdirection[$direction[$i]][3][0]] = 1 And $collision[$newdirdirection[$direction[$i]][3][1]] <> 1 And $collision[$newdirdirection[$direction[$i]][3][2]] <> 1 Then $newdir = $newdirdirection[$direction[$i]][3][3]
    If $collision[$newdirdirection[$direction[$i]][4][0]] <> 1 And $collision[$newdirdirection[$direction[$i]][4][1]] = 1 And $collision[$newdirdirection[$direction[$i]][4][2]] = 1 Then $newdir = $newdirdirection[$direction[$i]][4][3]
    If $collision[$newdirdirection[$direction[$i]][5][0]] <> 1 And $collision[$newdirdirection[$direction[$i]][5][1]] = 1 And $collision[$newdirdirection[$direction[$i]][5][2]] <> 1 Then $newdir = $newdirdirection[$direction[$i]][5][3]
    If $collision[$newdirdirection[$direction[$i]][6][0]] <> 1 And $collision[$newdirdirection[$direction[$i]][6][1]] <> 1 And $collision[$newdirdirection[$direction[$i]][6][2]] = 1 Then $newdir = $newdirdirection[$direction[$i]][6][3]
    If $collision[$newdirdirection[$direction[$i]][7][0]] <> 1 And $collision[$newdirdirection[$direction[$i]][7][1]] <> 1 And $collision[$newdirdirection[$direction[$i]][7][2]] <> 1 Then $newdir = $newdirdirection[$direction[$i]][7][3]
    $direction[$i] = $newdir
    Switch $direction[$i]
    Case 0
    $ballpos[0][$i] -= 1
    $ballpos[1][$i] -= 1
    Case 1
    $ballpos[0][$i] += 1
    $ballpos[1][$i] -= 1
    Case 2
    $ballpos[0][$i] += 1
    $ballpos[1][$i] += 1
    Case 3
    $ballpos[0][$i] -= 1
    $ballpos[1][$i] += 1
    EndSwitch

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

    If $array[$ballpos[0][$i]][$ballpos[1][$i]] = 2 Then
    If $lives > 0 Then
    $player_direction = -1
    $player_pos[0] = 0
    $player_pos[1] = 0
    $lives -= 1
    GUICtrlSetData($lifelabel, "Leben: "&$lives)
    For $x = 1 to $game_scale-2
    For $y = 1 to $game_scale-2
    If $array[$x][$y] = 2 then $array[$x][$y] = 0
    Next
    Next
    Else
    MsgBox(0, "Game Over", "Du hast bei Level "&$level-1&" verloren.")
    $level = 1
    $lives = 3
    GUICtrlSetData($lifelabel, "Leben: "&$lives)
    _newlevel()
    EndIf
    EndIf
    Next
    For $x = 0 to ($game_scale-1)
    For $y = 0 to ($game_scale-1)
    _GDIPlus_GraphicsfillRect($buffer, $x*10, $y*10, 10, 10, $pen[$array[$x][$y]])
    Next
    Next
    _GDIPlus_GraphicsfillRect($buffer, $player_pos[0]*10, $player_pos[1]*10, 10, 10, $pen[2])
    For $i = 0 to $level -2
    _GDIPlus_GraphicsfillRect($buffer, $ballpos[0][$i]*10, $ballpos[1][$i]*10, 10, 10, $pen[1])
    Next
    _GDIPlus_GraphicsDrawImage($graphic, $bitmap, 0, 0)
    _GDIPlus_GraphicsClear($buffer)
    EndFunc ;==>_ballmove

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

    Func _check($num)
    Local $allcol[8]
    $allcol[0] = $array[$ballpos[0][$num] - 1][$ballpos[1][$num]]
    $allcol[1] = $array[$ballpos[0][$num] - 1][$ballpos[1][$num] - 1]
    $allcol[2] = $array[$ballpos[0][$num]][$ballpos[1][$num] - 1]
    $allcol[3] = $array[$ballpos[0][$num] + 1][$ballpos[1][$num] - 1]
    $allcol[4] = $array[$ballpos[0][$num] + 1][$ballpos[1][$num]]
    $allcol[5] = $array[$ballpos[0][$num] + 1][$ballpos[1][$num] + 1]
    $allcol[6] = $array[$ballpos[0][$num]][$ballpos[1][$num] + 1]
    $allcol[7] = $array[$ballpos[0][$num] - 1][$ballpos[1][$num] + 1]
    Return $allcol
    EndFunc ;==>_check

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

    Func _fill($start, $end)
    Local $redpoints, $fnumber = 0
    $redpoints = _getRedPoints()
    For $i = 0 To $rpcounter - 1
    If $array[$redpoints[$i][0] + 1][$redpoints[$i][1]] = 0 Then
    _a($redpoints[$i][0] + 1, $redpoints[$i][1], $fnumber)
    $fnumber = 1
    EndIf
    If $array[$redpoints[$i][0] - 1][$redpoints[$i][1]] = 0 Then
    _a($redpoints[$i][0] - 1, $redpoints[$i][1], $fnumber)
    $fnumber = 1
    EndIf
    If $array[$redpoints[$i][0]][$redpoints[$i][1] + 1] = 0 Then
    _a($redpoints[$i][0], $redpoints[$i][1] + 1, $fnumber)
    $fnumber = 1
    EndIf
    If $array[$redpoints[$i][0]][$redpoints[$i][1] - 1] = 0 Then
    _a($redpoints[$i][0], $redpoints[$i][1] - 1, $fnumber)
    $fnumber = 1
    EndIf
    Next
    _compare()
    $rpcounter = 0
    For $x = 1 To ($game_scale-2)
    For $y = 1 To ($game_scale-2)
    If $array[$x][$y] = 2 Then
    $array[$x][$y] = 1
    EndIf
    Next
    Next
    _issolved()
    EndFunc ;==>_fill

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

    Func _getRedPoints()
    Local $redpoints[($game_scale-2)*100+20][2]
    For $i = 1 To ($game_scale-2)
    For $j = 1 To ($game_scale-2)
    If $array[$i][$j] = 2 Then
    $redpoints[$rpcounter][0] = $i
    $redpoints[$rpcounter][1] = $j
    $rpcounter = $rpcounter + 1
    EndIf
    Next
    Next
    Return $redpoints
    EndFunc ;==>_getRedPoints

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

    Func _a($xpos, $ypos, $fnumber)
    If $array[$xpos + 1][$ypos] = 0 Then
    $array[$xpos + 1][$ypos] = 3 + $fnumber
    _a($xpos + 1, $ypos, $fnumber)
    EndIf
    If $array[$xpos - 1][$ypos] = 0 Then
    $array[$xpos - 1][$ypos] = 3 + $fnumber
    _a($xpos - 1, $ypos, $fnumber)
    EndIf
    If $array[$xpos][$ypos + 1] = 0 Then
    $array[$xpos][$ypos + 1] = 3 + $fnumber
    _a($xpos, $ypos + 1, $fnumber)
    EndIf
    If $array[$xpos][$ypos - 1] = 0 Then
    $array[$xpos][$ypos - 1] = 3 + $fnumber
    _a($xpos, $ypos - 1, $fnumber)
    EndIf

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

    EndFunc ;==>_a

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

    Func _compare()
    Local $amount = 0
    For $i = 0 to $level-1
    If $array[$ballpos[0][$i]][$ballpos[1][$i]] = 3 Then $amount += 1
    Next
    If $amount = $level -1 Then
    For $i = 1 To ($game_scale-2)
    For $j = 1 To ($game_scale-2)
    If $array[$i][$j] = 3 Then
    $array[$i][$j] = 0
    EndIf
    If $array[$i][$j] = 4 Then
    $array[$i][$j] = 2
    EndIf
    Next
    Next
    Elseif $amount = 0 Then
    For $i = 1 To ($game_scale-2)
    For $j = 1 To ($game_scale-2)
    If $array[$i][$j] = 4 Then
    $array[$i][$j] = 0
    EndIf
    If $array[$i][$j] = 3 Then
    $array[$i][$j] = 2
    EndIf
    Next
    Next
    Else
    For $i = 1 To ($game_scale-2)
    For $j = 1 To ($game_scale-2)
    If $array[$i][$j] = 3 or $array[$i][$j] = 4 Then
    $array[$i][$j] = 0
    EndIf
    Next
    Next
    EndIf
    EndFunc ;==>_compare

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

    Func _Issolved()
    Local $black = 0
    For $i = 1 To ($game_scale-2)
    For $j = 1 To ($game_scale-2)
    If $array[$i][$j] = 1 Then
    $black += 1
    EndIf
    Next
    Next
    If $black / $game_scale^2 <= $grenze Then
    guictrlsetdata($percentlabel, "Prozent: "&round(($black / $game_scale^2)*100))
    Else
    _newlevel()
    EndIf
    EndFunc ;==>_Issolved

    [/autoit]

    Hier die "Control"-Variante:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <array.au3>
    #include <gdiplus.au3>
    HotKeySet("{LEFT}", "_up")
    HotKeySet("{UP}", "_left")
    HotKeySet("{RIGHT}", "_down")
    HotKeySet("{DOWN}", "_right")

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

    Global $ballpos[2][8]
    Global $direction[8]
    Global $array[52][52]
    Global $background_control[52][52]
    Global $level = 1
    Global $player_direction = -1
    Global $player_pos[2] = [0, 0]
    Global $grenze = 0.7
    Global $lives = 3
    Global $rpcounter = 0
    Global $newdirdirection[4][8][4] = [[[0, 1, 2, 2], [0, 1, 2, 1], [0, 1, 2, 2], [0, 1, 2, 0], [0, 1, 2, 3], [0, 1, 2, 2], [0, 1, 2, 0], [0, 1, 2, 0]], [[2, 3, 4, 3], [2, 3, 4, 2], [2, 3, 4, 3], [2, 3, 4, 1], [2, 3, 4, 0], [2, 3, 4, 3], [2, 3, 4, 1], [2, 3, 4, 1]], [[4, 5, 6, 0], [4, 5, 6, 3], [4, 5, 6, 0], [4, 5, 6, 2], [4, 5, 6, 1], [4, 5, 6, 0], [4, 5, 6, 2], [4, 5, 6, 2]], [[6, 7, 0, 1], [6, 7, 0, 0], [6, 7, 0, 1], [6, 7, 0, 3], [6, 7, 0, 2], [6, 7, 0, 1], [6, 7, 0, 3], [6, 7, 0, 3]]]

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

    $MainGui = GUICreate("Xonix -by Alex & RapIt & Fresapore", 521, 551, 192, 124)
    $percentlabel = guictrlcreatelabel("Prozent: 0", 0, 520, 520/3, 30)
    guictrlsetfont(-1, 20)
    $lifelabel = guictrlcreatelabel("Leben: 3", 520/3*2, 520, 520/3, 30)
    guictrlsetfont(-1, 20)
    $levellabel = guictrlcreatelabel("Level: ", 520/3, 520, 520/3, 30)
    guictrlsetfont(-1, 20)
    GUISetState(@SW_SHOW)

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

    GUISetState(@SW_LOCK)
    For $x = 0 To 51
    For $y = 0 To 51
    $background_control[$x][$y] = GUICtrlCreatebutton("", $y*10, $x*10, 10, 10)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    $array[$x][$y] = 0
    Next
    Next

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

    For $x = 0 To 51
    $array[0][$x] = 1
    GUICtrlSetBkColor($background_control[0][$x], 0x000000)
    $array[51][$x] = 1
    GUICtrlSetBkColor($background_control[51][$x], 0x000000)
    $array[$x][0] = 1
    GUICtrlSetBkColor($background_control[$x][0], 0x000000)
    $array[$x][51] = 1
    GUICtrlSetBkColor($background_control[$x][51], 0x000000)
    Next
    GUISetState(@SW_UNLOCK)
    ;------------Main----------------

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

    _newlevel()
    AdlibRegister("_ballmove", 100)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    Sleep(50)
    WEnd

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

    ;---------------------------------

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

    Func _left()
    If $player_direction <> 2 Or $array[$player_pos[0]][$player_pos[1]] = 1 Then $player_direction = 0
    EndFunc ;==>_left

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

    Func _up()
    If $player_direction <> 3 Or $array[$player_pos[0]][$player_pos[1]] = 1 Then $player_direction = 1
    EndFunc ;==>_up

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

    Func _right()
    If $player_direction <> 0 Or $array[$player_pos[0]][$player_pos[1]] = 1 Then $player_direction = 2
    EndFunc ;==>_right

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

    Func _down()
    If $player_direction <> 1 Or $array[$player_pos[0]][$player_pos[1]] = 1 Then $player_direction = 3
    EndFunc ;==>_down

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

    Func _newlevel()
    GUISetState(@SW_LOCK)
    guictrlsetdata($percentlabel, "Prozent: 0")
    For $x = 1 to 50
    For $y = 1 to 50
    $array[$x][$y] = 0
    GUICtrlSetBkColor($background_control[$y][$x], 0xFFFFFF)
    Next
    Next
    GUICtrlSetData($levellabel, "Level: "&$level)
    GUISetState(@SW_UNLOCK)
    $player_direction = -1
    $player_pos[0] = 0
    $player_pos[1] = 0
    For $i = 0 To $level - 1
    $direction[$i] = 0
    $ballpos[0][$i] = Random(2, 49, 1)
    $ballpos[1][$i] = Random(2, 49, 1)
    Next
    $level += 1
    EndFunc ;==>_newlevel

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

    Func _ballmove()
    Local $newdir
    Local $collision[7]
    Local $number_red = 0
    If $player_direction <> -1 Then
    If $array[$player_pos[0]][$player_pos[1]] = 0 Then
    GUICtrlSetBkColor($background_control[$player_pos[0]][$player_pos[1]], 0xFFFFFF)
    Elseif $array[$player_pos[0]][$player_pos[1]] = 1 Then
    GUICtrlSetBkColor($background_control[$player_pos[0]][$player_pos[1]], 0x000000)
    Endif
    Switch $player_direction
    Case 0
    If $player_pos[0] > 0 Then
    If $array[$player_pos[0] - 1][$player_pos[1]] = 0 Then
    $array[$player_pos[0] - 1][$player_pos[1]] = 2
    ElseIf $array[$player_pos[0] - 1][$player_pos[1]] = 2 Then
    If $lives > 0 Then
    $player_direction = -1
    $player_pos[0] = 0
    $player_pos[1] = 0
    $lives -= 1
    GUICtrlSetData($lifelabel, "Leben: "&$lives)
    For $x = 1 to 52-2
    For $y = 1 to 52-2
    If $array[$x][$y] = 2 then
    $array[$x][$y] = 0
    GUICtrlSetBkColor($background_control[$x][$y], 0xFFFFFF)
    EndIf
    Next
    Next
    Else
    MsgBox(0, "Game Over", "Du hast bei Level "&$level-1&" verloren.")
    $level = 1
    $lives = 3
    GUICtrlSetData($lifelabel, "Leben: "&$lives)
    _newlevel()
    EndIf
    Else
    If $array[$player_pos[0]][$player_pos[1]] <> 1 Then
    _fill(0, 0)
    EndIf
    EndIf
    If $player_pos[0] > 0 Then $player_pos[0] -= 1
    GUICtrlSetBkColor($background_control[$player_pos[0]][$player_pos[1]], 0xFF0000)
    Else
    $player_direction = -1
    EndIf
    Case 1
    If $player_pos[1] > 0 Then
    If $array[$player_pos[0]][$player_pos[1] - 1] = 0 Then
    $array[$player_pos[0]][$player_pos[1] - 1] = 2
    ElseIf $array[$player_pos[0]][$player_pos[1] - 1] = 2 Then
    If $lives > 0 Then
    $player_direction = -1
    $player_pos[0] = 0
    $player_pos[1] = 0
    $lives -= 1
    GUICtrlSetData($lifelabel, "Leben: "&$lives)
    For $x = 1 to 52-2
    For $y = 1 to 52-2
    If $array[$x][$y] = 2 then
    $array[$x][$y] = 0
    GUICtrlSetBkColor($background_control[$x][$y], 0xFFFFFF)
    EndIf
    Next
    Next
    Else
    MsgBox(0, "Game Over", "Du hast bei Level "&$level-1&" verloren.")
    $level = 1
    $lives = 3
    GUICtrlSetData($lifelabel, "Leben: "&$lives)
    _newlevel()
    EndIf
    Else
    If $array[$player_pos[0]][$player_pos[1]] <> 1 Then
    _fill(0, 0)
    EndIf
    EndIf
    If $player_pos[1] > 0 Then $player_pos[1] -= 1
    GUICtrlSetBkColor($background_control[$player_pos[0]][$player_pos[1]], 0xFF0000)
    Else
    $player_direction = -1
    EndIf
    Case 2
    If $player_pos[0] < 51 Then
    If $array[$player_pos[0] + 1][$player_pos[1]] = 0 Then
    $array[$player_pos[0] + 1][$player_pos[1]] = 2
    ElseIf $array[$player_pos[0] + 1][$player_pos[1]] = 2 Then
    If $lives > 0 Then
    $player_direction = -1
    $player_pos[0] = 0
    $player_pos[1] = 0
    $lives -= 1
    GUICtrlSetData($lifelabel, "Leben: "&$lives)
    For $x = 1 to 52-2
    For $y = 1 to 52-2
    If $array[$x][$y] = 2 then
    $array[$x][$y] = 0
    GUICtrlSetBkColor($background_control[$x][$y], 0xFFFFFF)
    EndIf
    Next
    Next
    Else
    MsgBox(0, "Game Over", "Du hast bei Level "&$level-1&" verloren.")
    $level = 1
    $lives = 3
    GUICtrlSetData($lifelabel, "Leben: "&$lives)
    _newlevel()
    EndIf
    Else
    If $array[$player_pos[0]][$player_pos[1]] <> 1 Then
    _fill(0, 0)
    EndIf
    EndIf
    If $player_pos[0] < 52 Then $player_pos[0] += 1
    GUICtrlSetBkColor($background_control[$player_pos[0]][$player_pos[1]], 0xFF0000)
    Else
    $player_direction = -1
    EndIf
    Case 3
    If $player_pos[1] < 51 Then
    If $array[$player_pos[0]][$player_pos[1] + 1] = 0 Then
    $array[$player_pos[0]][$player_pos[1] + 1] = 2
    ElseIf $array[$player_pos[0]][$player_pos[1] + 1] = 2 Then
    If $lives > 0 Then
    $player_direction = -1
    $player_pos[0] = 0
    $player_pos[1] = 0
    $lives -= 1
    GUICtrlSetData($lifelabel, "Leben: "&$lives)
    For $x = 1 to 52-2
    For $y = 1 to 52-2
    If $array[$x][$y] = 2 then
    $array[$x][$y] = 0
    GUICtrlSetBkColor($background_control[$x][$y], 0xFFFFFF)
    EndIf
    Next
    Next
    Else
    MsgBox(0, "Game Over", "Du hast bei Level "&$level-1&" verloren.")
    $level = 1
    $lives = 3
    GUICtrlSetData($lifelabel, "Leben: "&$lives)
    _newlevel()
    EndIf
    Else
    If $array[$player_pos[0]][$player_pos[1]] <> 1 Then
    _fill(0, 0)
    EndIf
    EndIf
    If $player_pos[1] < 52 Then $player_pos[1] += 1
    GUICtrlSetBkColor($background_control[$player_pos[0]][$player_pos[1]], 0xFF0000)
    Else
    $player_direction = -1
    EndIf
    EndSwitch
    Else
    GUICtrlSetBkColor($background_control[$player_pos[0]][$player_pos[1]], 0xFF0000)
    EndIf
    For $i = 0 To $level - 2
    GUICtrlSetBkColor($background_control[$ballpos[0][$i]][$ballpos[1][$i]], 0xFFFFFF)
    $collision = _Check($i)
    If $collision[$newdirdirection[$direction[$i]][0][0]] = 1 And $collision[$newdirdirection[$direction[$i]][0][1]] = 1 And $collision[$newdirdirection[$direction[$i]][0][2]] = 1 Then $newdir = $newdirdirection[$direction[$i]][0][3]
    If $collision[$newdirdirection[$direction[$i]][1][0]] = 1 And $collision[$newdirdirection[$direction[$i]][1][1]] = 1 And $collision[$newdirdirection[$direction[$i]][1][2]] <> 1 Then $newdir = $newdirdirection[$direction[$i]][1][3]
    If $collision[$newdirdirection[$direction[$i]][2][0]] = 1 And $collision[$newdirdirection[$direction[$i]][2][1]] <> 1 And $collision[$newdirdirection[$direction[$i]][2][2]] = 1 Then $newdir = $newdirdirection[$direction[$i]][2][3]
    If $collision[$newdirdirection[$direction[$i]][3][0]] = 1 And $collision[$newdirdirection[$direction[$i]][3][1]] <> 1 And $collision[$newdirdirection[$direction[$i]][3][2]] <> 1 Then $newdir = $newdirdirection[$direction[$i]][3][3]
    If $collision[$newdirdirection[$direction[$i]][4][0]] <> 1 And $collision[$newdirdirection[$direction[$i]][4][1]] = 1 And $collision[$newdirdirection[$direction[$i]][4][2]] = 1 Then $newdir = $newdirdirection[$direction[$i]][4][3]
    If $collision[$newdirdirection[$direction[$i]][5][0]] <> 1 And $collision[$newdirdirection[$direction[$i]][5][1]] = 1 And $collision[$newdirdirection[$direction[$i]][5][2]] <> 1 Then $newdir = $newdirdirection[$direction[$i]][5][3]
    If $collision[$newdirdirection[$direction[$i]][6][0]] <> 1 And $collision[$newdirdirection[$direction[$i]][6][1]] <> 1 And $collision[$newdirdirection[$direction[$i]][6][2]] = 1 Then $newdir = $newdirdirection[$direction[$i]][6][3]
    If $collision[$newdirdirection[$direction[$i]][7][0]] <> 1 And $collision[$newdirdirection[$direction[$i]][7][1]] <> 1 And $collision[$newdirdirection[$direction[$i]][7][2]] <> 1 Then $newdir = $newdirdirection[$direction[$i]][7][3]
    $direction[$i] = $newdir
    Switch $direction[$i]
    Case 0
    $ballpos[0][$i] -= 1
    $ballpos[1][$i] -= 1
    Case 1
    $ballpos[0][$i] += 1
    $ballpos[1][$i] -= 1
    Case 2
    $ballpos[0][$i] += 1
    $ballpos[1][$i] += 1
    Case 3
    $ballpos[0][$i] -= 1
    $ballpos[1][$i] += 1
    EndSwitch

    GUICtrlSetBkColor($background_control[$ballpos[0][$i]][$ballpos[1][$i]], 0x000000)

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

    If $array[$ballpos[0][$i]][$ballpos[1][$i]] = 2 Then
    If $lives > 0 Then
    $player_direction = -1
    $player_pos[0] = 0
    $player_pos[1] = 0
    $lives -= 1
    GUICtrlSetData($lifelabel, "Leben: "&$lives)
    For $x = 1 to 52-2
    For $y = 1 to 52-2
    If $array[$x][$y] = 2 then
    $array[$x][$y] = 0
    GUICtrlSetBkColor($background_control[$x][$y], 0xFFFFFF)
    EndIf
    Next
    Next
    Else
    MsgBox(0, "Game Over", "Du hast bei Level "&$level-1&" verloren.")
    $level = 1
    $lives = 3
    GUICtrlSetData($lifelabel, "Leben: "&$lives)
    _newlevel()
    EndIf
    EndIf
    Next
    EndFunc ;==>_ballmove

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

    Func _check($num)
    Local $allcol[8]
    $allcol[0] = $array[$ballpos[0][$num] - 1][$ballpos[1][$num]]
    $allcol[1] = $array[$ballpos[0][$num] - 1][$ballpos[1][$num] - 1]
    $allcol[2] = $array[$ballpos[0][$num]][$ballpos[1][$num] - 1]
    $allcol[3] = $array[$ballpos[0][$num] + 1][$ballpos[1][$num] - 1]
    $allcol[4] = $array[$ballpos[0][$num] + 1][$ballpos[1][$num]]
    $allcol[5] = $array[$ballpos[0][$num] + 1][$ballpos[1][$num] + 1]
    $allcol[6] = $array[$ballpos[0][$num]][$ballpos[1][$num] + 1]
    $allcol[7] = $array[$ballpos[0][$num] - 1][$ballpos[1][$num] + 1]
    Return $allcol
    EndFunc ;==>_check

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

    Func _fill($start, $end)
    Local $redpoints, $fnumber = 0
    $redpoints = _getRedPoints()
    For $i = 0 To $rpcounter - 1
    If $array[$redpoints[$i][0] + 1][$redpoints[$i][1]] = 0 Then
    _a($redpoints[$i][0] + 1, $redpoints[$i][1], $fnumber)
    $fnumber = 1
    EndIf
    If $array[$redpoints[$i][0] - 1][$redpoints[$i][1]] = 0 Then
    _a($redpoints[$i][0] - 1, $redpoints[$i][1], $fnumber)
    $fnumber = 1
    EndIf
    If $array[$redpoints[$i][0]][$redpoints[$i][1] + 1] = 0 Then
    _a($redpoints[$i][0], $redpoints[$i][1] + 1, $fnumber)
    $fnumber = 1
    EndIf
    If $array[$redpoints[$i][0]][$redpoints[$i][1] - 1] = 0 Then
    _a($redpoints[$i][0], $redpoints[$i][1] - 1, $fnumber)
    $fnumber = 1
    EndIf
    Next
    _compare()
    $rpcounter = 0
    For $x = 1 To 50
    For $y = 1 To 50
    If $array[$x][$y] = 2 Then
    $array[$x][$y] = 1
    GUICtrlSetBkColor($background_control[$x][$y], 0x000000)
    EndIf
    Next
    Next
    _issolved()
    EndFunc ;==>_fill

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

    Func _getRedPoints()
    Local $redpoints[2500][2]
    For $i = 1 To 50
    For $j = 1 To 50
    If $array[$i][$j] = 2 Then
    $redpoints[$rpcounter][0] = $i
    $redpoints[$rpcounter][1] = $j
    $rpcounter = $rpcounter + 1
    EndIf
    Next
    Next
    Return $redpoints
    EndFunc ;==>_getRedPoints

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

    Func _a($xpos, $ypos, $fnumber)
    If $array[$xpos + 1][$ypos] = 0 Then
    $array[$xpos + 1][$ypos] = 3 + $fnumber
    _a($xpos + 1, $ypos, $fnumber)
    EndIf
    If $array[$xpos - 1][$ypos] = 0 Then
    $array[$xpos - 1][$ypos] = 3 + $fnumber
    _a($xpos - 1, $ypos, $fnumber)
    EndIf
    If $array[$xpos][$ypos + 1] = 0 Then
    $array[$xpos][$ypos + 1] = 3 + $fnumber
    _a($xpos, $ypos + 1, $fnumber)
    EndIf
    If $array[$xpos][$ypos - 1] = 0 Then
    $array[$xpos][$ypos - 1] = 3 + $fnumber
    _a($xpos, $ypos - 1, $fnumber)
    EndIf

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

    EndFunc ;==>_a

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

    Func _compare()
    Local $amount = 0
    For $i = 0 to $level-1
    If $array[$ballpos[0][$i]][$ballpos[1][$i]] = 3 Then $amount += 1
    Next
    If $amount = $level -1 Then
    For $i = 1 To 50
    For $j = 1 To 50
    If $array[$i][$j] = 3 Then
    $array[$i][$j] = 0
    EndIf
    If $array[$i][$j] = 4 Then
    $array[$i][$j] = 2
    EndIf
    Next
    Next
    Elseif $amount = 0 Then
    For $i = 1 To 50
    For $j = 1 To 50
    If $array[$i][$j] = 4 Then
    $array[$i][$j] = 0
    EndIf
    If $array[$i][$j] = 3 Then
    $array[$i][$j] = 2
    EndIf
    Next
    Next
    Else
    For $i = 1 To 50
    For $j = 1 To 50
    If $array[$i][$j] = 3 or $array[$i][$j] = 4 Then
    $array[$i][$j] = 0
    EndIf
    Next
    Next
    EndIf
    EndFunc ;==>_compare

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

    Func _Issolved()
    Local $black = 0
    For $i = 1 To 50
    For $j = 1 To 50
    If $array[$i][$j] = 1 Then
    $black += 1
    EndIf
    Next
    Next

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

    If $black / 2500 <= $grenze Then
    GUICtrlSetData($percentlabel, "Prozent: "&round(($black / 52^2)*100))
    Else
    _newlevel()
    EndIf
    EndFunc ;==>_Issolved

    [/autoit]


    MfG,
    Rapit&Fresapore