示例#1
0
    private IEnumerator EngagePlayer()
    {
        while (true)
        {
            switch (currState)
            {
            case ShooterState.AIMING:
                Aim(player.transform.position);
                break;

            case ShooterState.FIRING:
                currState = ShooterState.RECOVERING;
                break;

            case ShooterState.RECOVERING:
            {
                float startTime = 0;
                while (startTime < recoverTime)
                {
                    startTime += Time.deltaTime;
                    yield return(null);
                }
                currState = ShooterState.AIMING;
                break;
            }

            default:
                Debug.LogError(currState + " is not a supported state.");
                break;
            }

            yield return(null);
        }
    }
示例#2
0
    IEnumerator OnTriggerEnter(Collider other)                                                                                  // other.transform.position == target.position
    {
        if (other.CompareTag("Player"))
        {
            if (gameObject.CompareTag("Enemy") && (target.position.y > collider.transform.position.y)) //  thisTransform.position.y + .1f))
            {
                linkToPlayerControls.velocity.y = deathForce;
                Managers.Audio.Play(soundCrash, thisTransform, 6.0f, 1.0f);
                enemyState = ShooterState.Stunned;
                animPlay.PlayFramesFixed(3, 0, 2, orientation);                                                 // animate Stunning..
                Destroy(Instantiate(ParticleStars, thisTransform.position, thisTransform.rotation), 5);
            }
            else if (Input.GetAxis("Vertical") != 0)
            {
                Destroy(Instantiate(ParticleStars, thisTransform.position, thisTransform.rotation), 5);

                Managers.Audio.Play(soundCrash, thisTransform);
                linkToPlayerControls.velocity.y = deathForce;
            }
        }
        else if (other.CompareTag("p_shot"))
        {
            BeatDown();
        }
        else if (gameObject.CompareTag("p_shot") && !other.CompareTag("Item"))
        {
            yield return(new WaitForSeconds(0.01f));

            BeatDown();
        }
    }
示例#3
0
    public void Shoot()
    {
        if (m_CurrentState == ShooterState.None && Input.GetButtonDown("Fire1"))
        {
            m_ForceSlider.value = 0.0f;
            m_ForceDirection    = 1;
            m_CurrentState      = ShooterState.Charging;
            StartCoroutine(ReleasesBall());
        }

        if (m_CurrentState == ShooterState.Charging && Input.GetButton("Fire1"))
        {
            m_ForceSlider.value   += (Time.deltaTime / m_TimeToMaxForce) * m_ForceDirection;
            m_ForceFillImage.color = Color.Lerp(m_MinForceColor, m_MaxForceColor, m_Curve.Evaluate(m_ForceSlider.value));
            if (m_ForceSlider.value >= 1.0f || m_ForceSlider.value <= 0.0f)
            {
                m_ForceDirection *= -1;
            }
        }

        if (m_CurrentState == ShooterState.Charging && Input.GetButtonUp("Fire1"))
        {
            Rb.mass = 0.1f;
            move    = true;
            FindObjectOfType <AudioManager>().play("ThrowBall");
            float force = m_ForceSlider.value * m_MaxForce;
            m_Rigidbody.AddForce(transform.forward * force);
            currentCamState = cameraState.side;
            m_CurrentState  = ShooterState.Moving;
            StartCoroutine(CheckStop());
        }
    }
示例#4
0
    IEnumerator Freeze()
    {
        float TimeLapse   = Time.time + 20;
        float OriginalPos = thisTransform.position.x;

        while (TimeLapse > Time.time)
        {
            thisTransform.position = new Vector3(OriginalPos + (Mathf.Sin(Time.time * 50) * .05f),
                                                 thisTransform.position.y,
                                                 thisTransform.position.z);
            if ((int)enemyState > 1)
            {
                if (gameObject.tag == "pickup" && enemyState != ShooterState.Dead)
                {
                    enemyState = ShooterState.Dead;
                }

                StartCoroutine(CoUpdate());
                yield break;
            }

            yield return(0);
        }

        thisTransform.position = new Vector3(OriginalPos, thisTransform.position.y, thisTransform.position.z);

        //if (gameObject.tag == "pickup")
        //    gameObject.tag = "Enemy";
        StartCoroutine(CoUpdate());

        //rigidbody.velocity = Vector3.zero;
        velocity = Vector3.zero;
        yield return(0);
    }
示例#5
0
 public void Start()
 {
     m_TimeToMaxForce = 2;       //Used to set the strength bar's speed at the start.
     Rb.mass          = 3000000; //Used to set the ball's mass at the start, avoiding it to move due to any collision
     m_CurrentState   = ShooterState.None;
     currentCamState  = cameraState.front;
     randomPosition();  // set the white ball's position at the start.
     changeWhiteBall(); // set the white ball's position at the start.
 }
示例#6
0
    IEnumerator  Search()
    {
        orientation = (int)Mathf.Sign(target.position.x - thisTransform.position.x);

        //  Seek distance and players position/angle
//	if (aimCompass)
//	{
        Quaternion lookPos = Quaternion.LookRotation(thisTransform.position - target.position, Vector3.forward);

        lookPos.y           = 0;
        lookPos.x           = 0;
        aimCompass.rotation = Quaternion.Slerp(aimCompass.rotation, lookPos, Time.deltaTime * aimDamping);
//	}

        if (distanceToTarget <= AttackRangeX2)                                                                  // if player's near enemy -> Aim & Attack him
        {
            if (AnimFlag)
            {
                animPlay.PlayFramesFixed(1, 2, 2, orientation);                         // Do Seeking Animation
            }
            if (Time.time > nextFire)                                                   // wait some time between shots
            {
                AnimFlag = false;
//
                Shoot();
                float timerHolder = Time.time + .15f;
                while (timerHolder > Time.time)                                                         // do some throw animation for a while
                {
                    animPlay.PlayFramesFixed(2, 0, 2, orientation);                                     // Do Throw Animation
                    if (enemyState != ShooterState.Alert)
                    {
                        AnimFlag = true; yield break;
                    }
                    yield return(0);
                }

                float timertrigger = Time.time + .35f;
                while (timertrigger > Time.time)                                                        // do some throw animation for a while
                {
                    animPlay.PlayFramesFixed(2, 2, 2, orientation);                                     // Do Throw Animation
                    if (enemyState != ShooterState.Alert)
                    {
                        AnimFlag = true; yield break;
                    }
                    yield return(0);
                }
                AnimFlag = true;
            }
        }
        else
        {
            enemyState = ShooterState.Sleeping;                                                         // else if player it's out enemy range -> go Sleep
        }
        yield return(0);
    }
示例#7
0
    private void OnTriggerExit(Collider _col)
    {
        if (_col.gameObject.tag != "Player")
        {
            return;
        }

        playerInRange = false;
        currState     = ShooterState.WAITING;
        StopCoroutine(engagePlayer);
    }
示例#8
0
    IEnumerator  Search()
    {
        //orientation = (int)Mathf.Sign( target.position.x - thisTransform.position.x  );

        if (distanceToTarget <= AttackRangeX2)                          // if player's near enemy -> Aim & Attack him
        {
            animPlay.PlayFrames(3, 2, 2, orientation, 16);              // Do Running Animation


//#if UNITY_EDITOR
            //velocity.x = 450 * orientation * Time.deltaTime;
            velocity.x = 2.5f * orientation;
//#else
//        //velocity.x = 900 * orientation * Time.deltaTime;
//        velocity.x = 4 * orientation;
//#endif


            if (Time.time > nextFire)                                                                                           // wait some time between shots
            {
                ReOrientate();
            }


            if (Time.time > nextJump)
            {
                Jump();
            }

            //Debug.DrawLine(thisTransform.position, thisTransform.TransformPoint(-Vector3.right), Color.blue);
            //Debug.DrawLine(thisTransform.position, thisTransform.TransformPoint(Vector3.right), Color.blue);

            RaycastHit hit;
            if (Physics.Linecast(thisTransform.position, thisTransform.TransformPoint(-Vector3.right), out hit) &&
                hit.collider.gameObject.tag == "Untagged" && hit.collider.gameObject.layer != 11)
            {
                orientation = 1;
            }

            if (Physics.Linecast(thisTransform.position, thisTransform.TransformPoint(Vector3.right), out hit) &&
                hit.collider.gameObject.tag == "Untagged" && hit.collider.gameObject.layer != 11)
            {
                orientation = -1;
            }
        }
        else
        {
            enemyState = ShooterState.Sleeping;                                                         // else if player it's out enemy range -> go Sleep
        }
        yield return(0);
    }
示例#9
0
        public override void Update(GameTime gameTime)
        {
            EnemyColor = Color.White;
            //StopEnemy = false;
            float posX  = Position.X + localBounds.Width / 2 * (int)direction;
            int   tileX = (int)Math.Floor(posX / Tile.Width) - (int)direction;
            int   tileY = (int)Math.Floor(Position.Y / Tile.Height);

            if (level.GetCollision(tileX + (int)direction, tileY - 1) == TileCollision.Impassable ||
                level.GetCollision(tileX + (int)direction, tileY + 1) == TileCollision.Passable)
            {
                if (state != ShooterState.Wait)
                {
                    waitTime = MaxWaitTime;
                    state    = ShooterState.Wait;
                }
            }

            if (level.GetCollision(tileX + (int)direction, tileY - 1) == TileCollision.Patrol &&
                state != ShooterState.Wait)
            {
                waitTime = MaxWaitTime;
                state    = ShooterState.Wait;
            }

            if (BeingHit == true)
            {
                state = ShooterState.Hit;
            }


            if (CanEnenmyAttack() == true && state != ShooterState.Shoot && beingHit == false)
            {
                state = ShooterState.Shoot;
            }


            //Vector2 targetDirection = new Vector2(level.Player.Position.X, level.Player.Position.Y - 40) - Position;
            //if (targetDirection.Length() < 150.0f)
            //{
            //    state = ShooterState.Run;
            //}


            EnenmyActions(gameTime);
            HandleCollisions(gameTime);
            HandleBullets();
        }
示例#10
0
    IEnumerator ReleasesBall()
    {
        yield return(new WaitForSeconds(6));

        if (move == false)
        {
            Rb.mass = 0.1f;
            FindObjectOfType <AudioManager>().play("ThrowBall");
            float force = m_ForceSlider.value * m_MaxForce;
            m_Rigidbody.AddForce(transform.forward * force);
            currentCamState = cameraState.side;
            m_CurrentState  = ShooterState.Moving;
            StartCoroutine(CheckStop());
        }
        move = false;
    }
示例#11
0
    IEnumerator Stunned()                                                                                                                               // "Boleado"
    {
        if (this.CompareTag("pickup"))
        {
            yield break;
        }
//      AnimFlag = false;
        this.tag = "pickup";                                                                                                    // change tag to a pickable thing for being holded

        float timertrigger = Time.time + stunTime;

        while (timertrigger > Time.time)                                                                                // start knock out time counter
        {
            animPlay.PlayFramesFixed(3, 0, 2, orientation);                                                             // animate Stunning..

//	//	if ( transform.parent && linkToPlayerControls.isHoldingObj && !collider.enabled )
//	//	if ( thisTransform.IsChildOf( target) && !collider.enabled )        // if Player Grabs him change EnemyState > Handled
//		if ( thisTransform.IsChildOf( target) )
//		{
//			thisTransform.position = target.position +  HoldedPosition;             // Update own hold position & player's too
//	//		linkToPlayerControls.properties.GrabPosition = HoldedPosition;
//              enemyState = ShooterState.Holded ;									// & change enemy state to holded..
//              moveDirection =	ThrowDirection;
//		}
            if (enemyState != ShooterState.Stunned)
            {
                yield break;                                            // so he is not stunned anymore & must quit here
            }
            yield return(0);
        }

        if (!thisTransform.parent.CompareTag("Player"))                                                                 // but if stun time is over & player !isHolding( this)..
        {
            this.tag = "Enemy";
            if (distanceToTarget > AlertRangeX2)
            {
                enemyState = ShooterState.Sleeping;                                                                                     // after a while change EnemyState > Default
            }
            else
            {
                enemyState = ShooterState.Alert;                                                                                        // or alert if the player is near
            }
        }
        yield return(0);
//	}
    }
示例#12
0
//function Stunned()																	// "Boleado"
//{
//              animPlay.PlayFramesFixed( 1, 1, 1, orientation);
//
//			yield return new WaitForSeconds(0.5f);
//
//			this.tag = "pickup";
//			velocity.x *= -.25;
//			velocity.y = 4.5f;
//			enemyState = ShooterState.Dead;
//
//}

    void  BeingHolded()
    {
        grounded    = true;
        velocity    = Vector3.zero;
        orientation = linkToPlayerControls.orientation;                                         // update own orientation according player direction
        animPlay.PlayFramesFixed(1, 1, 1, orientation);

        if (collider.enabled && !thisTransform.parent)                                  // if collider returned & we haven't parent anymore..
        {
            grounded = false;

            velocity       = moveDirection;
            velocity.y    += 3.5f * Input.GetAxis("Vertical");
            velocity.x    *= Mathf.Sign(orientation);
            enemyState     = ShooterState.Shooted;                                                                                      // Then it means we have been shooted...
            gameObject.tag = "p_shot";
        }
    }
示例#13
0
        protected override void LoadContent()
        {
            enemyAnimation      = new Animation(level.Content.Load <Texture2D>("Sprites/Enemies/ShootEnemy/ShootIdle"), 0.1f, 60, true);
            enemyAnimationWalk  = new Animation(level.Content.Load <Texture2D>("Sprites/Enemies/ShootEnemy/ShootEnemyRun"), 0.1f, 60, true);
            enemyAnimationShoot = new Animation(level.Content.Load <Texture2D>("Sprites/Enemies/ShootEnemy/ShootEnemy"), 0.1f, 60, false);
            bullet = level.Content.Load <Texture2D>("Sprites/Enemies/ShootEnemy/EnemyBullet");
            block  = level.Content.Load <Texture2D>("square");

            int width  = (int)(enemyAnimation.FrameWidth * 0.4);
            int left   = (enemyAnimation.FrameWidth - width) / 2;
            int height = (int)(enemyAnimation.FrameHeight * 0.75);
            int top    = enemyAnimation.FrameHeight - height;

            localBounds = new Rectangle(left, top, width, height);

            sprite.PlayAnimation(enemyAnimation);
            state = ShooterState.Patrol;
        }
示例#14
0
    public IEnumerator CheckStop()
    {
        m_Arrow.SetPosition(0, transform.position);
        m_Arrow.SetPosition(1, transform.position);

        yield return(new WaitForSeconds(1.0f));

        while (m_Rigidbody.velocity.magnitude > 0.1f)
        {
            yield return(new WaitForEndOfFrame());
        }

        m_Rigidbody.velocity = Vector3.zero;
        transform.rotation   = Quaternion.Euler(-Vector3.right);
        m_CurrentState       = ShooterState.ok;
        m_Shoot  = true;
        this.tag = "OffRedBall";
        StartCoroutine(FeedBack.DestroyFeedBack());
    }
示例#15
0
    protected override void OnTriggerEnter(Collider _col)
    {
        if (player == null)
        {
            if (_col.gameObject.tag != "Player")
            {
                return;
            }
            player = _col.gameObject;
        }
        else if (_col.gameObject != player)
        {
            return;
        }


        playerInRange = true;
        currState     = ShooterState.AIMING;
        engagePlayer  = StartCoroutine(EngagePlayer());
    }
示例#16
0
    IEnumerator OnTriggerEnter(Collider other)                                                                                  // other.transform.position == target.position
    {
        if (other.CompareTag("Player"))
        {
            if (gameObject.CompareTag("Enemy") && (target.position.y > thisTransform.position.y + .1f))
            {
                linkToPlayerControls.velocity.y = deathForce;
                this.tag    = "Untagged";
                velocity.x *= -.25f;
                velocity.y  = 4.5f;
                animPlay.PlayFramesFixed(1, 1, 1, orientation);
                enemyState = ShooterState.Dead;
                yield return(new WaitForSeconds(0.5f));

                this.tag = "pickup";
                Managers.Audio.Play(soundCrash, thisTransform, 6.0f, 1.0f);
                Destroy(Instantiate(ParticleStars, thisTransform.position, thisTransform.rotation), 5);


//			enemyState = ShooterState.Stunned;
            }
            else if (Input.GetAxis("Vertical") != 0)
            {
                Destroy(Instantiate(ParticleStars, thisTransform.position, thisTransform.rotation), 5);

                Managers.Audio.Play(soundCrash, thisTransform);
                linkToPlayerControls.velocity.y = deathForce;
            }
        }
        else if (other.CompareTag("p_shot"))
        {
            Managers.Register.Score += 100;
            BeatDown();
        }
        else if (gameObject.CompareTag("p_shot") && !other.CompareTag("Item"))
        {
            yield return(new WaitForSeconds(0.01f));

            BeatDown();
        }
    }
示例#17
0
    IEnumerator  Sleeping()
    {
        if (AnimFlag)
        {
            velocity = Vector3.zero;
            animPlay.PlayFrames(0, 0, 4, orientation, 2);                                                       // Do zzZZZ Animation


            if (distanceToTarget <= AlertRangeX2)
            {
                AnimFlag = false;
                float groundPosition = thisTransform.position.y;
                float timertrigger   = Time.time + 0.55f;

                while (timertrigger > Time.time)
                {
//				thisTransform.Translate( 0, 1.5f * TimeLapse.deltaTime, 0);
                    thisTransform.position = new Vector3(thisTransform.position.x,
                                                         groundPosition + Mathf.Sin((timertrigger - Time.time) * 5) * .5f,
                                                         thisTransform.position.z);
                    animPlay.PlayFramesFixed(1, 0, 2, orientation);                                             // Do Wake up Animation

                    if (enemyState != ShooterState.Sleeping)
                    {
                        thisTransform.position = new Vector3(thisTransform.position.x, groundPosition, thisTransform.position.z);
                        AnimFlag = true;
                        yield break;
                    }

                    yield return(0);
                }
                thisTransform.position = new Vector3(thisTransform.position.x, groundPosition, thisTransform.position.z);
                AnimFlag   = true;
                enemyState = ShooterState.Alert;
                yield break;
            }
        }
    }
示例#18
0
    IEnumerator Stunned()                                                                                                                               // "Boleado"
    {
        if (this.CompareTag("pickup"))
        {
            yield break;
        }
        this.tag = "pickup";                                                                                                    // change tag to a pickable thing for being holded

        float timertrigger = Time.time + stunTime;

        while (timertrigger > Time.time)                                                                                // start knock out time counter
        {
            animPlay.PlayFramesFixed(3, 0, 2, orientation);                                                             // animate Stunning..

            if (enemyState != ShooterState.Stunned)
            {
                yield break;    // so he is not stunned anymore & must quit here
            }
            yield return(0);
        }

        if (!thisTransform.parent.CompareTag("Player"))                                                                 // but if stun time is over & player !isHolding( this)..
        {
            this.tag = "Enemy";
            if (distanceToTarget > AlertRangeX2)
            {
                enemyState = ShooterState.Sleeping;                                                                                     // after a while change EnemyState > Default
            }
            else
            {
                enemyState = ShooterState.Alert;                                                                                        // or alert if the player is near
            }
        }
        yield return(0);
//	}
    }
示例#19
0
 protected virtual void Shoot()
 {
     currState = ShooterState.FIRING;
     SpawnBullet(bulletSpawnLocation.forward);
 }
示例#20
0
        public void EnenmyActions(GameTime gameTime)
        {
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            switch (state)
            {
            case ShooterState.Patrol:
                sprite.PlayAnimation(enemyAnimationWalk);
                velocity = new Vector2((int)direction * MoveSpeed * elapsed, 0.0f);

                if (StopEnemy == true)
                {
                    velocity = Vector2.Zero;
                }

                Position = Position + velocity;
                Position = new Vector2((float)Math.Round(Position.X), (float)Math.Round(Position.Y));
                break;

            case ShooterState.Wait:
                sprite.PlayAnimation(enemyAnimation);
                waitTime = Math.Max(0.0f, waitTime - (float)gameTime.ElapsedGameTime.TotalSeconds);
                if (waitTime <= 0.0f)
                {
                    direction = (FaceDirection)(-(int)direction);
                    state     = ShooterState.Patrol;
                }
                break;

            case ShooterState.Shoot:
                sprite.PlayAnimation(enemyAnimationShoot);


                if (bulletWaitTime > 0)
                {
                    bulletWaitTime = Math.Max(0.0f, bulletWaitTime - (float)gameTime.ElapsedGameTime.TotalSeconds);
                }

                if (bulletCount > 2)
                {
                    bulletWaitTime = bulletMaxWaitTime;
                    bulletCount    = 0;
                    state          = ShooterState.Patrol;
                }

                if (gameTime.TotalGameTime - previousFireTime > fireTime && bulletWaitTime <= 0)
                {
                    bulletCount++;
                    bullets.Add(new BulletInfo(new Vector2(Position.X, Position.Y - 32), (int)direction, bullet));
                    previousFireTime = gameTime.TotalGameTime;
                }

                break;

            case ShooterState.Run:
                sprite.PlayAnimation(enemyAnimationWalk);
                Vector2 targetDirection = Position - new Vector2(level.Player.Position.X, level.Player.Position.Y - 40);

                if (targetDirection.Length() > 150)
                {
                    if (CanEnenmyAttack() == true)
                    {
                        state = ShooterState.Shoot;
                    }
                    else
                    {
                        state = ShooterState.Patrol;
                    }
                    break;
                }

                if (targetDirection.X < 0)
                {
                    direction = FaceDirection.Left;
                }
                else
                {
                    direction = FaceDirection.Right;
                }

                targetDirection.Normalize();
                velocity = new Vector2(targetDirection.X, 0.0f) * MoveSpeed * elapsed;

                if (StopEnemy == true)
                {
                    velocity = Vector2.Zero;
                }

                Position = Position + velocity;
                Position = new Vector2((float)Math.Round(Position.X), (float)Math.Round(Position.Y));
                break;

            case ShooterState.Hit:
                EnemyColor = Color.Red;
                break;
            }
        }
示例#21
0
 protected override void CustomAwake()
 {
     currState = ShooterState.WAITING;
 }
示例#22
0
    IEnumerator CoUpdate()
    {
        while (thisTransform)
        {
            if (!target)
            {
                if (Managers.Game.PlayerPrefab)
                {
                    target = Managers.Game.PlayerPrefab.transform;
                    linkToPlayerControls = (PlayerControls)target.GetComponent <PlayerControls>();
                }
                else
                {
                    yield return(0);
                }
            }

            if (target)
            {
                if (thisTransform.IsChildOf(target))                                            // check if the player has taken us...
                {
                    thisTransform.position = target.position + HoldedPosition;                  // Update own hold position & player's too
                    enemyState             = ShooterState.Holded;                               // & change enemy state to holded..
                }
            }

            switch (enemyState)                         // check states of the character:
            {
            case ShooterState.Alert:                    // 1# ALERT STATE:
                animPlay.PlayFramesFixed(3, 0, 4, orientation);
                velocity    = Vector3.zero;
                velocity.x  = Mathf.Sin(Time.time);
                orientation = (int)Mathf.Sign(Mathf.Sin(Time.time));
                break;

            case ShooterState.Holded:                   // 3# ENEMY IS TAKEN
                BeingHolded();

                break;

            case ShooterState.Shooted:                  // 4# ENEMY IS THROWED IN THE AIR
                thisTransform.RotateAround(Vector3.forward, -orientation * 2 * Time.deltaTime);

                break;

            case ShooterState.Dead:                     // 5# ENEMY IS DEAD
                animPlay.PlayFramesFixed(0, 3, 1, orientation);
                thisTransform.RotateAround(Vector3.forward, -orientation * 45 * Time.deltaTime);
                grounded = false;
                break;
            }

            if (!grounded)
            {
                velocity.y -= gravity * Time.deltaTime;
            }
            thisTransform.position += velocity * Time.deltaTime;

            if (thisTransform.position.y < 0 && thisTransform != null)
            {
                Destroy(gameObject, 2);                                                         // If character falls get it up again
            }
            yield return(0);
        }
    }