Ejemplo n.º 1
0
        public void DrawUpperLayer(SpriteBatch spriteBatch)
        {
            foreach (var layer in _map.Layers.Where(l => l.Name != "UpperLayer"))
            {
                layer.IsVisible = false;
            }

            var upperLayer = _map.GetLayer("UpperLayer");

            upperLayer.IsVisible = true;

            InGameDebugger.AppendLine($"Opacity: {upperLayer.Opacity}");
            InGameDebugger.AppendLine($"Visibility: {upperLayer.IsVisible}");

            //_map.Draw(_camera.GetViewMatrix());

            spriteBatch.Begin(
                samplerState: SamplerState.PointClamp,
                blendState: BlendState.AlphaBlend,
                transformMatrix: _camera.GetViewMatrix()
                );

            foreach (var layer in _map.TileLayers.Where(t => t.Name.Equals("UpperLayer")))
            {
                layer.Draw(spriteBatch);
            }

            // Collisions DEBUG
            foreach (var rectangleF in Collisions)
            {
                spriteBatch.DrawRectangle(rectangleF, Color.Aqua);
            }
            spriteBatch.End();
        }
Ejemplo n.º 2
0
        public void UpdateUpperLayerVisibility(Player player)
        {
            var upperLayer = _map.TileLayers
                             .First(l => l.Name.Equals("UpperLayer"));
            var upperLayerTiles = from tile in upperLayer.Tiles
                                  where tile.Id != 0
                                  select new RectangleF(
                x: tile.X * upperLayer.TileWidth,
                y: tile.Y * upperLayer.TileHeight,
                width: upperLayer.TileWidth,
                height: upperLayer.TileHeight);
            var isCollidingWithPlayer = upperLayerTiles.Any(t => t.Intersects(player.BoundingBox));

            InGameDebugger.AppendLine($"IsColliding: {isCollidingWithPlayer}");

            upperLayer.Opacity = isCollidingWithPlayer ? 0.25f : 1f;
            //upperLayer.IsVisible = !isCollidingWithPlayer;
        }