;#AutoIt3Wrapper_AU3Check_Parameters= -q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ;#Tidy_Parameters=/sf #include-once #include #include #include #include #include OnAutoItExitRegister("on_exit") _GDIPlus_Startup() Opt("GUIOnEventMode", 1) Opt("GUIEventOptions", 1) Opt("MustDeclareVars", 1) Global Const $SD = "Scripting.Dictionary" Global $sGuiTitle = "Detefons's grid" Global $hGui Global $hGraphic, $hBitmap, $hBackbuffer, $hPen Global $oWall = ObjCreate($SD) Global $aDim[9] $aDim[0] = 32 $aDim[1] = 9 $aDim[2] = 5 $aDim[3] = $aDim[0] * $aDim[1] $aDim[4] = $aDim[0] * $aDim[2] $aDim[5] = 0 $aDim[6] = 0 $aDim[7] = $aDim[0] * $aDim[1] - $aDim[0] $aDim[8] = $aDim[0] * $aDim[2] - $aDim[0] ;_ArrayDisplay($aDim) ; 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 $mx, $my ; used to calc a movement's diagonal Global Const $ROOT = Round(Sqrt(2) / 2, 3) Global $hDLL = DllOpen("User32.dll") Global $aGrid[$aDim[1]][$aDim[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[$aDim[1]][$aDim[2]] Global $oActor = ObjCreate($SD) $oActor.Add(1, ObjCreate($SD)) $oActor.Item(1).Add("x", 3) ; start x position $oActor.Item(1).Add("y", 3) ; start y position $oActor.Item(1).Add("s", 0.15) ; speed horizontal and vertical $oActor.Item(1).Add("ss", $oActor.Item(1).Item("s") * $ROOT) ; speed diagonal $hGui = GUICreate($sGuiTitle, $aDim[3], $aDim[4], -1, -1, Default, Default) GUISetOnEvent($GUI_EVENT_CLOSE, "_quit") $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui) $hBitmap = _GDIPlus_BitmapCreateFromGraphics($aDim[3], $aDim[4], $hGraphic) $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) $hPen = _GDIPlus_PenCreate() _GDIPlus_GraphicsClear($hBackbuffer) _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2) walls() GUISetState(@SW_SHOW, $hGui) _update() AdlibRegister("_update", 25) While Sleep(25) WEnd Func _update() keyboard() move() _GDIPlus_GraphicsClear($hBackbuffer, 0xFFFFFFFF) draw_walls() _box($hBackbuffer, $oActor.Item(1).Item("x") * $aDim[0], $oActor.Item(1).Item("y") * $aDim[0], $aDim[0], $aDim[0]) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $aDim[3], $aDim[4]) EndFunc ;==>_update Func keyboard() For $ii = 0 To 5 If _IsPressed($aKeys[$ii], $hDLL) And Not $aPress[$ii] Then $aPress[$ii] = True If Not _IsPressed($aKeys[$ii], $hDLL) And $aPress[$ii] Then $aPress[$ii] = False Next EndFunc ;==>keyboard Func mov_vh($each, $dir, $speed, $sig = 1) ; movement vertical and horizontal Local $iTry = Round($oActor.Item($each).Item($dir) + $oActor.Item($each).Item($speed) * $sig, 1) Switch $dir Case "x" Switch $sig Case -1 If $iTry < 0 Then Return 0 If ($aPos[Floor($iTry)][Floor($oActor.Item($each).Item("y"))]) Or _ ($aPos[Floor($iTry)][Ceiling($oActor.Item($each).Item("y"))]) Then Return Ceiling($iTry) Case 1 If $iTry + 1 > $aDim[1] Then Return $aDim[1] - 1 If ($aPos[Ceiling($iTry)][Ceiling($oActor.Item($each).Item("y"))]) Or _ ($aPos[Ceiling($iTry)][Floor($oActor.Item($each).Item("y"))]) Then Return Floor($iTry) EndSwitch Case "y" Switch $sig Case -1 If $iTry < 0 Then Return 0 If ($aPos[Floor($oActor.Item($each).Item("x"))][Floor($iTry)]) Or _ ($aPos[Ceiling($oActor.Item($each).Item("x"))][Floor($iTry)]) Then Return Ceiling($iTry) Case 1 If $iTry + 1 > $aDim[2] Then Return $aDim[2] - 1 If ($aPos[Ceiling($oActor.Item($each).Item("x"))][Ceiling($iTry)]) Or _ ($aPos[Floor($oActor.Item($each).Item("x"))][Ceiling($iTry)]) Then Return Floor($iTry) EndSwitch 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) Next WinSetTitle($hGui, "", $sGuiTitle & " :: x,y[" & Round($oActor.Item(1).Item("x")) & "," & Round($oActor.Item(1).Item("y")) & "]") EndFunc ;==>move Func _quit() Exit EndFunc ;==>_quit Func on_exit() _GDIPlus_GraphicsDispose($hBackbuffer) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() If $hDLL <> -1 Then DllClose($hDLL) GUIDelete($hGui) EndFunc ;==>on_exit Func walls() $oWall.Add($oWall.Count + 1, ObjCreate($SD)) $oWall.Item($oWall.Count).Add("x", 1) $oWall.Item($oWall.Count).Add("y", 1) $oWall.Item($oWall.Count).Add("c", 0xFFFF0000) $oWall.Add($oWall.Count + 1, ObjCreate($SD)) $oWall.Item($oWall.Count).Add("x", 1) $oWall.Item($oWall.Count).Add("y", 2) $oWall.Item($oWall.Count).Add("c", 0xFF00FF00) $oWall.Add($oWall.Count + 1, ObjCreate($SD)) $oWall.Item($oWall.Count).Add("x", 3) $oWall.Item($oWall.Count).Add("y", 1) $oWall.Item($oWall.Count).Add("c", 0xFF0000FF) $oWall.Add($oWall.Count + 1, ObjCreate($SD)) $oWall.Item($oWall.Count).Add("x", 2) $oWall.Item($oWall.Count).Add("y", 1) $oWall.Item($oWall.Count).Add("c", 0xFF00FFFF) $oWall.Add($oWall.Count + 1, ObjCreate($SD)) $oWall.Item($oWall.Count).Add("x", 5) $oWall.Item($oWall.Count).Add("y", 2) $oWall.Item($oWall.Count).Add("c", 0xFFFFFF00) $oWall.Add($oWall.Count + 1, ObjCreate($SD)) $oWall.Item($oWall.Count).Add("x", 5) $oWall.Item($oWall.Count).Add("y", 1) $oWall.Item($oWall.Count).Add("c", 0xFF33FF99) For $each In $oWall $aPos[$oWall.Item($each).Item("x")][$oWall.Item($each).Item("y")] = $oWall.Item($each).Item("c") Next EndFunc ;==>walls Func add_wall($iXX, $iYY, $iWW, $iHH, $iColor) For $ii = $iXX To $iXX + $iWW - 1 For $jj = $iYY To $iYY + $iHH - 1 _box($hBackbuffer, $ii * $aDim[0], $jj * $aDim[0], $iWW * $aDim[0], $iHH * $aDim[0], $iColor) Next Next EndFunc ;==>add_wall Func draw_walls() For $each In $oWall _box($hBackbuffer, $oWall.Item($each).Item("x") * $aDim[0], $oWall.Item($each).Item("y") * $aDim[0], $aDim[0], $aDim[0], $oWall.Item($each).Item("c")) Next EndFunc ;==>draw_walls Func _box($hToGraphic, $iXX, $iYY, $iWW, $iHH, $iColor = 0xFF000000) ; _box2 Local $aBox[5][2] $aBox[0][0] = 4 $aBox[1][0] = $iXX $aBox[1][1] = $iYY $aBox[2][0] = $iXX + $iWW - 1 $aBox[2][1] = $iYY $aBox[3][0] = $iXX + $iWW - 1 $aBox[3][1] = $iYY + $iHH - 1 $aBox[4][0] = $iXX $aBox[4][1] = $iYY + $iHH - 1 If $iColor Then _GDIPlus_PenSetColor($hPen, $iColor) _GDIPlus_GraphicsDrawPolygon($hToGraphic, $aBox, $hPen) Else _GDIPlus_GraphicsDrawPolygon($hToGraphic, $aBox) EndIf EndFunc ;==>_box