예제 #1
0
	private void BuildGrid()
	{
		const int side = 5;
		grid = FlatTriGrid<SpriteCell>
			.BeginShape()
				.Hexagon(side)
			.EndShape();
		
		map = new FlatTriMap(TriDimensions)
			.WithWindow(ExampleUtils.ScreenRect)
			.AlignMiddleCenter(grid)
			.AnchorCellMiddleCenter()
			.To3DXY();
		
		foreach(FlatTriPoint point in grid)
		{
			SpriteCell cell = Instantiate(cellPrefab);
		    Vector3 worldPoint = map[point];
			
			cell.transform.parent = root.transform;
			cell.transform.localScale = Vector3.one;
			cell.transform.localPosition = worldPoint;
			
			cell.Color = ExampleUtils.Colors[point.GetColor2() * 2];
			cell.name = point.ToString();
			cell.SetAngle(360 / FlatTriPoint.SpliceCount * point.I);
			
			grid[point] = cell;
		}
	}
예제 #2
0
	private void BuildGrid()
	{
		grid = LineGrid<SpriteCell>
			.BeginShape()
			.Segment(300)
			.EndShape();

		map2D = new ArchimedeanSpiralMap(CellDimensions, grid)
			.AnchorCellMiddleCenter()
			.WithWindow(ExampleUtils.ScreenRect)
			.AlignMiddleCenter(grid);

		map = map2D
			.To3DXY();

		foreach (var point in grid)
		{
			var cell = Instantiate(cellPrefab);

			Vector3 worldPoint = map[point];

			cell.transform.parent = root.transform;
			cell.transform.localScale = Vector3.one;
			cell.transform.localPosition = worldPoint;

			cell.Color = ExampleUtils.Colors[ColorFunction(point)] + Color.white * 0.2f;
			cell.name = point.ToString();

			grid[point] = cell;
		}

		voronoiMap = new VoronoiMap<LinePoint>(grid, map2D);
		ExampleUtils.PaintScreenTexture(plane, voronoiMap, ColorFunction);
	}
예제 #3
0
	private void BuildGrid()
	{
		root.transform.DestroyChildren();

		grid = FlatHexGrid<SpriteCell>.Hexagon(4);
		
		map = new FlatHexMap(HexDimensions)
			.AnchorCellMiddleCenter()
			.WithWindow(ExampleUtils.ScreenRect)
			.AlignMiddleCenter(grid)
			.To3DXY()
				;	
		
		foreach(FlatHexPoint point in grid)
		{
			SpriteCell cell = Instantiate(cellPrefab);
			Vector3 worldPoint = map[point];
			
			cell.transform.parent = root.transform;
			cell.transform.localScale = Vector3.one;
			cell.transform.localPosition = worldPoint;	
			
			cell.Color = ExampleUtils.Colors[point.GetColor3_7()];
			cell.name = point.ToString();
			
			grid[point] = cell;
		}
	}
예제 #4
0
	private void BuildGrid()
	{
		const int width = 5;
		const int height = 5;

		grid = PointyRhombGrid<SpriteCell>
			.BeginShape()
			.Rectangle(width, height)
			.EndShape();
		
		map = new PointyRhombMap(CellDimensions)
			.WithWindow(ExampleUtils.ScreenRect)
			.AlignMiddleCenter(grid)
			.To3DXY();


		foreach(PointyRhombPoint point in grid)
		{
			SpriteCell cell = Instantiate(cellPrefab);
			Vector3 worldPoint = map[point];
			cell.transform.parent = root.transform;
			cell.transform.localScale = Vector3.one;
			cell.transform.localPosition = worldPoint;
			cell.Color = ExampleUtils.Colors[point.GetColor12()];
			cell.name = point.ToString();
			cell.SetAngle(-360f / PointyRhombPoint.SpliceCount * point.I);

			grid[point] = cell;
		}
	}
예제 #5
0
	private void BuildGrid()
	{
		var pointList = PoissonDisk.GeneratePoisson(ExampleUtils.ScreenRect, cellDimensions.magnitude, 10);
		grid = LineGrid<SpriteCell>.BeginShape().Segment(pointList.Count).EndShape();
		var map2D = VoronoiMap<LinePoint>.MakeMap(pointList);

		voronoiMap = map2D.To3DXY();

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

			cell.transform.parent = root.transform;
			cell.transform.localScale = Vector3.one;
			cell.transform.localPosition = worldPoint;

			cell.Color = ExampleUtils.Colors[ColorFunction(point)] + Color.white * 0.1f;
			cell.name = point.ToString();

			grid[point] = cell;
		}

		ExampleUtils.PaintScreenTexture(plane, voronoiMap.To2D(), ColorFunction);
	}
			public void UpdateTilePositions(IMap3D<RectPoint> map)
			{
				foreach (RectPoint tilePoint in TilePoints)
				{
					tileObjects[tilePoint].transform.localPosition = map[CurrentPosition + tilePoint];
				}
			}
예제 #7
0
	private void BuildGrid()
	{
		const int width = 2;
		const int height = 2;

		grid = CairoGrid<SpriteCell>.Default(width, height);
		
		map = new CairoMap(CellDimensions)
			.AnchorCellMiddleCenter()
			.WithWindow(ExampleUtils.ScreenRect)
			.AlignMiddleCenter(grid)
			.To3DXY();
		
		foreach(CairoPoint point in grid)
		{
			SpriteCell cell = Instantiate(cellPrefab);
			Vector3 worldPoint = map[point];
			
			cell.transform.parent = root.transform;
			cell.transform.localPosition = worldPoint;	
			cell.transform.localScale = Vector3.one;
			
			cell.Color = ExampleUtils.Colors[ColorMap(point.GetColor12())];
			cell.name = PointToString(point);
			cell.SetAngle(360f/CairoPoint.SpliceCount * point.I);
			
			grid[point] = cell;
		}		
	}
예제 #8
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);
        }
    }
예제 #9
0
	private void BuildGrid()
	{
		const int width = 6;
		const int height = 9;

		grid = PointyHexGrid<SpriteCell>.FatRectangle(width, height);

		map = new PointyBrickMap(CellDimensions)
			.AnchorCellMiddleCenter()
			.WithWindow(ExampleUtils.ScreenRect)
			.AlignMiddleCenter(grid)
			.To3DXY()
				;
		
		foreach(PointyHexPoint point in grid)
		{
			SpriteCell cell = Instantiate(cellPrefab);
			Vector2 worldPoint = map[point];
			
			cell.transform.parent = root.transform;
			cell.transform.localScale = Vector3.one;
			cell.transform.localPosition = worldPoint;
			
			cell.Color = ExampleUtils.Colors[point.GetColor3_7()];
			cell.name = point.ToString();
			
			grid[point] = cell;
		}
	}
예제 #10
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.
			}
		}
예제 #11
0
        public IEnumerator BuildGrid()
        {
            totalCellCount = 0;
            grid = PointyHexGrid<TileCell>.Rectangle(width, height);

            map = new PointyHexMap(new Vector2(69, 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;
                }
            }
        }
		private void BuildGrid()
		{
			//This is the base grid, we will use it to define
			//the shape of the splice grid.
			//The contents is not important.
			var baseGrid = PointyHexGrid<bool>
				.BeginShape()
				.Hexagon(5)
				.EndShape();

			//This is the base map, used for the course 
			//mapping
			var baseMap = new PointyHexMap(cellDimensions)
				.WithWindow(ExampleUtils.ScreenRect)
				.AlignMiddleCenter(baseGrid);

			//Now we make the actual spliced grid.
			//We feed it the base grid, and the number
			//of splices we want.
			grid = new SplicedGrid<SpriteCell, PointyHexPoint>(baseGrid, spliceOffsets.Length);

			//Now we make a spliced map. This is just a one-way map --
			//it only maps grid points to the world (using the base map plus 
			//splice point offsets
			var splicedMap = new SplicedMap<PointyHexPoint>(baseMap, spliceOffsets);

			//Finally, we make the above into a two way map. This map uses a Vonoroi diagram
			//to do the inverse mapping
			map = new VoronoiMap<SplicedPoint<PointyHexPoint>>(grid, splicedMap).To3DXY();

			//Then we instantiate cells as usual, and put them in our grid.
			foreach (var point in grid)
			{
				var cell = Instantiate(cellPrefab);
				Vector3 worldPoint = map[point];

				cell.transform.parent = root.transform;
				cell.transform.localScale = Vector3.one;
				cell.transform.localPosition = worldPoint;

				//slightly lighter than the DefaultColors we will use to paint the background
				cell.Color = ExampleUtils.Colors[ColorFunction(point)] + Color.white*0.1f;
				cell.name = point.ToString();

				grid[point] = cell;
			}

			// To make it easier to see how points are mapped, we 
			ExampleUtils.PaintScreenTexture(plane, map.To2D(), ColorFunction);
		}
예제 #13
0
    public void BuilkdGrid()
    {
        var spacing = cellPrefab.Dimensions;
        spacing.Scale (padding);

        Grid = FlatHexGrid<Cell>.Hexagon (size);
        Map = new FlatHexMap (spacing).AnchorCellMiddleCenter ().To3DXZ ();

        foreach(var point in Grid)
        {
            var cell = Instantiate (cellPrefab);
            Vector3 worldPoint = Map [point];
            cell.transform.parent = this.transform;
            cell.transform.localScale = Vector3.one;
            cell.transform.localPosition = worldPoint;

            cell.name = point.ToString ();
            Grid [point] = cell;

        }
    }
예제 #14
0
    // Instantiate all cell of the grid
    private IEnumerator BuildGrid()
    {
        //cellsPerIteration = (width*width)/(width/2);
        //const int height = 5;

        grid    = PointyHexGrid<Cell>.Hexagon(width);
        tileMap = PointyHexGrid<int>.Hexagon(width);

        // Generate an hexagonal map defining each cell type
        tileMap = WorldGenerator.GenerateHex (width);

        // Map setup
        map = new PointyHexMap(HexDimensions)
            .AnchorCellMiddleCenter()
            .WithWindow(ExampleUtils.ScreenRect)
            .AlignMiddleCenter(grid)
            .To3DXY();

        // Instantiate each cell over many frames
        foreach(PointyHexPoint point in grid)
        {
            CreateCell(point);
            cellCount++;

            if(cellCount >= cellsPerIteration)
            {

                cellCount = 0;
                //Debug.Log ("Time BuildGridFrame = " + Time.realtimeSinceStartup);

                yield return null;
            }
        }

        // After grid generation
        Debug.Log ("Time BuildGridFinished = " + Time.realtimeSinceStartup);
        CreateCities(); // Put cities on the map
        TimeSystem.SetSpeed(2);
        isGridBuilt = true;
    }
예제 #15
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.
		}
	}
예제 #16
0
	private void BuildGrid()
	{
		grid = new NestedRectGrid<SpriteCell>(bigDimensions, smallDimensions);

		var bigCellDimensions = new Vector2(cellDimensions.x*smallDimensions.X, cellDimensions.y*smallDimensions.Y);

		bigMap = new RectMap(bigCellDimensions * 1.05f)
			.AnchorCellBottomLeft()
			.WithWindow(ExampleUtils.ScreenRect)
			.AlignMiddleCenter(grid.BaseGrid) //pass in the base grid
			.Scale(1.2f)
			.To3DXY();

		smallMap = new RectMap(cellDimensions)
			.Scale(1.05f)
			.To3DXY();

		foreach (var bigPoint in grid.BaseGrid)
		{
			var smallGrid = grid.GetSmallGrid(bigPoint);

			foreach (var smallPoint in smallGrid)
			{
				SpriteCell cell = Instantiate(cellPrefab);
				cell.transform.parent = gridRoot.transform;
				cell.transform.localScale = Vector3.one;
				cell.transform.localPosition = bigMap[bigPoint] + smallMap[smallPoint];

				var colorIndex = bigPoint.GetColor(2, 1, 1)*4 + smallPoint.GetColor(3, 1, 1);

				cell.Color = ExampleUtils.Colors[colorIndex];
				cell.name = bigPoint.ToString() + " | " + smallPoint.ToString();
				grid[bigPoint, smallPoint] = cell;
			}
		}
	}
예제 #17
0
        private void BuildGrid()
        {
            grid = DiamondGrid<SpriteCell>.ThinRectangle(5, 5);

            map = new DiamondMap(cellPrefab.Dimensions)
                .WithWindow(ExampleUtils.ScreenRect)
                .AlignMiddleCenter(grid)
                .To3DXY();

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

                cell.transform.parent = root.transform;
                cell.transform.localScale = Vector3.one;
                cell.transform.localPosition = worldPoint;

                cell.Color = ExampleUtils.Colors[point.GetColor4()];
                cell.name = point.ToString();

                grid[point] = cell;
            }
        }
예제 #18
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);
		}