예제 #1
0
    public void InitGame()
    {
        soundsController.PlaySound(SoundsController.Type.Click);

        initUI.SetActive(false);
        musicController.StartGame();

        lifeTime   = 0;
        starsCount = 0;
        timer.SetActive(true);

        Destroy(starsParent.gameObject);

        starsParent        = (new GameObject("StarsParent")).transform;
        starsParent.parent = this.transform;

        stars.Clear();

        player = Instantiate(playerPrefab, starsParent) as CharacterStarController;
        player.Init(Vector3.zero, startMass);
        player.onDead += PlayerDead;
        player.onEat  += () =>
        {
            soundsController.PlaySound(SoundsController.Type.Eat);
            starsCount++;
        };

        cameraFollower.Init(player);
    }
예제 #2
0
 /// <summary>
 ///     Play the hit sound if we have one
 /// </summary>
 void playGenericHitSound()
 {
     if (genericHitSound.sound)
     {
         genericHitSound.PlaySound(position: transform.position);
     }
 }
예제 #3
0
    //  int j = 0;
    public void OnMouseUp()
    {
        transform.localScale = a;


        {
            if (bt == ButtonType.btnGearPressSound && j == 0)
            {
                Debug.Log("SoundOff");
                myani.SetTrigger("GearSoundOff"); j = 1;
                ScoreManage.checksound = false;
            }
            else
            {
                if (bt == ButtonType.btnGearPressSound && j == 1)
                {
                    Debug.Log("SoundOn");
                    myani.SetTrigger("GearSoundOn"); j = 0; ScoreManage.checksound = true;
                    SoundsController.PlaySound(soundsGame.onsound);
                }
            }

            if (bt == ButtonType.btnGearOpen && i == 1)
            {
                Debug.Log("Hide Bar");
                myani.SetTrigger("GearNor"); i = 0;
            }
            else
            {
                if (bt == ButtonType.btnGearOpen && i == 0 && ScoreManage.checksound == true)
                {
                    Debug.Log("OpenBar");
                    myani.SetTrigger("GearOpen"); i = 1;
                }
                else
                if (bt == ButtonType.btnGearOpen && i == 0 && ScoreManage.checksound == false)
                {
                    Debug.Log("OpenSoundOff");
                    myani.SetTrigger("GearOpenSoundOff"); i = 1; j = 1;
                }
            }
            if (bt == ButtonType.btnDel)
            {
                Delete.SetActive(true);
                Debug.Log("Del");
            }
        }

        if (bt == ButtonType.btnExit)
        {
            Application.Quit();
            Debug.Log("Exit");
        }
        if (bt == ButtonType.btnAbout)
        {
            Debug.Log("About");
            About.SetActive(true);
        }
    }
예제 #4
0
 //phân biệt ống để ghi điểm hay chết
 void OnTriggerEnter2D(Collider2D col)
 {
     if (GameStateManager.GameState == GameState.Playing)
     {
         if (col.gameObject.tag == "Point") // lấy những colider đc phân biệt bởi tag
         {
             SoundsController.PlaySound(soundsGame.point);
             ScoreManage.Score++;
             TreeMoving.MoveSpeed += Time.deltaTime;
         }
     }
 }
 /// <summary>
 ///     Plays the reload sound
 /// </summary>
 void playReloadSound()
 {
     if (reloadSound.sound)
     {
         reloadSound.PlaySound(transform.position);
     }
     else
     {
         if (showLogs)
         {
             Debug.LogError("There is no reload sound for " + gameObject.name);
         }
     }
 }
 /// <summary>
 ///     Play the shooting sound
 /// </summary>
 void playShootSound()
 {
     if (shootingSound.sound)
     {
         shootingSound.PlaySound(muzzleArea.transform.position);
     }
     else
     {
         if (showLogs)
         {
             Debug.LogError("There is no shoot sound for " + gameObject.name);
         }
     }
 }
예제 #7
0
 void FlappyDies()
 {
     scoreoffend.SetActive(false);
     SoundsController.PlaySound(soundsGame.die);
     SoundsController.PlaySound(soundsGame.hit);
     TreeMoving.MoveSpeed       = 0;
     TreeMoving.movey           = 0;
     GrassMoving.MoveSpeed      = 0;
     BackgroundMoving.MoveSpeed = 0;
     GameStateManager.GameState = GameState.Dead;
     myani.SetTrigger("BirdDie");
     DeathGUI.SetActive(true);
     menu.SetActive(true);
     cam.SetTrigger("CamDie");
     GetComponent <Rigidbody2D>().gravityScale = 1.2f;
     XuliHighScore();
 }
 /// <summary>
 ///     Play the empty bullet sound
 /// </summary>
 void PlayEmptySound()
 {
     if (emptySound.sound)
     {
         if (firecount == 0)
         {
             emptySound.PlaySound(muzzleArea.transform.position);
             firecount++;
         }
     }
     else
     {
         if (showLogs)
         {
             Debug.LogError("There is no empty sound for " + gameObject.name);
         }
     }
 }
예제 #9
0
 void XuliHighScore()
 {
     {
         if (ScoreManage.Score > int.Parse(d10.GetComponent <Text>().text))
         {
             HC._instance.SaveHighScore(Button.N, ScoreManage.Score); highscore = HC._instance.GetHighScore();
             SoundsController.PlaySound(soundsGame.cheer);
             high.SetActive(true);
             if (ScoreManage.Score >= int.Parse(d1.GetComponent <Text>().text))
             {
                 up.SetActive(true);
                 HighScore.ScoreBest = ScoreManage.Score;
                 Hbc.SetActive(true);
                 {
                     UploadHC();
                     Destroy(up, 2);
                 }
             }
             else
             {
                 HighScore.ScoreBest = highscore[0].score;
                 Hc.SetActive(true);
             }
         }
         else
         {
             if (ScoreManage.Score == 0 && checkreset.checkrss == 1)
             {
                 GameOver.SetActive(true);
                 HighScore.ScoreBest = 0;
                 Debug.Log("RESET"); checkreset.checkrss = 0;
             }
             else
             {
                 GameOver.SetActive(true);
                 HighScore.ScoreBest = highscore[0].score;
             }
         }
     }
 }
예제 #10
0
    // Use this for initialization
//	void Start ()
//	{
//
//	}

    // Update is called once per frame
    void Update()
    {
        if (CurrentGameState == EGameState.MainMenu)
        {
#if UNITY_ANDROID
            if (Input.GetMouseButtonUp(0))
#else
            if (Input.GetKeyDown("space"))
#endif

            {
                CurrentGameState = EGameState.Transition;
                Transition.StartFade(
                    () => {
                    MainMenuPanel.SetActive(false);
                    CreditsPanel.SetActive(false);
                    InGamePanel.SetActive(true);
                    StartNewGame();
                },
                    null
                    );
            }
            else if (Input.GetKey(KeyCode.Escape))
            {
                CurrentGameState = EGameState.Transition;
                Transition.StartFade(
                    () => {
                    MainMenuPanel.SetActive(false);
                    CreditsPanel.SetActive(true);
                    InGamePanel.SetActive(false);
                    CurrentGameState = EGameState.Credits;
                    //Application.Quit();
                },
                    null
                    );
            }
        }

        if (CurrentGameState == EGameState.Credits)
        {
#if UNITY_ANDROID
            if (Input.GetMouseButtonUp(0))
#else
            if (Input.GetKeyDown("space"))
#endif

            {
                CurrentGameState = EGameState.Transition;
                Transition.StartFade(
                    () => {
                    MainMenuPanel.SetActive(false);
                    CreditsPanel.SetActive(false);
                    InGamePanel.SetActive(true);
                    StartNewGame();
                },
                    null
                    );
            }
            else if (Input.GetKey(KeyCode.Escape))
            {
                CurrentGameState = EGameState.Transition;
                Transition.StartFade(
                    () => {
                    Application.Quit();
                },
                    null
                    );
            }
        }

        if (CurrentGameState == EGameState.GamePlay)
        {
            if (TimeLeft < 0f)
            {
                TimeLeft = 0f;

                GameOverText.gameObject.SetActive(true);
                gameOverPanel.gameObject.SetActive(true);
#if UNITY_ANDROID
                GameOverText.text = "GAME OVER\nPathetic lives ruined: " + Score.ToString() + "\nTime wasted: " + ((int)TimePlayed).ToString() + "s\nTap to try again";
#else
                GameOverText.text = "GAME OVER\nPathetic lives ruined: " + Score.ToString() + "\nTime wasted: " + ((int)TimePlayed).ToString() + "s\nPress SPACE to try again";
#endif
                MoreBuildingsIndicator.gameObject.SetActive(false);
                HideTutorial();

                // if tutorial wasn't finished, reset progress
                CurrentGameState      = EGameState.GameOver;
                CameraManager.enabled = false;
                CurrentFloor.Reveal(false);
                timerContainer.SetActive(false);
                timerAnimation.Stop();

                Sounds.PlaySound(ESoundType.GameOver);
                Music.PlayMusic(EMusicType.GameOver);
            }
            else
            {
                if (!IsFirstGame)
                {
                    TimeLeft -= Time.deltaTime;
                }
                TimePlayed += Time.deltaTime;

                if (TimeLeft < animateClockWhenSecondsLeft)
                {
                    timerAnimation.Play();
                    timerAnimation["ClockBeat"].speed = MAX_CLOCK_ANIMATION_SPEED * (1 - (TimeLeft / animateClockWhenSecondsLeft));
                }

                if (TimeLeft < TIME_LEFT_FAST_MUSIC_TRESHOLD)
                {
                    Music.PlayMusic(EMusicType.FastGameplay);
                }
                else
                {
                    if (IsFirstGame)
                    {
                        Music.PlayMusic(EMusicType.TutorialIntro);
                    }
                    else
                    {
                        Music.PlayMusic(EMusicType.Gameplay);
                    }
                }

                if (moreBuildingsIndicatorShown)
                {
                    moreBuildingsIndicatorTimer -= Time.deltaTime;
                    if (moreBuildingsIndicatorTimer < 0)
                    {
                        moreBuildingsIndicatorShown = false;
                        MoreBuildingsIndicator.gameObject.SetActive(false);
                    }
                }
            }
//			Timer.text = "Time Left: " + ((int)TimeLeft).ToString() + "s";
            Timer.text       = ((int)TimeLeft).ToString();
            timer.fillAmount = TimeLeft / TIME_LEFT;

#if UNITY_ANDROID
            // swipe detection source: http://pfonseca.com/swipe-detection-on-unity/
            if (Input.touchCount > 0)
            {
                foreach (Touch touch in Input.touches)
                {
                    switch (touch.phase)
                    {
                    case TouchPhase.Began:
                        /* this is a new touch */
                        isSwipe         = true;
                        fingerStartTime = Time.time;
                        fingerStartPos  = touch.position;
                        break;

                    case TouchPhase.Canceled:
                        /* The touch is being canceled */
                        isSwipe = false;
                        break;

                    case TouchPhase.Ended:

                        float gestureTime = Time.time - fingerStartTime;
                        float gestureDist = (touch.position - fingerStartPos).magnitude;

                        bool realSwipe = false;
                        if (isSwipe && gestureTime < maxSwipeTime && gestureDist > minSwipeDist)
                        {
                            Vector2 direction = touch.position - fingerStartPos;
                            Vector2 swipeType = Vector2.zero;

                            if (Mathf.Abs(direction.x) > Mathf.Abs(direction.y))
                            {
                                // the swipe is horizontal:
                                swipeType = Vector2.right * Mathf.Sign(direction.x);
                            }
                            else
                            {
                                // the swipe is vertical:
                                swipeType = Vector2.up * Mathf.Sign(direction.y);
                            }

                            if (swipeType.x != 0.0f)
                            {
                                if (swipeType.x > 0.0f)
                                {
                                    realSwipe = true;
                                    CameraManager.GoTo(Dir.W);
                                }
                                else
                                {
                                    realSwipe = true;
                                    CameraManager.GoTo(Dir.E);
                                }
                            }

                            if (swipeType.y != 0.0f)
                            {
                                if (swipeType.y > 0.0f)
                                {
                                    realSwipe = true;
                                    CameraManager.GoTo(Dir.S);
                                }
                                else
                                {
                                    realSwipe = true;
                                    CameraManager.GoTo(Dir.N);
                                }
                            }
                        }
                        if (!realSwipe && GetCurrentTapType() == EAndroidTapType.Middle)
                        {
                            ObjectInteraction();
                        }

                        break;
                    }
                }
            }
#else
            if (Input.GetKeyDown("space"))
            {
                ObjectInteraction();
            }
#endif
            if (Input.GetKey(KeyCode.Escape))
            {
                CurrentGameState = EGameState.Transition;

                Music.PlayMusic(EMusicType.TitleScreen);
                Transition.StartFade(
                    () => {
                    CurrentGameState = EGameState.MainMenu;
                    MainMenuPanel.SetActive(true);
                    CreditsPanel.SetActive(false);
                    InGamePanel.SetActive(false);
                },
                    null
                    );
            }
        }

        else if (CurrentGameState == EGameState.GameOver)
        {
#if UNITY_ANDROID
            if (Input.GetMouseButtonUp(0))
#else
            if (Input.GetKey("space"))
#endif
            {
                CurrentGameState = EGameState.Transition;
                Transition.StartFade(
                    () => {
                    StartNewGame();
                },
                    null
                    );
            }
            else if (Input.GetKey(KeyCode.Escape))
            {
                CurrentGameState = EGameState.Transition;

                Music.PlayMusic(EMusicType.TitleScreen);
                Transition.StartFade(
                    () => {
                    CurrentGameState = EGameState.MainMenu;
                    MainMenuPanel.SetActive(true);
                    CreditsPanel.SetActive(false);
                    InGamePanel.SetActive(false);
                },
                    null
                    );
            }
        }
    }
예제 #11
0
 void BoostOnYAxis()
 {
     GetComponent <Rigidbody2D>().velocity = new Vector2(0, VelocityPerJump);
     SoundsController.PlaySound(soundsGame.wing);
 }