Esempio n. 1
0
 public override void Interrupt()
 {
     StopAllCoroutines();
     body.moveSpeed = defaultSpeed;
     body.Move(Vector3.zero);
     attacking = false;
 }
Esempio n. 2
0
 protected virtual IEnumerator WalkInSpawn(Vector3 target)
 {
     body.gameObject.layer = LayerMask.NameToLayer("EnemySpawnLayer");
     if (anim.ContainsParam("Moving"))
     {
         anim.SetBool("Moving", true);
     }
     while (Vector3.Distance(transform.position, target) > 0.1f)
     {
         body.Move((target - transform.position).normalized);
         yield return(null);
     }
     body.gameObject.layer = DEFAULT_LAYER;
     StartCoroutine(DEFAULT_STATE);
     //Debug.Log ("Done");
 }
Esempio n. 3
0
    /** Parry */
    private IEnumerator ListenForParry()
    {
        EffectPooler.PlayEffect(player.parryEffect, transform.position, true, 0.1f);
        player.StrobeColor(Color.yellow, PARRY_TIME - 0.1f);
        body.Move(Vector2.zero);
        player.input.enabled = false;
        sound.PlaySingle(player.parrySound);
        yield return(new WaitForSeconds(PARRY_TIME));

        player.FlashColor(Color.gray, PARRY_COOLDOWN_TIME);
        player.OnPlayerTryHit -= Parry;
        yield return(new WaitForSeconds(PARRY_COOLDOWN_TIME));

        player.sr.color      = Color.white;
        player.input.enabled = true;
    }
Esempio n. 4
0
    // Update is called once per frame
    void Update()
    {
        // handle "sticking" when stopped horizontally
        if (enemyPhysics.movementStopped)
        {
            targetSpeed  = 0;
            currentSpeed = 0;
        }

        if (enemyPhysics.grounded)
        {
            amountToMove.y = 0;
        }

        amountToMove.x  = currentSpeed;
        amountToMove.y -= gravity * Time.deltaTime;
        enemyPhysics.Move(amountToMove * Time.deltaTime);
    }
Esempio n. 5
0
 private void Charge()
 {
     anim.CrossFade(chargeState, 0f);                    // triggers are unreliable, crossfade forces state to execute
     body.Move(Vector2.zero);
     //+ new Vector2(Random.value, Random.value);		// add a random offset
 }
Esempio n. 6
0
    // Update is called once per frame
    void Update()
    {
        //MOVEMENT
        // handle "sticking" when stopped horizontally
        if (physics.movementStopped)
        {
            targetSpeed  = 0;
            currentSpeed = 0;
        }
        if (!damaged)
        {
            //handle grounded movement
            if (physics.grounded)
            {
                amountToMove.y = 0;

                if (jumping)
                {
                    jumping = false;
                    animator.SetBool("Jumping", false);
                    animator.SetBool("Falling", false);
                }

                if (!sliding)
                {
                    if ((Input.GetAxisRaw("Vertical") < 0 && Input.GetButtonDown("Jump")) || Input.GetButtonDown("Slide"))
                    {
                        sliding = true;
                        animator.SetBool("Sliding", true);
                        //physics.SetSlideCollider(false);
                        slideStartTime = Time.time;
                    }
                }

                // Jump
                if (Input.GetButtonDown("Jump") && !sliding)
                {
                    amountToMove.y = jumpSpeed;
                    jumping        = true;
                    animator.SetBool("Jumping", true);
                }
            }

            //handle directional input
            if (!sliding)
            {
                targetSpeed  = (Input.GetAxisRaw("Horizontal") != 0) ? Mathf.Sign(Input.GetAxisRaw("Horizontal")) * speed : 0;
                currentSpeed = IncrementTowards(currentSpeed, targetSpeed, acceleration);
            }
            else
            {
                if (Time.time - slideStartTime >= slideDuration)
                {
                    // stop sliding
                    sliding = false;
                    animator.SetBool("Sliding", false);
                    //physics.SetSlideCollider(true);
                }
                else
                {
                    // move in correct direction

                    /*if (targetSpeed == 0) {
                     *  // right if facing right and left if facing left
                     *  currentSpeed = (transform.eulerAngles.y == 0) ? speed : -speed;
                     * }*/
                    currentSpeed = ((transform.eulerAngles.y == 0) ? speed : -speed) * slideSpeedMultiplier;
                }
            }

            // need to keep track of which direction the character is facing
            float facing = Mathf.Sign(targetSpeed);
            if (facing != 0 && targetSpeed != 0)
            {
                // Flip the character sprite if going left
                transform.eulerAngles = (facing < 0) ? Vector3.up * 180 : Vector3.zero;
            }

            if (invincible)
            {
                Debug.Log("invincibility check");
                //blink character to show invincibility after damage
                if (Time.time - timeDamaged <= invincibleTime)
                {
                    if ((Time.frameCount % 60) % 5 == 0)
                    {
                        sprite.enabled = (sprite.enabled) ? false : true;
                    }
                }
                else
                {
                    Debug.Log("invincibility done");
                    sprite.enabled = true;
                    invincible     = false;
                }
            }
        }
        else
        {
            // Damaged
            if (!physics.grounded)
            {
                amountToMove.y = (amountToMove.y >= 5) ? 5 : amountToMove.y;
            }
            currentSpeed = (transform.eulerAngles == Vector3.zero) ? -8.0f : 8.0f;

            if (Time.time - timeDamaged >= (invincibleTime / 5.0f))
            {
                damaged = false;
                animator.SetBool("Hit", false);
                currentSpeed = 0;
            }
        }

        animator.SetFloat("Speed", Mathf.Abs(currentSpeed));

        if (Input.GetButtonUp("Jump"))
        {
            amountToMove.y = (amountToMove.y >= 2) ? 5 : amountToMove.y;
        }
        amountToMove.x  = currentSpeed;
        amountToMove.y -= gravity * Time.deltaTime;

        //if(jumping) Debug.Log ("jump speed: " + jumpSpeed + ", negative speed: " + amountToMove.y );
        if (jumping && amountToMove.y < -5.0)
        {
            animator.SetBool("Falling", true);
        }

        physics.Move(amountToMove * Time.deltaTime);

        // FIRING
        if (Input.GetButtonDown("Fire") && GameObject.FindGameObjectsWithTag("PlayerProjectile").Length < 3 && !sliding)
        {
            // can fire anytime except when sliding
            charging = true;
            bulletPool.CreateObject(1);
            lastShotTime = Time.time;
            animator.SetBool("Shooting", true);
        }

        if (charging)
        {
            float chargeTime = Time.time - lastShotTime;
            Debug.Log("chargetime: " + chargeTime + " , chargethresh: " + chargeThreshold);
            if (Input.GetButton("Fire"))
            {
                if (chargeTime >= chargeThreshold)
                {
                    Debug.Log("FULLY CHARGED");
                    animator.SetInteger("ChargeLevel", 2);
                }
                else if (chargeTime >= (chargeThreshold / 3.0f))
                {
                    Debug.Log("HALF CHARGED");
                    animator.SetInteger("ChargeLevel", 1);
                }
            }
            else
            {
                charging = false;

                if (chargeTime >= chargeThreshold)
                {
                    bulletPool.CreateObject(2);
                    animator.SetInteger("ChargeLevel", 0);
                }
                else if (chargeTime >= chargeThreshold / 3.0f)
                {
                    bulletPool.CreateObject(3);
                    animator.SetInteger("ChargeLevel", 0);
                }
                lastShotTime = Time.time;
            }
        }
        else if (animator.GetBool("Shooting") && (Time.time - lastShotTime) >= 1.0f)
        {
            animator.SetBool("Shooting", false);
        }
    }