Ejemplo n.º 1
0
    /// <summary>
    /// Occurs when there is a collision between a projectile shot by
    /// the shooter and a interactive game object.
    /// It destroys the <param name="other"/> collider if it's an
    /// ennemy spaceship.
    /// </summary>
    /// <param name="other">A game object with a 2D collider which got hit by a projectile.</param>
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Boundary")
        {
            return;
        }
        if (other.tag == "Bonus")
        {
            return;
        }
        if (other.tag == "Planet")
        {
            return;
        }
        if (other.tag == "Player")
        {
            Spaceship_solo spaceship = other.GetComponent <Spaceship_solo>();
            if (spaceship == shooter)
            {
                return;
            }

            Destroy(other.gameObject);
        }
    }
Ejemplo n.º 2
0
 /// <summary>
 /// Occurs when <param name="other"/> is inside the bonus's detection radius.
 /// The spaceship gets the bonus effect.
 /// </summary>
 /// <param name="other">A game object with a 2d collider.</param>
 /// <seealso cref="Coroutine"/>
 void OnTriggerStay2D(Collider2D other)
 {
     if (other.tag == "Player")
     {
         Spaceship_solo spaceship = other.GetComponent <Spaceship_solo>();
         if (!spaceship.hasShotBonus)
         {
             StartCoroutine(Pickup(spaceship));
         }
     }
 }
Ejemplo n.º 3
0
    /// <summary>
    /// Apply bonus effect on <param name="spaceship"/>.
    /// </summary>
    /// <param name="spaceship">The lucky owner of the bonus.</param>
    /// <returns>
    /// A temporary suspension of the StartCoroutine method
    /// implying the duration of the bonus.
    /// </returns>
    /// <seealso cref="YieldInstruction"/>
    /// <seealso cref="Coroutine"/>
    IEnumerator Pickup(Spaceship_solo spaceship)
    {
        // START EFFECT //
        spaceship.hasSpeedBonus = true;
        spaceship.speed        *= multiplier;

        // DISABLE BONUS ENTITY //
        GetComponent <SpriteRenderer>().enabled   = false;
        GetComponent <CircleCollider2D>().enabled = false;

        // WAIT DURATION //
        yield return(new WaitForSeconds(duration));

        // END EFFECT //
        spaceship.hasSpeedBonus = false;
        spaceship.speed        /= multiplier;

        Destroy(gameObject);
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Occurs when there is a collision between the bonus and a spaceship.
    /// The spaceship gets the bonus effect.
    /// </summary>
    /// <remarks>
    /// Contrary to other bonuses based on duration,
    /// that one has an instant effect. Thus there's no need for a coroutine call
    /// in order to handle bonus activation and entity cleaning.
    /// </remarks>
    /// <param name="other">A game object with a 2d collider.</param>
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Player")
        {
            Spaceship_solo spaceship = other.GetComponent <Spaceship_solo>();

            // START EFFECT //
            spaceship.fuel += quantity;
            if (spaceship.fuel > 100)
            {
                spaceship.fuel = 100;
            }
            spaceship.fuelBar.UpdateBar(spaceship.fuel, 100);
            // END EFFECT //

            // DISABLE BONUS ENTITY //
            Destroy(gameObject);
        }
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Apply bonus effect on <param name="spaceship"/>.
    /// </summary>
    /// <param name="spaceship">The lucky owner of the bonus.</param>
    /// <returns>
    /// A temporary suspension of the StartCoroutine method
    /// implying the duration of the bonus.
    /// </returns>
    /// <seealso cref="YieldInstruction"/>
    /// <seealso cref="Coroutine"/>
    IEnumerator Pickup(Spaceship_solo spaceship)
    {
        // START EFFECT //
        spaceship.hasShotBonus = true;
        spaceship.shot         = spaceship.shotsDico["Triple"];
        spaceship.firemode     = FireMode_Solo.Triple;

        // DISABLE BONUS ENTITY //
        GetComponent <SpriteRenderer>().enabled   = false;
        GetComponent <CircleCollider2D>().enabled = false;

        // WAIT DURATION //
        yield return(new WaitForSeconds(duration));

        // END EFFECT //
        spaceship.hasShotBonus = false;
        spaceship.shot         = spaceship.shotsDico["Default"];
        spaceship.firemode     = FireMode_Solo.Default;

        Destroy(gameObject);
    }