Пример #1
0
        /// <summary>
        /// Function to build the background layer representing distant stars.
        /// </summary>
        /// <param name="renderer">The 2D renderer for the application.</param>
        /// <param name="resources">The resources for the application.</param>
        /// <returns>The background layer.</returns>
        public static BgStarLayer GetBackgroundLayer(Gorgon2D renderer, ResourceManagement resources)
        {
            var backgroundLayer = new BgStarLayer(renderer)
            {
                PostProcessGroup = "Final Pass",                                        // These post process groups allow us to assign which sprite layers end up in post processing, and which are blitted immediately.
                StarsTexture     = resources.Textures["StarsNoAlpha"]
            };

            backgroundLayer.LoadResources();
            return(backgroundLayer);
        }
Пример #2
0
        /// <summary>
        /// Function to initialize the scene to render.
        /// </summary>
        private static void SetupScene()
        {
            // This is our camera used to map our objects into relative space.
            // Because it's an Ortho camera, it doesn't really know how to handle aspect ratios, so we'll have to adjust for the current ratio.
            var camera = new Gorgon2DOrthoCamera(_renderer, new DX.Size2F(2, 2), 0.1f, 5000)
            {
                Anchor = new DX.Vector2(0.5f, 0.5f)
            };

            camera.AllowUpdateOnResize = false;    // Since we're using a custom coordinate set, we don't want to change it automatically when we resize the swap chain.
                                                   // That means we are responsible for any adjustments required on resize.

            // Scenes are composed of layers, which are composed of sprites/meshes/etc...
            // Each layer is used to give an illusion of depth by employing parallax scrolling.  While we could use the Gorgon camera to do this, it will not give an illusion of depth
            // because it is an orthographic projection camera which employs constant Z values.
            //
            // Each layer is added in the order in which it will be rendered.
            BgStarLayer  bgLayer       = LayerBuilder.GetBackgroundLayer(_renderer, _resources);
            SpritesLayer sunLayer      = LayerBuilder.GetSunLayer(_renderer, _resources);
            PlanetLayer  planetLayer   = LayerBuilder.GetPlanetLayer(_graphics, _resources);
            SpritesLayer shipLayer     = LayerBuilder.GetShipLayer(_renderer, _resources);
            SpritesLayer shipLayerDeux = LayerBuilder.GetShipLayer(_renderer, _resources);

            // Assign our rendering camera so that we have a means of projecting our coordinate information.
            sunLayer.Camera              =
                planetLayer.Camera       =
                    shipLayerDeux.Camera =
                        shipLayer.Camera = camera;

            // Link the light from the sun layer to only show on the planet layer.
            // With this particular setup, we can set a light to be parented on one layer, so that it will inherit its transformations, and affect a completely different layer.
            // In this example, our sun is distant, so when the layer camera moves, it should move slowly.  But in reality, the light source is fairly close to the planet to give
            // a subtle (or not, depending on bloom) lighting effect.
            sunLayer.Lights[0].Layers.Add(planetLayer);

            // Here we'll set up the layer camera controller. This is what will give the illusion of movement across space by shifting the planet, sun, and other sprites.
            var controller = new LayerCamera(new Layer[] { bgLayer, sunLayer, planetLayer, shipLayerDeux, shipLayer });

            // This is our renderer which is responsible the drawing the layers and applying any post processing effects.
            _sceneRenderer = new SceneRenderer(_renderer, _resources, _mainRtv, controller, camera);
            _sceneRenderer.LoadResources();

            // Our player ship.  Since this one is linked to the layer camera controller, we can use our keyboard to move around the scene.
            _ship                 = new Ship(shipLayer);
            _ship.Position        = new DX.Vector2(120.0f, 75.0f);
            _ship.Angle           = -45.0f;
            _ship.LayerController = controller;
            _ship.LoadResources();

            // A secondary ship. Just here to look pretty.
            _shipDeux          = new Ship(shipLayerDeux);
            _shipDeux.Position = new DX.Vector2(120.3f, 74.8f);
            _shipDeux.Angle    = -78.0f;
            _shipDeux.Ai       = new DummyAi();
            _shipDeux.LoadResources();

            // Create a big ship for some scene variety.
            _bigShip          = new BigShip(shipLayerDeux);
            _bigShip.Position = new DX.Vector2(120.3f, 74.5f);
            _bigShip.Angle    = -80.0f;
            _bigShip.LoadResources();
        }