private void CreateEnemy(MovableEnemy enemy) { List <Point> groundPoints; // // Remove first 5 points to create the first enemy at a distance from the Player. // if (!_enemies.Any()) { groundPoints = new List <Point>(GameSessionData.Instance.GroundPoints); groundPoints.RemoveRange(0, 5); } else { groundPoints = GameSessionData.Instance.GroundPoints; } var rand = new System.Random(); var point = groundPoints[rand.Next(0, groundPoints.Count)]; var createdEnemy = Instantiate(enemy, new Vector3(point.X, point.Y), transform.rotation); _enemies.Add(createdEnemy); }
//Creates all enemy objects public void CreateEnemyObjects() { int objCount = 0; int rand; for (int y = 0; y < boardInfo.height; y++) { if (objCount < boardInfo.nEnemies) { for (int x = 0; x < boardInfo.width; x++) { if (objCount < boardInfo.nEnemies) { if (nodes[x, y] != null) { placementChance = Functions.GetPlacementChance(x, y, boardInfo.width, boardInfo.height, boardInfo.nEnemies); rand = RNG.Next(100); int winObjCount = 0; foreach (WinObject winObj in winObjects) { //if the node is taken by a winObject, jump to the next node if (nodes[x, y].position == winObj.position) { break; } winObjCount++; } if (rand > placementChance) { if (winObjCount == winObjects.Count && nodes[x, y].isEmpty && (x != 0 || y != 0) && !(x == 1 || y == 0) && !(x == 1 || y == 1)) { //create and place the spikes Spike spike = new Spike(game); spike.position = nodes[x, y].position; bool error = false; //confirms if the enemy is separated from the other enemies by at least X units foreach (EnemyObject enemy in enemyObjects) { if (Math.Abs(enemy.position.X - spike.position.X) < 2 && Math.Abs(enemy.position.Y - spike.position.Y) < 2) { error = true; break; } } //Place the spike if (!error) { rand = RNG.Next(100); if (rand > 30) { enemyObjects.Add(spike); } else { Vector2 dir = new Vector2(0, 1); if (rand <= 15 && x != boardInfo.width - 1) { dir = new Vector2(0, -1); } MovableEnemy movingEnemy = new MovableEnemy(nodes[x, y].position, 3, "Copycat", dir); enemyObjects.Add(movingEnemy); } objCount++; } } } } } else { break; } } } else { break; } } }