public bool Generate(Vector2Int cords, MapGrid mapGrid = null, int type = -1) { bool isSuccessful = true; grid = (mapGrid == null) ? grid : mapGrid; figureType = (type == -1) ? figureType : type; if (!grid) { return(false); } var chosenMap = FigureMaps[figureType]; for (int y = chosenMap.GetLength(0) - 1; y >= 0; y--) { for (int x = chosenMap.GetLength(1) - 1; x >= 0; x--) { if (chosenMap[y, x] == 1) { GameObject current = Instantiate(cube, transform); if (!grid.Add(current, new Vector2Int(cords.x + x, cords.y + y))) { isSuccessful = false; } cubes.Add(current); cubesMap[y, x] = current; } } } axisCords = cords; return(isSuccessful); }
public void Add(Actor actor) { if (actors.Contains(actor)) { throw new Exception(string.Format("Actor {0} is already added to map {1}", actor, ID)); } SceneManager.MoveGameObjectToScene(actor.gameObject, scene); actors.Add(actor); grid.Add(actor); actor.Level = LevelInfo; }
public bool Rotate(bool isToRight = true) { GameObject[,] rotateMap = cubesMap.Clone() as GameObject[, ]; for (int i = cubes.Count - 1; i >= 0; i--) { grid.Remove(cubes[i], true); } int y = -1; for (y = rotateMap.GetLength(0) - 1; y >= 0; y--) { for (int x = rotateMap.GetLength(1) - 1; x >= 0; x--) { int rx = isToRight ? Math.Abs(y - rotateMap.GetLength(0) + 1) : y, ry = isToRight ? x : Math.Abs(x - rotateMap.GetLength(1) + 1); GameObject current = cubesMap[y, x]; rotateMap[ry, rx] = current; if (current && !grid.Add(current, new Vector2Int(rx, ry) + axisCords, true)) { goto multiBreak; } } } multiBreak: if (y > -1) { for (y = cubesMap.GetLength(0) - 1; y >= 0; y--) { for (int x = cubesMap.GetLength(1) - 1; x >= 0; x--) { if (cubesMap[y, x]) { grid.Add(cubesMap[y, x], new Vector2Int(axisCords.x + x, axisCords.y + y), true); } } } return(false); } cubesMap = rotateMap; return(true); }
private void BuildWorldMap() { MapGrid.Add(new SquareDesert()); MapGrid.Add(new SquareDesert()); MapGrid.Add(new SquareDesert()); MapGrid.Add(new SquareDesert()); MapGrid.Add(new SquareMountain()); MapGrid.Add(new SquareMountain()); MapGrid.Add(new SquareMountain()); MapGrid.Add(new SquareMountain()); MapGrid.Add(new SquarePrairie()); MapGrid.Add(new SquarePrairie()); MapGrid.Add(new SquarePrairie()); MapGrid.Add(new SquarePrairie()); MapGrid.Add(new SquarePrairie()); MapGrid.Add(new SquarePrairie()); MapGrid.Add(new SquarePrairie()); MapGrid.Add(new SquarePrairie()); }
public void AddSelfToGrid() { COORD c = MapGrid.GetTileCoord(_unit.transform.position.x, _unit.transform.position.z); if (_mapGrid.IsInsideMap(c.x, c.z)) { _tiles.Add(c); _mapGrid.Add(c.x, c.z); } if (USER_SQUARE) { float r = _unit.unit.dataUnit.GetCollisionRadius(); COORD c1 = MapGrid.GetTileCoord(_unit.transform.position.x - r, _unit.transform.position.z); if (_mapGrid.IsInsideMap(c1.x, c1.z)) { _tiles.Add(c1); _mapGrid.Add(c1.x, c1.z); } COORD c2 = MapGrid.GetTileCoord(_unit.transform.position.x + r, _unit.transform.position.z); if (_mapGrid.IsInsideMap(c2.x, c2.z)) { _tiles.Add(c2); _mapGrid.Add(c2.x, c2.z); } COORD c3 = MapGrid.GetTileCoord(_unit.transform.position.x, _unit.transform.position.z - r); if (_mapGrid.IsInsideMap(c3.x, c3.z)) { _tiles.Add(c3); _mapGrid.Add(c3.x, c3.z); } COORD c4 = MapGrid.GetTileCoord(_unit.transform.position.x, _unit.transform.position.z + r); if (_mapGrid.IsInsideMap(c4.x, c4.z)) { _tiles.Add(c4); _mapGrid.Add(c4.x, c4.z); } } }