Exemplo n.º 1
0
    private void PlaceGhost()
    {
        akabei = Instantiate(akabeiPrefab, maze.transform);
        akabei.Initialize(maze, pacman);

        pinky = Instantiate(pinkyPrefab, maze.transform);
        pinky.Initialize(maze, pacman);

        aosuke = Instantiate(aosukePrefab, maze.transform);
        aosuke.Initialize(maze, pacman, akabei);

        guzuta = Instantiate(guzutaPrefab, maze.transform);
        guzuta.Initialize(maze, pacman);

        ghosts = new List <AGhost>
        {
            akabei, pinky, aosuke, guzuta
        };

        ghosts.ForEach(g =>
        {
            //ゴーストが食べられたときの処理。
            g.OnEaten += (s, e) =>
            {
                //パックマン、ゴーストを一時停止。
                PauseAll(eatSpan);

                //食べたゴーストの数により、点数が変化する。
                var scr = g.Score * (1 << eatenGhost);
                //得点の更新。
                score         += scr;
                scoreText.text = score.ToString();
                //得点を表示。
                scorer.Set(scr, g.transform.position, eatSpan);

                eatenGhost++;

                soundManager.PlaySE("EatGhost", 0.6f);
            };

            //ゴーストが食べたときの処理。
            g.OnEat += (s, e) =>
            {
                pacman.Dead();
                //ゴーストを停止。
                ghosts.ForEach(g2 => g2.Stop());
                isScare = false;
                lives--;

                if (fruits != null)
                {
                    fruits.Destroy();
                }

                soundManager.PlaySE("Dead", 0.6f);
                soundManager.StopBGM();
            };
        });
    }
Exemplo n.º 2
0
        /// <summary>
        /// Create a new instance of the game by initilizing all game components
        /// </summary>
        public void NewGame()
        {
            // Clear the list of all game components
            this.Components.Clear();

            // Stop all musics
            SoundManager.Instance.StopMusic();
            SoundManager.Instance.StopInvincible();

            // Create new instances of game components
            menu   = new Menu(this, pacDied ? MenuType.GAMEOVER : MenuType.START);
            maze   = new Maze(this);
            blinky = new Blinky(this);
            pinky  = new Pinky(this);
            inky   = new Inky(this);
            clyde  = new Clyde(this);

            pac = new Pac(this, maze);

            // If there was a previous level before this new game, do not reset pac's life
            if (lastPacLife > 0)
            {
                pac.Life = lastPacLife;
            }

            // (Re)-initialize GhostManager
            GhostManager.Instance.Initialize(maze, pac, blinky, new Ghost[] { pinky, inky, clyde });

            // Initialize all game components
            menu.Initialize();
            maze.Initialize();
            blinky.Initialize();
            pinky.Initialize();
            inky.Initialize();
            clyde.Initialize();
            pac.Initialize();

            // Reset pacDied attribute
            pacDied = false;
        }