;#AutoIt3Wrapper_AU3Check_Parameters= -q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ;#Tidy_Parameters=/sf ; Author ........: Detefon ; Date ..........: 06/12/2014 #include-once #include #include #include #include OnAutoItExitRegister("on_exit") Opt("GUIOnEventMode", 1) Opt("GUIEventOptions", 1) Opt("MustDeclareVars", 1) Global $aGuiSize[2] = [830, 600] Global $sGuiTitle = "Detefons's grid" Global $hGui ; $aBox[0] size of box ; $aBox[1] horizontal space between boxes ; $aBox[2] vertical space between boxes ; $aBox[3] grid's left position ; $aBox[4] grid's top position Global $aBox[5] = [16, 1, 1, 10, 10] ; used to store the pressed keys Global $aPress[6] = [False, False, False, False, False, False] ; $aKeys[0] ctrl ; $aKeys[1] space ; $aKeys[2] left ; $aKeys[3] up ; $aKeys[4] right ; $aKeys[5] down Global $aKeys[6] = [11, 20, 25, 26, 27, 28] ; store old values from x and y Global $iox, $ioy Global $hLabelX, $hLabelY Global $mx, $my ; used to calc a movement's diagonal Global Const $ROOT = Round(Sqrt(2) / 2, 3) Global $aGrid[($aGuiSize[0] - $aBox[3]) / ($aBox[0] + $aBox[1])][($aGuiSize[1] - $aBox[4] - 30) / ($aBox[0] + $aBox[2])] ; $aPos is a shadow array, if a pos[x][y] have no value, is possible walk here ; if have a some value, this is not possible Global $aPos[UBound($aGrid, 1)][UBound($aGrid, 2)] ; limits Global $aLim[4] = [0, 0, UBound($aGrid, 1) - 1, UBound($aGrid, 2) - 1] Global $oActor = ObjCreate("Scripting.Dictionary") $oActor.Add(1, ObjCreate("Scripting.Dictionary")) $oActor.Item(1).Add("x", 4) ; start x position $oActor.Item(1).Add("y", 10) ; start y position $oActor.Item(1).Add("s", 0.5) ; speed horizontal and vertical $oActor.Item(1).Add("ss", $oActor.Item(1).Item("s") * $ROOT) ; speed diagonal $hGui = GUICreate($sGuiTitle, $aGuiSize[0], $aGuiSize[1], -1, -1, $WS_POPUPWINDOW, $WS_EX_COMPOSITED) GUISetOnEvent($GUI_EVENT_CLOSE, "_quit") create_walls() $hLabelX = GUICtrlCreateLabel("x " & $oActor.Item(1).Item("x"), 10, 555, 600, 20) $hLabelY = GUICtrlCreateLabel("y " & $oActor.Item(1).Item("y"), 10, 575, 600, 20) grid() GUISetState(@SW_SHOW, $hGui) While Sleep(20) keyboard() move() WEnd Func keyboard() For $ii = 0 To 5 If _IsPressed($aKeys[$ii]) And Not $aPress[$ii] Then $aPress[$ii] = True If Not _IsPressed($aKeys[$ii]) And $aPress[$ii] Then $aPress[$ii] = False Next EndFunc ;==>keyboard Func mov_vh($each, $dir, $speed, $sig = 1) ; movement vertical and horizontal Local $iTry = $oActor.Item($each).Item($dir) + $oActor.Item($each).Item($speed) * $sig Switch $dir Case "x" $mx = Round($iTry) $my = Round($oActor.Item($each).Item("y")) Switch $sig Case -1 If $iTry < $aLim[0] Then Return $aLim[0] Case 1 If $iTry > $aLim[2] Then Return $aLim[2] EndSwitch If ($aPos[$mx][$my]) Then Return $oActor.Item($each).Item("x") Case "y" $mx = Round($oActor.Item($each).Item("x")) $my = Round($iTry) Switch $sig Case -1 If $iTry < $aLim[1] Then Return $aLim[1] Case 1 If $iTry > $aLim[3] Then Return $aLim[3] EndSwitch If ($aPos[$mx][$my]) Then Return $oActor.Item($each).Item("y") EndSwitch Return $iTry EndFunc ;==>mov_vh Func move_d($each, $id) ; movement diagonal Switch $id Case 1 $oActor.Item($each).Item("x") = mov_vh($each, "x", "ss") $oActor.Item($each).Item("y") = mov_vh($each, "y", "ss", -1) Case 2 $oActor.Item($each).Item("x") = mov_vh($each, "x", "ss") $oActor.Item($each).Item("y") = mov_vh($each, "y", "ss") Case 3 $oActor.Item($each).Item("x") = mov_vh($each, "x", "ss", -1) $oActor.Item($each).Item("y") = mov_vh($each, "y", "ss") Case 4 $oActor.Item($each).Item("x") = mov_vh($each, "x", "ss", -1) $oActor.Item($each).Item("y") = mov_vh($each, "y", "ss", -1) EndSwitch EndFunc ;==>move_d Func move() For $each In $oActor $iox = $oActor.Item($each).Item("x") $ioy = $oActor.Item($each).Item("y") If $aPress[2] And Not $aPress[3] And Not $aPress[4] And Not $aPress[5] Then $oActor.Item($each).Item("x") = mov_vh($each, "x", "s", -1) If $aPress[4] And Not $aPress[2] And Not $aPress[3] And Not $aPress[5] Then $oActor.Item($each).Item("x") = mov_vh($each, "x", "s") If $aPress[3] And Not $aPress[2] And Not $aPress[4] And Not $aPress[5] Then $oActor.Item($each).Item("y") = mov_vh($each, "y", "s", -1) If $aPress[5] And Not $aPress[2] And Not $aPress[3] And Not $aPress[4] Then $oActor.Item($each).Item("y") = mov_vh($each, "y", "s") If $aPress[3] And $aPress[4] And Not $aPress[2] And Not $aPress[5] Then move_d($each, 1) If $aPress[4] And $aPress[5] And Not $aPress[2] And Not $aPress[3] Then move_d($each, 2) If $aPress[2] And $aPress[5] And Not $aPress[3] And Not $aPress[4] Then move_d($each, 3) If $aPress[2] And $aPress[3] And Not $aPress[4] And Not $aPress[5] Then move_d($each, 4) GUICtrlSetBkColor($aGrid[Round($iox)][Round($ioy)], 0xFFFFFF) GUICtrlSetBkColor($aGrid[Round($oActor.Item($each).Item("x"))][Round($oActor.Item($each).Item("y"))], 0x000000) Next GUICtrlSetData($hLabelX, "$x[" & Round($oActor.Item(1).Item("x")) & "]") GUICtrlSetData($hLabelY, "$y[" & Round($oActor.Item(1).Item("y")) & "]") EndFunc ;==>move Func grid() $mx = UBound($aGrid, 1) - 1 $my = UBound($aGrid, 2) - 1 For $ii = 0 To $mx For $jj = 0 To $my $aGrid[$ii][$jj] = GUICtrlCreateLabel("", $aBox[3] + $ii * ($aBox[0] + $aBox[1]), $aBox[4] + $jj * ($aBox[0] + $aBox[2]), $aBox[0], $aBox[0]) If $aPos[$ii][$jj] Then GUICtrlSetBkColor($aGrid[$ii][$jj], $aPos[$ii][$jj]) Else GUICtrlSetBkColor($aGrid[$ii][$jj], 0xFFFFFF) EndIf Next Next EndFunc ;==>grid Func _quit() Exit EndFunc ;==>_quit Func on_exit() GUIDelete($hGui) EndFunc ;==>on_exit Func add_wall($iXX, $iYY, $iWW, $iHH, $iColor) For $ii = $iXX To $iXX + $iWW - 1 For $jj = $iYY To $iYY + $iHH - 1 $aPos[$ii][$jj] = $iColor Next Next EndFunc ;==>add_wall Func create_walls() For $ii = 3 To 43 Step 3 add_wall($ii, 2, 1, 5, 0xFF0000) Next For $ii = 3 To 40 Step 6 add_wall($ii, 9, 4, 1, 0x00FF00) Next For $ii = 3 To 43 Step 3 add_wall($ii, 12, 1, 5, 0x0000FF) Next For $ii = 3 To 40 Step 6 add_wall($ii, 19, 4, 1, 0x00FFFF) Next For $ii = 3 To 43 Step 3 add_wall($ii, 22, 1, 5, 0xFFFF00) Next For $ii = 3 To 40 Step 6 add_wall($ii, 29, 4, 1, 0xFF6600) Next EndFunc ;==>create_walls