Exemple #1
0
 private void Update()
 {
     if (!isInGame)
     {
         if (ControlSelecter.activeSelf)
         {
             if (ActionInputController.getStartButton())
             {
                 isJoystick = true;
                 RightSelected.SetActive(true);
                 LeftSelected.SetActive(false);
                 fadeAnim.SetBool("isFadeOut", true);
                 StartCoroutine(TransitionFade());
                 ControlSelecter.SetActive(false);
                 aboutJoy.SetActive(true);
                 aboutKeyboard.SetActive(false);
             }
             else if (Input.GetKeyDown(KeyCode.Space))
             {
                 isJoystick = false;
                 RightSelected.SetActive(false);
                 LeftSelected.SetActive(true);
                 fadeAnim.SetBool("isFadeOut", true);
                 StartCoroutine(TransitionFade());
                 ControlSelecter.SetActive(false);
                 aboutJoy.SetActive(false);
                 aboutKeyboard.SetActive(true);
             }
         }
         else
         {
             if (isJoystick)
             {
                 if (ActionInputController.getBackButton())
                 {
                     isJoystick = false;
                     ControlSelecter.SetActive(true);
                     aboutJoy.SetActive(false);
                     aboutKeyboard.SetActive(false);
                 }
                 if (ActionInputController.getStartButton())
                 {
                     ControlSelecter.SetActive(false);
                     aboutJoy.SetActive(false);
                     aboutKeyboard.SetActive(false);
                     isGameStart = true;
                     isInGame    = true;
                 }
             }
             else
             {
                 if (Input.GetKeyDown(KeyCode.Backspace))
                 {
                     isJoystick = false;
                     ControlSelecter.SetActive(true);
                     aboutJoy.SetActive(false);
                     aboutKeyboard.SetActive(false);
                 }
                 if (Input.GetKeyDown(KeyCode.Space))
                 {
                     ControlSelecter.SetActive(false);
                     aboutJoy.SetActive(false);
                     aboutKeyboard.SetActive(false);
                     isGameStart = true;
                     isInGame    = true;
                 }
             }
         }
     }
     if (isGameStart)
     {
         if (progress1.totalProgress >= 100)
         {
             showText.text        = "Player1 is a winner!!!";
             isGameStart          = false;
             progresser1.isWinner = true;
             isGameEnd            = true;
         }
         if (progress2.totalProgress >= 100)
         {
             showText.text        = "Player2 is a winner!!!";
             isGameStart          = false;
             progresser2.isWinner = true;
             isGameEnd            = true;
         }
         if (progress1.totalProgress >= 100 && progress2.totalProgress >= 100)
         {
             showText.text        = "Draw";
             isGameStart          = false;
             progresser1.isWinner = true;
             progresser2.isWinner = true;
             isGameEnd            = true;
         }
     }
     if (isGameEnd)
     {
         if (Input.GetKeyDown(KeyCode.Space))
         {
             SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
         }
         else if (Input.GetKeyDown(KeyCode.Backspace))
         {
             SceneManager.LoadScene(0);
         }
         endGane.SetActive(true);
     }
     else
     {
         endGane.SetActive(false);
     }
     if (Input.GetKeyDown(KeyCode.Escape))
     {
         Application.Quit();
     }
 }
Exemple #2
0
    private void FixedUpdate()
    {
        if (gameController.isGameStart)
        {
            bubble.SetActive(!inventory.isSlotAvilable);
            if (isHaveStatus)
            {
                if (DurationStatus > 0)
                {
                    DurationStatus -= Time.deltaTime;
                }
                else
                {
                    restoreStatus();
                    PlayerAnim.SetBool("isKnockDown", isStun);
                }
            }
            if (!isStun)
            {
                Vector2 movement = ActionInputController.getMovement(PlayerOrder, gameController.isJoystick) * speed;
                PlayerAnimation(movement.x, movement.y);
                if (!punching)
                {
                    myRig.velocity = movement;
                }
                else
                {
                    myRig.velocity = Vector2.zero;
                }
                ArrowDirection = ActionInputController.getAim(PlayerOrder, gameController.isJoystick);
                float angle = Mathf.Atan2(-ArrowDirection.y, ArrowDirection.x);
                angle *= Mathf.Rad2Deg;

                if (ActionInputController.getPunchButton(PlayerOrder, gameController.isJoystick))
                {
                    if (!punching)
                    {
                        Punch();
                    }
                }
                Item use = null;
                use = inventory.useItem();
                if (use != null)
                {
                    if (use.UseType == ItemUsedType.AttackAim)
                    {
                        ArrowObj.SetActive(true);
                        ArrowObj.transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));
                    }
                    else
                    {
                        ArrowObj.SetActive(false);
                    }
                }
                else
                {
                    ArrowObj.SetActive(false);
                }
                if (ActionInputController.getUseButton1(PlayerOrder, gameController.isJoystick) || ActionInputController.getUseButton2(PlayerOrder))
                {
                    if (use != null)
                    {
                        switch (use.UseType)
                        {
                        case ItemUsedType.Attack:
                            if (effectChecking.targetObject != null)
                            {
                                use.UseItem(effectChecking.targetObject);
                                switch (use.objItem)
                                {
                                case gameItem.chair:
                                    effectAnim.SetTrigger("ChairSmash");
                                    audioSource.PlayOneShot(hit);
                                    break;

                                case gameItem.keyboard:
                                    effectAnim.SetTrigger("KeybordeSmash");
                                    audioSource.PlayOneShot(glass);
                                    break;
                                }
                                inventory.removeItem();
                            }
                            else if (progressChecker.targetObject != null)
                            {
                                if (progressChecker.targetObject.GetComponent <Progresser>().playerOrder != PlayerOrder)
                                {
                                    use.UseItem(progressChecker.targetObject);
                                    switch (use.objItem)
                                    {
                                    case gameItem.chair:
                                        audioSource.PlayOneShot(hit);
                                        effectAnim.SetTrigger("ChairSmash");
                                        break;

                                    case gameItem.keyboard:
                                        audioSource.PlayOneShot(glass);
                                        effectAnim.SetTrigger("KeybordeSmash");
                                        break;
                                    }
                                    inventory.removeItem();
                                }
                            }
                            break;

                        case ItemUsedType.AttackAim:
                            if (ArrowDirection.x != 0 || ArrowDirection.y != 0)
                            {
                                use.UseItem(ArrowDirection, this.gameObject);
                                inventory.removeItem();
                            }
                            break;

                        case ItemUsedType.Boots:
                            if (progressChecker.targetObject != null)
                            {
                                use.UseItem(progressChecker.targetObject);
                                inventory.removeItem();
                            }
                            break;

                        default:
                            break;
                        }
                    }
                }
                if (ActionInputController.getCollectButton(PlayerOrder, gameController.isJoystick) && pickupObj != null)
                {
                    Item pick = pickupObj.GetComponent <Item>();
                    pick.Pickup(this.gameObject);
                    if (pick.isSpecial)
                    {
                        gameController.isSpecialEmpty[pick.onIndex] = true;
                    }
                    else if (pick.isOnRedBull)
                    {
                        gameController.isRedbullEmpty[pick.onIndex] = true;
                    }
                    else
                    {
                        gameController.isCommonEmpty[pick.onIndex] = true;
                    }
                }
                if (ActionInputController.getDiscardButton(PlayerOrder, gameController.isJoystick))
                {
                    inventory.removeItem();
                    Item    used       = inventory.useItem();
                    Vector3 spawnPoint = transform.position;
                    if (used != null)
                    {
                        switch (used.objItem)
                        {
                        case gameItem.artAsset:
                            Instantiate(gameController.otherSpecial[0], spawnPoint, Quaternion.identity);
                            break;

                        case gameItem.chair:
                            Instantiate(gameController.commonObject[0], spawnPoint, Quaternion.identity);
                            break;

                        case gameItem.ice:
                            Instantiate(gameController.commonObject[1], spawnPoint, Quaternion.identity);
                            break;

                        case gameItem.keyboard:
                            Instantiate(gameController.commonObject[2], spawnPoint, Quaternion.identity);
                            break;

                        case gameItem.penpad:
                            Instantiate(gameController.commonObject[3], spawnPoint, Quaternion.identity);
                            break;

                        case gameItem.redbull:
                            Instantiate(gameController.otherSpecial[2], spawnPoint, Quaternion.identity);
                            break;

                        case gameItem.usb:
                            Instantiate(gameController.otherSpecial[1], spawnPoint, Quaternion.identity);
                            break;

                        case gameItem.virus:
                            Instantiate(gameController.otherSpecial[3], spawnPoint, Quaternion.identity);
                            break;
                        }
                    }
                }
                if (punching)
                {
                    if (punchTimer > 0)
                    {
                        punchTimer -= Time.deltaTime;
                    }
                    else
                    {
                        punching   = false;
                        punchTimer = 0;
                        PlayerAnim.SetBool("isPunch", punching);
                    }
                }
            }
            else
            {
                myRig.velocity = new Vector2(0, 0);
                PlayerAnim.SetBool("isKnockDown", isStun);
            }
        }
    }