Пример #1
0
        /// <summary>
        /// Function to build the layer that contains the sun.
        /// </summary>
        /// <param name="renderer">The 2D renderer for the application.</param>
        /// <param name="resources">The resources for the application.</param>
        /// <returns>The sprite layer that will contain the sun sprite.</returns>
        public static SpritesLayer GetSunLayer(Gorgon2D renderer, ResourceManagement resources)
        {
            GorgonSprite sunSprite = resources.Sprites["Star"];
            var          sunLayer  = new SpritesLayer(renderer)
            {
                ParallaxLevel = 2980.0f,                        // The sun is pretty far away the last I checked.
                Sprites       =
                {
                    new SpriteEntity("Sun")
                    {
                        Sprite        = sunSprite,
                        LocalPosition = new DX.Vector2(1200, -650)
                    }
                },
                PostProcessGroup = "Final Pass",
                Lights           =
                {
                    new Light
                    {
                        Attenuation        = float.MaxValue.Sqrt(),
                        Color              = GorgonColor.White,
                        SpecularPower      = 6.0f,
                        LocalLightPosition = new DX.Vector3(1200, -650, -1.0f),
                        Intensity          = 13.07f
                    }
                }
            };

            sunLayer.LoadResources();

            return(sunLayer);
        }
Пример #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();
        }
Пример #3
0
        /// <summary>
        /// Function to retrieve the layer with our ship on it.
        /// </summary>
        /// <param name="renderer">The 2D renderer for the application.</param>
        /// <param name="resources">The resources for the application.</param>
        /// <returns>The sprite layer containing our ship.</returns>
        public static SpritesLayer GetShipLayer(Gorgon2D renderer, ResourceManagement resources)
        {
            var ship = new SpritesLayer(renderer)
            {
                DeferredLighter = resources.Effects["deferredLighting"] as Gorgon2DDeferredLightingEffect,
                Sprites         =
                {
                    new SpriteEntity("BigShip")
                    {
                        Sprite   = resources.Sprites["BigShip"],
                        Color    = GorgonColor.Gray20, // Make this a bit darker so that we can light it using per-pixel lighting.
                        Rotation = -95.0f,
                        IsLit    = true,
                        Visible  = false
                    },
                    new SpriteEntity("BigShip_Illum")
                    {
                        Sprite     = resources.Sprites["BigShip_Illum"],
                        Color      = GorgonColor.YellowPure * 0.70f,
                        Rotation   = -95.0f,
                        IsLit      = false,
                        Visible    = false,
                        BlendState = GorgonBlendState.Additive
                    },
                    new SpriteEntity("EngineGlow")
                    {
                        Sprite    = resources.Sprites["Fighter_Engine_F0"],
                        Color     = new GorgonColor(GorgonColor.CyanPure * 0.75f, 0),
                        Rotation  = -45.0f,
                        Anchor    = new DX.Vector2(0.5f, -1.5f),
                        Animation = resources.Animations["EngineGlow"]
                    },
                    new SpriteEntity("Fighter")
                    {
                        Sprite   = resources.Sprites["Fighter"],
                        Color    = GorgonColor.Gray20, // Make this a bit darker so that we can light it using per-pixel lighting.
                        Rotation = -45.0f,
                        IsLit    = true
                    }
                },
                Offset           = DX.Vector2.Zero,
                PostProcessGroup = "Final Pass",
                Lights           =
                {
                    new Light
                    {
                        Intensity       = 0.25f,
                        LightType       = LightType.Directional,
                        LightDirection  = new DX.Vector3(1.0f, 0.0f, 0.7071068f),
                        SpecularEnabled = true,
                        SpecularPower   = 128,
                        Color           = GorgonColor.White,
                    }
                }
            };

            ship.Lights[0].Layers.Add(ship);
            ship.LoadResources();

            return(ship);
        }