Пример #1
0
 private bool GetPointOpened(v2i point)
 {
     return(
         a_Maze.a_Walls.Contains(new Tuple <v2i, v2i>(Coord, point)) ||
         a_Maze.a_Walls.Contains(new Tuple <v2i, v2i>(point, Coord))
         );
 }
Пример #2
0
 public static void CreateEffectTexture(
     Material _material,
     ref RenderTexture _texture,
     v2i _wh
     )
 {
     Instance._CreateEffectTexture(_material, ref _texture, _wh);
 }
Пример #3
0
        protected void Render()
        {
            WriteMaterialData();

            v2i wh = a_ImageElement.WidthHeight.Floor().Abs();

            Graphic.Manager.CreateEffectTexture(Material, ref a_RenderTexture, wh);
        }
Пример #4
0
        private void Init()
        {
            v2i wh = a_ImageElement.WidthHeight.Floor();

            Material = new Material(p_Shader);

            a_RenderTexture = new RenderTexture(wh.width, wh.height, 16);

            p_UnityImage.texture = a_RenderTexture;
        }
Пример #5
0
        private void _CreateEffectTexture(
            Material _material,
            ref RenderTexture _texture,
            v2i _wh
            )
        {
            // по дефолту текстура закрашена хз во что
            Texture input = new Texture2D(_wh.width, _wh.height, TextureFormat.ARGB32, false);

            Graphics.Blit(input, _texture, _material);
        }
Пример #6
0
        protected List <Tuple <v2i, v2i> > GetAllWalls(List <v2i> cells)
        {
            List <Tuple <v2i, v2i> > ret = new List <Tuple <v2i, v2i> >();

            foreach (var cell in cells)
            {
                // проверяем добавлены ли уже 4 стены вокруг каждой ячейки

                v2i topPoint = new v2i(cell.x, cell.y + 1);

                if (
                    !ret.Contains(new Tuple <v2i, v2i>(cell, topPoint)) &&
                    !ret.Contains(new Tuple <v2i, v2i>(topPoint, cell))
                    )
                {
                    ret.Add(new Tuple <v2i, v2i>(cell, topPoint));
                }

                v2i rightPoint = new v2i(cell.x + 1, cell.y);

                if (
                    !ret.Contains(new Tuple <v2i, v2i>(cell, rightPoint)) &&
                    !ret.Contains(new Tuple <v2i, v2i>(rightPoint, cell))
                    )
                {
                    ret.Add(new Tuple <v2i, v2i>(cell, rightPoint));
                }

                v2i bottomPoint = new v2i(cell.x, cell.y - 1);

                if (
                    !ret.Contains(new Tuple <v2i, v2i>(cell, bottomPoint)) &&
                    !ret.Contains(new Tuple <v2i, v2i>(bottomPoint, cell))
                    )
                {
                    ret.Add(new Tuple <v2i, v2i>(cell, bottomPoint));
                }

                v2i leftPoint = new v2i(cell.x - 1, cell.y);

                if (
                    !ret.Contains(new Tuple <v2i, v2i>(cell, leftPoint)) &&
                    !ret.Contains(new Tuple <v2i, v2i>(leftPoint, cell))
                    )
                {
                    ret.Add(new Tuple <v2i, v2i>(cell, leftPoint));
                }
            }

            return(ret);
        }
Пример #7
0
            private void SetPointOpened(v2i point, bool value)
            {
                if (value)
                {
                    if (GetPointOpened(point))
                    {
                        return;
                    }

                    a_Maze.a_Walls.Add(new Tuple <v2i, v2i>(Coord, point));
                }
                else
                {
                    a_Maze.a_Walls.Remove(new Tuple <v2i, v2i>(Coord, point));
                    a_Maze.a_Walls.Remove(new Tuple <v2i, v2i>(point, Coord));
                }
            }
Пример #8
0
    protected Tuple <bool, bool> IsInOutset(v2i _cellPoint)
    {
        // cellpoint (координаты ячейки) не то же самое что и координаты точки (point)

        PointPlace pointPlaceLeftBottom  = GetPointPlace((v2f)_cellPoint);
        PointPlace pointPlaceLeftTop     = GetPointPlace(new v2f(_cellPoint.x, _cellPoint.y + 1));
        PointPlace pointPlaceRightTop    = GetPointPlace(new v2f(_cellPoint.x + 1, _cellPoint.y + 1));
        PointPlace pointPlaceRightBottom = GetPointPlace(new v2f(_cellPoint.x + 1, _cellPoint.y));

        // inset
        bool inset =
            pointPlaceLeftBottom != PointPlace.OUTSET && pointPlaceLeftTop != PointPlace.OUTSET &&
            pointPlaceRightTop != PointPlace.OUTSET && pointPlaceRightBottom != PointPlace.OUTSET;

        bool outset =
            (pointPlaceLeftBottom == PointPlace.INSET || pointPlaceLeftTop == PointPlace.INSET ||
             pointPlaceRightTop == PointPlace.INSET || pointPlaceRightBottom == PointPlace.INSET) ||
            (pointPlaceLeftBottom == PointPlace.BORDER && pointPlaceLeftTop == PointPlace.BORDER &&
             pointPlaceRightTop == PointPlace.BORDER && pointPlaceRightBottom == PointPlace.BORDER);

        return(new Tuple <bool, bool>(inset, outset));
    }
Пример #9
0
    public override void CalculateCells()
    {
        // если бы реализация всегда оставалась такой - это можно было бы вынести в отдельную функцию в базовом классе и не печатать один и тот же код сто раз
        // однако когда мы это будем оптимизировать реализация у каждого дочернего класса от Field поменяется, поэтому код дублируется, его немного так шо пох

        int
            xMin = (int)(Center.x - Radius),
            xMax = (int)(Center.x + Radius),
            yMin = (int)(Center.y - Radius),
            yMax = (int)(Center.y + Radius);

        HashSet <v2i> inset  = new HashSet <v2i>();
        HashSet <v2i> outset = new HashSet <v2i>();

        for (int x = xMin; x <= xMax; x++)
        {
            for (int y = yMin; y <= yMax; y++)
            {
                v2i cellPoint = new v2i(x, y);

                Tuple <bool, bool> pointPlace = IsInOutset(cellPoint);

                if (pointPlace.Item1)
                {
                    inset.Add(cellPoint);
                }

                if (pointPlace.Item2)
                {
                    outset.Add(cellPoint);
                }
            }
        }

        a_CellsInset  = inset.ToList();
        a_CellsOutset = outset.ToList();
    }
Пример #10
0
 public int RandomeIntRange(v2i _ab)
 => a_Root.RandomeIntRange(_ab);
Пример #11
0
 public void GoLeft()
 {
     CheckMove(a_Maze.GetCellFromPoint(a_Coord.LeftPoint));
     a_Coord = a_Coord.LeftPoint;
 }
Пример #12
0
 public void GoBottom()
 {
     CheckMove(a_Maze.GetCellFromPoint(a_Coord.BottomPoint));
     a_Coord = a_Coord.BottomPoint;
 }
Пример #13
0
 public void GoRight()
 {
     CheckMove(a_Maze.GetCellFromPoint(a_Coord.RightPoint));
     a_Coord = a_Coord.RightPoint;
 }
Пример #14
0
 public void GoTop()
 {
     CheckMove(a_Maze.GetCellFromPoint(a_Coord.TopPoint));
     a_Coord = a_Coord.TopPoint;
 }
Пример #15
0
 public Walker(AldousBroderBelyakov _maze, int _zoneId, v2i _coord)
 {
     a_Maze   = _maze;
     a_Coord  = _coord;
     a_ZoneId = _zoneId;
 }
Пример #16
0
 private AldousBroderBelyakovCell GetCellFromPoint(v2i _cell)
 {
     return(a_MazeCells[_cell] as AldousBroderBelyakovCell);
 }
Пример #17
0
 protected override TreeMazeCell CreateCellFromPoint(v2i _cell)
 {
     return(new AldousBroderBelyakovCell(this, _cell));
 }
Пример #18
0
 public TreeMazeCell(TreeMaze _maze, v2i _coord)
 {
     a_Maze = _maze;
     Coord  = _coord;
 }
Пример #19
0
        /*protected override void InitDefault()
         * {
         *  base.InitDefault();
         *
         *  List<v2i> allCells = CutingBorderCells ? Field.CellsInset : Field.CellsOutset;
         *
         *  List<Tuple<v2i,v2i>> walls = GetAllWalls( allCells );
         * }*/

        protected abstract TreeMazeCell CreateCellFromPoint(v2i _cell);
Пример #20
0
    static int createmaze()
    {
        System.DateTime now = System.DateTime.Now;
        System.Random   r   = new System.Random(System.DateTime.Now.Millisecond + System.DateTime.Now.Second);

        v2i previous  = new v2i(r.Next(H), 9);
        v2i operation = previous;
        v2i next      = previous;


        set[previous.x, previous.y]      = true;
        map[previous.x, previous.y]      = allwall - up;
        distance[previous.x, previous.y] = 1;

        int assigned = 1;

        while (assigned < mazeSize)
        {
            operation = operations[r.Next(operations.Length)];
            next      = previous + operation;
            if (next.x >= 0 && next.x < H && next.y >= 2 && next.y < V)
            {
                if (!set[next.x, next.y])
                {
                    distance[next.x, next.y] = distance[previous.x, previous.y] + 1;
                    assigned++;
                    set[next.x, next.y] = true;
                    switch (operation.ToString())
                    {
                    case "-1 0":
                        map[next.x, next.y]         &= (allwall - right);
                        map[previous.x, previous.y] &= (allwall - left);
                        break;

                    case "1 0":
                        map[next.x, next.y]         &= (allwall - left);
                        map[previous.x, previous.y] &= (allwall - right);
                        break;

                    case "0 1":
                        map[next.x, next.y]         &= (allwall - down);
                        map[previous.x, previous.y] &= (allwall - up);
                        break;

                    case "0 -1":
                        map[next.x, next.y]         &= (allwall - up);
                        map[previous.x, previous.y] &= (allwall - down);
                        break;

                    default:
                        break;
                    }
                }
                previous = next;
            }
        }

        Game.text = "";
        for (int i = V - 1; i >= 0; i--)
        {
            for (int j = 0; j < H; j++)
            {
                if (distance[j, i] < 100)
                {
                    if (distance[j, i] < 10)
                    {
                        Game.text += "_" + distance[j, i] + " ";
                    }
                    else
                    {
                        Game.text += distance[j, i] + " ";
                    }
                }
            }
            Game.text += "\n";
        }

        entranceID = 0;
        int currmax = -1;

        for (int i = 0; i < H; i++)
        {
            if (distance[i, 2] < 16 && distance[i, 2] > currmax)
            {
                entranceID = i;
                currmax    = distance[i, 2];
            }
        }
        map[entranceID, 2] -= down;
        return(currmax);
    }
Пример #21
0
 public int RandomeIntRange(v2i _ab)
 {
     return(RandomeIntRange(_ab.x, _ab.y));
 }
Пример #22
0
    public override bool Equals(object o)
    {
        v2i b = (v2i)o;

        return(x == b.x && y == b.y);
    }
Пример #23
0
 public static int IntRange(v2i _ab)
 {
     return(IntRange(_ab.x, _ab.y));
 }
Пример #24
0
 public AldousBroderBelyakovCell(TreeMaze _maze, v2i _coord)
     : base(_maze, _coord)
 {
     WasVisited = false;
 }