Ejemplo n.º 1
0
        void Start()
        {
            MapDescriptor map = new MapDescriptor("1");

            Cell[,] gridState = new Cell[map.rows[0].cells.Length, map.rows.Length];

            for (int y = 0; y < map.rows.Length; y++)
            {
                for (int x = 0; x < map.rows[y].cells.Length; x++)
                {
                    GameObject cell = factory.GetCell(map.rows[y].cells[x].type);
                    cell.name = y + " - " + x;
                    cell.transform.SetParent(transform);
                    cell.transform.position = new Vector2(x * 1.0f, y * -1.0f);
                    gridState [x, y]        = cell.GetComponent <Cell> ();
                }
            }

            CrossPoints = new CrossPoints(map, gridState);

            GameObject tank = factory.GetTank();

            tank.transform.SetParent(transform);
            tank.GetComponent <CharacterController>().point = CrossPoints._points[3, 2];
        }
Ejemplo n.º 2
0
        public CrossPoints(MapDescriptor map, Cell[,] gridState)
        {
            _points = new Point[map.rows [0].cells.Length - 1, map.rows.Length - 1];
            for (int i = 0; i < map.rows.Length - 1; i++)
            {
                for (int e = 0; e < map.rows[i].cells.Length - 1; e++)
                {
                    _points [e, i] = new Point()
                    {
                        x = e,
                        y = i
                    };
                }
            }

            for (int x = 0; x < _points.GetLength(0); x++)
            {
                for (int y = 0; y < _points.GetLength(1); y++)
                {
                    if (y + 1 < _points.GetLength(1))
                    {
                        _points[x, y].DownCross = _points[x, y + 1];
                    }
                    if (y - 1 >= 0)
                    {
                        _points[x, y].UpCross = _points[x, y - 1];
                    }
                    if (x - 1 >= 0)
                    {
                        _points[x, y].LeftCross = _points[x - 1, y];
                    }
                    if (x + 1 < _points.GetLength(0))
                    {
                        _points[x, y].RightCross = _points[x + 1, y];
                    }

                    _points [x, y].UpLeft    = gridState [x, y];
                    _points [x, y].UpRight   = gridState [x + 1, y];
                    _points [x, y].DownLeft  = gridState [x, y + 1];
                    _points [x, y].DownRight = gridState [x + 1, y + 1];
                }
            }
        }