Beispiel #1
0
 /// <summary>
 /// Switches the state to a menu
 /// </summary>
 /// <param name="menu">Menu to switch to</param>
 public static void Menu(Menu menu)
 {
     menu.Reset();
     GetInstance().engineState = new MenuState(menu);
     SoundManager.PlaySong(menu.title);
 }
Beispiel #2
0
 public MenuState(Menu menu)
 {
     this.menu = menu;
 }
Beispiel #3
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            Vector2 screenSize = new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);

            // engine intialization

            GameAction skip = new GameAction(
              null,
              Level.GetInstance().GetType().GetMethod("NextLevel"),
              new object[0]);
            InputManager.AddToKeyboardMap(Keys.I, skip);

            Dictionary<string, string> gameFiles = new Dictionary<string, string>();
            gameFiles.Add("playersFile", "");
            gameFiles.Add("itemsFile", "");
            gameFiles.Add("blocksFile", "");
            gameFiles.Add("enemiesFile", "");
            gameFiles.Add("levelsFile", "");

            StreamReader reader = new StreamReader("Content/LRE_game.txt");
            rootPath = reader.ReadLine().Split(delimeter, StringSplitOptions.RemoveEmptyEntries)[1] + "/";
            Content.RootDirectory = rootPath;
            while (reader.Peek() >= 0)
            {
                string[] line = reader.ReadLine().Split(delimeter, StringSplitOptions.RemoveEmptyEntries);
                if(gameFiles.ContainsKey(line[0]))
                {
                    gameFiles[line[0]] = rootPath + line[1];
                }
            }

            // sound initialization
            //SoundManager.effects.Add("playerHit", Content.Load<SoundEffect>("RecievedDamage"));
            //SoundManager.effects.Add("itemCollected", Content.Load<SoundEffect>("ObtainedItem"));
            //SoundManager.effects.Add("playerDied", Content.Load<SoundEffect>("Death"));
            //SoundManager.effects.Add("itemUsed", Content.Load<SoundEffect>("UsedItem"));
            //SoundManager.effects.Add("doorUnlocked", Content.Load<SoundEffect>("UnlockADoor"));
            //SoundManager.songs.Add("mainMenu", Content.Load<Song>("StartScreenAudioLoop"));
            //SoundManager.songs.Add("winLevelMenu", Content.Load<Song>("LevelCompleteSplash"));
            //SoundManager.songs.Add("winGameMenu", Content.Load<Song>("YouWin(thegame)"));
            //SoundManager.songs.Add("dieMenu", Content.Load<Song>("YouHaveDiedSplash"));
            //SoundManager.songs.Add("game", Content.Load<Song>("Kalimba(InGameAudio)"));

            // player manager intialization
            PlayerManager.AddPlayer(Content.Load<Texture2D>("Players/whiterat"), 40, 40, Content.Load<Texture2D>("HUD/selected"),
                Content.Load<Texture2D>("HUD/unselected"), Content.Load<Texture2D>("HUD/inventory"), screenSize);

            // item manager intialization
            LoadItems(gameFiles["itemsFile"]);

            // Enemy initialization
            List<Effect> hazmatEffects = new List<Effect>();
            hazmatEffects.Add(new Effect("drugIntensity", new Modifier("+", ".33")));
            EnemyManager.possibleEnemies.Add("enemy", new Enemy(Content.Load<Texture2D>("Enemies/hazmat"), 56, 56, new Vector2(0, 0),
                new DoNothingAI(), new TeleportToHomeAI(), new BeelineAI(250), hazmatEffects, 256, 1024));

            List<Effect> brainEffects = new List<Effect>();
            brainEffects.Add(new Effect("drugIntensity", new Modifier("=", ".99")));
            EnemyManager.possibleEnemies.Add("brain", new Enemy(Content.Load<Texture2D>("Enemies/brains"), 60, 60, new Vector2(0, 0),
                new TeleportToHomeAI(), new TeleportToHomeAI(), new BeelineAI(300), brainEffects, 256, 1024));

            // HUD intialization
            HUD.GetInstance().setInventory(ItemManager.inventories[0]);
            HUD.GetInstance().setScreenSize(screenSize);
            SpriteFont font = Content.Load<SpriteFont>("Arial");
            SpriteFont small = Content.Load<SpriteFont>("Small");
            HUD.GetInstance().setScoreData(new Vector2(0, 0), font);
            HUD.GetInstance().setTimerData(new Vector2(0, 20), font);
            HUD.GetInstance().setFont(font);
            HUD.GetInstance().setSmallFont(small);
            HUD.GetInstance().overlay = new Sprite(Content.Load<Texture2D>("HUD/overlay"), new Vector2(screenSize.X/2, screenSize.Y/2));

            // level intialization
            LoadBlocks(gameFiles["blocksFile"]);

            LoadLevels(gameFiles["levelsFile"]);
            // load first level
            Level.GetInstance().LoadLevel(0);
            GameAction startGame = new GameAction(
             this,
             Engine.GetInstance().GetType().GetMethod("Play"),
             new object[0]);

            GameAction exitGame = new GameAction(
                this,
                this.GetType().GetMethod("Exit"),
                new object[0]);

            GameAction restartGame = new GameAction(
                Engine.GetInstance(),
                Engine.GetInstance().GetType().GetMethod("Reset"),
                new object[0]);

            List<MenuItem> startMenuItems = new List<MenuItem>();
            startMenuItems.Add(new MenuItem("Press Enter to Play!", startGame));
            startMenuItems.Add(new MenuItem("Press Enter to Exit!", exitGame));

            Menu mainMenu = new Menu(Content.Load<Texture2D>("Menu/Splash"), screenSize, font, "mainMenu", "Press Space to Begin", startMenuItems, Color.Red, Color.White);
            mainMenu.setUp();
            Engine.GetInstance().mainMenu = mainMenu;

            List<MenuItem> pauseMenuItems = new List<MenuItem>();
            pauseMenuItems.Add(new MenuItem("Resume", startGame));
            pauseMenuItems.Add(new MenuItem("Main Menu", restartGame));
            pauseMenuItems.Add(new MenuItem("Quit", exitGame));

            Menu pauseMenu = new Menu(Content.Load<Texture2D>("Menu/Splash"), screenSize, font, "pauseMenu", "Press Space to Begin", pauseMenuItems, Color.Red, Color.White);
            pauseMenu.setUp();
            Engine.GetInstance().pauseMenu = pauseMenu;

            List<MenuItem> dieMenuItems = new List<MenuItem>();
            dieMenuItems.Add(new MenuItem("Retry", startGame));
            dieMenuItems.Add(new MenuItem("Main Menu", restartGame));
            dieMenuItems.Add(new MenuItem("Quit", exitGame));

            Menu dieMenu = new Menu(Content.Load<Texture2D>("Menu/LabRat-Dead"), screenSize, font, "dieMenu", "Press Space to Begin", dieMenuItems, Color.Red, Color.White);
            dieMenu.setUp();
            Engine.GetInstance().dieMenu = dieMenu;

            List<MenuItem> winLevelMenuItems = new List<MenuItem>();
            winLevelMenuItems.Add(new MenuItem("Continue", startGame));
            winLevelMenuItems.Add(new MenuItem("Main Menu", restartGame));
            winLevelMenuItems.Add(new MenuItem("Quit", exitGame));

            Menu winLevel = new Menu(Content.Load<Texture2D>("Menu/LabRat-Level"), screenSize, font, "winLevelMenu", "Press Space to Begin", winLevelMenuItems, Color.Red, Color.White);
            winLevel.setUp();
            Engine.GetInstance().winLevelMenu = winLevel;

            List<MenuItem> winGameMenuItems = new List<MenuItem>();
            winGameMenuItems.Add(new MenuItem("Main Menu", restartGame));
            winGameMenuItems.Add(new MenuItem("Quit", exitGame));

            Menu winGameMenu = new Menu(Content.Load<Texture2D>("Menu/LabRat-Won"), screenSize, font, "winGameMenu", "Press Space to Begin", winGameMenuItems, Color.Red, Color.White);
            winGameMenu.setUp();
            Engine.GetInstance().winGameMenu = winGameMenu;

            List<MenuItem> cheeseMenuItems = new List<MenuItem>();
            cheeseMenuItems.Add(new MenuItem("Main Menu", restartGame));
            cheeseMenuItems.Add(new MenuItem("Quit", exitGame));

            Menu cheeseMenu = new Menu(Content.Load<Texture2D>("Menu/LabRat-WonCheese"), screenSize, font, "cheeseMenu", "Press Space to Begin", cheeseMenuItems, Color.Red, Color.White);
            cheeseMenu.setUp();
            Engine.GetInstance().cheeseMenu = cheeseMenu;

            Engine.Menu(Engine.GetInstance().mainMenu);

            base.Initialize();
        }