Esempio n. 1
0
    void HandleCursor(Vec3di tilePos0, Vec3di tilePos1)
    {
        if (Input.GetMouseButtonUp(0) == true)
        {
            if (dragModeHelper == 0)
            {
                if (pathStart.CompareXY(tilePos0))
                {
                    // enter drag mode - start tile
                    dragModeHelper = 1;
                }
                else if (pathEnd.CompareXY(tilePos0))
                {
                    // enter drag mode - end tile
                    dragModeHelper = 2;
                }
                else if (pathStart.CompareXY(tilePos1))
                {
                    // enter drag mode - start tile
                    dragModeHelper = 3;
                }
                else if (pathEnd.CompareXY(tilePos1))
                {
                    // enter drag mode - end tile
                    dragModeHelper = 4;
                }
            }
            else
            {
                dragModeHelper = 0;
            }
        }
        else
        {
            if (dragModeHelper == 1)
            {
                pathStart       = tilePos0;
                pathNeedsUpdate = true;
            }
            else if (dragModeHelper == 2)
            {
                pathEnd         = tilePos0;
                pathNeedsUpdate = true;
            }
            else if (dragModeHelper == 3)
            {
                pathStart   = tilePos1;
                pathStart.z = 1;

                pathNeedsUpdate = true;
            }
            else if (dragModeHelper == 4)
            {
                pathEnd   = tilePos1;
                pathEnd.z = 1;

                pathNeedsUpdate = true;
            }
        }
    }
Esempio n. 2
0
    public Vec3di LocalPosToTilePos(Vector3 local)
    {
        Vec3di tilePos = new Vec3di();

        tilePos.x = (int)((local.x + gridWidth * 0.5f + (width - 1) * gridWidth * 0.5f) / gridWidth);
        tilePos.y = (int)((-local.y + gridHeight * 0.5f + (height - 1) * gridHeight * 0.5f) / gridHeight);
        tilePos.z = 0;

        if (tilePos.x < 0)
        {
            tilePos.x = 0;
        }
        if (tilePos.x >= width)
        {
            tilePos.x = width - 1;
        }
        if (tilePos.y < 0)
        {
            tilePos.y = 0;
        }
        if (tilePos.y >= height)
        {
            tilePos.y = height - 1;
        }

        return(tilePos);
    }
Esempio n. 3
0
    override protected void OnUpdate()
    {
        if (generateMaze == true)
        {
            InitializeMaze();
            generateMaze    = false;
            pathNeedsUpdate = true;
        }

        base.OnUpdate();

        // calculate tile position
        Vec3di tilePosMouse = tilemaps_path[0].LocalPosToTilePos(tilemaps_path[0].transform.InverseTransformPoint(screenPos));

        if (pathNeedsUpdate)
        {
            agent.FindPath(pathEnd, curPath, AllowDiagonals);

            tilemaps[0].ApplyMap(srcGrid, 0);

            if (dragModeHelper == 0)
            {
                agent.Follow(curPath);
            }

            pathNeedsUpdate = false;
        }

        resGrid.Clear();
        ApplySolutionToMap(resGrid, 9);

        resGrid.SetAt(pathStart.x, pathStart.y, pathStart.z, 10);
        resGrid.SetAt(pathEnd.x, pathEnd.y, pathEnd.z, 10);

        resGrid.SetAt(tilePosMouse.x, tilePosMouse.y, 0, 11);

        tilemaps_path[0].ApplyMap(resGrid, 0);

        agentRep.transform.localPosition = tilemaps_path[0].TilePosToLocalPos(agent.ownPosition.x, agent.ownPosition.y, agentRep.transform.localPosition.z);
        agentRep.transform.eulerAngles   = new Vector3(0, 0, agent.curAimXYAnimated);

        if (lastTilePos.Compare(tilePosMouse) == false)
        {
            if (srcGrid.GetAt(tilePosMouse) != srcGrid.BorderCode)
            {
                agent.Stop();

                pathEnd   = tilePosMouse;
                pathStart = agent.ownPosition;

                dragModeHelper  = 0;
                pathNeedsUpdate = true;

                lastTilePos = tilePosMouse;
            }
        }
    }
Esempio n. 4
0
    override protected void OnUpdate()
    {
        base.OnUpdate();

        if (pathNeedsUpdate)
        {
            agent.ownPosition = pathStart;
            agent.FindPath(pathEnd, curPath, AllowDiagonals);

            for (int i = 0; i < tilemaps.Count; i++)
            {
                // apply first floor
                tilemaps[i].ApplyMap(srcGrid, i);
            }

            if (dragModeHelper == 0)
            {
                agent.Follow(curPath);
            }

            pathNeedsUpdate = false;
        }

        // calculate tile position
        Vector3 localPos0 = tilemaps_path[0].transform.InverseTransformPoint(screenPos);
        Vec3di  tilePos0  = tilemaps_path[0].LocalPosToTilePos(localPos0);

        tilePos0.z = 0;

        Vector3 localPos1 = tilemaps_path[1].transform.InverseTransformPoint(screenPos);
        Vec3di  tilePos1  = tilemaps_path[1].LocalPosToTilePos(localPos1);

        tilePos1.z = 1;

        resGrid.Clear();

        ApplySolutionToMap(resGrid, 9);

        resGrid.SetAt(pathStart.x, pathStart.y, 0, 10);
        resGrid.SetAt(pathEnd.x, pathEnd.y, 0, 10);

        resGrid.SetAt(pathStart.x, pathStart.y, 1, 10);
        resGrid.SetAt(pathEnd.x, pathEnd.y, 1, 10);

        resGrid.SetAt(tilePos0.x, tilePos0.y, 0, 11);
        resGrid.SetAt(tilePos1.x, tilePos1.y, 1, 11);

        tilemaps_path[0].ApplyMap(resGrid, 0);
        tilemaps_path[1].ApplyMap(resGrid, 1);

        // agentRep.transform.localPosition = tilemaps_path[0].TilePosToLocalPos(agent.ownPosition.x, agent.ownPosition.y, agentRep.transform.localPosition.z);
        // agentRep.transform.eulerAngles = new Vector3(0, 0, agent.curAimXYAnimated);

        HandleCursor(tilePos0, tilePos1);
    }
Esempio n. 5
0
    override protected void OnStart()
    {
        base.OnStart();

        pathStart = new Vec3di(1, 14, 0);
        pathEnd   = new Vec3di(30, 1, 0);

        InitializeMaze();

        btnExit.OnButtonUp += delegate(Button sender)
        {
            SceneManager.LoadScene(0);
        };

        //  agentRep.gameObject.SetActive(true);
    }
Esempio n. 6
0
    void InitializeMaze()
    {
        maze = new Maze(mapWidth / 3, mapHeight / 3);

        if (algorithm == Algo.DEEP_FIRST)
        {
            maze.GenerateRandomMazeDeepFirst(weightLeft, weightRight, weightTop, weightBottom);
        }
        else if (algorithm == Algo.BREATHE_FIRST)
        {
            maze.GenerateRandomMazeBreatheFirst(weightLeft, weightRight, weightTop, weightBottom);
        }

        maze.ApplyToMap(srcGrid, 1);

        pathStart = new Vec3di(maze.begin.Position.x * 3, maze.begin.Position.y * 3, 0);
        pathEnd   = new Vec3di(maze.end.Position.x * 3, maze.end.Position.y * 3, 0);

        agent.ownPosition = pathStart;
    }
Esempio n. 7
0
 // Use this for initialization
 void Start()
 {
     map         = GameObject.Find("World").GetComponent <World>().navGrid;
     ownPosition = new Vec3di(5, 5, 0);
 }