Exemplo n.º 1
0
	private void Start() {
        jumping = false;
        rigidbody = this.GetComponent<Rigidbody2D>();
        direction = new Vector2();
        attackPhase = AttackPhase.NONE;
        nextAttackPhase = 0.0f;

        flipPhase = FlipPhase.NONE;
        nextFlipPhase = 0.0f;
	}
Exemplo n.º 2
0
	private void Update() {
        if (GameManager.endGame) {
            return;
        }
        if (movingRight) {
            direction.x = 1.0f;
        } else {
            direction.x = -1.0f;
        }

        if (attackPhase == AttackPhase.END && Time.time > nextAttackPhase) {
            speed += normalSpeed * Time.deltaTime;
            if (speed > normalSpeed) {
                speed = normalSpeed;
                attackPhase = AttackPhase.NONE;
            }
        }

        if (flipPhase == FlipPhase.FLIPPLING && Time.time > nextFlipPhase) {
            flipPhase = FlipPhase.NONE;
        }

        if (playerStats.IsDead() == false) {
            if (Input.GetKeyDown(KeyCode.Space) || (Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Began)) {
                action = true;
            }
            else {
                action = false;
            }
        }

        if ((int)attackPhase > 0) {
            if (Time.time > nextAttackPhase) {
                if (attackPhase == AttackPhase.BEGIN) {
					SoundSingleton.Singleton.PlayAttackPlayer ();
                    rigidbody.velocity = new Vector2(0.0f, 0.0f);
                    rigidbody.AddForce(new Vector2(0.0f, -jumpSpeed * 0.8f), ForceMode2D.Impulse);
                    attackPhase = AttackPhase.MIDDLE;
                }
            }
        } else {
            if (action) {
                if (flipPhase == FlipPhase.TOUCHING) {
                    flipPhase = FlipPhase.FLIPPLING;
                    movingRight = !movingRight;

                    Vector3 theScale = transform.localScale;
                    theScale.x *= -1;
                    transform.localScale = theScale;

                    nextFlipPhase = Time.time + 1.0f;
                }
                else if (!jumping) {
                    rigidbody.AddForce(new Vector2(0.0f, jumpSpeed), ForceMode2D.Impulse);
                    jumping = true;
                }
                else {
                    if (attackPhase == AttackPhase.NONE) {
                        attackPhase = AttackPhase.BEGIN;
                        nextAttackPhase = Time.time + 0.05f;
                    }
                }
            }
        }

        if (animator != null) {
            animator.SetBool("movingRight", movingRight);
            animator.SetBool("jumping", jumping);
            animator.SetBool("attacking", (attackPhase == AttackPhase.MIDDLE));
        }
	}
Exemplo n.º 3
0
    void OnCollisionEnter2D(Collision2D coll) {
        if (coll.contacts[0].normal.y == 1.0f) {
            jumping = false;
            if (attackPhase == AttackPhase.MIDDLE) {
                nextAttackPhase = Time.time + 0.1f;
                speed = normalSpeed * 0.5f;

                // Hit the enemy.
                if (coll.gameObject.tag == "Enemy") {
                    Enemy enemy = coll.gameObject.GetComponent<Enemy>();
                    if (enemy != null) {
						SoundSingleton.Singleton.PlaySmashEnemy ();
                        enemy.setLife(enemy.getLife() - 1);
                    }
                }
            }
            attackPhase = AttackPhase.END;
        }

        if (coll.gameObject.tag == "Wall") {
            if (flipPhase == FlipPhase.NONE) {
                flipPhase = FlipPhase.TOUCHING;
            }
        }
    }