Example #1
0
 /// <summary>
 /// Creates a copy of an arena layer excluding its gobs.
 /// </summary>
 private ArenaLayer(ArenaLayer other)
 {
     _isGameplayLayer = other._isGameplayLayer;
     _z = other._z;
     _parallaxName = other._parallaxName;
     _gobs = new ArenaLayerGobCollection();
 }
Example #2
0
        private void DrawParallax(ArenaLayer layer)
        {
            if (layer.ParallaxName != "")
            {
                var oldState = GraphicsDevice.BlendState;

                // Modify renderstate for parallax.
                GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
                GraphicsDevice.BlendState = BlendState.AlphaBlend;
                GraphicsDevice.DepthStencilState = DepthStencilState.None;

                // Render looping parallax as two huge triangles.
                _effect.Texture = AssaultWingCore.Instance.Content.Load<Texture2D>(layer.ParallaxName);
                var texCenter = GetScale(layer.Z) * CurrentLookAt / _effect.Texture.Dimensions();
                var texCornerOffset = new Vector2(
                    Viewport.Width / (2f * _effect.Texture.Width) / ZoomRatio,
                    Viewport.Height / (2f * _effect.Texture.Height) / ZoomRatio);
                _vertexData[0].TextureCoordinate = texCenter - texCornerOffset;
                _vertexData[1].TextureCoordinate = texCenter + texCornerOffset.MirrorX();
                _vertexData[2].TextureCoordinate = texCenter + texCornerOffset.MirrorY();
                _vertexData[3].TextureCoordinate = texCenter + texCornerOffset;
                _effect.CurrentTechnique.Passes[0].Apply();
                GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleStrip, _vertexData, 0, 2);
            }
            // Modify renderstate for 3D graphics.
            GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
            GraphicsDevice.DepthStencilState = DepthStencilState.Default;
            GraphicsDevice.BlendState = BlendState.Opaque;
        }
Example #3
0
 private void Draw3D(ArenaLayer layer, ref Matrix view, ref Matrix projection)
 {
     var visible = LayerVisibleAreas[layer.Index];
     Vector2 gobMin, gobMax;
     foreach (var gob in layer.Gobs)
     {
         gob.GetDraw3DBounds(out gobMin, out gobMax);
         if (float.IsNaN(gobMin.X)) continue;
         if (gobMax.X < visible.Min.X ||
             gobMax.Y < visible.Min.Y ||
             visible.Max.X < gobMin.X ||
             visible.Max.Y < gobMin.Y) continue;
         gob.Draw3D(view, projection, Owner);
     }
 }
Example #4
0
 private void Draw2D(ArenaLayer layer, float layerScale)
 {
     DrawMode2D? drawMode = null;
     var gameToScreenMatrix = GetGameToScreenMatrix(layer.Z);
     layer.Gobs.ForEachIn2DOrder(gob =>
     {
         if (!drawMode.HasValue || drawMode.Value.CompareTo(gob.DrawMode2D) != 0)
         {
             if (drawMode.HasValue)
                 drawMode.Value.EndDraw(AssaultWingCore.Instance, SpriteBatch);
             drawMode = gob.DrawMode2D;
             drawMode.Value.BeginDraw(AssaultWingCore.Instance, SpriteBatch);
         }
         gob.Draw2D(gameToScreenMatrix, SpriteBatch, layerScale * ZoomRatio, Owner);
     });
     if (drawMode.HasValue)
         drawMode.Value.EndDraw(AssaultWingCore.Instance, SpriteBatch);
 }