예제 #1
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);
            GetHighScore(2);
        }
        else
        {
            playerNum = "1";

            Player1Score = PlayerPrefs.GetInt("Score1");
            Player1Score++;
            PlayerPrefs.SetInt("Score1", Player1Score);
            GetHighScore(1);
        }

        GameManagerBoss gManager = GetComponent <GameManagerBoss>();

        gManager.isPaused = true;

        MyWinText(playerNum);

        StartCoroutine(UiHandler());
    }
    void FixedUpdate()
    {
        if (GameManagerBoss.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;
    }
예제 #3
0
    /*
     *
     * Public functions
     *
     */

    public void TakeDamage(int damage)
    {
        playerHealth.AdjustCurrentHealth(-damage);
        if (playerHealth.curHealth <= 20 && !burnParticles.isPlaying)
        {
            burnParticles.Play();
        }

        if (playerHealth.curHealth == 0 && !GameManagerBoss.isGamePaused())
        {
            //GameOver
            animator.SetBool("isMoving", false);
            animator.SetBool("isKilled", true);
            explodeParticles.Play();
            gameManager.FinishGame(SecondPlayer);
            soundManager.PlayDeath();
        }
        else
        {
            soundManager.PlayHurt();
        }
    }
    /*
     *
     * Public functions
     *
     */

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

        Debug.Log(current);

        playerHealth.AdjustCurrentHealth(-damage);

        current -= damage;


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

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

        if (playerHealth.curHealth == 0 && !GameManagerBoss.isGamePaused())
        {
            //GameOver
            animator.SetBool("isMoving", false);
            animator.SetBool("isKilled", true);
            explodeParticles.Play();
            gameManager.FinishGame(SecondPlayer);
            soundManager.PlayDeath();
        }
        else
        {
            soundManager.PlayHurt();
        }
    }
예제 #5
0
 public void Awake()
 {
     anim   = GetComponent <Animator>();
     game   = FindObjectOfType <GameManagerBoss>();
     target = FindObjectOfType <HeroOnBoss>();
 }
예제 #6
0
    void FixedUpdate()
    {
        if (GameManagerBoss.isGamePaused())
        {
            return;
        }

        transform.Translate(Vector3.up * Time.deltaTime * patrolSpeed);

        if (Vector3.Distance(transform.position, currentPatrolPoint.position) < 0.1f)
        {
            soundManager.PlayRide();
            animator.SetBool("isMoving", true);
            if (currentPatrolIndex + 1 < patrolPoints.Length)
            {
                currentPatrolIndex++;
            }
            else
            {
                currentPatrolIndex = 0;
            }

            currentPatrolPoint = patrolPoints[currentPatrolIndex];
        }

        Vector2    localUp        = new Vector2(transform.up.x, transform.up.y);
        Vector3    patrolPointDir = currentPatrolPoint.position - transform.position;
        float      angle          = Mathf.Atan2(patrolPointDir.y, patrolPointDir.x) * Mathf.Rad2Deg - 90;
        Quaternion q = Quaternion.AngleAxis(angle, Vector3.forward);

        transform.rotation = Quaternion.RotateTowards(transform.rotation, q, 180f);
        SetupParticles(1);

        float distanceToTarget = Vector3.Distance(transform.position, target.position);

        if (distanceToTarget < chaseRange)
        {
            Vector3    targetDir = (target.position - transform.position).normalized;
            float      angleE    = Mathf.Atan2(targetDir.y, targetDir.x) * Mathf.Rad2Deg - 90f;
            Quaternion q2        = Quaternion.AngleAxis(angleE, Vector3.forward);
            transform.rotation = Quaternion.RotateTowards(transform.rotation, q2, 180f);
            transform.Translate(Vector3.up * Time.deltaTime * chaseSpeed);

            timer += Time.deltaTime;

            float distanceToPlayer = Vector3.Distance(transform.position, target.position);
            if (distanceToPlayer < attackRange)
            {
                Vector3    targetDir2 = target.position - transform.position;
                float      angleShoot = Mathf.Atan2(targetDir2.y, targetDir2.x) * Mathf.Rad2Deg - 90f;
                Quaternion q3         = Quaternion.AngleAxis(angleShoot, Vector3.forward);
                transform.rotation = Quaternion.RotateTowards(transform.rotation, q3, 180f);

                int shoot = 1;
                if (shoot != 0 && timer >= ReloadSpeed)
                {
                    RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.up, attackRange);
                    Shoot(localUp);
                }
            }
        }
    }
예제 #7
0
 public void Awake()
 {
     hero = FindObjectOfType <HeroOnBoss>();
     gm   = FindObjectOfType <GameManagerBoss>();
 }