コード例 #1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //Loads the player's texture
            sp_player = Content.Load <Texture2D>("marioSpriteSheet");
            sp_zombie = Content.Load <Texture2D>("ZombieSpriteSheet2");
            sp_slime  = Content.Load <Texture2D>("SlimeSpriteSheet");

            // Menu + Misc textures
            mainMenuImages = new List <Texture2D>(3);
            mainMenuImages.Add(Content.Load <Texture2D>("MenuBackground_City"));
            mainMenuImages.Add(Content.Load <Texture2D>("MenuBackground_Sewer"));
            mainMenuImages.Add(Content.Load <Texture2D>("MenuBackground_Skyscraper"));
            mainMenuImage = mainMenuImages[rand.Next(0, mainMenuImages.Count)];

            pauseImage = Content.Load <Texture2D>("pauseMenu");
            //gameOverImage = Content.Load<Texture2D>("mainMenu");
            gameOverImage = mainMenuImages[rand.Next(0, mainMenuImages.Count)];
            quitImage     = Content.Load <Texture2D>("QuitMenu");
            buttonImage   = Content.Load <Texture2D>("ButtonImage");
            shadeOverlay  = Content.Load <Texture2D>("ShadeOverlay");

            menuFont   = Content.Load <SpriteFont>("MenuFont");
            buttonFont = Content.Load <SpriteFont>("ButtonFont");

            //Loads map textures
            wallTexture        = Content.Load <Texture2D>("wall");
            collectibleTexture = Content.Load <Texture2D>("collectible");
            platTexture        = Content.Load <Texture2D>("tile");

            sewerTexture   = Content.Load <Texture2D>("sewer bg2");
            sewerTexture2  = Content.Load <Texture2D>("sewer BG");
            cityTexture    = Content.Load <Texture2D>("city BG");
            skyLineTexture = Content.Load <Texture2D>("highrise BG");
            enemyTexture   = Content.Load <Texture2D>("ghost");

            healthBarBase    = Content.Load <Texture2D>("Health Bar Base");
            healthBarOverlay = Content.Load <Texture2D>("Health Bar Overlay");

            healthFont = Content.Load <SpriteFont>("Consolas_9");

            MapReader.healthBarBackground = healthBarBase;
            MapReader.healthBarOverlay    = healthBarOverlay;

            Character.Random = rand;

            Player.PlayerSprite = sp_player;
            Player.HealthFont   = healthFont;

            Zombie.ZombieSprite = sp_zombie;
            Zombie.HealthFont   = healthFont;

            Slime.SlimeSprite = sp_slime;
            Slime.HealthFont  = healthFont;

            BattleManager.Texture_BackgroundHealth = healthBarBase;
            BattleManager.Texture_ForegroundHealth = healthBarOverlay;
            BattleManager.ScreenHeight             = GraphicsDevice.Viewport.Height;
            BattleManager.ScreenWidth = GraphicsDevice.Viewport.Width;


            //Initializes player and their texture
            player        = new Player(Vector2.Zero, healthBarBase, healthBarOverlay);
            player.Health = 14;

            reader.ReadMap("../../../Content/Rooms/room1.txt", quadTree, collectibleTexture, enemyTexture);

            wall        = new Wall(0, 0, 25, 25, wallTexture);
            platform    = new Platform(0, 0, 25, 25, platTexture);
            collectible = new Collectible(0, 0, 25, 25, collectibleTexture, "item");

            //reader.StoreObjects(platform, wall, collectList, spriteBatch);
            sewerBG   = new Background(0, 0, 800, 1200, sewerTexture);
            cityBG    = new Background(0, 0, 800, 1200, cityTexture);
            skyLineBG = new Background(0, 0, 800, 1200, skyLineTexture);

            // BUTTONS
            winButton = new Button(
                buttonImage,
                new Rectangle(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2, buttonImage.Width, buttonImage.Height),
                Exit,
                buttonFont,
                "Yay!",
                buttonTextLoc,
                Color.White,
                true,
                true,
                true,
                false
                );

            mainMenu_play = new Button(
                buttonImage,
                new Rectangle(GraphicsDevice.Viewport.Width / 2
                              - buttonImage.Width - 30, GraphicsDevice.Viewport.Height
                              / 2 - 30, buttonImage.Width, buttonImage.Height),
                ShowInstructions,  // ActivationFunction

                buttonFont,
                "Play",
                buttonTextLoc,
                Color.White,

                true,   // active
                true,   // highlightable
                true,   // clickable
                true);  // linger

            mainMenu_quit = new Button(
                buttonImage,
                new Rectangle(GraphicsDevice.Viewport.Width / 2
                              + 30, GraphicsDevice.Viewport.Height / 2 - 30,
                              buttonImage.Width, buttonImage.Height),
                ShowQuitMenu,  // ActivationFunction

                buttonFont,
                "Exit",
                buttonTextLoc,
                Color.White,

                true,  // active
                true,  // highlightable
                true,  // clickable
                true); // linger

            pause_menu = new Button(
                buttonImage,
                new Rectangle(GraphicsDevice.Viewport.Width - buttonImage.Width,
                              buttonImage.Height, buttonImage.Width, buttonImage.Height),
                MainMenu,  // ActivationFunction

                buttonFont,
                "Main Menu",
                buttonTextLoc,
                Color.White,

                true,  // active
                true,  // highlightable
                true,  // clickable
                true); // linger

            pause_resume = new Button(
                buttonImage,
                new Rectangle(GraphicsDevice.Viewport.Width - 100, 0,
                              buttonImage.Width, buttonImage.Height),
                UnpauseGame,  // ActivationFunction

                buttonFont,
                "Resume",
                buttonTextLoc,
                Color.White,

                true,  // active
                true,  // highlightable
                true,  // clickable
                true); // linger

            pause_quit = new Button(
                buttonImage,
                new Rectangle(GraphicsDevice.Viewport.Width - buttonImage.Width,
                              2 * buttonImage.Height, buttonImage.Width, buttonImage.Height),
                ShowQuitMenu,  // ActivationFunction

                buttonFont,
                "Quit game",
                buttonTextLoc,
                Color.White,

                true,  // active
                true,  // highlightable
                true,  // clickable
                true); // linger

            quit_no = new Button(
                buttonImage,
                new Rectangle(GraphicsDevice.Viewport.Width / 2
                              - buttonImage.Width - 10, GraphicsDevice.Viewport.Height
                              / 2, buttonImage.Width, buttonImage.Height),
                DenyQuit,  // ActivationFunction

                buttonFont,
                "No",
                buttonTextLoc,
                Color.White,

                true,  // active
                true,  // highlightable
                true,  // clickable
                true); // linger

            quit_yes = new Button(
                buttonImage,
                new Rectangle(GraphicsDevice.Viewport.Width / 2
                              + 10, GraphicsDevice.Viewport.Height / 2,
                              buttonImage.Width, buttonImage.Height),
                Exit,  // ActivationFunction

                buttonFont,
                "Yes",
                buttonTextLoc,
                Color.White,

                true,  // active
                true,  // highlightable
                true,  // clickable
                true); // linger

            instructions_Play = new Button(
                buttonImage,
                new Rectangle(GraphicsDevice.Viewport.Width / 2
                              - buttonImage.Width / 2 - 350, GraphicsDevice.Viewport.Height / 2
                              + buttonImage.Height / 2 + 10,
                              buttonImage.Width, buttonImage.Height),
                StartGame,  // ActivationFunction

                buttonFont,
                "Play Game",
                buttonTextLoc,
                Color.White,

                true,   // active
                true,   // highlightable
                true,   // clickable
                false); // linger

            instructions_Back = new Button(
                buttonImage,
                new Rectangle(GraphicsDevice.Viewport.Width / 2
                              - buttonImage.Width / 2 - 25, GraphicsDevice.Viewport.Height / 2
                              + buttonImage.Height / 2 + 10,
                              buttonImage.Width, buttonImage.Height),
                ReturnToMenu,  // ActivationFunction

                buttonFont,
                "Back",
                buttonTextLoc,
                Color.White,

                true,   // active
                true,   // highlightable
                true,   // clickable
                false); // linger

            battleButton = new Button(
                buttonImage,
                new Rectangle(GraphicsDevice.Viewport.Width / 2
                              - buttonImage.Width / 2, GraphicsDevice.Viewport.Height / 2
                              + buttonImage.Height / 2 + 10,
                              buttonImage.Width, buttonImage.Height),
                new List <ActivationFunction>()
            {
            },                                       // ActivationFunction

                buttonFont,
                "Battle",
                buttonTextLoc,
                Color.White,

                true,   // active
                true,   // highlightable
                true,   // clickable
                false); // linger

            mainMenuButtons = new List <Button>()
            {
                mainMenu_play,
                mainMenu_quit,
                //battleTime
            };

            pauseButtons = new List <Button>()
            {
                pause_resume,
                pause_menu,
                pause_quit
            };

            confirmQuitButtons = new List <Button>()
            {
                quit_no,
                quit_yes
            };

            gameOverButtons = new List <Button>()
            {
                winButton
            };


            instructionsButtons = new List <Button>()
            {
                instructions_Back,
                instructions_Play
            };

            // Main Menu
            mainMenu = new ListMenu(
                mainMenuImage,
                Vector2.Zero,
                Color.White,

                menuFont,
                "Don't Get Got",
                new Vector2(GraphicsDevice.Viewport.Width / 2 - 22,
                            GraphicsDevice.Viewport.Height / 4),
                Color.Black,

                menuFont,
                "Click or use arrow keys to select an option.",
                new Vector2(GraphicsDevice.Viewport.Width / 2 - 150,
                            GraphicsDevice.Viewport.Height / 4 + 20),
                Color.Black,

                mainMenuButtons,
                Keys.Left,
                Keys.Right,
                Keys.Enter,
                -1,
                true);

            instructionsMenu = new ListMenu(
                mainMenuImage,
                Vector2.Zero,
                Color.White,

                menuFont,
                "             Use the WASD keys to move and SPACE to jump.\nReach the final level and defeat the final boss to defeat the game!\n                                                  In Battle:\n        Select an enemy to attack with the buttons on screen.\nBefore an enemy hits you, time hitting Q correctly to avoid damage!\n       Before hitting an enemy, time hitting E to deal extra damage!",
                new Vector2(GraphicsDevice.Viewport.Width / 2 - 410,
                            GraphicsDevice.Viewport.Height / 4),
                Color.Black,

                menuFont,
                "Click or use arrow keys to select an option.\n                            Don't get got.",
                new Vector2(GraphicsDevice.Viewport.Width / 2 - 330,
                            GraphicsDevice.Viewport.Height / 4 + 180),
                Color.Black,

                instructionsButtons,
                Keys.Left,
                Keys.Right,
                Keys.Enter,
                -1,
                true);

            // Pause Menu
            pauseMenu = new ListMenu(
                pauseImage,
                new Vector2(20, 20),
                Color.White,

                menuFont,
                "PAUSED",
                new Vector2(5, 7),
                Color.White,

                menuFont,
                "Select an option w/ arrows or mouse\nPress P to resume",
                new Vector2(10, 30),
                Color.White,

                pauseButtons,
                Keys.Up,
                Keys.Down,
                Keys.Enter,
                0,
                true);

            // GameOver Menu
            gameOverMenu = new ListMenu(
                gameOverImage,
                Vector2.Zero,
                Color.White,

                menuFont,
                "GAME OVER",
                new Vector2(GraphicsDevice.Viewport.Width / 2
                            - pauseImage.Width, GraphicsDevice.Viewport.Height / 5),
                Color.White,

                menuFont,
                "Quit?",
                new Vector2(GraphicsDevice.Viewport.Width / 2 - 250,
                            GraphicsDevice.Viewport.Height / 2),
                Color.White,

                gameOverButtons,
                Keys.Left,
                Keys.Right,
                Keys.Enter,
                0,
                false);

            // GameOver Menu
            quitMenu = new ListMenu(
                quitImage,
                new Vector2(GraphicsDevice.Viewport.Width / 2
                            - quitImage.Width / 2, GraphicsDevice.Viewport.Height / 2
                            - quitImage.Height / 2),
                Color.White,

                menuFont,
                "Are you sure you want to quit?",
                new Vector2(25, 30),
                Color.White,

                confirmQuitButtons,
                Keys.Left,
                Keys.Right,
                Keys.Enter,
                0,
                false);

            gameWinMenu = new ListMenu(
                mainMenuImage,
                Vector2.Zero,
                Color.White,

                menuFont,
                "CONGRATULATIONS!",
                new Vector2(GraphicsDevice.Viewport.Width / 2
                            - pauseImage.Width, GraphicsDevice.Viewport.Height / 5),
                Color.Black,

                menuFont,
                "You won, and you didn't get got.",
                new Vector2(GraphicsDevice.Viewport.Width / 2 - 250,
                            GraphicsDevice.Viewport.Height / 2 - 50),
                Color.Black,

                gameOverButtons,
                Keys.Left,
                Keys.Right,
                Keys.Enter,
                0,
                false);

            mainMenu_play.ButtonActivationEvent += mainMenu.Reset;
            pause_resume.ButtonActivationEvent  += pauseMenu.Reset;
            pause_menu.ButtonActivationEvent    += pauseMenu.Reset;
            quit_no.ButtonActivationEvent       += quitMenu.Reset;

            BattleManager.BattleMenu         = pauseMenu;
            BattleManager.BattleButton       = battleButton;
            BattleManager.gameOverFunction  += GameOver;
            BattleManager.battleWinFunction += WinBattle;
        }
コード例 #2
0
        // Methods
        #region Methods
        /// <summary>
        /// Set up the stage for a new battle scene.
        /// </summary>
        /// <param name="player">The Player</param>
        /// <param name="allies">A list of Allies companioning Player</param>
        /// <param name="enemy">The Enemy that incited the battle beginning
        /// </param>
        /// <param name="levelType">The level type that the battle is taking
        /// place in. Used to determine what types of enemies to add to the
        /// battle, and what background should be drawn.</param>
        /// <param name="numEnemies">The number of enemies to start in this
        /// battle</param>
        public static void StageBattle(Player player, List <Ally> allies,
                                       Enemy enemy, LevelType levelType, int numEnemies = 3)
        {
            // Ensure that the correct number of enemies are made
            if (numEnemies > 3)
            {
                numEnemies = 3;
            }
            else if (numEnemies < 0)
            {
                numEnemies = 0;
            }

            // Miscellaneous data
            environment = levelType;

            target      = Vector2.Zero;
            currentBase = Vector2.Zero;

            currentTurn = -1;
            //targetIndex = -1;
            //subIndex = 0; // The sub-roster index of the current Character

            // Timers
            totalTime      = 0;
            timeCounter    = 0;
            pauseCounter   = 0.63;
            turnInProgress = false;
            attackExecuted = false;
            battleStarted  = false;
            gameOver       = false;
            battleWon      = false;

            // Create the appropriate rosters
            roster      = new List <Character>();
            enemyRoster = new List <Enemy>(numEnemies);
            allyRoster  = new List <Ally>(allies.Count);

            // Insert the Player into their rosters
            player.Direction     = CharDirection.right;
            player.State         = CharacterState.b_idle;
            BattleManager.player = player;
            roster.Add(BattleManager.player);

            // Insert the Allies into their rosters
            for (int i = 0; i < allies.Count; i++)
            {
                allies[i].Direction = CharDirection.right;
                allies[i].State     = CharacterState.b_idle;

                InsertActor(allies[i] as Ally);
            }

            // Insert the enemies into their rosters
            enemy.Direction = CharDirection.left;
            enemy.State     = CharacterState.b_idle;
            InsertActor(enemy);

            while (enemyRoster.Count < numEnemies)
            {
                PopulateByEnvironment();
            }

            // Calculate the locations that all characters should be placed in,
            // and put them where they belong
            CalculateFriendlyBases();
            CalculateEnemyBases(numEnemies);

            player.B_Location = friendlyLocations[friendlyLocations.Length - 1];
            for (int i = 0; i < friendlyLocations.Length - 1; i++)
            {
                allyRoster[i].B_Location = friendlyLocations[i];
            }

            for (int i = 0; i < enemyLocations.Length; i++)
            {
                enemyRoster[i].B_Location = enemyLocations[i];
            }


            // Populate the Buttons
            #region Buttons & Menus
            List <Button> selectButtons = new List <Button>();

            Button button0 = new Button(
                battleButton.Texture,
                new Rectangle(
                    0,
                    screenHeight - battleButton.Texture.Height,
                    battleButton.Texture.Width + 25,
                    battleButton.Texture.Height),
                Select0,
                battleButton.Font,
                enemyRoster[0].ToString() + " " + enemyRoster[0].Health + " / "
                + enemyRoster[0].MaxHealth,
                new Vector2(10, 10),
                Color.White,
                true,
                true,
                true,
                false);

            selectButtons.Add(button0);

            if (enemyRoster.Count > 1)
            {
                Button button1 = new Button(
                    battleButton.Texture,
                    new Rectangle(
                        (battleButton.Texture.Width + 25) + 10,
                        screenHeight - battleButton.Texture.Height,
                        battleButton.Texture.Width + 25,
                        battleButton.Texture.Height),
                    Select1,
                    battleButton.Font,
                    enemyRoster[1].ToString() + " " + enemyRoster[1].Health + " / "
                    + enemyRoster[1].MaxHealth,
                    new Vector2(10, 10),
                    Color.White,
                    true,
                    true,
                    true,
                    false);

                selectButtons.Add(button1);

                if (enemyRoster.Count > 2)
                {
                    Button button2 = new Button(
                        battleButton.Texture,
                        new Rectangle(
                            (battleButton.Texture.Width + 25) * 2 + 20,
                            screenHeight - battleButton.Texture.Height,
                            battleButton.Texture.Width + 25,
                            battleButton.Texture.Height),
                        Select2,
                        battleButton.Font,
                        enemyRoster[2].ToString() + " " + enemyRoster[2].Health
                        + " / " + enemyRoster[2].MaxHealth,
                        new Vector2(10, 10),
                        Color.White,
                        true,
                        true,
                        true,
                        false);

                    selectButtons.Add(button2);
                }
            }

            enemySelectMenu = new ListMenu(
                menu,
                selectButtons,
                Keys.Left,
                Keys.Right,
                Keys.Enter,
                -1,
                false);

            DeactivateAllButtons();
            #endregion

            // Set the first turn to zero and setup all appropriate variables
            IncrementTurn();

            // Deactivate all the buttons if the first turn is an Enemy
            if (roster[currentTurn] is Enemy)
            {
                currentBase = enemyLocations[subIndex];
            }
        }