Ejemplo n.º 1
0
 public MenuButton(Menu menu, int i, string t, Rectangle size)
 {
     sourceMenu = menu;
     id = i;
     text = t;
     dimensions = size;
 }
        private void createMainMenu()
        {
            mainMenu = new Menu(new Viewport(0, vBorder, width, height - 2 * vBorder));

            gameMusic.Stop();
            menuMusic.Play();

            string[] buttons = { "One Player", "Two Player", "Quit" };
            for(int i = 0; i < buttons.Length; i++) {
                int x = width / 2 - 128;
                int y = height / 2 + (i - buttons.Length / 2) * 72;
                mainMenu.controls.Add(new MenuButton(mainMenu, i, buttons[i], new Vector2(x, y)));
            }

            mainMenu.performEvent = delegate(int id) {
                switch(id) {
                    case 0:
                        saveData = new SaveData(numLevels);
                        saveData.readDataFromFile();
                        gameState = GameState.levelSelect;
                        break;
                    case 1:
                        battlefield = new Battlefield(levelData[rand.Next(levelData.length)], new Viewport(0, vBorder, width, height - 2 * vBorder), true);
                        gameState = GameState.inBattle;
                        break;
                    case 2:
                        Exit();
                        break;
                }
            };
        }
Ejemplo n.º 3
0
 public MenuButton(Menu menu, int i, string t, Vector2 pos)
     : this(menu, i, t, new Rectangle((int) pos.X, (int) pos.Y, 256, 64))
 {
 }
        private void createLevelSelectMenu()
        {
            levelMenu = new Menu(new Viewport(0, vBorder, width, height - 2 * vBorder));

            gameMusic.Stop();
            menuMusic.Play();

            levelMenu.controls.Add(new MenuButton(levelMenu, 0, "Back", new Vector2(width/2 - 288, height / 2 - vBorder + 64)));
            levelMenu.controls.Add(new MenuButton(levelMenu, 1, "Go!", new Vector2(width / 2 + 32, height / 2 - vBorder + 64)));
            levelMenu.performEvent = delegate(int id) {
                switch(id) {
                    case 0:
                        gameState = GameState.mainMenu;
                        break;
                    case 1:
                        battlefield = new Battlefield(levelData[selectedLevel], new Viewport(0, vBorder, width, height - 2 * vBorder));
                        if(selectedLevel == 0) tutorial = new Tutorial();
                        gameState = GameState.inBattle;
                        break;
                }
            };
        }