void OnTriggerStay2D(Collider2D other)
    {
        MoveableGridObject otherGridObject = other.GetComponent <MoveableGridObject>();
        BombObject         bombObject      = other.GetComponent <BombObject>();

        if (bombObject)
        {
            bombObject.Roll(direction);
        }
        if (other.gameObject.CompareTag("Player"))
        {
            PlayerGridObject player = other.GetComponent <PlayerGridObject>();
            if (player.platforms == 0)
            {
                player.Move(direction);
            }
        }
        else if (otherGridObject && !other.gameObject.CompareTag("WindSlime"))
        {
            otherGridObject.Move(direction);
            EnemyGridObject enemyGridObject = other.gameObject.GetComponent <EnemyGridObject>();
            if (enemyGridObject)
            {
                enemyGridObject.TakeDamage(damage);
            }
        }
    }
Esempio n. 2
0
    void OnTriggerEnter2D(Collider2D other)
    {
        //doesn't damage the player
        /*tentacle attack player*/

        /*if (other.gameObject.GetComponent<PlayerGridObject>())
         * {
         *  other.gameObject.GetComponent<PlayerGridObject>().TakeDamage(1);
         *  boss.touchedPlayer = true;
         * }*/

        /*player plants attack tentacle*/


        if (other.gameObject.GetComponent <PlantGridObject>() && boss.hp != 0)
        {
            if (((other.gameObject.GetComponent <WatermelonPlantObject>() || other.gameObject.GetComponent <PlantProjectileObject>()) && tentacleNum == 0) || //watermelon
                (other.gameObject.GetComponent <TurbinePlantObject>() && tentacleNum == 1) ||                                                                 //turbine
                (other.gameObject.GetComponent <CactusPlantObject>() && tentacleNum == 2) ||                                                                  //cactus
                ((other.gameObject.GetComponent <BombPlantObject>() || other.gameObject.GetComponent <BombObject>()) && tentacleNum == 3) ||                  //bomb
                (other.gameObject.GetComponent <LightPlantObject>() && tentacleNum == 4) ||                                                                   //mushroom
                ((other.gameObject.GetComponent <BoomerangPlantObject>() || other.gameObject.GetComponent <Boomerang>()) && tentacleNum == 5) ||              //boomerang
                (other.gameObject.GetComponent <SpinningPlant>() && tentacleNum == 6))                                                                        //spinning
            {
                if (anim)
                {
                    anim.Play("Damaged");
                }

                //play damaged animation for tentacle?
                boss.touchedPlayer = true; //makes tentacles retract
                if (!boss.spawnedMe)
                {
                    Instantiate(weedBoss, new Vector3(Random.Range(-4.5f, 4.5f), Random.Range(-3.5f, 3.5f), 0), spawnRotation);
                }
            }
            else
            {
                spawnPosition = new Vector3(other.gameObject.transform.position.x, other.gameObject.transform.position.y, 0f);
                if (other.gameObject.GetComponent <WatermelonPlantObject>())
                {
                    if (!other.gameObject.GetComponent <WatermelonPlantObject>().evil)
                    {
                        Destroy(other.gameObject);
                        Instantiate(evilWatermelonPlant, spawnPosition, spawnRotation);
                    }
                }
                if (other.gameObject.GetComponent <TurbinePlantObject>())
                {
                    if (!other.gameObject.GetComponent <TurbinePlantObject>().evil)
                    {
                        Destroy(other.gameObject);
                        Instantiate(evilTurbinePlant, spawnPosition, spawnRotation);
                    }
                }
                if (other.gameObject.GetComponent <CactusPlantObject>())
                {
                    if (!other.gameObject.GetComponent <CactusPlantObject>().evil)
                    {
                        Destroy(other.gameObject);
                        Instantiate(evilCactusPlant, spawnPosition, spawnRotation);
                    }
                }
                if (other.gameObject.GetComponent <BoomerangPlantObject>())
                {
                    if (!other.gameObject.GetComponent <BoomerangPlantObject>().evil)
                    {
                        Destroy(other.gameObject);
                        Instantiate(evilBoomerangPlant, spawnPosition, spawnRotation);
                    }
                }
                if (other.gameObject.GetComponent <BombPlantObject>())
                {
                    if (!other.gameObject.GetComponent <BombPlantObject>().evil)
                    {
                        if (other.gameObject.GetComponent <BombPlantObject>().bomb)
                        {
                            Destroy(other.gameObject.GetComponent <BombPlantObject>().bomb.gameObject);
                        }
                        Destroy(other.gameObject);
                        Instantiate(evilBombPlant, spawnPosition, spawnRotation);
                    }
                    else
                    {
                        BombObject temp = other.gameObject.GetComponent <BombPlantObject>().bomb;
                        if (temp)
                        {
                            temp.Roll(realDir);
                        }
                    }
                }
                if (other.gameObject.GetComponent <LightPlantObject>())
                {
                    if (!other.gameObject.GetComponent <LightPlantObject>().evil)
                    {
                        Destroy(other.gameObject);
                        Instantiate(evilLightPlant, spawnPosition, spawnRotation);
                    }
                    else
                    {
                        CircuitSystem cs = FindObjectOfType <CircuitSystem>();
                        cs.isLit = true;
                        cs.ConnectJunction();
                    }
                }
                if (other.gameObject.GetComponent <SpinningPlant>())
                {
                    if (!other.gameObject.GetComponent <SpinningPlant>().evil)
                    {
                        Destroy(other.gameObject);
                        Instantiate(evilSpinningPlant, spawnPosition, spawnRotation);
                    }
                }
            }
        }
    }
    public virtual void Attack()
    {
        if (!Globals.canvas.dialogue)
        {
            hitSomething = false;

            if (audioSource != null)
            {
                audioSource.clip = attackSound;
                audioSource.Play();
            }
            switch (direction)
            {
            case Globals.Direction.South:
                killList = southHitCollider.GetKillList();
                break;

            case Globals.Direction.East:
                killList = eastHitCollider.GetKillList();
                break;

            case Globals.Direction.North:
                killList = northHitCollider.GetKillList();
                break;

            case Globals.Direction.West:
                killList = westHitCollider.GetKillList();
                break;
            }

            /*
             * Clear all dead targets in killList.
             * This uses lambda syntax: if a KillableGridObject in
             * the list is null, then remove it.
             */
            killList.RemoveAll((KillableGridObject target) => target == null);

            // Deal damage to all targets of the enemy faction
            foreach (KillableGridObject target in killList)
            {
                if (target.faction != this.faction)
                {
                    hitSomething = true;
                    target.TakeDamage(damage);
                }
                if (this.GetComponent <PlayerGridObject>())
                {
                    BombObject bomb = target.GetComponent <BombObject>();

                    if (bomb && !bomb.evil)
                    {
                        bomb.Roll(direction);
                    }
                    //deplant code MOVED so deplanting is a different button

                    /*PlantGridObject plant = target.GetComponent<PlantGridObject>();
                     * if (plant) {
                     *  plant.TakeDamage(100);
                     * }*/
                }
            }
        }
    }