/// <summary>
    /// Method to substract 1 life point from the player
    /// </summary>
    public void dmgTaken()
    {
        textObjLifeDown      = textObj.GetComponent <Text>();
        textObjLifeDown.text = "<color=red>-1</color>";
        textObjLifeDown      = Instantiate(textObj, lifeText.transform.position, Quaternion.identity);
        textObjLifeDown.transform.SetParent(ui);
        textObjLifeDown = null;

        life--;
        OnLifeChange?.Invoke(life);
    }
示例#2
0
 public bool this[int x, int y]
 {
     get { return(world[x, y]); }
     set
     {
         if (world[x, y] != value)
         {
             world[x, y] = value;
             OnLifeChange?.Invoke(x, y, value);
         }
     }
 }
    /// <summary>
    /// Method to add one life point to the player
    /// </summary>
    public void AddLife()
    {
        Instantiate(uiParticle, lifeBubble.transform.position, Quaternion.identity);

        textObjLifeUp      = textObj.GetComponent <Text>();
        textObjLifeUp.text = "<color=green>+1</color>";
        textObjLifeUp      = Instantiate(textObj, lifeText.transform.position, Quaternion.identity);
        textObjLifeUp.transform.SetParent(ui);
        textObjLifeUp = null;

        life++;
        OnLifeChange?.Invoke(life);
    }
示例#4
0
    // Damage the ship
    public void TakeDamage(float kineticDamage, float energyDamage)
    {
        if (!Invincible)
        {
            shieldRegenDelay = Time.realtimeSinceStartup + shipStats.shieldRegenInterval;

            // Damage the shield
            currentShield = Mathf.Clamp(currentShield - energyDamage, 0, MaxShield);

            // If we have negative shields we can take it away from your life pool
            if (currentShield == 0)
            {
                currentLife -= kineticDamage;
            }

            // If we are dead cann OnDeath()
            if (currentLife <= 0 && !killed)
            {
                currentLife = 0;
                killed      = true;
                HandleDeath();
            }
        }

        // Invoke the On Life Change Event
        if (onLifeChange != null)
        {
            onLifeChange.Invoke(currentLife, MaxLife);
        }

        // Invoke the On Shield Change Event
        if (onShieldChange != null)
        {
            onShieldChange.Invoke(currentShield, MaxShield);
        }
    }
 private void OnCollisionEnter2D(Collision2D collision)
 {
     life--;
     OnLifeChange?.Invoke(life);
     if (collision.gameObject.tag == "Ball")
     {
         Ball.isMoving = false;
     }
     if (life == 0)
     {
         GameObject[] block = GameObject.FindGameObjectsWithTag("Block");
         foreach (GameObject obj in block)
         {
             GameObject.Destroy(obj);
         }
     }
 }
示例#6
0
    /// <summary>
    /// Reinitializes this scripts values
    /// </summary>
    /// <param name="invokeEvents"> Do you want to call the OnLifeChange events </param>
    public void ResetValues(bool invokeEvents = false)
    {
        currentLife   = MaxLife;
        currentShield = MaxShield;
        killed        = false;

        gameObject.SetActive(true);

        if (invokeEvents == true)
        {
            // Invoke the On Life Change Event
            onLifeChange?.Invoke(currentLife, MaxLife);

            // Invoke the On Shield Change Event
            onShieldChange?.Invoke(currentShield, MaxShield);
        }
    }
 public void InvokeLife()
 {
     OnLifeChange?.Invoke(life);
 }