private void CheckToDestroyOthers(Vector2 alienPositionInMatrix) { Vector2 [] positionsToCheck = new Vector2[4]; positionsToCheck[0] = new Vector2(alienPositionInMatrix.x, alienPositionInMatrix.y + 1); positionsToCheck[1] = new Vector2(alienPositionInMatrix.x, alienPositionInMatrix.y - 1); positionsToCheck[2] = new Vector2(alienPositionInMatrix.x - 1, alienPositionInMatrix.y); positionsToCheck[3] = new Vector2(alienPositionInMatrix.x + 1, alienPositionInMatrix.y); AlienController currentAlienControllers = alienControllers[(int)alienPositionInMatrix.x, (int)alienPositionInMatrix.y]; for (int i = 0; i < positionsToCheck.Length; i++) { int valueX = (int)positionsToCheck[i].x; int valueY = (int)positionsToCheck[i].y; if (valueX >= 0 && valueX < configuration.columns && valueY >= 0 && valueY < configuration.rows && currentAlienControllers.TypeID == alienControllers[valueX, valueY].TypeID && alienControllers[valueX, valueY].IsAlive ) { alienControllers[valueX, valueY].Destoy(); } } }
private IEnumerator ShootBullet() { yield return(new WaitForSeconds(2)); while (true) { yield return(new WaitForSeconds(Random.Range(1, 3))); if (isPause) { continue; } for (int i = 0; i < configuration.total; i++) { AlienController current = alienControllers[Random.Range(0, configuration.columns), Random.Range(0, configuration.rows)]; if (current.IsAlive) { current.Shoot(); break; } } } }
private void Attack(PlayerController controller, AlienController alien) { if (alien == null) { return; } Vector3 attackerToAlien = alien.transform.position - controller.transform.position; float distanceToAlien = Vector3.Distance(controller.transform.position, alien.transform.position); if (distanceToAlien <= minDistanceToAttackAlien) { //Attack timeSinceAttack[controller.id] += Time.deltaTime; if (timeSinceAttack[controller.id] > minTimeToAttack) { timeSinceAttack[controller.id] = 0f; alien.Hit(); } } else { //Move to alien Vector3 direction = controller.transform.position + attackerToAlien; controller.UpdateTrajectoryDirection(direction); controller.SetMove(true); controller.Move(); } }
void Start() { renderer = GetComponentInChildren <MeshRenderer>(); rigidbody = GetComponent <Rigidbody2D>(); fullSpeed = speed; alien = this; }
void Start() { pauseController = gameObject.GetComponent <PauseController>(); StartCoroutine("ResetAfterDeath"); playerHasDied = false; GameObject gameController = GameObject.FindWithTag("GameController"); GameObject gameOverObject = GameObject.FindWithTag("GameOverText"); areaToCheck = GameObject.FindWithTag("AlienArea"); if (gameController != null && gameOverObject != null && areaToCheck != null) { alienShooter = areaToCheck.GetComponent <ChooseAliensThatWillShoot>(); alienController = gameController.GetComponent <AlienController>(); tankSpawner = gameController.GetComponent <TankSpawn>(); lifeController = gameController.GetComponent <LifeController>(); gameOverText = gameOverObject.GetComponent <GameOverController>(); alienSpawnController = gameController.GetComponent <InitializeAlienPosition>(); StartCoroutine("CheckIfWaveShouldBeReset"); } else { Debug.Log("Cannot find game controller in reset Controller"); } }
// Callback for when an alien is destroyed public void OnAlienDestroyed(AlienController Alien) { // Find the index of the delayed object int DelayedIndex = System.Array.IndexOf(AliensComponents, Alien); // If we destroy an alien not in the front row skip the function if (DelayedIndex > 14) { return; } // Get the alien name string AlienName = Alien.name; // Get the coordinate of the destroyed alien int DelayedRow = int.Parse(AlienName.Substring(6, 1)); int DelayedCol = int.Parse(AlienName.Substring(8)); // Store the index of the next alien that can fire, if it's -1 there is no alien that can fire int NewIndex = -1; // Store the name of the next alien that can fire string NewName = ""; // If there is a row behind the alien with an alien that can fire while (--DelayedRow >= 0 && NewIndex == -1) { // Compute the new name NewName = string.Format("Alien_{0}_{1}", DelayedRow, DelayedCol); // Get the new index NewIndex = System.Array.FindIndex(AliensComponents, x => x != null && x.name == NewName); } // If we found an alien that can fire if (NewIndex >= 0) { // The new index can fire AliensComponents[NewIndex].CanFire = true; // Swap the AlienController tempswap = AliensComponents[DelayedIndex]; AliensComponents[DelayedIndex] = AliensComponents[NewIndex]; AliensComponents[NewIndex] = tempswap; } // If we went through the entire row and no alien can fire else { // Decrement the number of alien that can fire NewIndex = AliensCanFire - 1; AlienController tempswap = AliensComponents[DelayedIndex]; AliensComponents[DelayedIndex] = AliensComponents[AliensCanFire]; AliensComponents[AliensCanFire] = tempswap; } // Update the score UpdateScore(Alien.Points); }
public void FreeControllingAlien() { if (IsControllingAlien()) { ControlledAlien.FreeController(); ControlledAlien = null; } }
void Start() { SetupMoveBoundaries(); laserDetector = FindObjectOfType <LaserDetector>(); alienController = FindObjectOfType <AlienController>(); levelController = FindObjectOfType <LevelController>(); lagBehindOffset = initialLagBehindOffset; }
void Start() { alarmed = false; inAction = false; alienController = alien.GetComponent <AlienController>(); alienMove = alien.GetComponent <Transform>(); Invoke("EnableCollider", count); }
private void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.tag == "Barrier") { Destroy(gameObject); } if (col.gameObject.tag == "Rock") { Rock _rock = col.gameObject.GetComponent <Rock>(); if (_rock != null) { _rock.TakeDamage(); Destroy(gameObject); } } if (col.gameObject.tag == "Alien") { AlienController _alienController = col.gameObject.GetComponent <AlienController>(); if (_alienController != null) { _alienController.Die(); IncreaseScore(10); Destroy(gameObject); } } if (col.gameObject.tag == "Boss") { BossController _bossController = col.gameObject.GetComponent <BossController>(); if (_bossController != null) { _bossController.TakeDamage(); IncreaseScore(5); Destroy(gameObject); } } if (col.gameObject.tag == "Ship") { MotherShip _motherShip = col.gameObject.GetComponent <MotherShip>(); if (_motherShip != null) { _motherShip.Die(); AudioManager.audioManager.PlaySound("Ship Hit"); ShipSpawnStart _shipSpawner = GameObject.FindObjectOfType <ShipSpawnStart>(); _shipSpawner.canWeSpawn = true; _shipSpawner.CreateNewSpawnRate(); IncreaseScore(50); Destroy(gameObject); } } }
void Start() { tag = "Alien"; spriteRenderer = GetComponent <SpriteRenderer>(); color = spriteRenderer.color; unroundedPos = transform.position; segmentsPerUnityUnit = GetComponentInParent <AlienController>().GetSegmentsPerUnityUnit(); alienController = FindObjectOfType <AlienController>(); alienController.AddAlien(gameObject); }
public virtual void SaveControllingAlien() { if (!IsDead && IsControllingAlien()) { GM.GameState.CurrentSavedAliens++; ControlledAlien.DOSaveAlien(); ControlledAlien = null; // TODO: Destroy alien or something. Ver aliencontroller. } }
public void SetControllingAlien(AlienController alien) { if (!IsControllingAlien()) { if (alien.CanBeControlledByPlayer()) { alien.SetController(this); ControlledAlien = alien; } } }
private void MoveAway(AlienController controller, List <Vector3> direction) //Correr en la dirección indicada { Vector3 from = direction[0]; //Posición del alien Vector3 to = direction[1]; //Posición del astronauta Vector3 directionToAstronaut = (to - from).normalized; //(from - to).normalized PARA IR POR EL ASTRONAUTA controller.UpdateTrajectoryDirection(directionToAstronaut); controller.SetMove(true); controller.Move(); }
void OnTriggerEnter2D(Collider2D hitInfo) { Debug.Log(hitInfo.name); AlienController enemy = hitInfo.GetComponent <AlienController>(); if (enemy != null) { enemy.TakeDamage(damage); } Destroy(gameObject); }
void OnTriggerEnter2D(Collider2D other) { AlienController controller = other.GetComponent <AlienController>(); if (controller != null) { controller.ChangeScore(1); Destroy(gameObject); controller.PlaySound(pickupClip); } }
void Start() { player = GameObject.FindWithTag("Player"); playerLives = FindObjectOfType <Lives>(); aController = FindObjectOfType <AlienController>(); DisplayError(); initialPosition = player.transform.position; playerLives.OnLostLife += LostLife; playerLives.OnDeath += GameOver; aController.OnNextWave += GiveLife; StartGame(); }
private void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.tag == "Alien") { AlienController _alienController = col.gameObject.GetComponent <AlienController>(); if (_alienController != null) { _alienController.Die(); Destroy(gameObject); } } }
private AlienController GetAlienById(int id) { AlienController alienController = null; foreach (AlienController alien in alienControllers) { if (alien.id == id) { alienController = alien; } } return(alienController); }
private void DrawStateIcon(AlienController controller) { int state = GetAlienState(controller); switch (state) { case 0: controller.SetImageToDraw(0); break; //0 case 1: controller.SetImageToDraw(2); break; //2 case 2: controller.SetImageToDraw(1); break; //1 } }
private float GetSuccessRate(AlienController controller) { float numberOfSuccess = 0f; foreach (int element in controller.shootSuccesses) { if (element == 1) { numberOfSuccess++; } } return(numberOfSuccess / (float)numberOfShoots); }
private void ThrowBall(AlienController controller, List <Vector3> direction, Vector3 predictionOfMovement) { if (controller.isDead()) { return; //Si está muerto, no puede disparar } Vector3 from = direction[0]; //Posición del alien Vector3 to = direction[1]; //Posición del astronauta float distanceToObjective = Vector3.Magnitude(from - to); if (distanceToObjective > controller.GetMaxDistanceToShoot()) { return; //Disparar solo si están a menos de 20 unidades de distancia } Vector3 directionToAstronaut = (from - to).normalized + predictionOfMovement.normalized * 0.2f; bool nowThrowing = controller.ball.GetComponent <ThrowBall>().NowThrowing(); if (!nowThrowing) { if (controller.ball.GetComponent <ThrowBall>().hasHitAstronaut()) { hittedAstronaut[controller.id] = true; } if (hittedAstronaut[controller.id]) { timeBetweenShoots += Time.deltaTime; if (timeBetweenShoots >= minTimeBetweenShoots) { timeBetweenShoots = 0f; hittedAstronaut[controller.id] = false; Vector3 positionFromShoot = controller.transform.position; float distance = Vector3.Distance(positionFromShoot, Vector3.zero); float targetDistace = distance + 0.6f; Vector3 newPositionFromShoot = positionFromShoot * (targetDistace / distance); controller.ball.GetComponent <ThrowBall>().Throw(newPositionFromShoot, directionToAstronaut); } } else { Vector3 positionFromShoot = controller.transform.position; float distance = Vector3.Distance(positionFromShoot, Vector3.zero); float targetDistace = distance + 0.6f; Vector3 newPositionFromShoot = positionFromShoot * (targetDistace / distance); controller.ball.GetComponent <ThrowBall>().Throw(newPositionFromShoot, directionToAstronaut); } } }
void Start() { GameObject controller = GameObject.FindWithTag("GameController"); areaToCheck = GameObject.FindWithTag("AlienArea"); if (controller != null) { alienShotController = areaToCheck.GetComponent <ChooseAliensThatWillShoot>(); alienMovementController = controller.GetComponent <AlienController>(); } else { Debug.Log("Cannot find game controller in reset Controller"); } }
private Vector3 GetClosestAlienPosition(AlienController controller) { float minDistance = 400f; Vector3 position = Vector3.zero; foreach (AlienController alien in alienControllers) { if (Vector3.Distance(controller.transform.position, alien.transform.position) < minDistance && controller.id != alien.id) { minDistance = Vector3.Distance(controller.transform.position, alien.transform.position); position = alien.transform.position; } } return(position); }
public void UpdateAstronauts() { if (!AliensStartedAttack()) { foreach (PlayerController controller in astronautControllers) { controller.Stop(); } return; } //CHECK GAME OVER OR PASSED if (AllPlayerDead()) { GameOver(); } if (AllAlienDead()) { MissionSuccess(); //Should be Game passed or smthing } //int bestIdToLeave = GetBestAstronautToLeave(); foreach (PlayerController controller in astronautControllers) { if (controller.GetWeapon() == "shield") { //DEFENDERS controller.PerformJustGravity(); PlayerController defender = UpdateDefender(controller); Defend(controller, defender); } else { //ATTACKERS controller.PerformJustGravity(); AlienController alien = GetAlienToAttack(controller); Attack(controller, alien); } } //Cleaning of some variables foreach (AlienController alien in alienControllers) { alien.myDefensorId = -1; } }
public void SetConfiguration(AlienInstancerConfiguration config) { configuration = config; totalAliens = config.total; alienControllers = new AlienController[configuration.columns, configuration.rows]; AlienController alienController = alien.GetComponent <AlienController>(); width = alienController.Width; height = alienController.Height; totalWidth = width * configuration.columns + configuration.pandding * (configuration.columns - 1); totalHeight = height * configuration.rows + configuration.pandding * (configuration.rows - 1); }
private void OnTriggerEnter(Collider other) { if (other.CompareTag("AlienSaveSpot")) { SaveControllingAlien(); foreach (PlayerCharacter p in GameSceneManager.Instance.GameState.Invaders) { p.SaveControllingAlien(); } } if (other.CompareTag("AlienControlTrigger")) // Collision with alien { AlienController a = other.transform.parent.GetComponent <AlienController>(); // Get alien component if (a != null) // Check if alien component is ok { if (!IsControllingAlien()) // Player is not controlling alien { SetControllingAlien(a); } else // Player is controlling alien, find an invader available { List <InvaderController> availableInvaders = GameSceneManager.Instance.GameState.Invaders.Where(i => !i.IsDead && !i.IsControllingAlien()).ToList(); if (availableInvaders.Count > 0) { InvaderController first = availableInvaders.First(); first.SetControllingAlien(a); // Give alien controll to the first invader found } } } } if (GM.GameState.IsEnergyStateActive) { if (other.CompareTag("Soldier")) { SoldierController soldier = other.GetComponent <SoldierController>(); if (soldier != null && !soldier.IsDead) { HitSoldierParticles.Play(); soldier.DoDeath(); } } } }
void SwitchRight() { if (canWeSwitchRight) { canWeSwitchRight = false; for (int j = 0; j < aliens.Count; j++) { AlienController alienController = aliens[j].GetComponent <AlienController>(); if (alienController != null) { alienController.ReverseDirection(1); alienController.MoveDown(); } } canWeSwitchLeft = true; } }
void makeDead() { //berhenti pindah AudioSource.PlayClipAtPoint(deathSound, transform.position, 10.0f); Destroy(gameObject.transform.root.gameObject); if (drops) { Instantiate(drop, transform.position, Quaternion.identity); } AlienController aAlien = GetComponentInChildren <AlienController> (); if (aAlien != null) { aAlien.ragdollDeath(); } }
/*private void KeepDistance(AlienController controller, PlayerController astronaut) //Intentar mantener 17f unidades de distancia * { * float astronautSpeed = astronaut.GetSpeed(); * //Update speed to match objective's speed * controller.SetSpeed(astronautSpeed + 0.5f, false); * // * * Vector3 astronautPosition = astronaut.transform.position; * * Vector3 direction = (astronautPosition - controller.transform.position).normalized; * * controller.UpdateTrajectoryDirection(direction); * * float distance = Vector3.Distance(controller.transform.position, astronautPosition); * * if (distance < 7.5f) //Porque si se aleja más de 20 no puede disparar * { * Vector3 direction2 = (controller.transform.position - astronautPosition).normalized; * controller.UpdateTrajectoryDirection(direction2); * controller.SetMove(true); * controller.Move(); * } * else * { * controller.SetMove(true); * controller.Move(); * } * }*/ private int HittedAstronaut(AlienController controller) //0 -> ignore; 1 -> hit astronaut; 2 -> hit ground { bool nowThrowing = controller.ball.GetComponent <ThrowBall>().NowThrowing(); if (controller.ball.GetComponent <ThrowBall>().isColliding() && nowThrowing) { if (controller.ball.GetComponent <ThrowBall>().hasHitAstronaut()) { return(1); } else { return(2); } } else { return(0); } }
// Use this for initialization void Start() { //if (spaceShipType == VANISHED) { anim=GetComponentInChildren<Animator>(); audioSource = GetComponent<AudioSource> (); rend = GetComponentInChildren<Renderer> (); aliens = (GameObject[])GameObject.FindGameObjectsWithTag ("Alien"); alienController = GameObject.FindObjectOfType<AlienController> (); spaceshipController = GameObject.FindObjectOfType<SpaceshipController> (); //transform.rotation = Quaternion.identity; planet = GameObject.FindGameObjectWithTag ("Planet"); Random.seed = (int)System.DateTime.Now.Ticks; setUpSpaceShip (); functioningSpaceShip (); // if(spaceShipType=) //audioSource.PlayOneShot(disappearSound); //curScale = this.transform.localScale.x; //LeanTween.scale( this.gameObject, new Vector3 (curScale + 0.1f, curScale + 0.1f, curScale + 0.1f), 0.25f).setEase(LeanTweenType.easeOutCirc).setLoopPingPong(-1); }
// Use this for initialization void Start() { audioSource = GetComponent<AudioSource> (); alienController = GameObject.FindObjectOfType<AlienController> (); asteroidSprites = Resources.LoadAll<Sprite>("asteroid timer"); }
// Use this for initialization void Start() { rend = GetComponentInChildren<Renderer> (); aliens = (GameObject[])GameObject.FindGameObjectsWithTag("Alien"); alienController = GameObject.FindObjectOfType<AlienController>(); spaceshipController = GameObject.FindObjectOfType<SpaceshipController>(); //transform.rotation = Quaternion.identity; planet = GameObject.FindGameObjectWithTag("Planet"); Random.seed = (int)System.DateTime.Now.Ticks; setUpSpaceShip(); functioningSpaceShip (); }
// Use this for initialization void Start() { pc = player.GetComponent<PlayerController>(); ac = alienManager.GetComponent<AlienController>(); }
protected void Initialize() { agent = GetComponent<NavMeshAgent>(); player = FindObjectOfType<PlayerController>().gameObject; alienComponent = GetComponent<Alien>(); controller = GetComponent<AlienController>(); currentState = State.Patrol; waypoints = GameObject.FindGameObjectsWithTag("waypoint"); }