private void UntargetEnemy(EnemyIdentifier enemyId) { if (_target == enemyId) { _target = null; } }
// Spawn followers void Start() { GameObject prefab = EnemyIdentifier.GetEnemyPrefab(followerType); GameObject previous = gameObject; for (int i = 0; i < followerTotal; i++) { GameObject newFollower = Instantiate(prefab); //GM.Instance.Spawn (newFollower); newFollower.transform.position = transform.position; LeaderEnemy LE = newFollower.GetComponent <LeaderEnemy> (); if (LE != null && LE.enabled) { LE.enabled = false; } FollowerEnemy FComponent = newFollower.AddComponent <FollowerEnemy> () as FollowerEnemy; FComponent.objToFollow = previous; FComponent.followRadius = followRadius; FComponent.followerSprite = followerSprite; FComponent.leaderSprite = newFollower.GetComponentInChildren <SpriteRenderer>().sprite; previous = newFollower; } }
public OfficerData(Vector3 _pos, Quaternion _rot, List <Vector3> _path, Vector3 _checkPosition) { identifier = EnemyIdentifier.Officer; position = _pos; rotation = _rot; patrolPath = _path; checkPosition = _checkPosition; }
public void AddEnemy(EnemyIdentifier enemyId) { _enemies.Add(enemyId); var path = FindPath(_enemyPositionService[enemyId].ToMapCoordinate()); Emit(new PathFinderEvent.PathCalculated(enemyId, path)); }
private void FireBulletAt(EnemyIdentifier enemyId) { var toEnemy = (EnemyPositions[enemyId] - transform.position).normalized; var bullet = Instantiate(BulletPrefab); bullet.transform.position = transform.position; bullet.transform.rotation = Quaternion.LookRotation(Vector3.forward, toEnemy); var bulletRigidBody = bullet.GetComponent <Rigidbody2D>(); bulletRigidBody.velocity = toEnemy * BulletVelocity; }
public void AddEnemy(TowerIdentifier towerId, EnemyIdentifier enemyId) { if (!_enemiesInRange.TryGetValue(towerId, out var enemies)) { enemies = _enemiesInRange[towerId] = new List <EnemyIdentifier>(); } enemies.Add(enemyId); if (!_targettedEnemies.ContainsKey(towerId)) { _targettedEnemies[towerId] = enemyId; Emit(new TowersEvent.EnemyTargetted(towerId, enemyId)); } }
// SET currently_spawning TO TRUE BEFORE STARTING THIS COROUTINE IEnumerator spawnLoop(List <TypeNumPair>[] waveSpawns) { Debug.Assert(currently_spawning); for (int i = 0; i < 8; i++) { foreach (TypeNumPair pair in waveSpawns[i]) { GameObject prefab = EnemyIdentifier.GetEnemyPrefab(pair.type); for (int j = 0; j < pair.numEnemies; j++) { yield return(new WaitForSeconds(Random.value * .25f)); GameObject newEnemy = Instantiate(prefab, Spawners[i], Quaternion.identity); randomizePosition(newEnemy); } } } currently_spawning = false; }
public void RemoveEnemy(TowerIdentifier towerId, EnemyIdentifier enemyId) { if (!_enemiesInRange.TryGetValue(towerId, out var enemies)) { enemies = _enemiesInRange[towerId] = new List <EnemyIdentifier>(); } enemies.Remove(enemyId); if (_targettedEnemies.TryGetValue(towerId, out var currentTargetId) && enemyId == currentTargetId) { Emit(new TowersEvent.EnemyUntargetted(towerId, enemyId)); _targettedEnemies.Remove(towerId); if (enemies.Any()) { var newTargetId = enemies.First(); _targettedEnemies[towerId] = newTargetId; Emit(new TowersEvent.EnemyTargetted(towerId, newTargetId)); } } }
// Initialization private void Awake() { // Static instance setup if (_instance != null && _instance != this) { Destroy(this.gameObject); } else { _instance = this; } if (transform.parent == null) { DontDestroyOnLoad(this); } // Fill enemy type dictionary with array from editor EnemyTypeDict = new Dictionary <EnemyType, GameObject>(); for (int i = 0; i < TypePrefabs.Length; i++) { EnemyTypeDict.Add(TypePrefabs [i].Type, TypePrefabs [i].prefab); } }
public EnemyData(EnemyIdentifier _identifier, Vector3 _position, Quaternion _rotation) { identifier = _identifier; position = _position; rotation = _rotation; }
/// <summary> /// Activa los enemigos y los coloca donde corresponde /// Puede ser llamado por el boss /// </summary> /// <param name="i"></param> public void ActivateEnemies(int i, Vector3 spawnPoint = new Vector3()) { //Metodo con spawn points EnemyIdentifier enemyIdentifier = enemiesSpawnSettings[i].enemyPrefab.GetComponent <EnemyIdentifier>(); Transform groupSpawn; Vector3 pointForGroupSpawn; // if (spawnPoint != Vector3.zero) { pointForGroupSpawn = spawnPoint; } else if (enemyIdentifier) { EnemyType typeToSpawn = enemyIdentifier.enemyType; groupSpawn = GetRandomSpawmPointNearerThanX(typeToSpawn, farestSpawnDistanceToEpicenter); // Control de errores if (groupSpawn == null) { return; } pointForGroupSpawn = groupSpawn.position; } else { // TODO: Desarrorlo pointForGroupSpawn = epicenterPoint; } // NOTA: Control de error // De primeras no debería haber tamaño de spawn 0 int enemiesToSpawn = (int)GameManager.instance.ApplyDifficultyFactor(enemiesSpawnSettings[i].enemiesToSpawn, 1); Debug.Log("Spawning enemies: " + enemiesSpawnSettings[i].enemiesToSpawn + ", " + enemiesToSpawn); // Aparte, ahora sale todo el grupo o no sale if (/*enemiesSpawnSettings[i].*/ enemiesToSpawn > 0 && /*enemiesSpawnSettings[i].enemiesToSpawn*/ enemiesToSpawn <= enemiesSpawnSettings[i].maxActiveEnemies - activeEnemies[i].Count) { // Si no hay enemigos activos de ese tipo, aviso de Carol if (activeEnemies[i].Count == 0) { carolHelp.TriggerGeneralAdvice("EnemiesIncoming"); } // Primero iniciamos la formación EnemyFormation newEnemyFormation = null; if (enemiesSpawnSettings[i].formationData != null) { // //newEnemyFormation = new EnemyFormation(enemiesSpawnSettings[i].enemiesToSpawn, // enemiesSpawnSettings[i].formationData.formationInfo.formationType, // enemiesSpawnSettings[i].formationData.formationInfo.distanceBetweenMembers); newEnemyFormation = new EnemyFormation(enemiesSpawnSettings[i].formationData.formationInfo, /*enemiesSpawnSettings[i].*/ enemiesToSpawn); // enemyFormations.Add(newEnemyFormation); } // float memberSpawnAngle = 360 / /*enemiesSpawnSettings[i].*/ enemiesToSpawn; float meberSpawnRadius = 10; // Sacamos a los enemigos for (int j = 0; j < /*enemiesSpawnSettings[i].*/ enemiesToSpawn; j++) { // float memberSpawnCoordinates = memberSpawnAngle * j; Vector2 memberSpawnPositionXY = new Vector2(Mathf.Cos(memberSpawnCoordinates) * meberSpawnRadius, Mathf.Sin(memberSpawnCoordinates) * meberSpawnRadius); //Vector3 positionToSpawn = new Vector3(Random.Range(-groupToSpawnSize[i], groupToSpawnSize[i]) + pointForGroupSpawn.x, 1, // Random.Range(-groupToSpawnSize[i], groupToSpawnSize[i]) + pointForGroupSpawn.z); Vector3 positionToSpawn = new Vector3(pointForGroupSpawn.x + memberSpawnPositionXY.x, pointForGroupSpawn.y, pointForGroupSpawn.z + memberSpawnPositionXY.y); // TODO: Chequear cuando esté vacía if (reserveEnemies[i].Count == 0) { Debug.Log("No more enemies in reserve"); continue; } GameObject nextEnemy = reserveEnemies[i][0]; reserveEnemies[i].Remove(nextEnemy); // TODO: Revisar que falla aquí if (nextEnemy.gameObject == null) { Debug.Log(nextEnemy); continue; } // TODO: Revisar lo de la posición al activarlos nextEnemy.SetActive(true); nextEnemy.transform.position = positionToSpawn; EnemyConsistency enemyConsistency = nextEnemy.GetComponent <EnemyConsistency>(); // TODO: Cuando esté bien organizado este paso no debería ahcer falta if (enemyConsistency == null) { enemyConsistency = nextEnemy.GetComponentInChildren <EnemyConsistency>(); } // if (enemyConsistency != null) { enemyConsistency.ManagerIndex = i; enemyConsistency.ResetStatus(); } // Ponemos los bosses de lado de momento if (levelManager.LevelVictoryCondition == VictoryCondition.SlayTheBeast && i == 0) { nextEnemy.transform.Rotate(Vector3.up * -90); } // Y lo añadimos a enemigos activos activeEnemies[i].Add(nextEnemy); // Si he formación lo metemos a ella if (newEnemyFormation != null) { //TODO: Meterlo en la formación EnemyBaseBodyBehaviour behaviour = nextEnemy.GetComponent <EnemyBaseBodyBehaviour>(); // TODO: Arregalro para que no haga falta hacer esto if (behaviour == null) { behaviour = nextEnemy.GetComponentInChildren <EnemyBaseBodyBehaviour>(); } // newEnemyFormation.formationMembers.Add(behaviour); behaviour.enemyFormation = newEnemyFormation; } //GameObject nextEnemy = Instantiate(enemyPrefabsToUse[i], pointForGroupSpawn, Quaternion.identity); } } //else // Debug.Log("Zero enemies to spawn or no more room for enemies"); }
private void SpawnEnemy() { var enemyId = EnemyIdentifier.Create(); Emit(new EnemiesEvent.EnemySpawned(enemyId, _enemyVelocity)); }
public PathCalculated(EnemyIdentifier enemyId, MapCoordinate[] path) { EnemyId = enemyId; Path = path; }
// void DrawRadarWithEnemies() { // //RadarDimensions.radarXPositon = Screen.width * 33 / 1000; //RadarDimensions.radarYPosition = Screen.height * 96 / 100; //RadarDimensions.markerSize = 10; //RadarDimensions.markerCenter = RadarDimensions.markerSize / 2; // Igual pillamos el current up del player // La camara, coño float playerDirection = Vector3.SignedAngle(Vector3.forward, cameraControl.transform.forward, Vector3.up); playerDirection *= Mathf.Deg2Rad; // TODO: Decidir si dinámico el alcance del radar // Primero dibujamos el radar GUI.DrawTexture(new Rect(RadarDimensions.radarXPositon, RadarDimensions.radarYPosition - radarDimensions.y, radarDimensions.x, radarDimensions.y), radarTexture); // Epicentro si toca if (enemyManager != null) { //DrawEpicenterInRadar(playerDirection, RadarDimensions.radarXPositon, RadarDimensions.radarYPosition, RadarDimensions.markerSize); DrawElementInRadar(enemyManager.EpicenterPoint, playerDirection, targetedEnemyEstimatedFuturePositionTexture); } // Y enemigos // TODO: Cogerlo por refencia del manager apropiado cuando lo tengamos listo //Targeteable[] enemies = FindObjectsOfType<Targeteable>(); List <GameObject> allActiveEnemies = enemyManager.AllActiveEnemies; // allActiveEnemies = enemyManager.FormationLeaders; // TODO: Sacar la fuerza de las formaciones para indicar su nivel de peligro List <EnemyFormation> enemyFormations = enemyManager.EnemyFormations; // Aqui pasamos por todos los enemigos for (int i = 0; i < enemyFormations.Count; i++) { // EnemyIdentifier enemyIdentifier = allActiveEnemies[i].GetComponentInParent <EnemyIdentifier>(); // float formationStrength = enemyFormations[i].FormationStrength; Texture textureToUse = enemyInScreenTextures[0]; if (formationStrength >= 0.75f) { textureToUse = enemyInScreenTextures[3]; } else if (formationStrength >= 0.5f) { textureToUse = enemyInScreenTextures[2]; } else if (formationStrength >= 0.25f) { textureToUse = enemyInScreenTextures[1]; } //Debug.Log("Formation strngth: " + formationStrength + ", texture to use: " + textureToUse.name); // //DrawElementInRadar(allActiveEnemies[i].transform.position, playerDirection, enemyInScreenTextures[(int)enemyIdentifier.enemyType]); DrawElementInRadar(allActiveEnemies[i].transform.position, playerDirection, textureToUse); } // Y los ataques peligrosos también if (bulletPool == null) { return; } // TODO: Sacar función para no tener codigo repe for (int i = 0; i < bulletPool.DangerousBullets.Count; i++) { // DrawElementInRadar(bulletPool.DangerousBullets[i].transform.position, playerDirection, alertTexture); } }
private void SpawnEnemy(EnemyIdentifier enemyId, float velocity) { EnemyFactory.Create(new EnemyParameters(enemyId, transform.position, velocity)); }
public EnemyUntargetted(TowerIdentifier towerId, EnemyIdentifier enemyId) { TowerId = towerId; EnemyId = enemyId; }
public void Destroy(EnemyIdentifier enemyId) { _enemiesDestroyed++; Emit(new EnemiesEvent.EnemyDestroyed(enemyId, _enemiesDestroyed)); }
public EnemySpawned(EnemyIdentifier enemyId, float velocity) { EnemyId = enemyId; Velocity = velocity; }
public Vector3 this[EnemyIdentifier enemyId] { get => _positions[enemyId];
public EnemyDestroyed(EnemyIdentifier enemyId, int totalDestroyed) { EnemyId = enemyId; TotalDestroyed = totalDestroyed; }
public EnemyParameters(EnemyIdentifier enemyId, Vector3 position, float velocity) { EnemyId = enemyId; Position = position; Velocity = velocity; }
private void TargetEnemy(EnemyIdentifier enemyId) { _target = enemyId; //FireBulletAt(enemyId); }