Exemplo n.º 1
0
        //▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
        protected IEnumerator DeathAnimCoroutine()
        {
            alive = false;
            Game.instance.PlayerDeath(this);

            animator.Start("death");
            int duration = animator.GetDuration();

            for (int c = 0; c < duration; c++)
            {
                animator.Play();
                yield return(new WaitForEndOfFrame());
            }

            yield return(new WaitForSeconds(0.7f));

            GetComponent <SpriteRenderer>().sprite = null;

            // TODO spawn collected items in stage
            for (int i = 0; i < collectedPowerups.Count; i++)
            {
                Powerup powerup  = (Powerup)collectedPowerups[i];
                Tile    position = stage.GetTile(powerup.i, powerup.j);
                // TODO check that there is no entities
                if (position.isEmpty)
                {
                    stage.AddTile(powerup.i, powerup.j, powerup.prefab);
                }
                else
                {
                    // find a random valid position
                    Vector2 newPosition = stage.GetEmptyPosition();
                    stage.AddTile((int)newPosition.x, (int)newPosition.y, powerup.prefab);
                }
                yield return(new WaitForEndOfFrame());
            }
        }