示例#1
0
    private void CreatePower <T>()
    {
        BasePower newPower;

        if (typeof(T) == typeof(Food))
        {
            newPower = new Food(this);
        }
        else if (typeof(T) == typeof(Laxative))
        {
            newPower = new Laxative(this);
        }
        else if (typeof(T) == typeof(SpeedUp))
        {
            newPower = new SpeedUp(this);
        }
        else if (typeof(T) == typeof(DoublePoints))
        {
            newPower = new DoublePoints(this);
        }
        else if (typeof(T) == typeof(BeakOfSteel))
        {
            newPower = new BeakOfSteel(this);
        }
        else if (typeof(T) == typeof(Constipation))
        {
            newPower = new Constipation(this);
        }
        else if (typeof(T) == typeof(RottenFood))
        {
            newPower = new RottenFood(this);
        }
        else
        {
            newPower = new Food(this);
        }
        _powerUpLayer.AddChild(newPower);
        newPower.SetXY(Utils.Random(100, MyGame.OldX() - 100), Utils.Random(newPower.height / 2, MyGame.OldY() - newPower.height / 2) - game.height * 2);
    }
    void SetupGame(Boolean reset)
    {
        // Reset the game if the user goes back to the main menu, else advance to the next level.
        if (reset)
        {
            died = false;
            won  = false;
            playerObject.Reset(true);

            if (level < 3)
            {
                ghost1.Reset(true);
            }
            else if (level < 5)
            {
                ghost1.Reset(true);
                ghost2.Reset(true);

                ghost2.gameObject.SetActive(false);
            }
            else if (level < 7)
            {
                ghost1.Reset(true);
                ghost2.Reset(true);
                ghost3.Reset(true);

                ghost2.gameObject.SetActive(false);
                ghost3.gameObject.SetActive(false);
            }
            else
            {
                ghost1.Reset(true);
                ghost2.Reset(true);
                ghost3.Reset(true);
                ghost4.Reset(true);

                ghost2.gameObject.SetActive(false);
                ghost3.gameObject.SetActive(false);
                ghost4.gameObject.SetActive(false);
            }
            level = 1;
        }
        else
        {
            level++;
            won  = false;
            died = false;
            playerObject.Reset(false);

            if (level == 3)
            {
                ghost2.gameObject.SetActive(true);
                ghost2.Start();
            }
            else if (level == 5)
            {
                ghost3.gameObject.SetActive(true);
                ghost3.Start();
            }
            else if (level == 7)
            {
                ghost4.gameObject.SetActive(true);
                ghost4.Start();
            }

            if (level < 3)
            {
                ghost1.Reset(false);
            }
            else if (level < 5)
            {
                ghost1.Reset(false);
                ghost2.Reset(false);
            }
            else if (level < 7)
            {
                ghost1.Reset(false);
                ghost2.Reset(false);
                ghost3.Reset(false);
            }
            else
            {
                ghost1.Reset(false);
                ghost2.Reset(false);
                ghost3.Reset(false);
                ghost4.Reset(false);
            }
        }


        foreach (var pellet in pellets)
        {
            Pellet pelletObject = pellet.GetComponent <Pellet>();
            pelletObject.Start();
        }

        foreach (var powerup in powerups)
        {
            Powerup powerupObject = powerup.GetComponent <Powerup>();
            powerupObject.Start();
        }

        foreach (var speedup in speedups)
        {
            SpeedUp speedupObject = speedup.GetComponent <SpeedUp>();
            speedupObject.Start();
        }

        foreach (var doublepoint in doublepoints)
        {
            DoublePoints doublepointObject = doublepoint.GetComponent <DoublePoints>();
            doublepointObject.Start();
        }
    }