Exemplo n.º 1
0
    protected override void Activate()
    {
        GameObject ExplosionSprite = new GameObject("bombsuit explosion");

        ExplosionSprite.AddComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("PowerUps/Powers/BombSuit/Explosion");
        ExplosionSprite.transform.position = owner.transform.position;
        Collider2D[] colliders = Physics2D.OverlapCircleAll(owner.transform.position, explosionRadius);
        for (int i = 0; i < colliders.GetLength(0); i++)
        {
            PlayerHit hit = colliders[i].gameObject.GetComponent <PlayerHit>();
            if (hit == null)
            {
                continue;
            }
            if (hit.gameObject == owner)
            {
                continue;
            }
            if (colliders[i] is BoxCollider2D == false)
            {
                continue;
            }
            hit.OnDeath(owner);
        }
        ExplosionSprite.transform.parent   = null;
        ExplosionSprite.transform.rotation = Quaternion.identity;
        DestroyAfterSeconds DAS = ExplosionSprite.AddComponent <DestroyAfterSeconds>();

        DAS.Seconds = 0.5f;
        ScoreManager.gameData.BombSuitUsed++;

        PowerupUser PU = owner.GetComponent <PowerupUser>();

        PU.EndPowerup();
        PU.SetPowerup(new EmptyPowerup(owner));
    }
 public override void OnPickup(PowerupUser player)
 {
     base.OnPickup(player);
     Debug.Log("Player picked up debug powerup item.");
 }
 public override void Activate(PowerupUser player)
 {
     Debug.Log("Player activated debug powerup item.");
     player.ClearPowerup();
 }
 public abstract void Activate(PowerupUser player);
 public virtual void OnPickup(PowerupUser player)
 {
     //if we need the default callback
 }
 public override void OnPickup(PowerupUser player)
 {
     base.OnPickup(player);
 }
Exemplo n.º 7
0
    public void OnDeath(GameObject other)
    {
        FindObjectOfType <Splat>().DoSplat(transform.position, 0, (int)color);

        /*
         * //splat
         * GameObject splatObject = new GameObject("splatInstance");
         * splatObject.transform.position = this.gameObject.transform.position;
         * SpriteRenderer SR = splatObject.AddComponent<SpriteRenderer>();
         * SR.flipX = UnityEngine.Random.Range(0, 2) == 0? false : true;
         * SR.flipY = UnityEngine.Random.Range(0, 2) == 0 ? false : true;
         *
         * SR.sortingOrder = -14;  //before background but behind the rest
         * SheetAnimation ani = splatObject.AddComponent<SheetAnimation>();
         * LevelBounds.instance.RegisterObject(splatObject, true);
         * ani.PlayAnimation("Splat", color, false, 1);
         */
        /*
         * //shield powerup / spawn immunity
         * if(Immunity)
         * {
         *  if (!StayImmune) Immunity = false;
         *  IC();
         *  return;
         * }*/
        //score
        //Debug.Log(other.name + gameObject.name);
        int playerID     = other.name.Contains("1") ? 0 : (other.name.Contains("2") ? 1 : (other.name.Contains("3") ? 2 : 3));
        int thisplayerID = gameObject.name.Contains("1") ? 0 : (gameObject.name.Contains("2") ? 1 : (gameObject.name.Contains("3") ? 2 : 3));

        if (playerID == thisplayerID)
        {
            return;
        }
        //if (playerID > ScoreManager.instance.score.Length) playerID = 1;
        int useingID = ScoreManager.instance.scoreMode == ScoreManager.ScoreMode.Health ? thisplayerID : playerID;

        ScoreManager.instance.ChangeScore(useingID, ScorePerKill);
        if (ScoreManager.instance.scoreMode == ScoreManager.ScoreMode.Health && ScoreManager.instance.score[useingID] <= 0)
        {
            Respawn = false;
        }



        //Tag mode
        if (ScoreManager.instance.gameMode is TagMode)
        {
            TagMode Tagmode = (TagMode)ScoreManager.instance.gameMode;
            if (Tagmode.currentTag == other)
            {
                Tagmode.RemoveTag(other);
                //if (other.GetComponentInChildren<PlayerHit>())
                Tagmode.SetTag(gameObject);
            }

            /*
             * else if (Tagmode.currentTag == other)
             * {
             *  ScoreManager.instance.ChangeScore(playerID, 5);//bonus points if you are the Tag
             * }*/
        }
        else

        if (ScoreManager.instance.gameMode is OwnedMode)
        {
            OwnedMode ownedMode = (OwnedMode)ScoreManager.instance.gameMode;
            ownedMode.SetOwned(gameObject, other);
        }
        else

        //chicken mode
        if (ScoreManager.instance.gameMode is ChickenMode)
        {
            ChickenMode chickenmode = (ChickenMode)ScoreManager.instance.gameMode;
            if (chickenmode.currentChicken == gameObject || chickenmode.currentChicken == null)
            {
                chickenmode.RemoveChicken(gameObject);
                if (other.GetComponentInChildren <PlayerHit>())
                {
                    chickenmode.SetChicken(other);
                }
            }
            else if (chickenmode.currentChicken == other)
            {
                ScoreManager.instance.ChangeScore(playerID, 5);//bonus points if you are the chicken
            }
        }


        float          deathTime = 0.5f;
        PlayerMovement pm        = isClone ? gameObject.transform.parent.gameObject.GetComponent <PlayerMovement>() : GetComponent <PlayerMovement>();

        pm.StunnedTimer = deathTime;
        Rigidbody2D rig = isClone ? gameObject.transform.parent.gameObject.GetComponent <Rigidbody2D>() : GetComponent <Rigidbody2D>();

        rig.gravityScale = 0;
        rig.velocity     = Vector2.zero;
        rig.isKinematic  = true;
        PowerupUser pu = isClone? gameObject.transform.parent.gameObject.GetComponent <PowerupUser>() : GetComponent <PowerupUser>();

        pu.EndAllPowerups();
        Array.ForEach(GetComponentsInChildren <Collider2D>(), x => x.isTrigger = true);
        SheetAnimation sa = isClone ? gameObject.transform.parent.gameObject.GetComponent <SheetAnimation>() : GetComponent <SheetAnimation>();

        sa.PlayAnimation("Death", color, false, 5.0f / deathTime);
        StartCoroutine(DelayedRespawn(deathTime));

        /*
         * if (Respawn)
         * {
         *  PlayerMovement pm = gameObject.GetComponent<PlayerMovement>();
         *  if (pm == null) pm = gameObject.transform.parent.GetComponent<PlayerMovement>();
         *  PlayerMovement.Controls controls = pm.controls;
         *  pm.gameObject.transform.position = SpawnManager.instance.GetRandomSpawnPoint();
         * }
         * else
         * {
         *  GameObject.Destroy(this.gameObject);
         * }*/
    }