Exemplo n.º 1
0
    /*
     *
     * Public functions
     *
     */

    public void TakeDamage(int damage)
    {
        int current = playerHealth.curHealth;

        Debug.Log(current);
        playerHealth.AdjustCurrentHealth(-damage);
        current -= damage;

        if (current >= 30 && burnParticles.isPlaying)
        {
            // playerHealth.curHealth = current;
            burnParticles.Stop();
        }

        if (current <= 20 && !burnParticles.isPlaying)
        {
            //playerHealth.curHealth = current;
            burnParticles.Play();
        }

        if (playerHealth.curHealth == 0 && !GameManagerSnow.isGamePaused())
        {
            //GameOver
            animator.SetBool("isMoving", false);
            animator.SetBool("isKilled", true);
            explodeParticles.Play();
            gameManager.FinishGame(SecondPlayer);
            soundManager.PlayDeath();
        }
        else
        {
            soundManager.PlayHurt();
        }
    }
Exemplo n.º 2
0
    public void FinishGame(bool firstPlayerWin)
    {
        isGameBegan = false;
        isPaused    = true;

        string playerNum;

        if (!firstPlayerWin)
        {
            playerNum = "2";

            Player2Score = PlayerPrefs.GetInt("Score2");
            Player2Score++;
            PlayerPrefs.SetInt("Score2", Player2Score);
        }
        else
        {
            playerNum = "1";

            Player1Score = PlayerPrefs.GetInt("Score1");
            Player1Score++;
            PlayerPrefs.SetInt("Score1", Player1Score);
        }
        GameManagerSnow gManager = GetComponent <GameManagerSnow>();

        gManager.isPaused = true;

        MyWinText(playerNum);

        StartCoroutine(UiHandler());
    }
Exemplo n.º 3
0
    void FixedUpdate()
    {
        if (GameManagerSnow.isGamePaused())
        {
            return;
        }

        float vertical   = Input.GetAxisRaw(vAxisName);
        float horizontal = Input.GetAxisRaw(hAxisName);
        float shoot      = Input.GetAxisRaw(attackAxisName);

        Vector2 localUp = new Vector2(transform.up.x, transform.up.y);

        if (vertical != 0)
        {
            Vector2 engineForce = Vector2.Lerp(Vector2.zero, localUp * vertical * MaximalSpeed, Velocity * Time.deltaTime);
            rb.AddForce(engineForce);
            soundManager.PlayRide();
            animator.SetBool("isMoving", true);
        }
        else
        {
            animator.SetBool("isMoving", false);
        }

        SetupParticles(vertical);

        Vector2 velocityVector = rb.velocity.normalized;
        float   dot            = Vector2.Dot(velocityVector, localUp);

        if (horizontal != 0)
        {
            if (dot < 0 && rb.velocity.magnitude > 0 && vertical < 0)
            {
                rb.MoveRotation(rb.rotation + RotationSpeed * horizontal);
            }
            else
            {
                rb.MoveRotation(rb.rotation - RotationSpeed * horizontal);
            }
        }


        if ((dot != 1) && (dot != -1) && (velocityVector.magnitude != 0))
        {
            rb.velocity = Vector2.Lerp(rb.velocity, localUp * dot * rb.velocity.magnitude, FrictionScale * Time.deltaTime);
        }

        if (shoot != 0 && timer >= ReloadSpeed)
        {
            Shoot(localUp);
        }

        timer += Time.deltaTime;
    }