Exemplo n.º 1
0
    IEnumerator DoCannonFire()
    {
        SpriteHFlipRigidbodyVelX tankSpriteFlip = tank.GetComponent <SpriteHFlipRigidbodyVelX>();

        WaitForFixedUpdate waitUpdate    = new WaitForFixedUpdate();
        WaitForSeconds     waitFireDelay = new WaitForSeconds(seekerFireDelay);

        tank.bodyCtrl.moveSide           = 0.0f;
        tank.bodyCtrl.rigidbody.velocity = Vector3.zero;

        //face player
        float sign = Mathf.Sign(mPlayer.collider.bounds.center.x - collider.bounds.center.x);

        tankSpriteFlip.SetFlip(sign < 0.0f);
        bodySpriteCtrl.isLeft = sign < 0.0f;

        //play particle ready and wait
        cannonParticleReady.Play();
        while (cannonParticleReady.isPlaying || !tank.bodyCtrl.isGrounded)
        {
            sign = Mathf.Sign(mPlayer.collider.bounds.center.x - collider.bounds.center.x);
            tankSpriteFlip.SetFlip(sign < 0.0f);
            bodySpriteCtrl.isLeft = sign < 0.0f;

            yield return(waitUpdate);
        }

        //jump
        tank.bodyCtrl.moveSide = sign * cannonMoveScale;
        tank.Jump(1.0f);

        //check if we start dropping, then fire
        while (tank.bodyCtrl.isGrounded || tank.bodyCtrl.isJump || tank.bodyCtrl.localVelocity.y < 0.0f)
        {
            yield return(waitUpdate);
        }

        //fire
        for (int i = 0; i < cannonFirePts.Length; i++)
        {
            Vector3 pt = cannonFirePts[i].position; pt.z = 0.0f;
            Projectile.Create(projGroup, cannonProjType, pt, cannonFirePts[i].up, null);
        }

        cannonSfx.Play();

        //wait till we land
        while (!tank.bodyCtrl.isGrounded)
        {
            yield return(waitUpdate);
        }

        tank.Jump(0.0f);

        ToPhase(Phase.Move);
    }
Exemplo n.º 2
0
    IEnumerator DoSeekerFire()
    {
        SpriteHFlipRigidbodyVelX tankSpriteFlip = tank.GetComponent <SpriteHFlipRigidbodyVelX>();

        WaitForFixedUpdate waitUpdate    = new WaitForFixedUpdate();
        WaitForSeconds     waitFireDelay = new WaitForSeconds(seekerFireDelay);

        //prep
        seekerAnimDat.Play("prep");
        do
        {
            yield return(waitUpdate);
        } while(seekerAnimDat.isPlaying);

        //move to a far spot away from player
        Vector3 playerPos = mPlayer.collider.bounds.center;

        float farthestX      = 0;
        float farthestDistSq = 0;

        for (int j = 0; j < movePts.Length; j++)
        {
            Vector3 p = movePts[j].position;
            float   d = Mathf.Abs(playerPos.x - p.x);
            if (d > farthestDistSq)
            {
                farthestDistSq = d;
                farthestX      = p.x;
            }
        }

        //move till we are close
        while (Mathf.Abs(farthestX - collider.bounds.center.x) > 0.1f)
        {
            if (tank.bodyCtrl.moveSide == 0.0f || Mathf.Abs(tank.bodyCtrl.rigidbody.velocity.x) > 2.0f)
            {
                tank.bodyCtrl.moveSide = Mathf.Sign(farthestX - collider.bounds.center.x);
            }
            yield return(waitUpdate);
        }

        tank.bodyCtrl.moveSide           = 0.0f;
        tank.bodyCtrl.rigidbody.velocity = Vector3.zero;

        //fire stuff
        for (int i = 0; i < seekerCount; i++)
        {
            //face player
            float sign = Mathf.Sign(mPlayer.collider.bounds.center.x - collider.bounds.center.x);
            tankSpriteFlip.SetFlip(sign < 0.0f);
            bodySpriteCtrl.isLeft = sign < 0.0f;

            seekerLauncherAnimDat.Play("fire");
            do
            {
                yield return(waitUpdate);
            } while(seekerLauncherAnimDat.isPlaying);

            yield return(waitFireDelay);
        }

        //holster
        seekerAnimDat.Play("holster");
        do
        {
            yield return(waitUpdate);
        } while(seekerAnimDat.isPlaying);

        ToPhase(Phase.Move);
    }