/// <summary> /// Rotates the city to the left. /// </summary> public void RotateLeft() { Vector2 spacing = new Vector2 (Tiles.GRIDWIDTH / 2f, Tiles.GRIDHEIGHT / 2f); spacing.X = (float)Math.Round (spacing.X, 0); spacing.Y = (float)Math.Round (spacing.Y, 0); Direction.RotateLeft(); Camera.Direction.RotateRight(); Block[,,] blockresult = new Block[Game1.MAXX, Game1.MAXY, Game1.MAXZ]; Tile[,] tileresult = new Tile[Game1.MAXX, Game1.MAXY]; for (int y = 0; y < Game1.MAXY; y++) for (int x = 0; x < Game1.MAXX; x++) { //Rotate the tiles tileresult [x, y] = _tiles [y, Game1.MAXX - 1 - x]; //Recalculate the drawrect. tileresult [x, y].DrawRect = GetTileDrawRect(x,y); //Rotate the blocks for (int z = 0; z < Game1.MAXZ; z++) { blockresult [x, y, z] = _blocks [y, Game1.MAXX - 1 - x, z]; //Recalc block position blockresult[x,y,z].DrawRect = new Rectangle( tileresult[x,y].DrawRect.X, tileresult[x,y].DrawRect.Y - (Blocks.BLOCKHEIGHT*(z+1)), 31,31); } } _blocks = (Block[,,])blockresult.Clone(); _tiles = (Tile[,])tileresult.Clone(); CheckRoadSanity(); }
//TODO: Flip tiles and blocks to match rotations. /// <summary> /// Rotates the city to the right. /// </summary> public void RotateRight() { //To find the distance each piece of the grid should be to connect it together Vector2 spacing = new Vector2 (Tiles.GRIDWIDTH / 2f, Tiles.GRIDHEIGHT / 2f); spacing.X = (float)Math.Round (spacing.X, 0); spacing.Y = (float)Math.Round (spacing.Y, 0); //Direction for the orientation of the city. Is used to draw features correctly. Direction.RotateRight(); Camera.Direction.RotateRight(); Block[,,] blockresult = new Block[Game1.MAXX, Game1.MAXY, Game1.MAXZ]; Tile[,] tileresult = new Tile[Game1.MAXX, Game1.MAXY]; for (int y = 0; y < Game1.MAXY; y++) for (int x = 0; x < Game1.MAXX; x++) { //Rotate the tiles tileresult [x, y] = _tiles [Game1.MAXY - 1 - y, x]; //Recalculate the drawrect. tileresult [x, y].DrawRect = GetTileDrawRect(x,y); //Rotate the blocks for (int z = 0; z < Game1.MAXZ; z++) { blockresult [x, y, z] = _blocks [Game1.MAXY - 1 - y, x, z]; //Recalc block position blockresult[x,y,z].DrawRect = new Rectangle( tileresult[x,y].DrawRect.X, tileresult[x,y].DrawRect.Y - (Blocks.BLOCKHEIGHT*(z+1)), 31,31); } } _blocks = (Block[,,])blockresult.Clone(); _tiles = (Tile[,])tileresult.Clone(); CheckRoadSanity(); }
/// <summary> /// Generates the grid. /// </summary> public void GenerateGrid() { _tiles = new Tile[Game1.MAXX, Game1.MAXY]; Vector2 spacing = new Vector2 (Tiles.GRIDWIDTH/ 2f, Tiles.GRIDHEIGHT / 2f); spacing.X = (float)Math.Round (spacing.X, 0); spacing.Y = (float)Math.Round (spacing.Y, 0); //Our point of influence to make the center of the city. _influencepoint = new Point (Assets.Random.Next (0, Game1.MAXX), Assets.Random.Next (0, Game1.MAXY)); List<Point> corners = new List<Point> () {new Point(0,0), new Point(0, _tiles.GetUpperBound(1)), new Point(_tiles.GetUpperBound(0), 0), new Point(_tiles.GetUpperBound(0), _tiles.GetUpperBound(1))}; int largest = 0; foreach (Point c in corners) { int distance = GetInfluenceDistance(c); if(distance > largest) largest = distance; } _largestinfluencedistance = largest; for (int x = 0; x < Game1.MAXX; x++) { for (int y = 0; y < Game1.MAXY; y++) { Tile t = new Tile(); t.SetIndex(Tiles.GRASS); t.DrawRect = GetTileDrawRect(x,y); t.ShowInfluence = InfluenceViewIsOn; t.InfluenceColor = new Color ( 1f * GetInfluencePercent(new Point(x,y)),1f - GetInfluencePercent (new Point(x, y)),1f - GetInfluencePercent (new Point(x, y))); _tiles[x,y] = t; } } }