private void Start() { permutation = new int[lanes.Length]; for (int i = 0; i < permutation.Length; i++) { permutation[i] = i; } width = lanes[0].childCount; grid = new EnemyPos[lanes.Length, width]; for (int i = 0; i < lanes.Length; i++) { for (int j = 0; j < width; j++) { grid[i, j] = new EnemyPos() { position = lanes[i].GetChild(j).position } } } ; moveSpread = new WaitForSeconds(enemyMoveSpread); cache = new List <Enemy>(); blockedI = -5; blockedJ = -5; }
void CreateEnemies() { LevelDatabase.ResetEnemyIndex(); int enemiesAmount = currentLevel; enemies = new Enemy[enemiesAmount]; //check that there is no enemy being instantiated over other enemy EnemyPos currentPos = new EnemyPos(); //position assigned to a new enemy List <EnemyPos> ep = new List <EnemyPos>(); //record of previously created enemies bool repeated = false; for (int i = 0; i < enemiesAmount; i++) { enemies[i] = Instantiate(EnemyModel); enemies[i].transform.SetParent(EnemiesParent); do { repeated = false; currentPos.Floor = Random.Range(0, FloorsAmount); currentPos.XPos = Random.Range(-7, 7); for (int j = 0; j < ep.Count; j++) { if (currentPos.Floor == ep[j].Floor && currentPos.XPos == ep[j].XPos) { repeated = true; } } } while(repeated); ep.Add(currentPos); enemies[i].Set(currentPos.Floor, currentPos.XPos, LevelDatabase.GetEnemyModel(), InitialFloorPosition, FloorSpace, FloorsAmount); } }
private void Attack_Btn_Click(object sender, EventArgs e) { if (EnemyLocationList.Text != "") { var Target_Pos = EnemyLocationList.Text.ToLower(); int Targer_index = EnemyPos.FindIndex(a => a.Name == Target_Pos); if (EnemyPos[Targer_index].Enabled && round > 0) { round -= 1; Rounds.Text = "Round:" + round; if ((string)EnemyPos[Targer_index].Tag == "enemyship") { EnemyPos[Targer_index].Enabled = false; EnemyPos[Targer_index].BackColor = Color.Red; score += 1; Player_Txt.Text = score.ToString(); Enemy_Timer.Start(); } else { EnemyPos[Targer_index].Enabled = false; EnemyPos[Targer_index].BackColor = Color.Black; Enemy_Timer.Start(); } } } else { MessageBox.Show("Choose Location from List", "Hint"); } }
void SpawnEnemiesIterativeMode() { int counterType = 0; int counterTotal = 0; while (counterTotal != _possibleEnemies.Count) { do { counterType = UnityEngine.Random.Range(0, _possibleEnemies.Count); } while (IsEnemyTypeUsed(counterType)); numEnemyTypes[counterTotal] = counterType; counterTotal++; EnemiesRoom enemy = _possibleEnemies[counterType]; if (_counterPoints == _maximumPoints) { break; } int numOfEnemyType = UnityEngine.Random.Range(0, enemy.maxEnemiesOfType + 1); for (int i = 1; i < numOfEnemyType; i++) { EnemyPos enemyPos = GetPositionToSpawnNotUsed(); if (enemyPos == null && _counterPoints + enemy.mydificultyPoints > _maximumPoints) { break; } GameObject go = Instantiate(enemy.myEnemy); go.transform.position = enemyPos._position; _enemiesInRoom.Add(new EnemiesRoom(enemy.myEnemyType, go, enemy.mydificultyPoints)); _counterPoints += enemy.mydificultyPoints; if (_counterPoints >= _maximumPoints) { break; } } if (_counterPoints >= _maximumPoints) { break; } } while (_enemiesInRoom.Count == 0) { ClearEnemyTypeArray(); SpawnEnemiesIterativeMode(); } _enemiesInRoomCount = _enemiesInRoom.Count; }
private void FixedUpdate() { if (player) { if (!PlayerIsEngaged && !Cleared && IsABossArea && BossCamera && player.transform.position.x < MaxBound.x && player.transform.position.x > MinBound.x && player.transform.position.y < MaxBound.y && player.transform.position.y > MinBound.y) { PlayerIsEngaged = true; MainCamera.SetActive(false); BossCamera.SetActive(true); } else if (PlayerIsEngaged && CheckIfVictorious()) { PlayerIsEngaged = false; BossCamera.SetActive(false); MainCamera.SetActive(true); } if (PlayerIsEngaged && !Cleared) { if (MaxBound != null && MinBound != null) { Vector2 pos = player.GetComponent <Rigidbody2D>().position; pos.x = Mathf.Clamp(pos.x, MinBound.x, MaxBound.x); pos.y = Mathf.Clamp(pos.y, MinBound.y, MaxBound.y); player.GetComponent <Rigidbody2D>().position = pos; } } if (Enemies != null && MaxBound != null && MinBound != null) { foreach (Transform EnemyPos in Enemies) { if (EnemyPos) { Vector2 pos = EnemyPos.position; pos.x = Mathf.Clamp(pos.x, MinBound.x, MaxBound.x); pos.y = Mathf.Clamp(pos.y, MinBound.y, MaxBound.y); EnemyPos.GetComponent <Rigidbody2D>().position = pos; } } } } }
void SpawnEnemies() { //First test to spawn //_enemiesInRoom.Add(new EnemiesRoom(_possibleEnemies[0].myEnemyType, Instantiate(_possibleEnemies[0].myEnemy), _possibleEnemies[0].mydificultyPoints)); //_enemiesInRoom[0].myEnemy.transform.position = _enemyPositions[4]._position; //_enemyPositions[4]._alreadyUsed = true; //_enemiesInRoom.Add(new EnemiesRoom(_possibleEnemies[1].myEnemyType, Instantiate(_possibleEnemies[1].myEnemy), _possibleEnemies[1].mydificultyPoints)); //_enemiesInRoom[1].myEnemy.transform.position = _enemyPositions[6]._position; //_enemyPositions[6]._alreadyUsed = true; if (_continueSpawning) { foreach (EnemiesRoom enemy in _possibleEnemies) { if (NumberEnemiesOfType(enemy.myEnemyType) <= 2) { EnemyPos enemyPos = GetPositionToSpawnNotUsed(); GameObject go = Instantiate(enemy.myEnemy); go.transform.position = enemyPos._position; _enemiesInRoom.Add(new EnemiesRoom(enemy.myEnemyType, go, enemy.mydificultyPoints)); _counterPoints += enemy.mydificultyPoints; } } if (_counterPoints == _maximumPoints) { _continueSpawning = true; } else { SpawnEnemies(); } } _enemiesInRoomCount = _enemiesInRoom.Count; }