コード例 #1
0
/// <summary>
/// Shared constructor intialization code.
/// </summary>
/// <param name="offsetX"> center brick's x position</param>
/// <param name="offsetZ"> center brick's z position</param>
        private void initWall(int offsetX, int offsetZ)
        {
            isCollidable = true;
            int     spacing = stage.Terrain.Spacing;
            Terrain terrain = stage.Terrain;
            int     baseX   = offsetX;
            int     baseZ   = offsetZ;

            // brick[x,z] vertex positions on terrain
            int[,] brick =                                                                                                                                             // "just another brick in the wall", Pink Floyd
            {
                {   0,   0 }, {   1,   0 }, {   2,   0 }, {   3,   0 }, {   4,   0 }, {   5,   0 }, {   6,   0 },                                                      // 7 middle right
                {   7,  -9 }, {   7,  -8 }, {   7,  -7 }, {   7,  -6 }, {   7,  -5 }, {   7,  -4 }, {   7,  -3 }, {   7, -2 }, {   7, -1 }, {   7,   0 },
                {   7,   1 }, {   7,   2 }, {   7,   3 }, {   7,   4 }, {   7,   5 }, {   7,   6 }, {   7,   7 }, {   7,  8 }, {   7,  9 }, {   7,  10 }, {   7, 11 }, // 21 down on right
                {  -3,  14 }, {  -3,  13 }, {  -3,  12 }, {  -3,  11 }, {  -3,  10 },                                                                                  // 5 up on right
                {  -3,  10 }, {  -4,  10 }, {  -5,  10 }, {  -6,  10 }, {  -7,  10 }, {  -8,  10 }, {  -9,  10 }, { -10, 10 },                                         // 8 middle left
                { -10,  10 }, { -10,   9 }, { -10,   8 }, { -10,   7 }, { -10,   6 }, { -10,   5 }, { -10,   4 }, { -10,  3 }, { -10,  2 }, { -10,   1 }, { -10,  0 },
                { -10,  -1 }, { -10,  -2 }, { -10,  -3 }, { -10,  -4 }, { -10,  -5 }, { -10,  -6 }, { -10,  -7 }, { -10, -8 }, { -10, -9 }, { -10, -10 },              // 21 up on left
                {  -9, -10 }, {  -8, -10 }, {  -7, -10 }, {  -6, -10 }, {  -5, -10 }, {  -4, -10 }, {  -3, -10 },                                                      // 7 right
                {  -3, -10 }, {  -3, -11 }, {  -3, -12 }, {  -3, -13 }, {  -3, -14 } // 5 up right
            };
            for (int i = 0; i < brick.GetLength(0); i++)
            {
                int xPos = brick[i, 0] + baseX;
                int zPos = brick[i, 1] + baseZ;
                addObject(new Vector3(xPos * spacing, terrain.surfaceHeight(xPos, zPos), zPos * spacing), Vector3.Up, 0.0f);
            }
        }
コード例 #2
0
ファイル: Treasure.cs プロジェクト: akatoshbla/AdvGraphics565
        /// <summary>
        /// This method adds the four static treasures to the scene and initializes the tagged array.
        /// </summary>
        private void addTreasures()
        {
            treasureLocations = new List <Vector3> ();
            tagged            = new int[4] {
                0, 0, 0, 0
            };                                // 0 means it is not tagged, 1 means it has already been tagged
            IsCollidable = false;             // Treasures are not collidable
            int     spacing = stage.Spacing;
            Terrain terrain = stage.Terrain;

            treasureLocations.Add(new Vector3(442 * spacing, terrain.surfaceHeight(442, 468), 468 * spacing));
            treasureLocations.Add(new Vector3(400 * spacing, terrain.surfaceHeight(400, 420), 420 * spacing));
            treasureLocations.Add(new Vector3(390 * spacing, terrain.surfaceHeight(390, 390), 390 * spacing));
            treasureLocations.Add(new Vector3(495 * spacing, terrain.surfaceHeight(495, 505), 450 * spacing));

            foreach (Vector3 treasure in treasureLocations)
            {
                addObject(treasure, Vector3.Up, 0.0f);
            }
        }
コード例 #3
0
        /// <summary>
        /// This method adds the four static treasures to the scene and initializes the tagged array. Updated the
        /// treasure locations to make sure they are not in a wall.
        /// </summary>
        private void addTreasures()
        {
            treasureLocations = new List <Vector3> ();
            tagged            = new int[5] {
                0, 0, 0, 0, 0
            };                                // 0 means it is not tagged, 1 means it has already been tagged
            IsCollidable = false;             // Treasures are not collidable
            int     spacing = stage.Spacing;
            Terrain terrain = stage.Terrain;

            treasureLocations.Add(new Vector3(442 * spacing, terrain.surfaceHeight(442, 466), 466 * spacing));
            treasureLocations.Add(new Vector3(418 * spacing, terrain.surfaceHeight(418, 442), 442 * spacing));
            treasureLocations.Add(new Vector3(420 * spacing, terrain.surfaceHeight(420, 481), 481 * spacing));
            treasureLocations.Add(new Vector3(474 * spacing, terrain.surfaceHeight(474, 474), 474 * spacing));
            treasureLocations.Add(new Vector3(463 * spacing, terrain.surfaceHeight(463, 417), 417 * spacing));

            foreach (Vector3 treasure in treasureLocations)
            {
                addObject(treasure, Vector3.Up, 0.0f);
            }
        }
コード例 #4
0
ファイル: Stage.cs プロジェクト: Hoxsey22/Comp565-AGMGSK
        /// <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
            // viewports
            defaultViewport          = GraphicsDevice.Viewport;
            inspectorViewport        = defaultViewport;
            sceneViewport            = defaultViewport;
            inspectorViewport.Height = InfoPaneSize * inspectorFont.LineSpacing;
            inspectorProjection      = Matrix.CreatePerspectiveFieldOfView((float)Math.PI / 4.0f,
                                                                           inspectorViewport.Width / inspectorViewport.Height, 1.0f, 200.0f);
            sceneViewport.Height = defaultViewport.Height - inspectorViewport.Height;
            sceneViewport.Y      = inspectorViewport.Height;
            sceneProjection      = Matrix.CreatePerspectiveFieldOfView((float)Math.PI / 4.0f,
                                                                       sceneViewport.Width / sceneViewport.Height, 1.0f, 1000.0f);
            // 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, "AGMGSKv7 -- Academic Graphics MonoGames/XNA Starter Kit for CSUN Comp 565 assignments.");
            inspector.setInfo(1, "Press keyboard for input (not case sensitive 'H' || 'h')");
            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, 'F' fog, 'T' updates, 'Y' yon");
            // 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);
            // Set initial camera and projection matrix
            setCamera(0);                                                // select the first camera
            boundingSphere3D = Content.Load <Model>("boundingSphereV3");
            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);
            // create a treasure chest

            treasure = new Treasure(this, "treasure", "treasurechest", 4);
            Components.Add(treasure);

            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 AGMGSKv7", 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", "dogV6", 6, 450, 430, player.AgentObject);
            Components.Add(pack);



            // create building


            building = new Model3D(this, "building", "darkBuilding");
            building.IsCollidable = true;
            building.addObject(new Vector3(400 * spacing, terrain.surfaceHeight(400, 400) + 1300, 430 * spacing), Vector3.Up, 4.3f, new Vector3(4300));
            Components.Add(building);


            // ----------- 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 20 clouds
            Cloud cloud = new Cloud(this, "cloud", "cloudV3", 20);

            Components.Add(cloud);
            Trace = string.Format("Scene created with {0} collidable objects.", Collidable.Count);

            graph = new NavGraph(this);
            createGraph();
            Components.Add(graph);
        }
コード例 #5
0
ファイル: Stage.cs プロジェクト: Hoxsey22/Comp565-AGMGSK
 /// <summary>
 /// Get the height of the surface containing stage coordinates (x, z)
 /// </summary>
 public float surfaceHeight(float x, float z)
 {
     return(terrain.surfaceHeight((int)x / spacing, (int)z / spacing));
 }