void CreatePacmanLayer() { pacmanLayer = new Layer("PacmanLayer", gameObject.transform.position, Width, Height); GameObjectUtils.AppendChild(gameObject, pacmanLayer.LayerGameObject); pacmanLayer.LayerGameObject.transform.position = Vector3.zero; int pacmanX = Random.Range(0, Width); int pacmanY = Random.Range(0, Height); pacmanLayer.AddTileFromPrefab(PacmanPrefab, pacmanX, pacmanY); CreatePacdot(); }
public bool AddTile(GameObject gameObject, int indexX, int indexY) { if (gameObject != null && layerArray != null && !ContainsTile(gameObject)) { if (indexX >= 0 && indexX < Width && indexY >= 0 && indexY < Height) { layerArray [indexX, indexY] = gameObject; gameObject.transform.position = CalculateRealCoordinates(indexX, indexY); GameObjectUtils.AppendChild(layerGameObject, gameObject); return(true); } } return(false); }
public bool AddTile(GameObject prefabTile, int indexX, int indexY) { if (prefabTile != null && layerArray != null) { GameObject tileInstance = (GameObject)MonoBehaviour.Instantiate(prefabTile); tileInstance.name = prefabTile.name + "Tile"; if (indexX >= 0 && indexX < Width && indexY >= 0 && indexY < Height) { layerArray[indexX, indexY] = tileInstance; tileInstance.transform.position = CalculateRealCoordinates(indexX, indexY); GameObjectUtils.AppendChild(layerGameObject, tileInstance); } } return(false); }
void GenerateEmptyMaze() { if (mazeLayer != null) { mazeLayer.Destroy(); } mazeLayer = new Layer("Maze", gameObject.transform.position, Width, Height); GameObjectUtils.AppendChild(gameObject, mazeLayer.LayerGameObject); mazeLayer.LayerGameObject.transform.position = Vector3.zero; GameObject cellPrefab = GameObjectUtils.GetPrefabFromResources("Prefabs/Cell"); for (int i = 0; i < Width; i++) { for (int j = 0; j < Height; j++) { mazeLayer.AddTileFromPrefab(cellPrefab, i, j); } } }
void GenerateFloorLayer() { floorLayer = new Layer("FloorLayer", gameObject.transform.position, Width, Height); GameObjectUtils.AppendChild(gameObject, floorLayer.LayerGameObject); floorLayer.LayerGameObject.transform.position = Vector3.zero; GameObject floorPrefab = GameObjectUtils.GetPrefabFromResources(AvailableTiles.Floor); GameObject fountainPrefab = GameObjectUtils.GetPrefabFromResources(AvailableTiles.Fountain); if (floorPrefab != null && fountainPrefab != null) { // Generating fountain int fountainX = Random.Range(1, Width - 1); int fountainY = Random.Range(1, Height - 1); for (int i = 0; i < Width; i++) { for (int j = 0; j < Height; j++) { GameObject tilePrefab = floorPrefab; if (fountainX == i && fountainY == j) { tilePrefab = fountainPrefab; } floorLayer.AddTile(tilePrefab, i, j); if (tilePrefab.Equals(fountainPrefab)) { fountainPosition = new Vector2(i, j); } } } } //GameObjectUtils.CenterOnChildren (floorLayer.LayerGameObject); }
void GenerateMainLayer() { mainLayer = new Layer("MainLayer", gameObject.transform.position, Width, Height); GameObjectUtils.AppendChild(gameObject, mainLayer.LayerGameObject); mainLayer.LayerGameObject.transform.position = Vector3.zero; collectiblesLayer = new Layer("CollectiblesLayer", gameObject.transform.position, Width, Height); GameObjectUtils.AppendChild(gameObject, collectiblesLayer.LayerGameObject); collectiblesLayer.LayerGameObject.transform.position = Vector3.zero; GameObject wallPrefab = GameObjectUtils.GetPrefabFromResources(AvailableTiles.Wall); GameObject rockPrefab = GameObjectUtils.GetPrefabFromResources(AvailableTiles.Rock); GameObject dirtPrefab = GameObjectUtils.GetPrefabFromResources(AvailableTiles.Dirt); GameObject coinPrefab = GameObjectUtils.GetPrefabFromResources(AvailableTiles.Coin); GameObject gemStonePrefab = GameObjectUtils.GetPrefabFromResources(AvailableTiles.Gemstone); if (wallPrefab != null && rockPrefab != null) { GameObject[] tilesOnMainLayer = { dirtPrefab, dirtPrefab, rockPrefab }; for (int i = 0; i < Width; i++) { for (int j = 0; j < Height; j++) { GameObject prefabMain = null, prefabCollectible = null; if (i == 0 || j == 0 || i == Width - 1 || j == Height - 1) { prefabMain = wallPrefab; } else { int randomTileIndex = Random.Range(0, tilesOnMainLayer.Length + 1); if (randomTileIndex != tilesOnMainLayer.Length) { prefabMain = tilesOnMainLayer[randomTileIndex]; if (prefabMain.Equals(dirtPrefab)) { int randomNumber = Random.Range(1, 100); if (randomNumber > 90) { prefabCollectible = gemStonePrefab; totalGems++; } else if (randomNumber > 50) { prefabCollectible = coinPrefab; totalCoins++; } } } } if (prefabMain != null) { mainLayer.AddTile(prefabMain, i, j); } if (prefabCollectible != null) { collectiblesLayer.AddTile(prefabCollectible, i, j); } } } } //GameObjectUtils.CenterOnChildren (mainLayer.LayerGameObject); //GameObjectUtils.CenterOnChildren (collectiblesLayer.LayerGameObject); }