Exemple #1
0
        private static Rectangle GetStormBounds(Direction direction, double amount, GameLocation gameLocation, Phase.TwoPointRectangle closeInRectangle)
        {
            if (amount < 0 || amount > 1)
            {
                throw new ArgumentException("Must be between 0 and 1", nameof(amount));
            }

            int locationWidth  = gameLocation.Map.Layers[0].LayerWidth * Game1.tileSize;
            int locationHeight = gameLocation.Map.Layers[0].LayerHeight * Game1.tileSize;

            int x, y, w, h;

            x = y = w = h = 0;

            switch (direction)
            {
            case Direction.LeftToRight:
                x = 0;
                y = 0;
                w = (int)(amount * locationWidth);
                h = locationHeight;
                break;

            case Direction.RightToLeft:
                x = (int)((1 - amount) * locationWidth);
                y = 0;
                w = locationWidth; h = locationHeight;
                break;

            case Direction.UpToDown:
                x = 0;
                y = 0;
                w = locationWidth;
                h = (int)(amount * locationHeight);
                break;

            case Direction.DownToUp:
                x = 0;
                y = (int)((1 - amount) * locationHeight);
                w = locationWidth;
                h = locationHeight;
                break;

            case Direction.CloseIn:
                x = (int)(amount * closeInRectangle.X1);
                y = (int)(amount * closeInRectangle.Y1);
                w = (int)(locationWidth - amount * (locationWidth - closeInRectangle.X2)) - x;
                h = (int)(locationHeight - amount * (locationHeight - closeInRectangle.Y2)) - y;
                break;
            }

            return(new Rectangle(x, y, w, h));
        }
Exemple #2
0
        /// <summary>
        /// amount: 0 to 1
        /// </summary>
        public static void DrawSingleStorm(Direction direction, double amount, GameLocation gameLocation, SpriteBatch spriteBatch, Phase.TwoPointRectangle closeInRectangle)
        {
            if (gameLocation == null)
            {
                return;
            }

            if (pixelTexture == null)
            {
                pixelTexture = new Texture2D(Game1.graphics.GraphicsDevice, 1, 1);
                pixelTexture.SetData(new Color[1] {
                    StormColor
                });
            }

            if (SpectatorMode.InSpectatorMode && Game1.activeClickableMenu != null)
            {
                return;
            }

            Rectangle b = GetStormBounds(direction, amount, gameLocation, closeInRectangle);

            if (direction != Direction.CloseIn)
            {
                spriteBatch.Draw(pixelTexture,
                                 new Rectangle(b.X - Game1.viewport.X, b.Y - Game1.viewport.Y, b.Width, b.Height),
                                 Color.White);
                //StormColor);
            }
            else
            {
                int locationWidth  = gameLocation.Map.Layers[0].LayerWidth * Game1.tileSize;
                int locationHeight = gameLocation.Map.Layers[0].LayerHeight * Game1.tileSize;

                Rectangle[] rectangles = new Rectangle[4]
                {
                    new Rectangle(0 - Game1.viewport.X, 0 - Game1.viewport.Y, b.X, locationHeight),
                    new Rectangle(b.Right - Game1.viewport.X, 0 - Game1.viewport.Y, locationWidth - b.Right, locationHeight),
                    new Rectangle(b.X - Game1.viewport.X, 0 - Game1.viewport.Y, b.Width, b.Y),
                    new Rectangle(b.X - Game1.viewport.X, b.Y + b.Height - Game1.viewport.Y, b.Width, locationHeight - (b.Y + b.Height)),
                };

                foreach (Rectangle rectangle in rectangles)
                {
                    spriteBatch.Draw(pixelTexture, rectangle,
                                     Color.White);
                    //StormColor);
                }
            }
        }