Ejemplo n.º 1
0
    private void BuildGrid()
    {
        const int   width    = 6;
        const int   height   = 5;
        const float border   = 0f;
        const float quadSize = 15f;

        grid = RectGrid <MeshTileCell> .HorizontallyWrappedParallelogram(width, height);

        map = new PolarRectMap(Vector2.zero, 50, 350, new VectorPoint(width, height));

        foreach (var point in grid)
        {
            var cell = Instantiate(cellPrefab);
            cell.transform.parent = gridRoot.transform;

            float innerRadius = map.GetInnerRadius(point) + border / 2;
            float outerRadius = map.GetOuterRadius(point) - border / 2;
            float startAngle  = map.GetStartAngleZ(point);
            float endAngle    = map.GetEndAngleZ(point) - border * Mathf.Rad2Deg / outerRadius;
            int   quadCount   = Mathf.CeilToInt(outerRadius * 2 * Mathf.PI / (quadSize * width));

            Mesh mesh = cell.GetComponent <MeshFilter>().mesh;
            MeshUtils.MakeBandedSector(mesh, startAngle, endAngle, innerRadius, outerRadius, quadCount, v => v);

            cell.Color          = ExampleUtils.Colors[point.GetColor(6, 3, 1)];
            cell.HighlightOn    = false;
            cell.__CenterOffset = map[point].XYTo3D();

            grid[point] = cell;
        }
    }
Ejemplo n.º 2
0
        void Start()
        {
            _grid     = ForbiddenTiles._grid;
            _renderer = _grid.gameObject.GetComponent <Parallelepiped>();

            _grid.AlignTransform(transform);
        }
Ejemplo n.º 3
0
		private void BuildGrid()
		{
			// Creates a grid in a rectangular shape.
			grid = RectGrid<SpriteCell>.Rectangle(GRID_WIDTH, GRID_HEIGHT);
			
			// Creates a map...
			map = new RectMap(cellPrefab.Dimensions) 
				.WithWindow(ExampleUtils.ScreenRect)
					.AlignMiddleCenter(grid)
					.To3DXY();
			
			
			foreach (RectPoint point in grid) //Iterates over all points (coordinates) contained in the grid
			{
				SpriteCell cell = Instantiate(cellPrefab); 
				
				Vector3 worldPoint = map[point];
				
				cell.transform.parent = root.transform; 
				cell.transform.localScale = Vector3.one;
				cell.transform.localPosition = worldPoint;
				
				//if ( point.X % 2 == 1 && point.Y % 2 == 0)
				if ( Random.Range(0,100) > 85)
				{
					cell.Color = Color.black;
				} else {
					cell.Color = Color.blue;
				}

				cell.name = point.ToString(); // Makes it easier to identify cells in the editor.
				grid[point] = cell; // Finally, put the cell in the grid.
			}
		}
Ejemplo n.º 4
0
    // Use this for initialization
    void Start()
    {
        instance  = this;
        _grid     = GameObject.Find("Grid").GetComponent <RectGrid>();
        _renderer = _grid.gameObject.GetComponent <Parallelepiped>();
        xMin      = 0;  //(int)_renderer.From[0];
        xMax      = 20; //(int)_renderer.To[0];
        zMin      = 0;  //(int)_renderer.From[2];
        zMax      = 20; //(int)_renderer.To[2];

        for (int x = xMin; x < xMax; x++)
        {
            for (int z = zMin; z < zMax; z++)
            {
                int        elevationMax = mapTopography[x][z];
                Coordinate coordinate   = new Coordinate();
                coordinate.x             = x;
                coordinate.z             = z;
                coordinate.y             = elevationMax - 1;
                coordinate.respawnMarker = respawnMarkerList.Exists(r => r[0] == x && r[1] == z);
                syncCoordinates.Add(coordinate);
            }
        }

        CacheMatrix();

        RenderVoxels();

        CursorController.instance.Load();
    }
Ejemplo n.º 5
0
        public IEnumerator BuildGrid()
        {
            totalCellCount = 0;
            grid           = RectGrid <TileCell> .Rectangle(width, height);

            map = new RectMap(new Vector2(80, 80) * 3)
                  .To3DXY();

            int cellCount = 0;

            foreach (var point in grid)
            {
                var cell       = Instantiate(cellPrefab);
                var worldPoint = map[point];

                cell.transform.localPosition = worldPoint;

                cellCount++;
                totalCellCount++;

                grid[point] = cell;

                if (cellCount >= cellsPerIteration)
                {
                    cellCount = 0;
                    yield return(null);
                }
            }
        }
Ejemplo n.º 6
0
    private void SetupGrid()
    {
        gridCopy = (RectGrid <TileCell>)Grid.Clone();

        var map = new RectMap(Vector2.one)
                  .WithWindow(new Rect(0, 0, 1, 1))
                  .Stretch(Grid);

        var textureScaleVector = new Vector2(1f / GridBuilder.Dimensions.X, 1f / GridBuilder.Dimensions.Y);

        foreach (var point in Grid)
        {
            var cellObject = (TextureCell)Grid[point];

            var material = new Material(Shader.Find("Unlit/Texture"))
            {
                mainTexture       = puzzleImage,
                mainTextureScale  = textureScaleVector,
                mainTextureOffset = map[point]
            };

            cellObject.Renderer.material = material;
            materialBag.Add(material);
        }

        emptyCell = RectPoint.Zero;
        ((TextureCell)Grid[emptyCell]).Renderer.enabled = false;
    }
Ejemplo n.º 7
0
        private void BuildGrid()
        {
            // Creates a grid in a rectangular shape.
            grid = RectGrid <SpriteCell> .Rectangle(51, 111);

            // Creates a map...
            map = new RectMap(cellPrefab.Dimensions)             // The cell dimensions usually correspond to the visual
                  // part of the sprite in pixels. Here we use the actual
                  // sprite size, which causes a border between cells.
                  //

                  .WithWindow(ExampleUtils.ScreenRect) // ...that is centered in the rectangle provided
                  .AlignMiddleCenter(grid)             // by this and the previous line.
                  .To3DXY();                           // This makes the 2D map returned by the last function into a 3D map
            // This map assumes the grid is in the XY plane.
            // To3DXZ assumes the grid is in the XZ plane (you have to make sure
            //your tiles are similarly aligned / rotated).


            foreach (RectPoint point in grid)              //Iterates over all points (coordinates) contained in the grid
            {
                SpriteCell cell = Instantiate(cellPrefab); // Instantiate a cell from the given prefab.
                //This generic version of Instantiate is defined in GLMonoBehaviour
                //If you don't want to use GLMonoBehvaiour, you have to cast the result of
                //Instantiate

                Vector3 worldPoint = map[point];                 //Calculate the world point of the current grid point

                cell.transform.parent        = root.transform;   //Parent the cell to the root
                cell.transform.localScale    = Vector3.one;      //Readjust the scale - the re-parenting above may have changed it.
                cell.transform.localPosition = worldPoint;       //Set the localPosition of the cell.


                cell.Color = (point.Magnitude() % 2 == 0)? Color2 : Color2;
                if ((point.X == 3 || point.X == 47) && (point.Y > 2 && point.Y < 108))
                {
                    cell.Color = new Color(0.8f, 0.8f, 0.8f);
                }
                if ((point.Y == 3 || point.Y == 107 || point.Y == 55) && (point.X > 2 && point.X < 48))
                {
                    cell.Color = new Color(0.8f, 0.8f, 0.8f);
                }

                if ((point.X == 21 || point.X == 29) && (point.Y <= 2 || point.Y >= 108))
                {
                    cell.Color = new Color(0.8f, 0.8f, 0.8f);
                }
                if ((point.Y == 0 || point.Y == 110) && (point.X > 21 && point.X < 29))
                {
                    cell.Color = new Color(0.8f, 0.8f, 0.8f);
                }
                cell.name   = point.ToString();     // Makes it easier to identify cells in the editor.
                grid[point] = cell;                 // Finally, put the cell in the grid.

                //if (point.X >= 3 && point.X <= 47 && point.Y >= 3 && point.Y <= 107)
                //{
                rectPointArr[point.X, point.Y] = point;
                //}
            }
        }
Ejemplo n.º 8
0
 void OnEnable()
 {
     _grid    = target as RectGrid;
     _docsURL = "file://" + Application.dataPath
                + "/Plugins/GridFramework/Documentation/html/"
                + "class_grid_framework_1_1_grids_1_1_rect_grid.html";
 }
Ejemplo n.º 9
0
        private void BuildPuzzle()
        {
            const int size = 5;

            tileGrid = RectGrid <SpriteCell> .Rectangle(size, size);

            blocksGrid = (RectGrid <Block>)tileGrid.CloneStructure <Block>();

            map = new RectMap(new Vector2(200, 200))
                  .AnchorCellMiddleCenter()
                  .WithWindow(ExampleUtils.ScreenRect)
                  .AlignMiddleCenter(tileGrid)
                  .To3DXY();

            foreach (RectPoint point in tileGrid)
            {
                var cell = MakeCell(point);

                tileGrid[point]   = cell;
                blocksGrid[point] = null;
            }

            blocks = new List <Block>();

            AddFirstBlock();
            AddOtherBlocks();

            winPosition = new RectPoint(4, 2);
        }
Ejemplo n.º 10
0
	public IEnumerator BuildGrid()
	{	
		totalCellCount = 0;
		grid = RectGrid<TileCell>.Rectangle(width, height);
		
		map = new RectMap(new Vector2(80, 80)*3)
			.To3DXY();
		
		int cellCount = 0;
		
		foreach(var point in grid)
		{
			var cell = Instantiate(cellPrefab);			
			Vector3 worldPoint = map[point];

			cell.transform.localPosition = worldPoint;
			
			cellCount++;
			totalCellCount++;
			
			grid[point] = cell;
			
			if(cellCount >= cellsPerIteration)
			{
				cellCount = 0;
				yield return null;
			}
		}
	}
Ejemplo n.º 11
0
    public override void OnInspectorGUI()
    {
        RectGrid rectGrid = (RectGrid)target;

        int newWidth  = EditorGUILayout.IntField("width", rectGrid.width);
        int newHeight = EditorGUILayout.IntField("height", rectGrid.height);

        EditorGUILayout.LabelField("cell count", rectGrid.Graph.Size.ToString());

        if (newWidth != prevWidth || newHeight != prevHeight)
        {
            prevWidth  = newWidth;
            prevHeight = newHeight;
            ChangeSize(newWidth, newHeight);
        }

        int builderIndex = EditorGUILayout.Popup(prevBuilderIndex, builderNames);

        if (builderIndex != prevBuilderIndex || GUILayout.Button("rebuild"))
        {
            prevBuilderIndex = builderIndex;
            RebuildMaze(builders[builderIndex]);
        }

        DisplayImage();
    }
Ejemplo n.º 12
0
    public void BuildGrid()
    {
        // Creates a grid in a rectangular shape.
        grid = RectGrid<Cell>.Rectangle(6, 6);

        // Creates a map...
        map = new RectMap(cellPrefab.Dimensions) // The cell dimensions usually correspond to the visual
            // part of the sprite in pixels. Here we use the actual
            // sprite size, which causes a border between cells.
            .WithWindow(ExampleUtils.ScreenRect) // ...that is centered in the rectangle provided
            .AlignMiddleCenter(grid) // by this and the previous line.
            .To3DXY(); // This makes the 2D map returned by the last function into a 3D map
        // This map assumes the grid is in the XY plane.
        // To3DXZ assumes the grid is in the XZ plane (you have to make sure
        //your tiles are similarly aligned / rotated).

        //Iterates over all points (coordinates) contained in the
        foreach (RectPoint point in grid)  {
            Cell cell = (Cell) GameObject.Instantiate(cellPrefab, Vector3.zero, Quaternion.identity); // Instantiate a cell from the given prefab.
            Vector3 worldPoint = map[point]; //Calculate the world point of the current grid point

            cell.transform.parent = root.transform; //Parent the cell to the root
            cell.transform.localScale = Vector3.one; //Readjust the scale - the re-parenting above may have changed it.
            cell.transform.localPosition = worldPoint; //Set the localPosition of the cell.

            cell.name = point.ToString(); // Makes it easier to identify cells in the editor.
            grid[point] = cell; // Finally, put the cell in the grid.

            NetworkServer.Spawn(cell.gameObject);
        }
    }
Ejemplo n.º 13
0
 /// <summary>
 /// </summary>
 /// <param name="reference">
 ///   Position of the switch that was pressed.
 /// </param>
 /// <param name="grid">
 ///   Grid we use for gameplay.
 /// </param>
 /// <remarks>
 ///   <para>
 ///     This function broadcasts a signal (an event) once a switch has
 ///     been hit. Static means we don't need to use any specific
 ///     instance of this function.
 ///   </para>
 /// </remarks>
 public static void SendSignal(Vector3 reference, RectGrid grid)
 {
     //always make sure there a subscribers to the event, or you get errors
     if (OnHitSwitch != null)
     {
         OnHitSwitch(reference, grid);
     }
 }
Ejemplo n.º 14
0
        private void GridField()
        {
            const string label       = "Grid:";
            var          currentGrid = (Grid)_rectGrid ?? (Grid)_hexGrid;
            var          grid        = EditorGUILayout.ObjectField(label, currentGrid, typeof(Grid), true);

            _rectGrid = grid as RectGrid;
            _hexGrid  = grid as HexGrid;
        }
Ejemplo n.º 15
0
 // Use this for initialization
 void Awake()
 {
     instance  = this;
     _grid     = GameObject.Find("Grid").GetComponent <RectGrid>();
     _renderer = _grid.gameObject.GetComponent <Parallelepiped>();
     xMin      = (int)_renderer.From[0];
     xMax      = (int)_renderer.To[0];
     zMin      = (int)_renderer.From[2];
     zMax      = (int)_renderer.To[2];
 }
Ejemplo n.º 16
0
    private void ChangeSize(int width, int height)
    {
        RectGrid rectGrid = (RectGrid)target;

        rectGrid.SetSize(width, height);

        EditorUtility.SetDirty(target);

        image.Draw(rectGrid);
    }
Ejemplo n.º 17
0
		public static bool __CompilerHint__Rect__TileCell()
		{
			var grid = new RectGrid<TileCell[]>(1, 1);

			foreach(var point in grid) { grid[point] = new TileCell[1]; } 

			var shapeStorageInfo = new ShapeStorageInfo<RectPoint>(new IntRect(), p => true);
			var shapeInfo = new RectShapeInfo<TileCell>(shapeStorageInfo);

			return grid[grid.First()][0] == null || shapeInfo.Translate(RectPoint.Zero) != null;
		}
Ejemplo n.º 18
0
        public static bool __CompilerHint__Rect()
        {
            //Ensures abstract super classes for base grids gets created
            var grid = new RectGrid<TileCell>(1, 1, p => p == RectPoint.Zero, x => x, x => x, new List<RectPoint>());

            //Ensures shape infpo classes get created
            var shapeStorageInfo = new ShapeStorageInfo<RectPoint>(new IntRect(), p => true);
            var shapeInfo = new RectShapeInfo<TileCell>(shapeStorageInfo);

            return grid[grid.First()] == null || shapeInfo.Translate(RectPoint.Zero) != null;
        }
Ejemplo n.º 19
0
        /// <summary>
        ///   Whether two points are adjacent in the grid. Assumes whole
        ///   numbers for simplicity.
        /// </summary>
        /// <param name="grid">
        ///   Grid used for comparison.
        /// </param>
        /// <param name="a">
        ///   First coordinate in world coordinates.
        /// </param>
        /// <param name="b">
        ///   Second coordinate in world coordinates.
        /// </param>
        public static bool AreAdjacent(this RectGrid grid, Vector3 a, Vector3 b)
        {
            // Convert to grid-coordinates
            var u = grid.WorldToGrid(a);
            var v = grid.WorldToGrid(b);
            // Manhattan distance is the sum of the horizontal and vertical distances
            var manhattanDistance = AbsDelta(u.x, v.x) + AbsDelta(u.y, v.y);

            // Diagonal positions would have a Manhattan distance of 2.
            return(manhattanDistance <= 1.25);
        }
Ejemplo n.º 20
0
    public IEnumerator ScreenAnimator()
    {
        frame1.SetActive(true);
        frame2.SetActive(false);
        frame3.SetActive(false);
        yield return(new WaitForSeconds(0.6f));

        frame1.SetActive(false);
        frame2.SetActive(true);
        yield return(new WaitForSeconds(0.6f));

        frame1.SetActive(false);
        frame2.SetActive(false);
        frame3.SetActive(true);
        yield return(new WaitForSeconds(1f));

        float    origin_width, origin_height;
        RectGrid grid = frame3.GetComponent <RectGrid>();

        origin_width  = grid.Width;
        origin_height = grid.Height;
        float target_width   = 1.2f * origin_width;
        float target_height  = 1.2f * origin_height;
        float current_width  = origin_width;
        float current_height = origin_height;
        float ratio          = 0;
        float delta          = 0.005f;

        while ((Mathf.Abs(current_width - target_width) > float.Epsilon))
        {
            current_width  = Mathf.Lerp(origin_width, target_width, ratio);
            current_height = Mathf.Lerp(origin_height, target_height, ratio);
            ratio         += delta;
            grid.Width     = current_width;
            grid.Height    = current_height;
            grid.Rank();
            yield return(new WaitForEndOfFrame());
        }
        yield return(new WaitForSeconds(1f));

        ratio = 0;
        delta = 0.01f;
        while ((Mathf.Abs(current_width - origin_width) > float.Epsilon))
        {
            current_width  = Mathf.Lerp(target_width, origin_width, ratio);
            current_height = Mathf.Lerp(target_height, origin_height, ratio);
            ratio         += delta;
            grid.Width     = current_width;
            grid.Height    = current_height;
            grid.Rank();
            yield return(new WaitForEndOfFrame());
        }
    }
Ejemplo n.º 21
0
        public void RectGridTest()
        {
            for (int height = 1; height <= 8; height++)
            {
                for (int width = 1; width <= 8; width++)
                {
                    Console.WriteLine($"size = {width}, {height}");

                    RectGrid grid = new RectGrid(width, height);

                    Console.WriteLine($"mapsize = {grid.MapWidth}, {grid.MapHeight}");

                    Console.WriteLine("map :");

                    Console.WriteLine(grid.ToString());

                    Console.WriteLine("link :");

                    foreach ((int index, var link) in grid.Link)
                    {
                        Console.WriteLine($"{index} : {string.Join(',', link)}");
                    }

                    Assert.IsTrue(GridValidationUtil.IsValid(grid), $"{width}, {height}");
                    Assert.AreEqual(width * height, grid.Count, $"count {width}, {height}");

                    if (width >= 2 && height >= 2)
                    {
                        Assert.AreEqual(2, grid[0].Links);
                        Assert.AreEqual(3, grid[width - 1].Links);

                        if (height % 2 == 0)
                        {
                            Assert.AreEqual(3, grid[width * height - width].Links);
                            Assert.AreEqual(2, grid[width * height - 1].Links);
                        }
                        else
                        {
                            Assert.AreEqual(2, grid[width * height - width].Links);
                            Assert.AreEqual(3, grid[width * height - 1].Links);
                        }

                        Assert.AreEqual(2, grid.Cells.Where((cell) => cell.Links == 2).Count());
                    }

                    Console.WriteLine("---------------------------");
                }
            }
        }
Ejemplo n.º 22
0
            /// <summary>
            ///   Construct a new grid made of two rectangular grids.
            /// </summary>
            public Grid(RectGrid mainGrid, RectGrid subGrid,
                        Parallelepiped mainRenderer, Parallelepiped subRenderer,
                        float height)
            {
                this._mainGrid = mainGrid;
                this._subGrid  = subGrid;

                this._mainRenderer = mainRenderer;
                this._subRenderer  = subRenderer;

                this._spacing = 10.0f;
                this._mode    = Mode.Flex;

                this.Update(height);
            }
Ejemplo n.º 23
0
		/** 
			Call this method if you use a RectGrid.
			Replace	the type __CellType to whatever type you have in your grid.

			You can call the method anywhere in your code.
			
				if(!__CompilerHint__Rect()) return;

			This methods always returns true.

			@since 1.6
		*/
		public static bool __CompilerHint1__Rect()
		{
			//Ensures abstract super classes for base grids gets created
			var grid = new RectGrid<__CellType[]>(1, 1);

			foreach(var point in grid)
			{
				grid[point] = new __CellType[1];
			} 

			//Ensures shape infpo classes get created
			var shapeStorageInfo = new ShapeStorageInfo<RectPoint>(new IntRect(), p => true);
			var shapeInfo = new RectShapeInfo<__CellType>(shapeStorageInfo);

			return grid[grid.First()][0] == null || shapeInfo.Translate(RectPoint.Zero) != null;
		}
Ejemplo n.º 24
0
        /**
         *      This method is provided for generic testing purposes.
         *      It should generally not be used in production code: it may
         *      be slow and not type-safe.
         */
        public static TGrid MakeGrid <TPoint, TGrid, TCell>(int width, int height, TPoint offset)
            where TPoint : IGridPoint <TPoint>
            where TGrid : IGrid <TCell, TPoint>
        {
            if (typeof(TPoint) == typeof(PointyHexPoint))
            {
                Debug.Assert(typeof(TGrid) == typeof(PointyHexGrid <TCell>));

                return((TGrid)(object)new PointyHexGrid <TCell>(
                           width,
                           height,
                           x => PointyHexGrid <TCell> .DefaultContains(x, width, height),
                           (PointyHexPoint)(object)offset));
            }
            if (typeof(TPoint) == typeof(FlatHexPoint))
            {
                Debug.Assert(typeof(TGrid) == typeof(FlatHexGrid <TCell>));

                return((TGrid)(object)new FlatHexGrid <TCell>(
                           width,
                           height,
                           x => FlatHexGrid <TCell> .DefaultContains(x, width, height),
                           (FlatHexPoint)(object)offset));
            }
            if (typeof(TPoint) == typeof(RectPoint))
            {
                Debug.Assert(typeof(TGrid) == typeof(RectGrid <TCell>));

                return((TGrid)(object)new RectGrid <TCell>(
                           width,
                           height,
                           x => RectGrid <TCell> .DefaultContains(x, width, height),
                           (RectPoint)(object)offset));
            }
            if (typeof(TPoint) == typeof(DiamondPoint))
            {
                Debug.Assert(typeof(TGrid) == typeof(DiamondGrid <TCell>));

                return((TGrid)(object)new DiamondGrid <TCell>(
                           width,
                           height,
                           x => DiamondGrid <TCell> .DefaultContains(x, width, height),
                           (DiamondPoint)(object)offset));
            }

            throw new NotSupportedException();
        }
Ejemplo n.º 25
0
        public override IGrid <TCell, TPoint> MakeGrid <TCell, TPoint>()
        {
            if (typeof(TPoint) == typeof(RectPoint))
            {
                var grid = RectGrid <TCell>
                           .BeginShape()
                           .ChainMail()              //You can now chain the newly defined method to BeginShape
                           .EndShape();

                return((IGrid <TCell, TPoint>)grid);
            }

            Debug.LogError("<color=blue><b>" + GetType() + "</b></color> does not support grids for points of type " +
                           typeof(TPoint));

            return(null);
        }
Ejemplo n.º 26
0
    public static IEnumerable <RectPoint> GenerateMazeWalls <TCell>(RectGrid <TCell> grid)
    {
        var walls = grid.CloneStructure <bool>();        //true indicates passable

        foreach (var point in walls)
        {
            walls[point] = point.GetColor3() == 0;

            //Debug.Log(point);
        }

        var wallList = new PointList <RectPoint>();

        var newMaizePoint = grid.Where(p => p.GetColor3() == 0).RandomItem();
        var inMaze        = new PointList <RectPoint> {
            newMaizePoint
        };

        var edges = grid.GetNeighbors(newMaizePoint);

        wallList.AddRange(edges);

        while (wallList.Any())
        {
            var randomWall = wallList.RandomItem();
            var faces      = GetEdgeFaces(randomWall).Where(grid.Contains);

            //At least one of the two faces must be in the maze
            if (faces.Any(point => !inMaze.Contains(point)))
            {
                newMaizePoint = faces.First(point => !inMaze.Contains(point));
                inMaze.Add(newMaizePoint);
                walls[randomWall] = true;

                yield return(randomWall);

                // Add all edges that are not passages
                edges = grid.GetNeighbors(newMaizePoint).Where(edge => !(walls[edge]));
                wallList.AddRange(edges);
            }
            else
            {
                wallList.Remove(randomWall);
            }
        }
    }
Ejemplo n.º 27
0
        /// <summary>
        ///   Builds the matrix and sets everything up, gets called by a script
        ///   attached to the grid object.
        /// </summary>
        /// <param name="grid">
        ///   The grid will be assigned to this class's <c>_grid</c>.
        /// </param>
        /// <param name="renderer">
        ///   The grid's parallelepiped renderer is used for determining the
        ///   size of the matrix.
        /// </param>
        public static void Initialize(RectGrid grid, Parallelepiped renderer)
        {
            _grid = grid;

            // Amount of rows and columns based on the rendering range (assumes
            // the From is the zero-vector).
            var rows    = Mathf.FloorToInt(renderer.To.x);
            var columns = Mathf.FloorToInt(renderer.To.y);

            _tiles = new bool[rows, columns];

            for (var row = 0; row < rows; ++row)
            {
                for (var column = 0; column < columns; ++column)
                {
                    _tiles[row, column] = true;
                }
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        ///   Gets called upon the event <c>OnHitSwitch</c>.
        /// </summary>
        /// <param name="reference">
        ///   Position of the clicked switch in grid coordinates.
        /// </param>
        /// <param name="grid">
        ///   The grid we use for reference.
        /// </param>
        private void OnHitSwitch(Vector3 reference, RectGrid grid)
        {
            // Don't do anything if this light doesn't belong to the grid we
            // use.
            if (grid != _grid)
            {
                return;
            }

            // Check if this light is adjacent to the switch; this is an
            // extenion method that always picks the method that belongs to the
            // specific grid type. The implementation is in another file.
            var isAdjacent = grid.AreAdjacent(transform.position, reference);

            if (isAdjacent)
            {
                _isOn = !_isOn;
                SwitchLights();
            }
        }
Ejemplo n.º 29
0
    // Use this for initialization
    void Start()
    {
        _grid = GameObject.Find("Grid").GetComponent <RectGrid>();
        name  = "Cursor " + xPos + ", " + zPos;

        Vector3 position = transform.position;

        position.x = xPos + 0.5f;
        position.z = zPos + 0.5f;
        position.y = yPos + 1.1f;

        transform.position = position;

        NegotiateColor();

        //_grid.AlignTransform(transform);
        if (!useable)
        {
            gameObject.active = false;
        }
    }
Ejemplo n.º 30
0
        void Awake()
        {
            _mf   = gameObject.AddComponent <MeshFilter>();
            _mc   = gameObject.AddComponent <MeshCollider>();
            _mr   = gameObject.AddComponent <MeshRenderer>();
            _grid = GetComponent <RectGrid>();

            // Create the mesh, then assign it to the components that need it
            // and show the height map in the GUI.
            BuildMesh();
            AssignMesh();
            UpdateHeightString();

            // Disable the renderer, looks better that way.
            var gr = GetComponent <GridRenderer>();

            if (gr)
            {
                gr.enabled = false;
            }
        }
Ejemplo n.º 31
0
    private void BuildGrid()
    {
        // Creates a grid in a rectangular shape.
        grid = RectGrid <SpriteCell> .Rectangle(7, 7);

        // Creates a map...
        map = new RectMap(cellPrefab.Dimensions)                // The cell dimensions usually correspond to the visual
              // part of the sprite in pixels. Here we use the actual
              // sprite size, which causes a border between cells.
              //

              .WithWindow(ExampleUtils.ScreenRect) // ...that is centered in the rectangle provided
              .AlignMiddleCenter(grid)             // by this and the previous line.
              .To3DXY();                           // This makes the 2D map returned by the last function into a 3D map
        // This map assumes the grid is in the XY plane.
        // To3DXZ assumes the grid is in the XZ plane (you have to make sure
        //your tiles are similarly aligned / rotated).


        foreach (RectPoint point in grid)              //Iterates over all points (coordinates) contained in the grid
        {
            SpriteCell cell = Instantiate(cellPrefab); // Instantiate a cell from the given prefab.
            //This generic version of Instantiate is defined in GLMonoBehaviour
            //If you don't want to use GLMonoBehvaiour, you have to cast the result of
            //Instantiate

            Vector3 worldPoint = map[point];                             //Calculate the world point of the current grid point

            cell.transform.parent        = root.transform;               //Parent the cell to the root
            cell.transform.localScale    = Vector3.one;                  //Readjust the scale - the re-parenting above may have changed it.
            cell.transform.localPosition = worldPoint;                   //Set the localPosition of the cell.

            cell.Color = ExampleUtils.Colors[point.GetColor4() % 4 * 4]; //Sets the color of the cell
            //See http://gamelogic.co.za/2013/12/18/what-are-grid-colorings/ for more information on colorings.

            cell.name   = point.ToString(); // Makes it easier to identify cells in the editor.
            grid[point] = cell;             // Finally, put the cell in the grid.
        }
    }
Ejemplo n.º 32
0
	private void BuildGrid()
	{
		// Creates a grid in a rectangular shape.
		grid = RectGrid<SpriteCell>.Rectangle(7, 7);

		// Creates a map...
		map = new RectMap(cellPrefab.Dimensions)	// The cell dimensions usually correspond to the visual 
													// part of the sprite in pixels. Here we use the actual 
													// sprite size, which causes a border between cells.
													// 

			.WithWindow(ExampleUtils.ScreenRect) // ...that is centered in the rectangle provided
			.AlignMiddleCenter(grid)             // by this and the previous line.
			.To3DXY();	// This makes the 2D map returned by the last function into a 3D map
			// This map assumes the grid is in the XY plane.
			// To3DXZ assumes the grid is in the XZ plane (you have to make sure 
			//your tiles are similarly aligned / rotated).


		foreach (RectPoint point in grid) //Iterates over all points (coordinates) contained in the grid
		{
			SpriteCell cell = Instantiate(cellPrefab); // Instantiate a cell from the given prefab.
			//This generic version of Instantiate is defined in GLMonoBehaviour
			//If you don't want to use GLMonoBehvaiour, you have to cast the result of
			//Instantiate

			Vector3 worldPoint = map[point];	//Calculate the world point of the current grid point

			cell.transform.parent = root.transform;	//Parent the cell to the root
			cell.transform.localScale = Vector3.one;	//Readjust the scale - the re-parenting above may have changed it.
			cell.transform.localPosition = worldPoint;	//Set the localPosition of the cell.

			cell.Color = ExampleUtils.Colors[point.GetColor4() % 4 * 4]; //Sets the color of the cell
			//See http://gamelogic.co.za/2013/12/18/what-are-grid-colorings/ for more information on colorings.

			cell.name = point.ToString(); // Makes it easier to identify cells in the editor.
			grid[point] = cell; // Finally, put the cell in the grid.
		}
	}
Ejemplo n.º 33
0
    private void SetupGrid()
    {
        gridCopy = (RectGrid <TileCell>)Grid.Clone();

        var map = new RectMap(Vector2.one)
                  .WithWindow(new Rect(0, 0, 1, 1))
                  .Stretch(Grid);

        var textureScaleVector = new Vector2(1f / GridBuilder.Dimensions.X, 1f / GridBuilder.Dimensions.Y);

        foreach (var point in Grid)
        {
            var cellObject = (UVCell)Grid[point];

            cellObject.SetTexture(puzzleImage);
            cellObject.SetUVs(map[point], textureScaleVector);

            materialBag.Add(cellObject.Material);
        }

        emptyCell = RectPoint.Zero;
        Grid[emptyCell].GetComponent <MeshRenderer>().enabled = false;
    }
Ejemplo n.º 34
0
    private void RebuildMaze(VertexLinker builder)
    {
        Debug.Log("rebuilding " + builder.ToString());

        RectGrid maze = (RectGrid)target;

        maze.Graph.ClearLinks();
        builder.Build(new VertexLinkerHelper(maze.Graph, maze.AdjacentGraph));
        EditorUtility.SetDirty(maze);

        BreadthFirst bf = new BreadthFirst(maze.Graph, maze.BottomLeftVertex);

        bf.Run();
        int[] distances   = bf.Distances;
        float maxDistance = (float)bf.MaxDistance;
        Color nearColor   = Color.red;
        Color farColor    = Color.black;

        Color[] distanceColors = System.Array.ConvertAll <int, Color>(
            distances, distance => Color.Lerp(nearColor, farColor, (distance / maxDistance))
            );
        image.Draw(maze, distanceColors);
    }
Ejemplo n.º 35
0
        private void BuildGrid()
        {
            //ShipCell defaultCell = CreateDefaultShipCell();

            // Creates a grid in a rectangular shape.
            grid = RectGrid <ShipCell> .Rectangle((int)gridSize.x, (int)gridSize.y);

            // Creates a map...
            map = new RectMap(cellSize).To3DXY();

            foreach (RectPoint point in grid) //Iterates over all points (coordinates) contained in the grid
            {
                ShipCell cell = Instantiate(prefab);

                Vector3 worldPoint = map[point];            //Calculate the world point of the current grid point

                cell.transform.parent        = transform;   //Parent the cell to the root
                cell.transform.localScale    = Vector3.one; //Readjust the scale - the re-parenting above may have changed it.
                cell.transform.localPosition = worldPoint;  //Set the localPosition of the cell.

                cell.name   = point.ToString();             // Makes it easier to identify cells in the editor.
                grid[point] = cell;                         // Finally, put the cell in the grid.
            }
        }
Ejemplo n.º 36
0
 //Parent class for generation things
 //subclass of normal nodes
 //start of the chain type deal
 public InputNode(NodeMap map) : base(map)
 {
     outGrid = new RectGrid(map.outHeight, map.outWidth);
 }
Ejemplo n.º 37
0
		private void BuildPuzzle()
		{
			const int size = 5;

			tileGrid = RectGrid<SpriteCell>.Rectangle(size, size);
			blocksGrid = (RectGrid<Block>) tileGrid.CloneStructure<Block>();

			map = new RectMap(new Vector2(152, 152))
				.AnchorCellMiddleCenter()
				.WithWindow(ExampleUtils.ScreenRect)
				.AlignMiddleCenter(tileGrid)
				.To3DXY();

			foreach (RectPoint point in tileGrid)
			{
				var cell = MakeCell(point);

				tileGrid[point] = cell;
				blocksGrid[point] = null;
			}

			blocks = new List<Block>();

			AddFirstBlock();
			AddOtherBlocks();

			winPosition = new RectPoint(4, 2);
		}
Ejemplo n.º 38
0
 /// <summary>
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// </summary>
 private void InitializeComponent()
 {
     this.panel1         = new CellLifeGame1.UIForm.RectGrid();
     this.StartStop      = new System.Windows.Forms.Button();
     this.btnClear       = new System.Windows.Forms.Button();
     this.btnSave        = new System.Windows.Forms.Button();
     this.btnLoad        = new System.Windows.Forms.Button();
     this.automaton      = new System.Windows.Forms.Button();
     this.btnDone        = new System.Windows.Forms.Button();
     this.sldrSpeed      = new System.Windows.Forms.TrackBar();
     this.numSteps       = new System.Windows.Forms.NumericUpDown();
     this.btnStep        = new System.Windows.Forms.Button();
     this.btnCurrentAuto = new System.Windows.Forms.Button();
     this.groupAutomaton = new System.Windows.Forms.GroupBox();
     ((System.ComponentModel.ISupportInitialize)
          (this.sldrSpeed)).BeginInit();
     ((System.ComponentModel.ISupportInitialize)
          (this.numSteps)).BeginInit();
     this.groupAutomaton.SuspendLayout();
     this.SuspendLayout();
     //
     // panel1
     //
     this.panel1.Location = new System.Drawing.Point(56, 40);
     this.panel1.Name     = "panel1";
     this.panel1.Size     = new System.Drawing.Size(512, 512);
     this.panel1.TabIndex = 0;
     this.panel1.MouseUp += new
                            System.Windows.Forms.MouseEventHandler(this.panel1_MouseUp);
     this.panel1.Paint += new
                          System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
     this.panel1.DragLeave += new
                              System.EventHandler(this.panel1_DragLeave);
     this.panel1.MouseMove += new
                              System.Windows.Forms.MouseEventHandler(this.panel1_MouseMove);
     this.panel1.MouseDown += new
                              System.Windows.Forms.MouseEventHandler(this.panel1_MouseDown);
     //
     // StartStop
     //
     this.StartStop.Location = new System.Drawing.Point(72, 8);
     this.StartStop.Name     = "StartStop";
     this.StartStop.Size     = new System.Drawing.Size(40, 24);
     this.StartStop.TabIndex = 2;
     this.StartStop.Text     = "Start";
     this.StartStop.Click   += new
                               System.EventHandler(this.StartStop_Click);
     //
     // btnClear
     //
     this.btnClear.Location = new System.Drawing.Point(256, 8);
     this.btnClear.Name     = "btnClear";
     this.btnClear.Size     = new System.Drawing.Size(40, 24);
     this.btnClear.TabIndex = 3;
     this.btnClear.Text     = "Clear";
     this.btnClear.Click   += new System.EventHandler(this.btnClear_Click);
     //
     // btnSave
     //
     this.btnSave.Location = new System.Drawing.Point(304, 8);
     this.btnSave.Name     = "btnSave";
     this.btnSave.Size     = new System.Drawing.Size(40, 24);
     this.btnSave.TabIndex = 4;
     this.btnSave.Text     = "Save";
     this.btnSave.Click   += new System.EventHandler(this.btnSave_Click);
     //
     // btnLoad
     //
     this.btnLoad.Location = new System.Drawing.Point(352, 8);
     this.btnLoad.Name     = "btnLoad";
     this.btnLoad.Size     = new System.Drawing.Size(40, 24);
     this.btnLoad.TabIndex = 5;
     this.btnLoad.Text     = "Load";
     this.btnLoad.Click   += new System.EventHandler(this.btnLoad_Click);
     //
     // automaton
     //
     this.automaton.Location = new System.Drawing.Point(4, 16);
     this.automaton.Name     = "automaton";
     this.automaton.Size     = new System.Drawing.Size(36, 20);
     this.automaton.TabIndex = 6;
     this.automaton.Text     = "New";
     this.automaton.Click   += new
                               System.EventHandler(this.automaton_Click);
     //
     // btnDone
     //
     this.btnDone.Enabled  = false;
     this.btnDone.Location = new System.Drawing.Point(108, 16);
     this.btnDone.Name     = "btnDone";
     this.btnDone.Size     = new System.Drawing.Size(40, 20);
     this.btnDone.TabIndex = 7;
     this.btnDone.Text     = "Done";
     this.btnDone.Click   += new
                             System.EventHandler(this.btnDone_Click);
     //
     // sldrSpeed
     //
     this.sldrSpeed.Location    = new System.Drawing.Point(8, 8);
     this.sldrSpeed.Maximum     = 1000;
     this.sldrSpeed.Minimum     = 1;
     this.sldrSpeed.Name        = "sldrSpeed";
     this.sldrSpeed.Orientation =
         System.Windows.Forms.Orientation.Vertical;
     this.sldrSpeed.Size          = new System.Drawing.Size(45, 544);
     this.sldrSpeed.TabIndex      = 9;
     this.sldrSpeed.TickStyle     = System.Windows.Forms.TickStyle.None;
     this.sldrSpeed.Value         = 200;
     this.sldrSpeed.ValueChanged += new
                                    System.EventHandler(this.sldSpeed_Changed);
     //
     // numSteps
     //
     this.numSteps.Location = new System.Drawing.Point(168, 8);
     this.numSteps.Maximum  = new System.Decimal(new int[] {
         5000,
         0,
         0,
         0
     });
     this.numSteps.Minimum = new System.Decimal(new int[] {
         1,
         0,
         0,
         0
     });
     this.numSteps.Name     = "numSteps";
     this.numSteps.Size     = new System.Drawing.Size(80, 20);
     this.numSteps.TabIndex = 10;
     this.numSteps.Value    = new System.Decimal(new int[] {
         1,
         0,
         0,
         0
     });
     //
     // btnStep
     //
     this.btnStep.Location = new System.Drawing.Point(120, 8);
     this.btnStep.Name     = "btnStep";
     this.btnStep.Size     = new System.Drawing.Size(40, 24);
     this.btnStep.TabIndex = 8;
     this.btnStep.Text     = "Step";
     this.btnStep.Click   += new System.EventHandler(this.btnStep_Click);
     //
     // btnCurrentAuto
     //
     this.btnCurrentAuto.Location = new System.Drawing.Point(48, 16);
     this.btnCurrentAuto.Name     = "btnCurrentAuto";
     this.btnCurrentAuto.Size     = new System.Drawing.Size(52, 20);
     this.btnCurrentAuto.TabIndex = 11;
     this.btnCurrentAuto.Text     = "Current";
     this.btnCurrentAuto.Click   += new
                                    System.EventHandler(this.btnCurrentAuto_Click);
     //
     // groupAutomaton
     //
     this.groupAutomaton.Controls.Add(this.btnDone);
     this.groupAutomaton.Controls.Add(this.btnCurrentAuto);
     this.groupAutomaton.Controls.Add(this.automaton);
     this.groupAutomaton.Location = new System.Drawing.Point(400, 0);
     this.groupAutomaton.Name     = "groupAutomaton";
     this.groupAutomaton.Size     = new System.Drawing.Size(152, 40);
     this.groupAutomaton.TabIndex = 13;
     this.groupAutomaton.TabStop  = false;
     this.groupAutomaton.Text     = "Automaton";
     //
     // UIForm
     //
     this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
     this.ClientSize        = new System.Drawing.Size(576, 557);
     this.Controls.Add(this.groupAutomaton);
     this.Controls.Add(this.numSteps);
     this.Controls.Add(this.sldrSpeed);
     this.Controls.Add(this.btnStep);
     this.Controls.Add(this.btnLoad);
     this.Controls.Add(this.btnSave);
     this.Controls.Add(this.btnClear);
     this.Controls.Add(this.StartStop);
     this.Controls.Add(this.panel1);
     this.FormBorderStyle =
         System.Windows.Forms.FormBorderStyle.FixedToolWindow;
     this.Name        = "UIForm";
     this.RightToLeft = System.Windows.Forms.RightToLeft.No;
     this.Text        =
         "Cellular Automata Computer Aided Design and Conversion (CACADAC)";
     ((System.ComponentModel.ISupportInitialize)
          (this.sldrSpeed)).EndInit();
     ((System.ComponentModel.ISupportInitialize)
          (this.numSteps)).EndInit();
     this.groupAutomaton.ResumeLayout(false);
     this.ResumeLayout(false);
 }