Esempio n. 1
0
        /// <summary>
        /// Set GraphicDevice display and rendering BasicEffect effect.
        /// Create SpriteBatch, font, and font positions.
        /// Creates the traceViewport to display information and the sceneViewport
        /// to render the environment.
        /// Create and add all DrawableGameComponents and Cameras.
        /// First, add all required contest:  Inspector, Cameras, Terrain, Agents
        /// Second, add all optional (scene specific) content
        /// </summary>
        protected override void LoadContent()
        {
            display = graphics.GraphicsDevice;
            effect  = new BasicEffect(display);

            // Set up Inspector display
            spriteBatch   = new SpriteBatch(display);               // Create a new SpriteBatch
            inspectorFont = Content.Load <SpriteFont> ("Consolas"); // Windows XNA && MonoGames

            // set window size
            if (runFullScreen)
            {
                graphics.IsFullScreen              = true;
                graphics.PreferredBackBufferWidth  = GraphicsDevice.DisplayMode.Width;
                graphics.PreferredBackBufferHeight = GraphicsDevice.DisplayMode.Height;
            }
            else   // run with window values
            {
                graphics.PreferredBackBufferWidth  = windowWidth;
                graphics.PreferredBackBufferHeight = windowHeight;
            }
            graphics.ApplyChanges();

            // viewports
            defaultViewport          = GraphicsDevice.Viewport;
            inspectorViewport        = defaultViewport;
            sceneViewport            = defaultViewport;
            inspectorViewport.Height = InfoPaneSize * inspectorFont.LineSpacing;
            inspectorProjection      = Matrix.CreatePerspectiveFieldOfView(fov,
                                                                           inspectorViewport.Width / inspectorViewport.Height, hither, yon);
            sceneViewport.Height = defaultViewport.Height - inspectorViewport.Height;
            sceneViewport.Y      = inspectorViewport.Height;
            sceneProjection      = Matrix.CreatePerspectiveFieldOfView(fov,
                                                                       sceneViewport.Width / sceneViewport.Height, hither, yon);

            // create Inspector display
            Texture2D inspectorBackground = Content.Load <Texture2D>("inspectorBackground");

            inspector = new Inspector(display, inspectorViewport, inspectorFont, Color.Black, inspectorBackground);

            // create information display strings
            // help strings
            inspector.setInfo(0, "Academic Graphics MonoGames 3.6 Starter Kit for CSUN Comp 565 assignments.");
            inspector.setInfo(1, "Press keyboard for input (not case sensitive 'H' || 'h')   'Esc' to quit");
            inspector.setInfo(2, "Inspector toggles:  'H' help or info   'M'  matrix or info   'I'  displays next info pane.");
            inspector.setInfo(3, "Arrow keys move the player in, out, left, or right.  'R' resets player to initial orientation.");
            inspector.setInfo(4, "Stage toggles:  'B' bounding spheres, 'C' || 'X' cameras, 'T' fixed updates, 'N' treasure hunting, 'P' flocking");

            // initialize empty info strings
            for (int i = 5; i < 20; i++)
            {
                inspector.setInfo(i, "  ");
            }

            // set blending for bounding sphere drawing
            blending = new BlendState();
            blending.ColorSourceBlend      = Blend.SourceAlpha;
            blending.ColorDestinationBlend = Blend.InverseSourceAlpha;
            blending.ColorBlendFunction    = BlendFunction.Add;
            notBlending = new BlendState();
            notBlending = display.BlendState;

            // Create and add stage components
            // You must have a TopDownCamera, BoundingSphere3D, WayPoint3D, Terrain, and Agents (player, npAgent) in your stage!
            // Place objects at a position, provide rotation axis and rotation radians.
            // All location vectors are specified relative to the center of the stage.
            // Create a top-down "Whole stage" camera view, make it first camera in collection.
            topDownCamera = new Camera(this, Camera.CameraEnum.TopDownCamera);
            camera.Add(topDownCamera);
            boundingSphere3D = Content.Load <Model>("boundingSphereV8");
            wayPoint3D       = Content.Load <Model>("100x50x100Marker");                        // model for navigation node display

            // Create required entities:
            collidable = new List <Object3D>();  // collection of objects to test for collisions
            terrain    = new Terrain(this, "terrain", "heightTexture", "colorTexture");
            Components.Add(terrain);

            // Create the treasures for the map
            TreasureMaker treasures = new TreasureMaker(this, "treasure", "flammable_tank", "flammable_tank_side", 0.5f, nTreasures);

            for (int i = 0; i < nTreasures; i++)
            {
                Components.Add(treasures.Treasures[i]);
            }

            // Load Agent mesh objects, meshes do not have textures
            player = new Player(this, "Chaser",
                                new Vector3(510 * spacing, terrain.surfaceHeight(510, 507), 507 * spacing),
                                new Vector3(0, 1, 0), 1.0f, "tiger_tank", treasures.Name, treasures.Treasures, 0.6f, 6, 2); // face looking diagonally across stage
            player.IsCollidable = true;                                                                                     // test collisions for player
            Components.Add(player);
            npAgent = new NPAgent(this, "Evader",
                                  new Vector3(0, 1, 0), 1.0f, "PoliceCar15", treasures.Name, treasures.Treasures, 0.6f); // facing +Z
            npAgent.IsCollidable = true;                                                                                 // npAgent does not test for collisions
            Components.Add(npAgent);

            // create file output stream for trace()
            fout  = new StreamWriter("trace.txt", false);
            Trace = string.Format("{0} trace output from AGMGSKv8", DateTime.Today.ToString("MMMM dd, yyyy"));

            //  ------ The wall and pack are required for Comp 565 projects, but not AGMGSK   ---------
            // create walls for navigation algorithms
            Wall wall = new Wall(this, "wall", "wooden_box");

            Components.Add(wall);

            // create a pack for "flocking" algorithms
            // create a Pack of 6 dogs centered at (450, 500) that is lead by player.
            Pack pack = new Pack(this, "dog", "Dragster15", 5, 450, 430, player.AgentObject, 0.6f);

            Components.Add(pack);


            // ----------- OPTIONAL CONTENT HERE -----------------------
            // Load content for your project here
            // create a temple
            Model3D m3d = new Model3D(this, "temple", "templeV3");

            m3d.IsCollidable = true;                    // must be set before addObject(...) and Model3D doesn't set it
            m3d.addObject(new Vector3(340 * spacing, terrain.surfaceHeight(340, 340), 340 * spacing),
                          new Vector3(0, 1, 0), 0.79f); // , new Vector3(1, 4, 1));
            Components.Add(m3d);

            // create 2 clouds
            Cloud cloud = new Cloud(this, "cloud", "cloudV3", 2);

            // Set initial camera and projection matrix
            setCamera(1);      // select the "whole stage" camera
            Components.Add(cloud);

            // Describe the scene created
            Trace = string.Format("scene created:");
            Trace = string.Format("\t {0,4:d} components", Components.Count);
            Trace = string.Format("\t {0,4:d} collidable objects", Collidable.Count);
            Trace = string.Format("\t {0,4:d} cameras", camera.Count);
        }
Esempio n. 2
0
        /// <summary>
        /// Set GraphicDevice display and rendering BasicEffect effect.
        /// Create SpriteBatch, font, and font positions.
        /// Creates the traceViewport to display information and the sceneViewport
        /// to render the environment.
        /// Create and add all DrawableGameComponents and Cameras.
        /// First, add all required contest:  Inspector, Cameras, Terrain, Agents
        /// Second, add all optional (scene specific) content
        /// </summary>
        protected override void LoadContent()
        {
            display = graphics.GraphicsDevice;
            effect  = new BasicEffect(display);
            // Set up Inspector display
            spriteBatch   = new SpriteBatch(display);              // Create a new SpriteBatch
            inspectorFont = Content.Load <SpriteFont>("Consolas"); // Windows XNA && MonoGames
                                                                   // set window size
            graphics.PreferredBackBufferWidth  = windowWidth;
            graphics.PreferredBackBufferHeight = windowHeight;

            graphics.ApplyChanges();
            // viewports
            defaultViewport          = GraphicsDevice.Viewport;
            inspectorViewport        = defaultViewport;
            sceneViewport            = defaultViewport;
            inspectorViewport.Height = InfoPaneSize * inspectorFont.LineSpacing;
            inspectorProjection      = Matrix.CreatePerspectiveFieldOfView(fov,
                                                                           inspectorViewport.Width / inspectorViewport.Height, hither, yon);
            sceneViewport.Height = defaultViewport.Height - inspectorViewport.Height;
            sceneViewport.Y      = inspectorViewport.Height;
            sceneProjection      = Matrix.CreatePerspectiveFieldOfView(fov,
                                                                       sceneViewport.Width / sceneViewport.Height, hither, yon);
            // create Inspector display
            Texture2D inspectorBackground = Content.Load <Texture2D>("inspectorBackground");

            inspector = new Inspector(display, inspectorViewport, inspectorFont, Color.Black, inspectorBackground);
            // create information display strings
            // help strings
            inspector.setInfo(0, "Academic Graphics MonoGames 3.6 Starter Kit for CSUN Comp 565 assignments.");
            inspector.setInfo(1, "Press keyboard for input (not case sensitive 'H' || 'h')   'Esc' to quit");
            inspector.setInfo(2, "Inspector toggles:  'H' help or info   'M'  matrix or info   'I'  displays next info pane.");
            inspector.setInfo(3, "Arrow keys move the player in, out, left, or right.  'R' resets player to initial orientation.");
            inspector.setInfo(4, "Stage toggles:  'B' bounding spheres, 'C' || 'X' cameras, 'T' fixed updates");
            // initialize empty info strings
            for (int i = 5; i < 20; i++)
            {
                inspector.setInfo(i, "  ");
            }
            // set blending for bounding sphere drawing
            blending = new BlendState();
            blending.ColorSourceBlend      = Blend.SourceAlpha;
            blending.ColorDestinationBlend = Blend.InverseSourceAlpha;
            blending.ColorBlendFunction    = BlendFunction.Add;
            notBlending = new BlendState();
            notBlending = display.BlendState;
            // Create and add stage components
            // You must have a TopDownCamera, BoundingSphere3D, WayPoint3D, Terrain, and Agents (player, npAgent) in your stage!
            // Place objects at a position, provide rotation axis and rotation radians.
            // All location vectors are specified relative to the center of the stage.
            // Create a top-down "Whole stage" camera view, make it first camera in collection.
            topDownCamera = new Camera(this, Camera.CameraEnum.TopDownCamera);
            camera.Add(topDownCamera);
            boundingSphere3D = Content.Load <Model>("boundingSphereV8");
            wayPoint3D       = Content.Load <Model>("100x50x100Marker"); // model for navigation node display
                                                                         // Create required entities:
            collidable = new List <Object3D>();                          // collection of objects to test for collisions
            terrain    = new Terrain(this, "terrain", "HongyouAdded/heightTexture", "HongyouAdded/colorTexture");
            Components.Add(terrain);
            // Load Agent mesh objects, meshes do not have textures
            player = new Player(this, "Chaser",
                                new Vector3(510 * spacing, terrain.surfaceHeight(510, 507), 507 * spacing),
                                new Vector3(0, 1, 0), 0.78f, "redAvatarV6"); // face looking diagonally across stage
            player.IsCollidable = true;                                      // test collisions for player
            Components.Add(player);
            npAgent = new NPAgent(this, "Evader",
                                  new Vector3(490 * spacing, terrain.surfaceHeight(490, 450), 450 * spacing),
                                  new Vector3(0, 1, 0), 0.0f, "magentaAvatarV6"); // facing +Z
            npAgent.IsCollidable = true;                                          // npAgent does not test for collisions
            Components.Add(npAgent);
            // create file output stream for trace()
            fout  = new StreamWriter("trace.txt", false);
            Trace = string.Format("{0} trace output from AGMGSKv8", DateTime.Today.ToString("MMMM dd, yyyy"));
            //  ------ The wall and pack are required for Comp 565 projects, but not AGMGSK   ---------
            // create walls for navigation algorithms
            Wall wall = new Wall(this, "wall", "100x100x100Brick");

            Components.Add(wall);
            // create a pack for "flocking" algorithms
            // create a Pack of 6 dogs centered at (450, 500) that is leaderless
            Pack pack = new Pack(this, "dog", "dogV6", 6, 450, 430, player.AgentObject);

            Components.Add(pack);

            // ---------------------------------------------------
            // ----------- MY CONTENT HERE -----------------------
            // ---------------------------------------------------
            inspector.setInfo(20, "Lerp is currently not active");
            inspector.setInfo(21, "Treasure Seeking mode is off");

            //Treasures (4 of them)
            Treasure t1 = new Treasure(this, "treasure_box_1", "HongyouAdded/TreasureBox1", 444, 454);

            treasures.Add(t1);
            Components.Add(t1);

            Treasure t2 = new Treasure(this, "treasure_box_2", "HongyouAdded/TreasureBox2", 502, 451);

            treasures.Add(t2);
            Components.Add(t2);

            Treasure t3 = new Treasure(this, "treasure_box_3", "HongyouAdded/TreasureBox3", 398, 110);

            treasures.Add(t3);
            Components.Add(t3);

            Treasure t4 = new Treasure(this, "treasure_box_4", "HongyouAdded/TreasureBox4", 328, 139);

            treasures.Add(t4);
            Components.Add(t4);

            //Shrubs (300 of them)
            Bushes bushes = new Bushes(this, "Bush", "HongyouAdded/Bush", 300);

            Components.Add(bushes);

            //Huts (10 of them)
            Huts huts = new Huts(this, "hut", "HongyouAdded/Hut", 10);

            Components.Add(huts);

            ObstacleHuts obstacles = new ObstacleHuts(this, "hut", "HongyouAdded/Hut");

            Components.Add(obstacles);

            // --------------------------------------------------
            // ----------- MY CONTENT END -----------------------
            // --------------------------------------------------

            // create a temple
            Model3D m3d = new Model3D(this, "temple", "templeV3");

            m3d.IsCollidable = true;                    // must be set before addObject(...) and Model3D doesn't set it
            m3d.addObject(new Vector3(340 * spacing, terrain.surfaceHeight(340, 340), 340 * spacing),
                          new Vector3(0, 1, 0), 0.79f); // , new Vector3(1, 4, 1));
            Components.Add(m3d);
            // create 20 clouds
            Cloud cloud = new Cloud(this, "cloud", "cloudV3", 20);

            // Set initial camera and projection matrix
            setCamera(1);  // select the "whole stage" camera
            Components.Add(cloud);
            // Describe the scene created
            Trace = string.Format("scene created:");
            Trace = string.Format("\t {0,4:d} components", Components.Count);
            Trace = string.Format("\t {0,4:d} collidable objects", Collidable.Count);
            Trace = string.Format("\t {0,4:d} cameras", camera.Count);
        }
Esempio n. 3
0
        /// <summary>
        /// Set GraphicDevice display and rendering BasicEffect effect.
        /// Create SpriteBatch, font, and font positions.
        /// Creates the traceViewport to display information and the sceneViewport
        /// to render the environment.
        /// Create and add all DrawableGameComponents and Cameras.
        /// First, add all required contest:  Inspector, Cameras, Terrain, Agents
        /// Second, add all optional (scene specific) content
        /// </summary>
        protected override void LoadContent()
        {
            display = graphics.GraphicsDevice;
            effect  = new BasicEffect(display);

            // Set up Inspector display
            spriteBatch   = new SpriteBatch(display);              // Create a new SpriteBatch
            inspectorFont = Content.Load <SpriteFont>("Consolas"); // Windows XNA && MonoGames
                                                                   // set window size
            if (runFullScreen)
            {
                graphics.IsFullScreen              = true;
                graphics.PreferredBackBufferWidth  = GraphicsDevice.DisplayMode.Width;
                graphics.PreferredBackBufferHeight = GraphicsDevice.DisplayMode.Height;
            }
            else
            { // run with window values
                graphics.PreferredBackBufferWidth  = windowWidth;
                graphics.PreferredBackBufferHeight = windowHeight;
            }
            graphics.ApplyChanges();

            // viewports
            defaultViewport          = GraphicsDevice.Viewport;
            inspectorViewport        = defaultViewport;
            sceneViewport            = defaultViewport;
            inspectorViewport.Height = InfoPaneSize * inspectorFont.LineSpacing;
            inspectorProjection      = Matrix.CreatePerspectiveFieldOfView(fov,
                                                                           inspectorViewport.Width / inspectorViewport.Height, hither, yon);
            sceneViewport.Height = defaultViewport.Height - inspectorViewport.Height;
            sceneViewport.Y      = inspectorViewport.Height;
            sceneProjection      = Matrix.CreatePerspectiveFieldOfView(fov,
                                                                       sceneViewport.Width / sceneViewport.Height, hither, yon);

            // create Inspector display
            Texture2D inspectorBackground = Content.Load <Texture2D>("inspectorBackground");

            inspector = new Inspector(display, inspectorViewport, inspectorFont, Color.Black, inspectorBackground);

            // create information display strings
            // help strings
            inspector.setInfo(0, "Academic Graphics MonoGames 3.6 Starter Kit for CSUN Comp 565 assignments.");
            inspector.setInfo(1, "Press keyboard for input (not case sensitive 'H' || 'h')   'Esc' to quit");
            inspector.setInfo(2, "Inspector toggles:  'H' help or info   'M'  matrix or info   'I'  displays next info pane.");
            inspector.setInfo(3, "Arrow keys move the player in, out, left, or right.  'R' resets player to initial orientation.");
            inspector.setInfo(4, "Stage toggles:  'B' bounding spheres, 'C' || 'X' cameras, 'T' fixed updates");

            // initialize empty info strings
            for (int i = 5; i < 20; i++)
            {
                inspector.setInfo(i, "  ");
            }

            // set blending for bounding sphere drawing
            blending = new BlendState();
            blending.ColorSourceBlend      = Blend.SourceAlpha;
            blending.ColorDestinationBlend = Blend.InverseSourceAlpha;
            blending.ColorBlendFunction    = BlendFunction.Add;
            notBlending = new BlendState();
            notBlending = display.BlendState;

            // Create and add stage components
            // You must have a TopDownCamera, BoundingSphere3D, WayPoint3D, Terrain, and Agents (player, npAgent) in your stage!
            // Place objects at a position, provide rotation axis and rotation radians.
            // All location vectors are specified relative to the center of the stage.
            // Create a top-down "Whole stage" camera view, make it first camera in collection.
            topDownCamera = new Camera(this, Camera.CameraEnum.TopDownCamera);
            camera.Add(topDownCamera);
            boundingSphere3D = Content.Load <Model>("boundingSphereV8");
            wayPoint3D       = Content.Load <Model>("100x50x100Marker"); // model for navigation node display
                                                                         // Create required entities:
            collidable = new List <Object3D>();                          // collection of objects to test for collisions
            terrain    = new Terrain(this, "terrain", "heightTexture", "colorTexture");
            Components.Add(terrain);


            // Note: m3dTreasures need to be loaded before NPAgent or else we are a passing a null
            // instance of the parameter into npAgent.

            m3dTreasures = new Treasures(this, "treasure", "treasure");
            Components.Add(m3dTreasures);


            // Load Agent mesh objects, meshes do not have textures
            player = new Player(this, "Chaser",
                                new Vector3(510 * spacing, terrain.surfaceHeight(510, 507), 507 * spacing),
                                new Vector3(0, 1, 0), 0.78f, "redAvatarV6"); // face looking diagonally across stage
            player.IsCollidable = true;                                      // test collisions for player
            Components.Add(player);
            npAgent = new NPAgent(this, "Evader",
                                  new Vector3(490 * spacing, terrain.surfaceHeight(490, 450), 450 * spacing),
                                  new Vector3(0, 1, 0), 0.0f, "magentaAvatarV6", m3dTreasures); // facing +Z
            npAgent.IsCollidable = false;                                                       // alter depending on whether we want a collidable npAgent or not -JC
            Components.Add(npAgent);

            // create file output stream for trace()
            fout  = new StreamWriter("trace.txt", false);
            Trace = string.Format("{0} trace output from AGMGSKv8", DateTime.Today.ToString("MMMM dd, yyyy"));

            //  ------ The wall and pack are required for Comp 565 projects, but not AGMGSK   ---------
            // create walls for navigation algorithms
            Wall wall = new Wall(this, "wall", "100x100x100Brick");

            Components.Add(wall);

            // create a pack for "flocking" algorithms
            // create a Pack of 6 dogs centered at (450, 500) that is leaderless
            //Pack pack = new Pack(this, "dog", "dogV6", 6, 450, 430, null);
            //Components.Add(pack);
            Random random = new Random();

            pack = new Pack(this, "dog", "dogV6", player.AgentObject);
            Components.Add(pack);
            for (int x = -9; x < 10; x += 6)
            {
                for (int z = -3; z < 4; z += 6)
                {
                    float scale = (float)(0.5 + random.NextDouble());
                    float xPos  = (480 + x) * spacing; // position of pack
                    float zPos  = (480 + z) * spacing;
                    pack.addObject(
                        new Vector3(xPos, terrain.surfaceHeight((int)xPos / spacing, (int)zPos / spacing), zPos),
                        new Vector3(0, 1, 0), 0.0f,
                        new Vector3(scale, scale, scale));
                }
            }


            // ----------- OPTIONAL CONTENT HERE -----------------------
            // Load content for your project here

            // Project needs custom/extra models and treasures.
            // I'll load those in here.

            /*Model3D treasure = new Model3D(this, "treasure1", "box");
             * treasure.IsCollidable = true;
             * treasure.addObject(new Vector3(500 * spacing, terrain.surfaceHeight(500, 500), 500 * spacing),
             *   new Vector3(0, 1, 0), 0.79f);
             * Components.Add(treasure);*/

            // create a temple
            Model3D m3d = new Model3D(this, "temple", "templeV3");

            m3d.IsCollidable = true;                    // must be set before addObject(...) and Model3D doesn't set it
            m3d.addObject(new Vector3(340 * spacing, terrain.surfaceHeight(340, 340), 340 * spacing),
                          new Vector3(0, 1, 0), 0.79f); // , new Vector3(1, 4, 1));
            Components.Add(m3d);



            /*TreasureList = new Treasures(this, "treasures", "treasure", false);
             * Components.Add(TreasureList);*/

            /* //create treasure at location (447,453)
             * int xCoord;
             * int zCoord;
             * m3d = new Model3D(this, "treasure1", "treasure");
             * m3d.IsCollidable = true;
             * xCoord = 447;
             * zCoord = 453;
             * m3d.addObject(new Vector3(xCoord * spacing, terrain.surfaceHeight(xCoord, zCoord), zCoord * spacing),
             *   Vector3.Up, 0.0f);
             * Components.Add(m3d);
             *
             * //create treasure at location (320, 320)
             * m3d = new Model3D(this, "treasure2", "treasure");
             * m3d.IsCollidable = true;
             * xCoord = 320;
             * zCoord = 320;
             * m3d.addObject(new Vector3(xCoord * spacing, terrain.surfaceHeight(xCoord, zCoord), zCoord * spacing),
             *   Vector3.Up, 0.0f);
             * Components.Add(m3d);
             *
             * //create treasure at location (100, 400)
             * m3d = new Model3D(this, "treasure3", "treasure");
             * m3d.IsCollidable = true;
             * xCoord = 100;
             * zCoord = 400;
             * m3d.addObject(new Vector3(xCoord * spacing, terrain.surfaceHeight(xCoord, zCoord), zCoord * spacing),
             *   Vector3.Up, 0.0f);
             * Components.Add(m3d);
             *
             * //create treasure at location (200, 300)
             * m3d = new Model3D(this, "treasure4", "treasure");
             * m3d.IsCollidable = true;
             * xCoord = 200;
             * zCoord = 300;
             * m3d.addObject(new Vector3(xCoord * spacing, terrain.surfaceHeight(xCoord, zCoord), zCoord * spacing),
             *   Vector3.Up, 0.0f);
             * Components.Add(m3d);*/



            // create 20 clouds
            Cloud cloud = new Cloud(this, "cloud", "cloudV3", 20);

            // Set initial camera and projection matrix
            setCamera(1);  // select the "whole stage" camera
            Components.Add(cloud);
            // Describe the scene created
            Trace = string.Format("scene created:");
            Trace = string.Format("\t {0,4:d} components", Components.Count);
            Trace = string.Format("\t {0,4:d} collidable objects", Collidable.Count);
            Trace = string.Format("\t {0,4:d} cameras", camera.Count);
        }