Пример #1
0
    private float DamageShield(float damageAmount)
    {
        foreach (var shield in shields.Reverse())
        {
            ShieldHealth box = shield.Value;

            if (box.shieldHealth.Value == 0)
            {
                continue;
            }

            // Calculate Overkill Damage
            float overkillDmg = Mathf.Max(damageAmount - box.shieldHealth.Value, 0);

            // Trigger Event
            PlayerActionEventManager.Trigger(PlayerActions.ShieldDamaged);

            // Damage Shield
            box.shieldHealth.ModFlat -= damageAmount;

            // Trigger Event
            PlayerActionEventManager.Trigger(PlayerActions.ShieldChanged);

            // Damage Player
            damageAmount = overkillDmg;

            if (damageAmount == 0)
            {
                return(0);
            }
        }

        return(damageAmount);
    }
Пример #2
0
 void OnTriggerStay(Collider other)
 {
     if (!gameController.won)
     {
         PlayerController playerController = other.GetComponent <PlayerController>();
         ShieldHealth     shieldHealth     = other.GetComponent <ShieldHealth>();
         if (other.CompareTag("Player") && playerController)
         {
             playerController.onHit(9223372036854775807, true);
         }
         else if (other.CompareTag("Shield") && shieldHealth)
         {
             shieldHealth.takeDamage(9223372036854775807);
         }
     }
 }
Пример #3
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "Player")
     {
         Destroy(other.gameObject);
         PlayerLifeSystem.playerLives--;
         Destroy(bullet.gameObject);
         GameOver.isPlayerDead = true;
     }
     else if (other.tag == "Shield")
     {
         GameObject   playerShield = other.gameObject;
         ShieldHealth shieldHealth = playerShield.GetComponent <ShieldHealth>();
         shieldHealth.health -= 1;
         Destroy(bullet.gameObject);
     }
 }
Пример #4
0
    public float GetTotalShieldHealth()
    {
        if (shields.Count == 0)
        {
            return(0);
        }

        float total = 0;

        foreach (var shield in shields)
        {
            ShieldHealth box = shield.Value;

            if (box.shieldHealth.Value == 0)
            {
                continue;
            }

            total += box.shieldHealth.Value;
        }

        return(total);
    }
Пример #5
0
 void OnTriggerStay(Collider other)
 {
     if (!gameController.won)
     {
         PlayerController playerController = other.GetComponent <PlayerController>();
         ShieldHealth     shieldHealth     = other.GetComponent <ShieldHealth>();
         if (other.CompareTag("Player") && playerController)
         {
             if (!playerController.invulnerable)
             {
                 playerController.onHit(damage, false);
                 if (explosion)
                 {
                     GameObject newExplosion = Instantiate(explosion, transform.position, transform.rotation);
                     if (newExplosion.GetComponent <AudioSource>())
                     {
                         newExplosion.GetComponent <AudioSource>().volume = PlayerPrefs.GetFloat("SoundVolume");
                     }
                 }
                 Destroy(gameObject);
             }
         }
         else if (other.CompareTag("Shield") && shieldHealth)
         {
             if (explosion)
             {
                 GameObject newExplosion = Instantiate(explosion, transform.position, transform.rotation);
                 if (newExplosion.GetComponent <AudioSource>())
                 {
                     newExplosion.GetComponent <AudioSource>().volume = PlayerPrefs.GetFloat("SoundVolume");
                 }
             }
             shieldHealth.takeDamage(damage);
             Destroy(gameObject);
         }
     }
 }
Пример #6
0
 void OnTriggerStay(Collider other)
 {
     if (other.CompareTag("Enemy"))
     {
         EnemyHealth enemyHealth = other.GetComponent <EnemyHealth>();
         if (enemyHealth)
         {
             enemyHealth.takeDamage(damage);
             if (explosion)
             {
                 GameObject newExplosion = Instantiate(explosion, transform.position, transform.rotation);
                 if (newExplosion.GetComponent <AudioSource>())
                 {
                     newExplosion.GetComponent <AudioSource>().volume = PlayerPrefs.GetFloat("SoundVolume");
                 }
             }
             Destroy(gameObject);
         }
     }
     else if (other.CompareTag("Shield"))
     {
         ShieldHealth shieldHealth = other.GetComponent <ShieldHealth>();
         if (shieldHealth)
         {
             shieldHealth.takeDamage(damage);
             if (explosion)
             {
                 GameObject newExplosion = Instantiate(explosion, transform.position, transform.rotation);
                 if (newExplosion.GetComponent <AudioSource>())
                 {
                     newExplosion.GetComponent <AudioSource>().volume = PlayerPrefs.GetFloat("SoundVolume");
                 }
             }
             Destroy(gameObject);
         }
     }
 }