private void Awake()
    {
        iceBehaviour   = GetComponent <IceBehaviour>();
        waterBehaviour = GetComponent <WaterBehaviour>();
        collider       = GetComponent <BoxCollider2D>();
        renderer       = GetComponent <SpriteRenderer>();

        Regen();
    }
Esempio n. 2
0
    public IceBehaviour Attack(List <IceBehaviour> list)
    {
        isAlive = true;
        int randomIndex = Random.Range(0, list.Count);

        iceBehaviour = list[randomIndex];

        // Enquanto nao achar uma plataforma que nao tenha tubarao, continua sorteando... Nojo haha
        while (SpawnerInimigo.dic.ContainsKey(iceBehaviour.MyPosition))
        {
            randomIndex  = Random.Range(0, list.Count);
            iceBehaviour = list[randomIndex];
        }

        SpawnerInimigo.dic.Add(iceBehaviour.MyPosition, this);
        IceController.Instance.StartSharkAnim(iceBehaviour.MyPosition);

        return(iceBehaviour);
    }
Esempio n. 3
0
 private void OnTriggerEnter2D(Collider2D other)
 {
     if (other.CompareTag("Obstacle"))
     {
         life--;
         if (life == 0)
         {
             bossObstacles.GetComponent <Animator>().SetTrigger("final");
             gameObject.SetActive(false);
             GameManager.Instance.isBossAlive = false;
         }
     }
     if (other.CompareTag("Player"))
     {
         IceBehaviour iceToDamage = null;
         for (int i = 0; i < IceController.Instance.iceScripts.Length; i++)
         {
             if (IceController.Instance.iceScripts[i] != null)
             {
                 iceToDamage = IceController.Instance.iceScripts[i];
                 break;
             }
         }
         if (iceToDamage != null)
         {
             IceController.Instance.TakeDamageByElement(-50, iceToDamage.MyPosition);
         }
     }
     if (other.CompareTag("Player") || other.CompareTag("Obstacle"))
     {
         transform.position = initialPosition.position;
         attacking          = false;
         attackTimer        = 0;
         intro = true;
     }
 }
 	// public void Move (Tubarao tubarao, float velocidadeRodeio, float centerX, float centerY) 
	// {
	// 	alpha += velocidadeRodeio;

	// 	X = centerX + (a * Mathf.Cos(alpha));
	// 	Y = centerY + (b * Mathf.Sin(alpha));

	// 	// Flips image when it reaches the max points of the ellipse
	// 	if(X - centerX <= -a + 0.1f && tubarao.isFacingLeft)
	// 		tubarao.Flip();
	// 	else if(X - centerX >= a - 0.1f && !tubarao.isFacingLeft)
	// 		tubarao.Flip();

	// 	// Set as the new position
	// 	tubarao.rb2D.position = new Vector3(X,Y);
 	// }

	public IEnumerator Move (Tubarao tubarao, float velocidadeRodeio) 
	{
		currentSurroundingTime = 0f;
		
		while(currentSurroundingTime <= surroundingTime)
		{
			float centerX = tubarao.urso.position.x;
			float centerY = tubarao.urso.position.y;

			alpha += (velocidadeRodeio * Time.deltaTime);

			X = centerX + (a * Mathf.Cos(alpha));
			Y = centerY + (b * Mathf.Sin(alpha));

			// Flips image when it reaches the max points of the ellipse
			if(X - centerX <= -a + 0.1f && tubarao.isFacingLeft)
				tubarao.Flip();
			else if(X - centerX >= a - 0.1f && !tubarao.isFacingLeft)
				tubarao.Flip();

			// Set as the new position
			tubarao.rb2D.position = new Vector3(X,Y);

			currentSurroundingTime += Time.deltaTime;

			yield return null;
		}

		// Desabilita barbatana
		for (int i = 0; i < children.Length; i++)
		{
			children[i] = transform.GetChild(i).gameObject;
			children[i].SetActive(false);
		}

		int plataformasDisponiveis = 0;

		List<IceBehaviour> l = new List<IceBehaviour>();

		for(int i = 0; i< IceController.Instance.iceScripts.Length; i++)
		{
			if(IceController.Instance.iceScripts[i] != null && IceController.Instance.iceScripts[i].MyPosition != IcePosition.ICE_CENTER)
			{
				plataformasDisponiveis++;
				l.Add(IceController.Instance.iceScripts[i]);
			}
		}

		// Se ha plataformas disponiveis
		if((plataformasDisponiveis - SpawnerInimigo.dic.Count) > 0)
		{	
			// Escolhe plataforma
			IceBehaviour ice = tubarao.Attack(l);
			IcePosition position = ice.MyPosition;

			float currentChewingTime = 0f;

			// Comeca a morder...
			while(tubarao.isAlive)
			{
				currentChewingTime += Time.deltaTime;
				
				// Apica dano a plataforma
				if(currentChewingTime > 1)
				{
					currentChewingTime = 0f;

					if(ice != null)
					{
						IceController.Instance.TakeDamageByElement(-tubarao.damagePerSecond, position);
					}
					// plataforma destruida
					else
					{
						tubarao.isAlive = false;
						SpawnerInimigo.dic.Remove(position);
						break;
					}
					// if(ice.Life <= 2)
					// {
						
					// }
				}

				yield return null;
			}

			// Quando player hitar o tubarao, pare a animcao de morder
			IceController.Instance.StopSharkAnim(position);
		}

		// Desabilita tubarao (caso nao haja plataformas disponiveis, simplesmente desaparece)
		gameObject.SetActive(false);
 	}