コード例 #1
0
 public override void Update(GameTime gameTime)
 {
     base.Update(gameTime);
     foreach (LevelButton button in levelButtons)
     {
         if (button.Status != PenguinPairs.GetLevelStatus(button.LevelIndex))
         {
             button.Status = PenguinPairs.GetLevelStatus(button.LevelIndex);
         }
     }
 }
コード例 #2
0
    public LevelMenuState()
    {
        // add a background
        SpriteGameObject background = new SpriteGameObject("Sprites/spr_background_levelselect");

        gameObjects.AddChild(background);

        // add a back button
        backButton = new Button("Sprites/UI/spr_button_back");
        backButton.LocalPosition = new Vector2(415, 720);
        gameObjects.AddChild(backButton);

        // Add a level button for each level.
        // For now, let's pretend that there are 12 levels, without actually loading them yet.
        int numberOfLevels = 12;

        levelButtons = new LevelButton[numberOfLevels];

        Vector2   gridOffset          = new Vector2(155, 230);
        const int buttonsPerRow       = 5;
        const int spaceBetweenColumns = 30;
        const int spaceBetweenRows    = 5;

        for (int i = 0; i < PenguinPairs.NumberOfLevels; i++)
        {
            // create the button
            LevelButton levelButton = new LevelButton(i + 1, PenguinPairs.GetLevelStatus(i + 1));

            // give it the correct position
            int row    = i / buttonsPerRow;
            int column = i % buttonsPerRow;

            levelButton.LocalPosition = gridOffset + new Vector2(
                column * (levelButton.Width + spaceBetweenColumns),
                row * (levelButton.Height + spaceBetweenRows)
                );

            // add the button as a child object
            gameObjects.AddChild(levelButton);
            // also store it in the array of level buttons
            levelButtons[i] = levelButton;
        }
    }