Beispiel #1
0
    void OnCollisionEnter2D(Collision2D col)
    {
        if (col.rigidbody || col.gameObject.CompareTag("DPlatform"))
        {
            if (first)
            {
                first  = false;
                second = true;
            }
            else if (second)
            {
                second = false;
                StartCoroutine(SelfDestruct());
            }

            if (!hit)
            {
                force = Mathf.Abs(Vector2.Dot(col.contacts[0].normal, col.relativeVelocity) * rigidbody2D.mass);

                if (force > forceThresh)
                {
                    if (col.gameObject.GetComponent <GetDamage>() && !hit)
                    {
                        getDamage = col.gameObject.GetComponent <GetDamage>();
                        hit       = true;
                    }

                    if (hit)
                    {
                        StartCoroutine(getDamage.SendDamage(smallBulletDamage, blockType));
                    }
                }
            }
        }
    }
Beispiel #2
0
    void OnCollisionEnter2D(Collision2D col)
    {
        if (rigidbody2D)
        {
            i        = 0;
            force    = Mathf.Abs(Vector2.Dot(col.contacts[0].normal, col.relativeVelocity) * rigidbody2D.mass);
            doDamage = false;
            if (force > 5f && Vector2.Distance(Vector2.zero, rigidbody2D.velocity) > 2f)
            {
                if (nowProjectile && col.gameObject.GetComponent <GetDamage>())
                {
                    doDamage = true;
                    if (blockType == 7 || blockType == 8)                  //telekinetic blocks
                    {
                        if (col.gameObject.GetComponent <Player>())
                        {
                            //only hurt on mismatch (so the owner of the block doesn't hurt himself or his other Telekineticblocks)
                            if ((col.gameObject.GetComponent <Player>().char1&& wepDSID == 1) || (col.gameObject.GetComponent <Player>().char2&& wepDSID == 2))
                            {
                                doDamage = false;
                            }
                        }
                        else if (col.gameObject.GetComponent <TelekineticBlock>())
                        {
                            if ((col.gameObject.GetComponent <TelekineticBlock>().wepDSID == wepDSID))
                            {
                                doDamage = false;
                            }
                        }
                        else if (col.gameObject.GetComponent <SuperTelekineticBlock>())
                        {
                            if ((col.gameObject.GetComponent <SuperTelekineticBlock>().wepDSID == wepDSID))
                            {
                                doDamage = false;
                            }
                        }
                    }
                }
            }
            if (doDamage)
            {
                GetDamage getDamage = col.gameObject.GetComponent <GetDamage>();
                damageFactor = force / maxForce;

                if (damageFactor > 1)
                {
                    damageFactor = 1;
                }
                hurtNoise.volume = damageFactor;
                hurtNoise.Play();

                damage2Deal = Mathf.RoundToInt(damageFactor * blockDamage);
                StartCoroutine(getDamage.SendDamage(damage2Deal, 1));
            }
        }
    }
Beispiel #3
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        hitObject = collision.collider.gameObject;

        if (hitObject.GetComponent<GetDamage>()){
            getDamage = hitObject.GetComponent<GetDamage>();
            getDamage.StartCoroutine(getDamage.SendDamage(missleDamage,blockType));
            Destroy (this.gameObject);
        }
    }
Beispiel #4
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        hitObject = collision.collider.gameObject;

        if (hitObject.GetComponent <GetDamage>())
        {
            getDamage = hitObject.GetComponent <GetDamage>();
            getDamage.StartCoroutine(getDamage.SendDamage(missleDamage, blockType));
            Destroy(this.gameObject);
        }
    }
Beispiel #5
0
 void OnCollisionEnter2D(Collision2D col)
 {
     damageable = false;
     if (col.rigidbody)
     {
         if (col.gameObject.GetComponent <GetDamage>())
         {
             getDamage  = col.gameObject.GetComponent <GetDamage>();
             damageable = true;
         }
         colliderSpeed = col.rigidbody.velocity.magnitude;
     }
     else if (col.transform.parent)          //so if this is a child gameobject with a collider, its rigidbody is on the parent, so find it there
     {
         if (col.transform.parent.rigidbody2D)
         {
             if (col.transform.parent.GetComponent <GetDamage>())
             {
                 getDamage  = col.transform.parent.GetComponent <GetDamage>();
                 damageable = true;
             }
             colliderSpeed = col.transform.parent.rigidbody2D.velocity.magnitude;
         }
     }
     if (damageable && !delaying)
     {
         if (attacking && attackTimer > 0 && (rigidbody2D.velocity.magnitude - colliderSpeed) > damageVelocity) //if launching
         {
             if (!col.collider.GetComponent <MiniCopterBlock>())                                                //don't hurt other copters
             {
                 StartCoroutine(Delaying());
                 StartCoroutine(getDamage.SendDamage(baselineDamage, blockType));
             }
         }
         else if (transform.localScale.x == 3 && (rigidbody2D.velocity.magnitude - colliderSpeed) > damageVelocity)            //if being shot
         {
             StartCoroutine(Delaying());
             StartCoroutine(getDamage.SendDamage(baselineDamage, blockType));
         }
     }
 }
Beispiel #6
0
    void OnTriggerEnter2D(Collider2D col)
    {
        if (smacking || smashing)
        {
            if (col.gameObject.GetComponent <GetDamage>() && !col.gameObject.CompareTag("Player"))
            {
                getDamageScript = col.gameObject.GetComponent <GetDamage>();
                if (smacking)
                {
                    damage = smackDamage;
                }
                else
                {
                    damage = smackDamage;
                }

                StartCoroutine(getDamageScript.SendDamage(damage, weaponType));
            }
        }
    }
Beispiel #7
0
    public IEnumerator DangerHighVoltage()
    {
        cols     = Physics2D.OverlapCircleAll(transform.position, shockRadius);
        doDamage = new bool[cols.Length];
        j        = 0;
        while (j < cols.Length)
        {
            if (cols[j].GetComponent <GetDamage>())
            {
                doDamage[j] = true;
                distFactor  = 1 - Vector2.Distance(transform.position, cols[j].transform.position) / shockRadius;
                reducedRate = Mathf.RoundToInt(distFactor * stickerShock);
                GetDamage damageScript = cols[j].GetComponent <GetDamage>();
                StartCoroutine(damageScript.SendDamage(reducedRate, weaponBlockScript.blockType));
            }
            j++;
        }

        yield return(new WaitForSeconds(.2f));

        StartCoroutine(DangerHighVoltage());
    }
Beispiel #8
0
    public IEnumerator BlowYourLoad()
    {
        yield return(new WaitForEndOfFrame());

        allObjects     = Physics2D.OverlapCircleAll(transform.position, exRadius);
        allGameObjects = new GameObject[allObjects.Length];

        i = 0;
        foreach (Collider2D coller in allObjects)
        {
            allGameObjects[i] = coller.gameObject;
            i++;
        }

        i = 0;
        foreach (Collider2D thing in allObjects)
        {
            if (!dontBlowStrings.Contains(thing.name) && thing.gameObject != gameObject)
            {
                Vector3 bPos     = transform.position;
                Vector3 thingPos = thing.transform.position;
                Vector3 exDir    = Vector3.Normalize(thingPos - bPos);

                float dist2exploder = Vector3.Distance(bPos, thingPos);

                /*RaycastHit2D[] rayThings = Physics2D.RaycastAll (bPos,exDir,dist2exploder);
                 * foreach (RaycastHit2D rayThing in rayThings){
                 *      if (rayThing.collider.gameObject == thing.gameObject){
                 *              hitPointThing = rayThing.point;
                 *              break;
                 *      }
                 * }
                 * RaycastHit2D[] rayExps = Physics2D.RaycastAll (thingPos,-exDir,dist2exploder);
                 * foreach (RaycastHit2D rayExp in rayExps){
                 *      if (rayExp.collider.gameObject == this.gameObject){
                 *              hitPointExp = rayExp.point;
                 *              break;
                 *      }
                 * }
                 *
                 * dist2exploder = Vector3.Distance(hitPointExp,hitPointThing);
                 */


                if (dist2exploder < 0)
                {
                    dist2exploder = 0;
                }

                exMultiplier = Mathf.Exp(-.6f * dist2exploder);

                exForce = exForceBaseline * exMultiplier;
                damage  = Mathf.RoundToInt(damageBaseline * exMultiplier);

                if (thing.GetComponent <GetDamage>())
                {
                    j          = 0;
                    makeItHurt = true;
                    while (j < i)
                    {
                        if (allGameObjects[i] == allGameObjects[j])
                        {
                            makeItHurt = false;
                        }
                        j++;
                    }

                    if (makeItHurt)
                    {
                        getDamage = thing.GetComponent <GetDamage>();
                        StartCoroutine(getDamage.SendDamage(damage, weaponBlockScript.blockType));
                        if (thing.rigidbody2D)
                        {
                            thing.rigidbody2D.AddForce(exDir * exForce);
                        }
                    }
                }
                //only addforce to things that are not locked in blocks/copters

                else
                {
                    if (thing.rigidbody2D)
                    {
                        thing.rigidbody2D.AddForce(exDir * exForce);
                    }
                }
            }
            i++;
        }
        GameObject expo = Instantiate(Resources.Load("Prefabs/Effects/Explosion"), this.transform.position, this.transform.rotation) as GameObject;

        expo.transform.localScale = Vector3.one * 25;
        Destroy(this.gameObject);
    }
Beispiel #9
0
    public IEnumerator FreezeIt()
    {
        Instantiate(Resources.Load("Prefabs/Effects/Frozesplosion"), transform.position, Quaternion.identity);
        freezeTimer    = timeFrozen;
        allFrozen      = Physics2D.OverlapCircleAll(transform.position, exRadius);
        allGameObjects = new GameObject[allFrozen.Length];

        i = 0;
        foreach (Collider2D coller in allFrozen)
        {
            allGameObjects[i] = coller.gameObject;
            i++;
        }

        i = 0;
        foreach (Collider2D fro in allFrozen)
        {
            itsAPlayer = false;
            bPos       = transform.position;
            thingPos   = fro.transform.position;
            freDir     = Vector3.Normalize(thingPos - bPos);

            dist2frozeSploder = Vector3.Distance(bPos, thingPos);            //center to center distance

            RaycastHit2D[] rayThings = Physics2D.RaycastAll(bPos, freDir, dist2frozeSploder);
            foreach (RaycastHit2D rayThing in rayThings)
            {
                if (rayThing.collider.gameObject == fro.gameObject)
                {
                    hitPointThing = rayThing.point;                     //world space point
                    break;
                }
            }
            RaycastHit2D[] rayExps = Physics2D.RaycastAll(thingPos, -freDir, dist2frozeSploder);
            foreach (RaycastHit2D rayExp in rayExps)
            {
                if (rayExp.collider.gameObject == this.gameObject)
                {
                    hitPointFro = rayExp.point;                     //world space point
                    break;
                }
            }

            dist2frozeSploder = Vector3.Distance(hitPointFro, hitPointThing);            //edge to edge distance

            if (icecle)
            {
                froMultiplier = 1f - Mathf.Exp(-1.25f * dist2frozeSploder);
            }
            else
            {
                froMultiplier = 1f - Mathf.Exp(-.6f * dist2frozeSploder);
            }
            damage = Mathf.RoundToInt(damageBaseline * (1f - froMultiplier));

            if (fro.GetComponent <GetDamage>())             //this protects against double damage to gameobjects with a circle and a box collider (and triple to those also with a polygon collider!)
            {
                j          = 0;
                makeItHurt = true;
                while (j < i)
                {
                    if (allGameObjects[i] == allGameObjects[j])
                    {
                        makeItHurt = false;
                        break;
                    }
                    j++;
                }

                if (makeItHurt)
                {
                    getDamage = fro.GetComponent <GetDamage>();
                    StartCoroutine(getDamage.SendDamage(damage, weaponBlockScript.blockType));
                }
            }

            if (fro.sharedMaterial)              //store its starting name, bounciness and friction for later use
            {
                GatherAllKnowledge know = GameObject.Find("theOmniscient").GetComponent <GatherAllKnowledge> ();
                k = 0;

                while (k < know.numMats)
                {
                    if (fro.sharedMaterial.name.Contains(know.allNames[k]))
                    {
                        startingName     = know.allNames[k];
                        startingBounce   = know.allBounciness[k];
                        startingFriction = know.allFriction[k];
                        break;
                    }
                    k++;
                }

                froFriction = froMultiplier * startingFriction;
                froBounce   = froMultiplier * startingBounce;

                if (fro.transform.parent)
                {
                    if (fro.transform.parent.parent)
                    {
                        if (fro.transform.parent.parent.CompareTag("Player"))
                        {
                            player     = fro.transform.parent.parent.GetComponent <Player>();
                            itsAPlayer = true;
                        }
                    }
                    else
                    {
                        if (fro.transform.parent.CompareTag("Player"))
                        {
                            player     = fro.transform.parent.GetComponent <Player>();
                            itsAPlayer = true;
                        }
                        else
                        {
                            if (fro.CompareTag("Player"))
                            {
                                player     = fro.GetComponent <Player>();
                                itsAPlayer = true;
                            }
                        }
                    }
                }
                else
                {
                    if (fro.CompareTag("Player"))
                    {
                        player     = fro.GetComponent <Player>();
                        itsAPlayer = true;
                    }
                }

                if (itsAPlayer)
                {
                    if (!player.onMyKnees)
                    {
                        startingJumpSpeed    = player.startingJumpSpeed;
                        startingRunningSpeed = player.startingRunningSpeed;
                        startingMaxVelocity  = player.startingMaxVelocity;
                    }
                    else
                    {
                        startingJumpSpeed    = player.startingJumpSpeed * .5f;
                        startingRunningSpeed = player.startingRunningSpeed * .5f;
                        startingMaxVelocity  = player.startingMaxVelocity * .5f;
                    }

                    froJumpSpeed    = froMultiplier * startingJumpSpeed;
                    froRunningSpeed = froMultiplier * startingRunningSpeed;
                    froMaxVelocity  = froMultiplier * startingMaxVelocity;

                    player.jumpSpeed     = froJumpSpeed;
                    player.runningSpeed  = froRunningSpeed;
                    player.maxVelocity.x = froMaxVelocity;
                }

                if (!fro.GetComponent <Unfreeze>())                 // if it doesn't already have the unfreeze, check to add

                {
                    if (fro.transform.parent)                      //if there is a parent

                    {
                        if (fro.transform.parent.parent)                          //if there is a grandparent!

                        {
                            fro.transform.parent.parent.gameObject.AddComponent <Unfreeze>();
                            unfreeze = fro.transform.parent.parent.GetComponent <Unfreeze>();
                            unfreeze.startingFriction = startingFriction;
                            unfreeze.startingBounce   = startingBounce;
                            unfreeze.mydickiscold     = true;

                            fro.transform.parent.gameObject.AddComponent <Unfreeze>();
                            unfreeze = fro.transform.parent.GetComponent <Unfreeze>();
                            unfreeze.startingFriction = startingFriction;
                            unfreeze.startingBounce   = startingBounce;
                            unfreeze.mydickiscold     = true;

                            fro.transform.gameObject.AddComponent <Unfreeze>();
                            unfreeze = fro.GetComponent <Unfreeze>();
                            unfreeze.startingFriction = startingFriction;
                            unfreeze.startingBounce   = startingBounce;
                            unfreeze.mydickiscold     = true;

                            foreach (Collider2D col in fro.transform.parent.parent.GetComponents <Collider2D>())                             //slip up the grandparentparent colliders
                            {
                                startingEnabled    = col.enabled;
                                col.enabled        = false;
                                col.sharedMaterial = GetMaterial(froFriction, froBounce, startingName);
                                col.enabled        = true;
                                col.enabled        = startingEnabled;
                            }
                            foreach (Collider2D col in fro.transform.parent.GetComponents <Collider2D>())                            //and the parents
                            {
                                startingEnabled    = col.enabled;
                                col.enabled        = false;
                                col.sharedMaterial = GetMaterial(froFriction, froBounce, startingName);
                                col.enabled        = true;
                                col.enabled        = startingEnabled;
                            }
                            foreach (Collider2D col in fro.GetComponents <Collider2D>())                             //and the thing
                            {
                                startingEnabled    = col.enabled;
                                col.enabled        = false;
                                col.sharedMaterial = GetMaterial(froFriction, froBounce, startingName);
                                col.enabled        = true;
                                col.enabled        = startingEnabled;
                            }
                        }
                        else                          //ok it's not on the grandparent, so we should add one to the parent
                        {
                            fro.transform.parent.gameObject.AddComponent <Unfreeze>();
                            unfreeze = fro.transform.parent.GetComponent <Unfreeze>();
                            unfreeze.startingFriction = startingFriction;
                            unfreeze.startingBounce   = startingBounce;
                            unfreeze.mydickiscold     = true;

                            fro.transform.gameObject.AddComponent <Unfreeze>();
                            unfreeze = fro.GetComponent <Unfreeze>();
                            unfreeze.startingFriction = startingFriction;
                            unfreeze.startingBounce   = startingBounce;
                            unfreeze.mydickiscold     = true;

                            foreach (Collider2D col in fro.transform.parent.GetComponents <Collider2D>())                            //and the parents
                            {
                                startingEnabled    = col.enabled;
                                col.enabled        = false;
                                col.sharedMaterial = GetMaterial(froFriction, froBounce, startingName);
                                col.enabled        = true;
                                col.enabled        = startingEnabled;
                            }
                            foreach (Collider2D col in fro.GetComponents <Collider2D>())                             //and the thing
                            {
                                startingEnabled    = col.enabled;
                                col.enabled        = false;
                                col.sharedMaterial = GetMaterial(froFriction, froBounce, startingName);
                                col.enabled        = true;
                                col.enabled        = startingEnabled;
                            }
                        }
                    }
                    else                      //so it's not on this gameobject, and it's there's no parent. add it
                    {
                        fro.transform.gameObject.AddComponent <Unfreeze>();
                        unfreeze = fro.GetComponent <Unfreeze>();
                        unfreeze.startingFriction = startingFriction;
                        unfreeze.startingBounce   = startingBounce;
                        unfreeze.mydickiscold     = true;

                        foreach (Collider2D col in fro.GetComponents <Collider2D>())                         //and the thing
                        {
                            startingEnabled    = col.enabled;
                            col.enabled        = false;
                            col.sharedMaterial = GetMaterial(froFriction, froBounce, startingName);
                            col.enabled        = true;
                            col.enabled        = startingEnabled;
                        }
                    }
                }
                else                  //so it was here all along
                {
                    unfreeze = fro.GetComponent <Unfreeze>();
                    unfreeze.mydickiscold = true;
                    if (fro.transform.parent)                      //if there is a parent
                    {
                        unfreeze = fro.transform.parent.GetComponent <Unfreeze>();
                        unfreeze.mydickiscold = true;
                        if (fro.transform.parent.parent)                          //if there is a grandparent!
                        {
                            unfreeze = fro.transform.parent.parent.GetComponent <Unfreeze>();
                            unfreeze.mydickiscold = true;
                        }
                    }
                }
            }
            i++;
        }
        yield return(null);

        Destroy(this.gameObject);
    }
Beispiel #10
0
    // Update is called once per frame
    void Update()
    {
        jPos = transform.position;

        if (char1)
        {
            p1Pos        = character1.transform.position;
            dist2Player1 = Vector3.Distance(p1Pos, jPos);
        }
        if (char2)
        {
            p2Pos        = character2.transform.position;
            dist2Player2 = Vector3.Distance(p2Pos, jPos);
        }
        if (dist2Player1 <= dist2Player2)
        {
            pPos        = p1Pos;
            dist2Player = dist2Player1;
        }
        else
        {
            pPos        = p2Pos;
            dist2Player = dist2Player2;
        }


        aDir = Vector3.Normalize(pPos - jPos);
        vely = rigidbody2D.velocity.y;

        standing = DetectFloor();
        Animate(standing, aDir);

        //Debug.DrawLine (transform.position, transform.position + transform.localScale.x * Vector3.right * dangerZone);

        //////////ATTACKING SCRIPT////////////////

        if (dist2Player < dangerZone && allowJump)
        {
            ready2Attack = true;             // time-based
            if (standing)
            {
                attack = true;                 //single frame (and really, only within the frame because it gets reset the same frame)
            }
        }

        if (attack)
        {
            allowJump    = false;
            attack       = false;
            ready2Attack = true;

            jumpTimer = time2Jump;

            if (aDir.x > 0)
            {
                rigidbody2D.AddForce(attackVectorR * aForce);
            }
            else if (aDir.x < 0)
            {
                rigidbody2D.AddForce(attackVectorL * aForce);
            }
        }

        if (ready2Attack || spinAttacking || stompAttacking)
        {
            if (!spinAttacking && !stompAttacking && rigidbody2D.velocity.y > 1f)
            {
                spot1 = new Vector2(Mathf.Cos(Mathf.Deg2Rad * 45f) * transform.localScale.x, Mathf.Sin(Mathf.Deg2Rad * 45f)) * spinDist + new Vector2(transform.position.x, transform.position.y);
                spot2 = new Vector2(Mathf.Cos(Mathf.Deg2Rad * 80f) * transform.localScale.x, Mathf.Sin(Mathf.Deg2Rad * 80f)) * spinDist + new Vector2(transform.position.x, transform.position.y);
                Debug.DrawLine(transform.position, new Vector3(spot1.x, spot1.y, 0));
                Debug.DrawLine(transform.position, new Vector3(spot2.x, spot2.y, 0));

                aboveObjects1 = Physics2D.LinecastAll(transform.position, spot1);
                aboveObjects2 = Physics2D.LinecastAll(transform.position, spot2);
                aboveObjects  = aboveObjects1.Concat(aboveObjects2).ToArray();

                foreach (RaycastHit2D above in aboveObjects)
                {
                    if (hurtThings.Contains(above.collider.tag))
                    {
                        spinAttack    = true;
                        spinAttacking = true;
                        spinTimer     = time2Spin;
                        break;
                    }
                }
            }

            if (spinAttack)
            {
                rigidbody2D.fixedAngle = false;
                spinAttack             = false;
            }

            if (spinAttacking)
            {
                if (spinTimer > 0)
                {
                    rigidbody2D.angularVelocity = 2000f;
                    spinTimer -= Time.deltaTime;
                    hitObjects = Physics2D.OverlapCircleAll(transform.position, .115f);

                    foreach (Collider2D hit in hitObjects)
                    {
                        if (hit.GetComponent <GetDamage>())
                        {
                            getDamage = hit.GetComponent <GetDamage>();
                            getDamage.StartCoroutine(getDamage.SendDamage(spinDamage, blockType));
                            spinTimer            = 0f;
                            rigidbody2D.velocity = new Vector2(0, 0);
                            rigidbody2D.AddForce(Vector3.Normalize(new Vector3(-(transform.localScale.x * 3), 1, 0)) * 155f);
                            break;
                        }
                        else if (rigidbody2D.velocity.y < -2f)
                        {
                            spinTimer = 0f;
                        }
                    }
                }

                if (spinTimer <= 0 && rotateTimer <= 0)
                {
                    ready2Attack = false;
                    rotateTimer  = time2Rotate;
                }

                if (rotateTimer > 0)
                {
                    rotateTimer -= Time.deltaTime;
                    Quaternion.Slerp(transform.rotation, Quaternion.identity, Time.deltaTime * rotoSpeed);                        //slerp back to upright rotation and fix angle
                    if (rotateTimer <= 0 || (Mathf.Abs(transform.rotation.eulerAngles.z) < 2f && Mathf.Abs(rigidbody2D.angularVelocity) < 2f))
                    {
                        spinAttacking          = false;
                        transform.rotation     = Quaternion.identity;
                        rigidbody2D.fixedAngle = true;
                        recoveryTimer          = time2Recover;
                    }
                }
            }


            //END SPINNING ATTACK


            //START STOMPING ATTACK

            if (!stompAttacking && !spinAttacking && rigidbody2D.velocity.y < -.1f)
            {
                spot3 = new Vector2(Mathf.Cos(Mathf.Deg2Rad * 50f) * transform.localScale.x, -Mathf.Sin(Mathf.Deg2Rad * 50f)) * stompDist + new Vector2(transform.position.x, transform.position.y);
                spot4 = new Vector2(Mathf.Cos(Mathf.Deg2Rad * 65f) * transform.localScale.x, -Mathf.Sin(Mathf.Deg2Rad * 65f)) * stompDist + new Vector2(transform.position.x, transform.position.y);
                spot5 = new Vector2(Mathf.Cos(Mathf.Deg2Rad * 80f) * transform.localScale.x, -Mathf.Sin(Mathf.Deg2Rad * 80f)) * stompDist + new Vector2(transform.position.x, transform.position.y);

                Debug.DrawLine(transform.position, new Vector3(spot3.x, spot3.y, 0));
                Debug.DrawLine(transform.position, new Vector3(spot4.x, spot4.y, 0));
                Debug.DrawLine(transform.position, new Vector3(spot5.x, spot5.y, 0));

                belowObjects1 = Physics2D.LinecastAll(transform.position, spot3);
                belowObjects2 = Physics2D.LinecastAll(transform.position, spot4);
                belowObjects3 = Physics2D.LinecastAll(transform.position, spot5);

                belowObjects = belowObjects1.Concat(belowObjects2).ToArray();
                belowObjects = belowObjects.Concat(belowObjects3).ToArray();

                foreach (RaycastHit2D below in belowObjects)
                {
                    if (hurtThings.Contains(below.collider.tag))
                    {
                        stompAttack    = true;
                        stompAttacking = true;
                        stompTimer     = time2Stomp;
                        break;
                    }
                }
            }

            if (stompAttack)
            {
                rigidbody2D.AddForce(aDir * stompForce);
                if (rigidbody2D.velocity.x > 0 && aDir.x < 0)
                {
                    rigidbody2D.AddForce(-Vector2.right * 80f);
                }
                else if (rigidbody2D.velocity.x < 0 && aDir.x > 0)
                {
                    rigidbody2D.AddForce(Vector2.right * 80f);
                }

                stompAttack = false;
            }

            if (stompAttacking)
            {
                if (stompTimer > 0)
                {
                    hitObjects = Physics2D.OverlapAreaAll(botLeft, topRight);

                    foreach (Collider2D hit in hitObjects)
                    {
                        if (hit.GetComponent <GetDamage>())
                        {
                            getDamage = hit.GetComponent <GetDamage>();
                            getDamage.StartCoroutine(getDamage.SendDamage(spinDamage, blockType));

                            stompTimer = 0f;
                            break;
                        }
                        else if (hit.CompareTag("Platform"))
                        {
                            stompTimer = 0f;
                        }
                    }
                }

                if (stompTimer > 0)
                {
                    stompTimer -= Time.deltaTime;
                }
                if (stompTimer <= 0)
                {
                    ready2Attack   = false;
                    stompAttacking = false;
                    recoveryTimer  = time2Recover;
                }
            }
        }
        if (recoveryTimer > 0)
        {
            recoveryTimer -= Time.deltaTime;
        }
        //END STOMP ATTACK



        //////END ATTACKING SCRIPT//////

        //Jump Around
        if (allowJump && standing)
        {
            allowJump = false;
            jumpTimer = time2Jump;

            if (aDir.x > 0)
            {
                rigidbody2D.AddForce(jumpVectorR * jForce);
            }
            else if (aDir.x < 0)
            {
                rigidbody2D.AddForce(jumpVectorL * jForce);
            }
        }

        if (standing && rigidbody2D.velocity.y < .1f)
        {
            jumpTimer -= Time.deltaTime;
            if (jumpTimer <= 0 && recoveryTimer <= 0)
            {
                allowJump = true;
            }
        }
    }
Beispiel #11
0
    // Update is called once per frame
    void Update()
    {
        jPos = transform.position;

        if (char1) {
            p1Pos = character1.transform.position;
            dist2Player1 = Vector3.Distance (p1Pos,jPos);
        }
        if (char2){
            p2Pos = character2.transform.position;
            dist2Player2 = Vector3.Distance (p2Pos,jPos);
        }
        if ( dist2Player1 <= dist2Player2 ){
            pPos = p1Pos;
            dist2Player = dist2Player1;
        }
        else{
            pPos = p2Pos;
            dist2Player = dist2Player2;
        }

        aDir = Vector3.Normalize(pPos - jPos);
        vely = rigidbody2D.velocity.y;

        standing = DetectFloor ();
        Animate (standing,aDir);

        //Debug.DrawLine (transform.position, transform.position + transform.localScale.x * Vector3.right * dangerZone);

        //////////ATTACKING SCRIPT////////////////

        if (dist2Player < dangerZone && allowJump) {
            ready2Attack = true; // time-based
            if (standing){
                attack = true; //single frame (and really, only within the frame because it gets reset the same frame)
            }
        }

        if (attack){
            allowJump = false;
            attack = false;
            ready2Attack = true;

            jumpTimer = time2Jump;

            if (aDir.x > 0 ){
                rigidbody2D.AddForce (attackVectorR * aForce);
            }
            else if (aDir.x < 0 ){
                rigidbody2D.AddForce (attackVectorL * aForce);
            }
        }

        if (ready2Attack || spinAttacking || stompAttacking){

            if (!spinAttacking && !stompAttacking && rigidbody2D.velocity.y>1f){
                spot1 = new Vector2( Mathf.Cos(Mathf.Deg2Rad * 45f) * transform.localScale.x, Mathf.Sin(Mathf.Deg2Rad * 45f) ) * spinDist + new Vector2(transform.position.x,transform.position.y);
                spot2 = new Vector2( Mathf.Cos(Mathf.Deg2Rad * 80f) * transform.localScale.x, Mathf.Sin(Mathf.Deg2Rad * 80f) ) * spinDist + new Vector2(transform.position.x,transform.position.y);
                Debug.DrawLine (transform.position, new Vector3 (spot1.x,spot1.y,0));
                Debug.DrawLine (transform.position, new Vector3 (spot2.x,spot2.y,0));

                aboveObjects1 = Physics2D.LinecastAll(transform.position,spot1);
                aboveObjects2 = Physics2D.LinecastAll(transform.position,spot2);
                aboveObjects = aboveObjects1.Concat(aboveObjects2).ToArray();

                foreach (RaycastHit2D above in aboveObjects){
                    if (hurtThings.Contains (above.collider.tag)){
                        spinAttack = true;
                        spinAttacking = true;
                        spinTimer = time2Spin;
                        break;
                    }
                }
            }

            if (spinAttack){
                rigidbody2D.fixedAngle = false;
                spinAttack = false;
            }

            if (spinAttacking){

                if (spinTimer>0){
                    rigidbody2D.angularVelocity = 2000f;
                    spinTimer -= Time.deltaTime;
                    hitObjects = Physics2D.OverlapCircleAll(transform.position,.115f);

                    foreach (Collider2D hit in hitObjects){
                        if (hit.GetComponent<GetDamage>()){

                            getDamage = hit.GetComponent<GetDamage>();
                            getDamage.StartCoroutine(getDamage.SendDamage(spinDamage,blockType));
                            spinTimer = 0f;
                            rigidbody2D.velocity = new Vector2 (0,0);
                            rigidbody2D.AddForce ( Vector3.Normalize(new Vector3(-(transform.localScale.x * 3),1,0)) * 155f);
                            break;
                        }
                        else if (rigidbody2D.velocity.y<-2f){
                            spinTimer = 0f;
                        }
                    }
                }

                if (spinTimer <= 0 && rotateTimer <= 0 ){
                    ready2Attack = false;
                    rotateTimer = time2Rotate;
                }

                if (rotateTimer>0){
                    rotateTimer -= Time.deltaTime;
                    Quaternion.Slerp( transform.rotation , Quaternion.identity , Time.deltaTime * rotoSpeed); //slerp back to upright rotation and fix angle
                    if (rotateTimer<=0 || (Mathf.Abs (transform.rotation.eulerAngles.z) < 2f && Mathf.Abs (rigidbody2D.angularVelocity)<2f) ){
                        spinAttacking = false;
                        transform.rotation = Quaternion.identity;
                        rigidbody2D.fixedAngle = true;
                        recoveryTimer = time2Recover;
                    }
                }

            }

            //END SPINNING ATTACK

            //START STOMPING ATTACK

            if (!stompAttacking && !spinAttacking && rigidbody2D.velocity.y<-.1f){
                spot3 = new Vector2( Mathf.Cos(Mathf.Deg2Rad * 50f) * transform.localScale.x, -Mathf.Sin(Mathf.Deg2Rad * 50f) ) * stompDist + new Vector2(transform.position.x,transform.position.y);
                spot4 = new Vector2( Mathf.Cos(Mathf.Deg2Rad * 65f) * transform.localScale.x, -Mathf.Sin(Mathf.Deg2Rad * 65f) ) * stompDist + new Vector2(transform.position.x,transform.position.y);
                spot5 = new Vector2( Mathf.Cos(Mathf.Deg2Rad * 80f) * transform.localScale.x, -Mathf.Sin(Mathf.Deg2Rad * 80f) ) * stompDist + new Vector2(transform.position.x,transform.position.y);

                Debug.DrawLine (transform.position, new Vector3 (spot3.x,spot3.y,0));
                Debug.DrawLine (transform.position, new Vector3 (spot4.x,spot4.y,0));
                Debug.DrawLine (transform.position, new Vector3 (spot5.x,spot5.y,0));

                belowObjects1 = Physics2D.LinecastAll(transform.position,spot3);
                belowObjects2 = Physics2D.LinecastAll(transform.position,spot4);
                belowObjects3 = Physics2D.LinecastAll(transform.position,spot5);

                belowObjects = belowObjects1.Concat(belowObjects2).ToArray();
                belowObjects = belowObjects.Concat(belowObjects3).ToArray();

                foreach (RaycastHit2D below in belowObjects){
                    if (hurtThings.Contains (below.collider.tag)){
                        stompAttack = true;
                        stompAttacking = true;
                        stompTimer = time2Stomp;
                        break;
                    }
                }
            }

            if (stompAttack){
                rigidbody2D.AddForce (aDir * stompForce);
                if (rigidbody2D.velocity.x>0 && aDir.x<0){
                    rigidbody2D.AddForce (-Vector2.right * 80f);
                }
                else if (rigidbody2D.velocity.x<0 && aDir.x>0){
                    rigidbody2D.AddForce (Vector2.right * 80f);
                }

                stompAttack = false;
            }

            if (stompAttacking){
                if (stompTimer>0){
                    hitObjects = Physics2D.OverlapAreaAll(botLeft,topRight);

                    foreach (Collider2D hit in hitObjects){
                        if (hit.GetComponent<GetDamage>()){

                            getDamage = hit.GetComponent<GetDamage>();
                            getDamage.StartCoroutine(getDamage.SendDamage(spinDamage,blockType));

                            stompTimer = 0f;
                            break;
                        }
                        else if (hit.CompareTag("Platform")){
                            stompTimer = 0f;
                        }
                    }
                }

                if (stompTimer>0){
                    stompTimer -= Time.deltaTime;
                }
                if (stompTimer<=0){
                    ready2Attack = false;
                    stompAttacking = false;
                    recoveryTimer = time2Recover;
                }

            }

        }
        if (recoveryTimer>0){
            recoveryTimer -= Time.deltaTime;
        }
        //END STOMP ATTACK

        //////END ATTACKING SCRIPT//////

        //Jump Around
        if (allowJump && standing){
            allowJump = false;
            jumpTimer = time2Jump;

            if (aDir.x > 0){
                rigidbody2D.AddForce (jumpVectorR * jForce);
            }
            else if (aDir.x < 0){
                rigidbody2D.AddForce (jumpVectorL * jForce);
            }
        }

        if (standing && rigidbody2D.velocity.y<.1f){
            jumpTimer -= Time.deltaTime;
            if (jumpTimer<=0 && recoveryTimer<=0){
                allowJump = true;
            }
        }
    }
Beispiel #12
0
    //explode some time after this block is fired
    public IEnumerator BlowMe()
    {
        yield return new WaitForSeconds (time2Blow);

        allObjects = Physics2D.OverlapCircleAll (transform.position,exRadius);
        allGameObjects = new GameObject[allObjects.Length];

        i = 0;
        foreach (Collider2D coller in allObjects){
            allGameObjects[i] = coller.gameObject;
            i++;
        }

        i = 0;
        foreach (Collider2D thing in allObjects){
            if (!dontBlowStrings.Contains(thing.name) && thing.gameObject!=gameObject){

                bPos = transform.position;
                thingPos = thing.transform.position;
                exDir = Vector3.Normalize(thingPos - bPos);

                dist2exploder = Vector3.Distance(bPos,thingPos);

                /*rayThings = Physics2D.RaycastAll (bPos,exDir,dist2exploder);
                foreach (RaycastHit2D rayThing in rayThings){
                    if (rayThing.collider.gameObject == thing.gameObject){
                        hitPointThing = rayThing.point;
                        break;
                    }
                }
                rayExps = Physics2D.RaycastAll (thingPos,-exDir,dist2exploder);
                foreach (RaycastHit2D rayExp in rayExps){
                    if (rayExp.collider.gameObject == this.gameObject){
                        hitPointExp = rayExp.point;
                        break;
                    }
                }

                dist2exploder = Vector3.Distance(hitPointExp,hitPointThing);
                */
                if (dist2exploder<0){
                    dist2exploder=0;
                }

                exMultiplier = Mathf.Exp(-.6f * dist2exploder);

                exForce = exForceBaseline * exMultiplier;
                damage = Mathf.RoundToInt ( damageBaseline * exMultiplier );

                if (thing.GetComponent<GetDamage>()){
                    j = 0;
                    makeItHurt = true;
                    while ( j < i ){
                        if (allGameObjects[i] == allGameObjects[j]){
                            makeItHurt = false;
                        }
                        j++;
                    }

                    if (makeItHurt){
                        getDamage = thing.GetComponent<GetDamage>();
                        StartCoroutine(getDamage.SendDamage(damage,weaponBlockScript.blockType));
                        if (thing.rigidbody2D){
                            thing.rigidbody2D.AddForce(exDir * exForce);
                        }
                    }
                }
                else{
                    if (thing.rigidbody2D){
                        thing.rigidbody2D.AddForce(exDir * exForce);
                    }
                }
            }
            i++;
        }
        GameObject expo = Instantiate ( Resources.Load("Prefabs/Effects/Explosion"),this.transform.position,this.transform.rotation) as GameObject;
        expo.transform.localScale = Vector3.one * 25;
        Destroy (this.gameObject);
    }
Beispiel #13
0
    public IEnumerator FreezeIt()
    {
        Instantiate ( Resources.Load ("Prefabs/Effects/Frozesplosion"),transform.position,Quaternion.identity);
        freezeTimer = timeFrozen;
        allFrozen = Physics2D.OverlapCircleAll (transform.position, exRadius);
        allGameObjects = new GameObject[allFrozen.Length];

        i = 0;
        foreach (Collider2D coller in allFrozen){
            allGameObjects[i] = coller.gameObject;
            i++;
        }

        i = 0;
        foreach (Collider2D fro in allFrozen){
            itsAPlayer = false;
            bPos = transform.position;
            thingPos = fro.transform.position;
            freDir = Vector3.Normalize(thingPos - bPos);

            dist2frozeSploder = Vector3.Distance(bPos,thingPos); //center to center distance

            RaycastHit2D[] rayThings = Physics2D.RaycastAll (bPos,freDir,dist2frozeSploder);
            foreach (RaycastHit2D rayThing in rayThings){
                if (rayThing.collider.gameObject == fro.gameObject){
                    hitPointThing = rayThing.point; //world space point
                    break;
                }
            }
            RaycastHit2D[] rayExps = Physics2D.RaycastAll (thingPos,-freDir,dist2frozeSploder);
            foreach (RaycastHit2D rayExp in rayExps){
                if (rayExp.collider.gameObject == this.gameObject){
                    hitPointFro = rayExp.point; //world space point
                    break;
                }
            }

            dist2frozeSploder = Vector3.Distance(hitPointFro,hitPointThing); //edge to edge distance

            if (icecle){
                froMultiplier = 1f-Mathf.Exp (-1.25f*dist2frozeSploder);
            }
            else{
                froMultiplier = 1f-Mathf.Exp (-.6f*dist2frozeSploder);
            }
            damage = Mathf.RoundToInt ( damageBaseline * (1f-froMultiplier) );

            if (fro.GetComponent<GetDamage>()){ //this protects against double damage to gameobjects with a circle and a box collider (and triple to those also with a polygon collider!)
                j = 0;
                makeItHurt = true;
                while ( j < i ){
                    if (allGameObjects[i] == allGameObjects[j]){
                        makeItHurt = false;
                        break;
                    }
                    j++;
                }

                if (makeItHurt){
                    getDamage = fro.GetComponent<GetDamage>();
                    StartCoroutine(getDamage.SendDamage(damage, weaponBlockScript.blockType));
                }
            }

            if (fro.sharedMaterial){ //store its starting name, bounciness and friction for later use
                GatherAllKnowledge know = GameObject.Find ("theOmniscient").GetComponent<GatherAllKnowledge> ();
                k=0;

                while (k<know.numMats) {
                    if (fro.sharedMaterial.name.Contains (know.allNames[k]) ){
                        startingName = know.allNames[k];
                        startingBounce = know.allBounciness[k];
                        startingFriction = know.allFriction[k];
                        break;
                    }
                    k++;
                }

                froFriction = froMultiplier * startingFriction;
                froBounce = froMultiplier * startingBounce;

                if (fro.transform.parent){
                    if (fro.transform.parent.parent){
                        if (fro.transform.parent.parent.CompareTag("Player")){
                            player = fro.transform.parent.parent.GetComponent<Player>();
                            itsAPlayer = true;
                        }
                    }
                    else{
                        if (fro.transform.parent.CompareTag("Player")){
                            player = fro.transform.parent.GetComponent<Player>();
                            itsAPlayer = true;
                        }
                        else{
                            if (fro.CompareTag("Player")){
                                player = fro.GetComponent<Player>();
                                itsAPlayer = true;
                            }
                        }
                    }
                }
                else{
                    if (fro.CompareTag("Player")){
                        player = fro.GetComponent<Player>();
                        itsAPlayer = true;
                    }
                }

                if (itsAPlayer){
                    if (!player.onMyKnees){
                        startingJumpSpeed = player.startingJumpSpeed;
                        startingRunningSpeed = player.startingRunningSpeed;
                        startingMaxVelocity = player.startingMaxVelocity;
                    }
                    else{
                        startingJumpSpeed = player.startingJumpSpeed * .5f;
                        startingRunningSpeed = player.startingRunningSpeed * .5f;
                        startingMaxVelocity = player.startingMaxVelocity * .5f;
                    }

                    froJumpSpeed = froMultiplier * startingJumpSpeed;
                    froRunningSpeed = froMultiplier * startingRunningSpeed;
                    froMaxVelocity = froMultiplier * startingMaxVelocity;

                    player.jumpSpeed = froJumpSpeed;
                    player.runningSpeed = froRunningSpeed;
                    player.maxVelocity.x = froMaxVelocity;
                }

                if (!fro.GetComponent<Unfreeze>()){ // if it doesn't already have the unfreeze, check to add

                    if (fro.transform.parent){ //if there is a parent

                        if (fro.transform.parent.parent){ //if there is a grandparent!

                            fro.transform.parent.parent.gameObject.AddComponent<Unfreeze>();
                            unfreeze = fro.transform.parent.parent.GetComponent<Unfreeze>();
                            unfreeze.startingFriction = startingFriction;
                            unfreeze.startingBounce = startingBounce;
                            unfreeze.mydickiscold = true;

                            fro.transform.parent.gameObject.AddComponent<Unfreeze>();
                            unfreeze = fro.transform.parent.GetComponent<Unfreeze>();
                            unfreeze.startingFriction = startingFriction;
                            unfreeze.startingBounce = startingBounce;
                            unfreeze.mydickiscold = true;

                            fro.transform.gameObject.AddComponent<Unfreeze>();
                            unfreeze = fro.GetComponent<Unfreeze>();
                            unfreeze.startingFriction = startingFriction;
                            unfreeze.startingBounce = startingBounce;
                            unfreeze.mydickiscold = true;

                            foreach (Collider2D col in fro.transform.parent.parent.GetComponents<Collider2D>()){ //slip up the grandparentparent colliders
                                startingEnabled = col.enabled;
                                col.enabled = false;
                                col.sharedMaterial = GetMaterial (froFriction,froBounce,startingName);
                                col.enabled = true;
                                col.enabled = startingEnabled;
                            }
                            foreach (Collider2D col in fro.transform.parent.GetComponents<Collider2D>()){//and the parents
                                startingEnabled = col.enabled;
                                col.enabled = false;
                                col.sharedMaterial = GetMaterial (froFriction,froBounce,startingName);
                                col.enabled = true;
                                col.enabled = startingEnabled;
                            }
                            foreach (Collider2D col in fro.GetComponents<Collider2D>()){ //and the thing
                                startingEnabled = col.enabled;
                                col.enabled = false;
                                col.sharedMaterial = GetMaterial (froFriction,froBounce,startingName);
                                col.enabled = true;
                                col.enabled = startingEnabled;
                            }
                        }
                        else{ //ok it's not on the grandparent, so we should add one to the parent
                            fro.transform.parent.gameObject.AddComponent<Unfreeze>();
                            unfreeze = fro.transform.parent.GetComponent<Unfreeze>();
                            unfreeze.startingFriction = startingFriction;
                            unfreeze.startingBounce = startingBounce;
                            unfreeze.mydickiscold = true;

                            fro.transform.gameObject.AddComponent<Unfreeze>();
                            unfreeze = fro.GetComponent<Unfreeze>();
                            unfreeze.startingFriction = startingFriction;
                            unfreeze.startingBounce = startingBounce;
                            unfreeze.mydickiscold = true;

                            foreach (Collider2D col in fro.transform.parent.GetComponents<Collider2D>()){//and the parents
                                startingEnabled = col.enabled;
                                col.enabled = false;
                                col.sharedMaterial = GetMaterial (froFriction,froBounce,startingName);
                                col.enabled = true;
                                col.enabled = startingEnabled;
                            }
                            foreach (Collider2D col in fro.GetComponents<Collider2D>()){ //and the thing
                                startingEnabled = col.enabled;
                                col.enabled = false;
                                col.sharedMaterial = GetMaterial (froFriction,froBounce,startingName);
                                col.enabled = true;
                                col.enabled = startingEnabled;
                            }
                        }
                    }
                    else{ //so it's not on this gameobject, and it's there's no parent. add it
                        fro.transform.gameObject.AddComponent<Unfreeze>();
                        unfreeze = fro.GetComponent<Unfreeze>();
                        unfreeze.startingFriction = startingFriction;
                        unfreeze.startingBounce = startingBounce;
                        unfreeze.mydickiscold = true;

                        foreach (Collider2D col in fro.GetComponents<Collider2D>()){ //and the thing
                            startingEnabled = col.enabled;
                            col.enabled = false;
                            col.sharedMaterial = GetMaterial (froFriction,froBounce,startingName);
                            col.enabled = true;
                            col.enabled = startingEnabled;
                        }
                    }
                }
                else{ //so it was here all along
                    unfreeze = fro.GetComponent<Unfreeze>();
                    unfreeze.mydickiscold = true;
                    if (fro.transform.parent){ //if there is a parent
                        unfreeze = fro.transform.parent.GetComponent<Unfreeze>();
                        unfreeze.mydickiscold = true;
                        if (fro.transform.parent.parent){ //if there is a grandparent!
                            unfreeze = fro.transform.parent.parent.GetComponent<Unfreeze>();
                            unfreeze.mydickiscold = true;
                        }
                    }

                }
            }
            i++;

        }
        yield return null;
        Destroy(this.gameObject);
    }