#include #include #include #include Opt("GUIOnEventMode", 1) Opt("GUIEventOptions", 1) Opt("MustDeclareVars", 1) OnAutoItExitRegister("on_exit") Global $hDLL = DllOpen("User32.dll") ; direções da roda dos ventos ; wind rose's direction Global $ww, $ee, $nn, $ss, $nw, $ne, $sw, $se ; verifica se há contato ; contact's check Global $iTouch ; diração do ator ; directon's actor Global $iDir = 0 Global Const $ROOT = Round(Sqrt(2) / 2, 3) Global $hGui Global $hGraphic, $hPen, $hBitmap, $hBackbuffer Global Const $SD = "Scripting.Dictionary" Global $oWall = ObjCreate($SD) Global $oActor = ObjCreate($SD) ; $aMap[0] linhas / lines ; $aMap[1] colunas / columns Global $aMap[2] = [10, 5] ; tamanho da célula (o ator e cada bloco do muro possuem este tamanho) ; size's cell (the actor and each wall block have this size) Global $iCell = 32 ; limite do gráfico ; graphics limit Global $aLim[4] $aLim[0] = 0 $aLim[1] = 0 $aLim[2] = $aMap[0] * $iCell - $iCell $aLim[3] = $aMap[1] * $iCell - $iCell Global $aSize[2] = [$aMap[0] * $iCell, $aMap[1] * $iCell] Global $aGrid[$aSize[0]][$aSize[1]] add_actor(64, 96, 3, 0xFF0000FF) Func add_actor($xx, $yy, $speed, $iColor) $oActor.Add($oActor.Count + 1, ObjCreate($SD)) $oActor.Item($oActor.Count).Add("x", $xx) $oActor.Item($oActor.Count).Add("y", $yy) $oActor.Item($oActor.Count).Add("st", $speed) $oActor.Item($oActor.Count).Add("sx", $oActor.Item($oActor.Count).Item("st") * $ROOT) $oActor.Item($oActor.Count).Add("c", $iColor) EndFunc ;==>add_actor Global $aPress[6] = [False, False, False, False, False, False] Global $aKeys[6] = [11, 20, 25, 26, 27, 28] $hGui = GUICreate("Detefon's grid", $aSize[0], $aSize[1]) GUISetOnEvent($GUI_EVENT_CLOSE, "_quit") GUISetState(@SW_SHOWNORMAL) _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui) $hBitmap = _GDIPlus_BitmapCreateFromGraphics($aSize[0], $aSize[1], $hGraphic) $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) $hPen = _GDIPlus_PenCreate() _GDIPlus_GraphicsClear($hBackbuffer) _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2) add_wall($iCell, $iCell, $iCell, $iCell, 0xFFFF0000) add_wall($iCell * 2, $iCell, $iCell, $iCell, 0xFFFF0000) add_wall($iCell * 4, $iCell, $iCell, $iCell, 0xFFFF0000) add_wall($iCell * 6, $iCell, $iCell, $iCell, 0xFFFF0000) add_wall($iCell * 6, $iCell * 2, $iCell, $iCell, 0xFFFF0000) add_wall($iCell * 6, $iCell * 4, $iCell, $iCell, 0xFFFF0000) AdlibRegister("_update", 20) While Sleep(20) WEnd Func _update() keyboard() _GDIPlus_GraphicsClear($hBackbuffer, 0xFFFFFFFF) draw_wall() move_actors() _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $aSize[0], $aSize[1]) EndFunc ;==>_update Func move_actors() For $each In $oActor move($each) _box($hBackbuffer, $oActor.Item($each).Item("x"), $oActor.Item($each).Item("y"), $iCell, $iCell, $oActor.Item($each).Item("c")) Next EndFunc ;==>move_actors Func draw_wall() For $each In $oWall _box($hBackbuffer, _ $oWall.Item($each).Item("x"), _ $oWall.Item($each).Item("y"), _ $oWall.Item($each).Item("w"), _ $oWall.Item($each).Item("h"), _ $oWall.Item($each).Item("c")) Next EndFunc ;==>draw_wall Func add_wall($xx, $yy, $ww, $hh, $iColor) Local $oo = ObjCreate($SD) $oWall.Add($oWall.Count + 1, ObjCreate($SD)) $oWall.Item($oWall.Count).Add("x", $xx) $oWall.Item($oWall.Count).Add("y", $yy) $oWall.Item($oWall.Count).Add("w", $ww) $oWall.Item($oWall.Count).Add("h", $hh) $oWall.Item($oWall.Count).Add("c", $iColor) For $ii = $xx To $xx + $hh - 1 For $jj = $yy To $yy + $ww - 1 $aGrid[$ii][$jj] = $oWall.Count Next Next EndFunc ;==>add_wall Func move($each) ;~ nw n ne ;~ w 0 e ;~ sw s se ;~ 32 3 34 ;~ 2 0 4 ;~ 52 5 54 $ww = $aPress[2] And Not $aPress[4] ? True : False $ee = $aPress[4] And Not $aPress[2] ? True : False $nn = $aPress[3] And Not $aPress[5] ? True : False $ss = $aPress[5] And Not $aPress[3] ? True : False $ne = $nn And $ee ? True : False $se = $ss And $ee ? True : False $sw = $ww And $ss ? True : False $nw = $ww And $nn ? True : False Select Case $nw ;ConsoleWrite("nw" & @LF) __move_x($each, 8, "sx") Case $ne ;ConsoleWrite("ne" & @LF) __move_x($each, 2, "sx") Case $se ;ConsoleWrite("se" & @LF) __move_x($each, 4, "sx") Case $sw ;ConsoleWrite("sw" & @LF) __move_x($each, 6, "sx") Case Else Select Case $nn __move_t($each, 1, "st") Case $ee __move_t($each, 3, "st") Case $ss __move_t($each, 5, "st") Case $ww __move_t($each, 7, "st") Case Else __move_t($each, 0, 0) EndSelect EndSelect EndFunc ;==>move Func __move_t($each, $dir, $speed = "") If Not $dir Then Return EndIf Switch $dir Case 1 ; $nn $oActor.Item($each).Item("y") -= $oActor.Item($each).Item($speed) If $oActor.Item($each).Item("y") < $aLim[1] Then $oActor.Item($each).Item("y") = $aLim[1] Else $iTouch = $aGrid[$oActor.Item($each).Item("x")][$oActor.Item($each).Item("y")] If $iTouch Then $oActor.Item($each).Item("y") = $oWall.Item($iTouch).Item("y") + $iCell $iTouch = $aGrid[$oActor.Item($each).Item("x") + $iCell - 1][$oActor.Item($each).Item("y")] If $iTouch Then $oActor.Item($each).Item("y") = $oWall.Item($iTouch).Item("y") + $iCell EndIf Case 3 ; $ee $oActor.Item($each).Item("x") += $oActor.Item($each).Item($speed) If $oActor.Item($each).Item("x") > $aLim[2] Then $oActor.Item($each).Item("x") = $aLim[2] Else $iTouch = $aGrid[$oActor.Item($each).Item("x") + $iCell - 1][$oActor.Item($each).Item("y")] If $iTouch Then $oActor.Item($each).Item("x") = $oWall.Item($iTouch).Item("x") - $iCell $iTouch = $aGrid[$oActor.Item($each).Item("x") + $iCell - 1][$oActor.Item($each).Item("y") + $iCell - 1] If $iTouch Then $oActor.Item($each).Item("x") = $oWall.Item($iTouch).Item("x") - $iCell EndIf Case 5 ; $ss $oActor.Item($each).Item("y") += $oActor.Item($each).Item($speed) If $oActor.Item($each).Item("y") > $aLim[3] Then $oActor.Item($each).Item("y") = $aLim[3] Else $iTouch = $aGrid[$oActor.Item($each).Item("x")][$oActor.Item($each).Item("y") + $iCell - 1] If $iTouch Then $oActor.Item($each).Item("y") = $oWall.Item($iTouch).Item("y") - $iCell $iTouch = $aGrid[$oActor.Item($each).Item("x") + $iCell - 1][$oActor.Item($each).Item("y") + $iCell - 1] If $iTouch Then $oActor.Item($each).Item("y") = $oWall.Item($iTouch).Item("y") - $iCell EndIf Case 7 ; $ww $oActor.Item($each).Item("x") -= $oActor.Item($each).Item($speed) If $oActor.Item($each).Item("x") < $aLim[0] Then $oActor.Item($each).Item("x") = $aLim[0] Else $iTouch = $aGrid[$oActor.Item($each).Item("x")][$oActor.Item($each).Item("y")] If $iTouch Then $oActor.Item($each).Item("x") = $oWall.Item($iTouch).Item("x") + $iCell $iTouch = $aGrid[$oActor.Item($each).Item("x")][$oActor.Item($each).Item("y") + $iCell - 1] If $iTouch Then $oActor.Item($each).Item("x") = $oWall.Item($iTouch).Item("x") + $iCell EndIf EndSwitch EndFunc ;==>__move_t Func __move_x($each, $dir, $speed = 0) If Not $dir Then Return EndIf Switch $dir Case 2 ; $ne __move_t($each, 1, "sx") __move_t($each, 3, "sx") Case 4 ; $se __move_t($each, 3, "sx") __move_t($each, 5, "sx") Case 6 ; $sw __move_t($each, 5, "sx") __move_t($each, 7, "sx") Case 8; $nw __move_t($each, 1, "sx") __move_t($each, 7, "sx") EndSwitch EndFunc ;==>__move_x 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 _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) Exit EndFunc ;==>on_exit 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