Example #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);

            // TODO: use this.Content to load your game content here
            allPurposeTexture    = this.Content.Load <Texture2D>("white");
            selecterArrowTexture = this.Content.Load <Texture2D>("arrow");
            splashScreenTexture  = this.Content.Load <Texture2D>("splashScreen");
            font1   = this.Content.Load <SpriteFont>("SpriteFont1");
            bigFont = this.Content.Load <SpriteFont>("SpriteFont2");

            firstMap   = new Map(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, allPurposeTexture, "Content/MazeGameMap.txt");
            CurrentMap = firstMap;

            p1 = new Player(true, pSize, allPurposeTexture, CurrentMap, 1);
            p2 = new Player(false, pSize, allPurposeTexture, CurrentMap, 2);
            while (p1.pRect.Intersects(p2.pRect))
            {
                p2.newRandomStart();
            }
            p1Border = new Rectangle(p1.pRect.X + p1.pRect.Width / 7, p1.pRect.Y + p1.pRect.Width / 7, p1.pRect.Width - ((p1.pRect.Width / 7) * 2), p1.pRect.Height - ((p1.pRect.Width / 7) * 2));
            p2Border = new Rectangle(p2.pRect.X + p2.pRect.Width / 7, p2.pRect.Y + p2.pRect.Width / 7, p2.pRect.Width - ((p2.pRect.Width / 7) * 2), p2.pRect.Height - ((p2.pRect.Width / 7) * 2));

            // Songs
            songs.Add(this.Content.Load <Song>("Menu_Audio"));
            songs.Add(this.Content.Load <Song>("In_Game_Song"));


            menus = new Menus(gameState, instructionState, GraphicsDevice, stringScale, ScreenWidth, ScreenHeight, bigFont, font1, selecterArrowTexture, splashScreenTexture, allPurposeTexture, splashScreen);

            MediaPlayer.Play(songs[0]);
        }
Example #2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // escape key missing

            // Add your update logic here
            KeyboardState kb = Keyboard.GetState();

            if (kb.IsKeyDown(Keys.Back) && !oldKb.IsKeyDown(Keys.Back))
            {
                this.Exit();
            }

            // Methods from the Menus class to run the menus
            menus.Navigations(gameState, instructionState, kb, CurrentBackgroundC, oldKb, timer, gameOverTimer);
            gameState        = menus.GameStateValue();
            instructionState = menus.InstructionStateValue();

            if (gameState == GameState.Game)
            {
                if (changeSongs == false)
                {
                    changeSongs = true;
                    MediaPlayer.Stop();
                }

                // Pauses game. Currently does not work
                if (kb.IsKeyDown(Keys.P) && oldKb != kb)
                {
                    gameState = GameState.Paused;
                }

                // Update Player collision with map obstacles.
                firstMap.MapPlayerCollisions(p1);
                firstMap.MapPlayerCollisions(p2);

                CurrentBackgroundC = firstMap.FLOORCOLOR;

                p1.update(1, p2);
                p2.update(2, p1);


                RoundOverCheck();
            }

            if (gameState == GameState.StartScreen)
            {
                p1.Reset();
                p2.Reset();
                p1.TotalReset();
                p2.TotalReset();
                CurrentBackgroundC = Color.Black;
            }

            if (menus.ReturnTimer() >= 240)
            {
                //Reset
                p1.Reset();
                p2.Reset();
                while (p1.pRect.Intersects(p2.pRect))
                {
                    p2.newRandomStart();
                }
                //CurrentBackgroundC = Color.Black;
            }

            // Keep so the player can choose to exit the game
            if (gameState == GameState.Exit)
            {
                this.Exit();
            }

            // Splash screen timer
            timer++;

            if ((gameState == GameState.StartScreen || gameState == GameState.Instructions) && (MediaPlayer.State == MediaState.Stopped || changeSongs == true))
            {
                if (changeSongs == true)
                {
                    changeSongs = false;
                    MediaPlayer.Stop();
                }

                MediaPlayer.Play(songs[0]);
            }

            if (gameState == GameState.Game && MediaPlayer.State == MediaState.Stopped)
            {
                MediaPlayer.Play(songs[1]);
            }

            if (gameState == GameState.RoundOver)
            {
                MediaPlayer.Pause();
            }
            else
            {
                MediaPlayer.Resume();
            }
            if (gameState == GameState.GameOver)
            {
                MediaPlayer.Pause();
                changeSongs = true;
            }

            oldKb = kb;

            base.Update(gameTime);
        }