void onStart(SocketIOEvent e) { statusGame = STARTING; Debug.Log("Starting Game"); Debug.Log(e.data.ToString()); JSONObject[] itemList = e.data.GetField("data").GetField("items").list.ToArray(); Debug.Log(itemList); MapGenerator mapGen = map.GetComponent <MapGenerator> (); mapGen.GenerateMap(); Debug.Log("Generate Randomizer"); PositionRandomizer randomizer = map.GetComponent <PositionRandomizer> (); ItemsGenerator itemsGen = items.GetComponent <ItemsGenerator> (); itemsGen.GenerateItems(randomizer, itemList); EnvironmentGenerator enviGen = environment.GetComponent <EnvironmentGenerator> (); enviGen.GenerateEnvironment(randomizer); player.transform.position = randomizer.RandomPosition(PositionRandomizer.PLAYER); EnemyManager enemyManager = enemies.GetComponent <EnemyManager> (); enemyManager.CreateEnemyManager(randomizer); socket.Emit("GAME_STATUS_READY"); }
public void CreateEnemyManager(PositionRandomizer posr) { randomizer = posr; StartCoroutine(navMeshCheck()); blueEnemy.tag = "Enemy"; redEnemy.tag = "Enemy"; }
public void GenerateMap() { randomFillPercent = UnityEngine.Random.Range(48, 53); map = new int[width, height]; RandomFillMap(); for (int i = 0; i < 5; i++) { SmoothMap(); } ProcessMap(); int borderSize = BORDER_SIZE; int[,] borderedMap = new int[width + borderSize * 2, height + borderSize * 2]; for (int x = 0; x < borderedMap.GetLength(0); x++) { for (int y = 0; y < borderedMap.GetLength(1); y++) { if (x >= borderSize && x < width + borderSize && y >= borderSize && y < height + borderSize) { borderedMap [x, y] = map [x - borderSize, y - borderSize]; } else { borderedMap [x, y] = 1; } } } MeshGenerator meshGen = GetComponent <MeshGenerator> (); meshGen.GenerateMesh(borderedMap, SQUARE_SIZE); PositionRandomizer randomizer = GetComponent <PositionRandomizer> (); randomizer.CreateRandomizer(borderedMap, SQUARE_SIZE); }
public void GenerateItems(PositionRandomizer randomizer, JSONObject[] items) { for (int i = 0; i < items.Length; i++) { string temp = items [i].ToString(); Debug.Log("temp: " + temp); string item = temp.Substring(1, temp.Length - 2); Debug.Log("item: " + item); if (item.Equals("KEY")) { Debug.Log("add key"); Instantiate(key, randomizer.RandomPosition(PositionRandomizer.ITEM), Quaternion.identity); } else if (item.Equals("DOOR")) { Debug.Log("add door"); Instantiate(door, randomizer.RandomPosition(PositionRandomizer.ITEM), Quaternion.identity); } } }
void Create(PositionRandomizer randomizer, GameObject obj) { var rotation = Quaternion.Euler(0, Random.Range(0, 360), 0); Instantiate(obj, randomizer.RandomPosition(PositionRandomizer.ENVI), rotation); }
public void GenerateEnvironment(PositionRandomizer randomizer) { for (int i = 0; i < MAX; i++) { switch (Random.Range(0, 3)) { case 0: treePine01.layer = 8; treePine01.tag = "Environment"; Create(randomizer, treePine01); break; case 1: treePine04.layer = 8; treePine04.tag = "Environment"; Create(randomizer, treePine04); break; case 2: treePine07.layer = 8; treePine07.tag = "Environment"; Create(randomizer, treePine07); break; } } for (int i = 0; i < 20; i++) { switch (Random.Range(0, 3)) { case 0: brush02.layer = 8; brush02.tag = "Environment"; Create(randomizer, brush02); break; case 1: brush03.layer = 8; brush03.tag = "Environment"; Create(randomizer, brush03); break; case 2: rock.layer = 8; rock.tag = "Environment"; Create(randomizer, rock); break; } } for (int i = 0; i < 10; i++) { switch (Random.Range(0, 3)) { case 0: treeStump.layer = 8; treeStump.tag = "Environment"; Create(randomizer, treeStump); break; case 1: cloud01.layer = 8; cloud01.tag = "Environment"; Create(randomizer, cloud01); break; case 2: cloud02.layer = 8; cloud02.tag = "Environment"; Create(randomizer, cloud02); break; } } }