Beispiel #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
            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.5 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 goal, 'L' lerp, 'P' packing level");
            // 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);
            // 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 = false;                                         // 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 = new Pack(this, "dog", "crab", 12, 450, 430, player.AgentObject);             // dogs changed to crabs
            Components.Add(pack);
            // ----------- OPTIONAL CONTENT HERE -----------------------
            // Load content for your project here
            // create a temple
            Model3D m3d = new Model3D(this, "temple", "temple");

            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", "fish", 300);                // clouds have become fish

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

            //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
            //Create treasure
            treasureLocations = new Vector3[totalTreasures]
            {
                new Vector3(447 * spacing, terrain.surfaceHeight(340, 340), 453 * spacing),
                new Vector3(475 * spacing, terrain.surfaceHeight(340, 340), 344 * spacing),
                new Vector3(450 * spacing, terrain.surfaceHeight(340, 340), 400 * spacing),
                new Vector3(400 * spacing, terrain.surfaceHeight(340, 340), 400 * spacing),
                new Vector3(320 * spacing, terrain.surfaceHeight(340, 340), 325 * spacing)
            };

            taggedTreasure = new bool[totalTreasures]                   // initialize all treasures to untagged
            {
                false, false, false, false, false
            };

            Model3D money = new Model3D(this, "moolah", "treasureV2");                                      //create treasure models

            money.IsCollidable = true;                                                                      //make treasure collidable

            money.addObject(treasureLocations[0], new Vector3(0, 1, 0), 0.79f, new Vector3(.5f, .5f, .5f)); //treasure 1
            money.addObject(treasureLocations[1], new Vector3(0, 1, 0), 0.79f, new Vector3(.5f, .5f, .5f)); //treasure 2
            money.addObject(treasureLocations[2], new Vector3(0, 1, 0), 0.79f, new Vector3(.5f, .5f, .5f)); //treasure 3
            money.addObject(treasureLocations[3], new Vector3(0, 1, 0), 0.79f, new Vector3(.5f, .5f, .5f)); //treasure 4
            money.addObject(treasureLocations[4], new Vector3(0, 1, 0), 0.79f, new Vector3(.5f, .5f, .5f)); //treasure 5
            Components.Add(money);

            // Create Seaweed

            Model3D seaweed = new Model3D(this, "grass", "seaweed");

            seaweed.addObject(new Vector3(447 * spacing, terrain.surfaceHeight(340, 340), 420 * spacing), new Vector3(0, 1, 0), 0.79f);
            seaweed.addObject(new Vector3(475 * spacing, terrain.surfaceHeight(340, 340), 365 * spacing), new Vector3(0, 1, 0), 0.79f);
            seaweed.addObject(new Vector3(250 * spacing, terrain.surfaceHeight(340, 340), 434 * spacing), new Vector3(0, 1, 0), 0.79f);
            seaweed.addObject(new Vector3(400 * spacing, terrain.surfaceHeight(340, 340), 270 * spacing), new Vector3(0, 1, 0), 0.79f);
            seaweed.addObject(new Vector3(447 * spacing, terrain.surfaceHeight(340, 340), 120 * spacing), new Vector3(0, 1, 0), 0.79f);
            seaweed.addObject(new Vector3(475 * spacing, terrain.surfaceHeight(340, 340), 565 * spacing), new Vector3(0, 1, 0), 0.79f);
            seaweed.addObject(new Vector3(250 * spacing, terrain.surfaceHeight(340, 340), 734 * spacing), new Vector3(0, 1, 0), 0.79f);
            seaweed.addObject(new Vector3(400 * spacing, terrain.surfaceHeight(340, 340), 470 * spacing), new Vector3(0, 1, 0), 0.79f);
            Components.Add(seaweed);


            //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
            // 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);

            //-----------------------------------------------------
            // Graph stuff
            graph = new NavGraph();
            foreach (Object3D gameObject in collidable)
            {
                if (gameObject.Name.Contains("temple") || gameObject.Name.Contains("wall"))
                {
                    int npAgentRadius    = (int)Math.Ceiling(npAgent.BoundingSphereRadius);
                    int gameObjectRadius = (int)Math.Ceiling(gameObject.ObjectBoundingSphereRadius);
                    int radius           = (int)(npAgentRadius + gameObjectRadius + 150) / spacing;
                    int xCenter          = (int)(gameObject.Translation.X / spacing);
                    int zCenter          = (int)(gameObject.Translation.Z / spacing);

                    for (int x = zCenter - radius; x < xCenter + radius; x++)
                    {
                        for (int z = zCenter - radius; z < zCenter + radius; z++)
                        {
                            if (x < range && x > 0 && z < range && z > 0 &&
                                (distance(x, xCenter, z, zCenter) < radius))
                            {
                                graph.Add(x, z);
                            }
                        }
                    }
                }
            }

            //-----------------------------------------------------
        }