Beispiel #1
0
        /// <summary>
        /// The collision box is created based on a rectangle passed by parameter.
        /// This rectangle gives the dimension of the desired rectangle that will
        /// be converted to 4 points (Corners), every corner is a vertex of the
        /// rectangle, the CurrentRotatedCorner saves the current position of the
        /// rectangle around its owner.
        /// </summary>
        /// <param name="Owner">Owner of the box where it is going to be wrapped around.</param>
        /// <param name="Rectangle">Source Rectangle used as reference.</param>
        /// <param name="CollisionOffset">Offset of the rectangle around the owner.</param>
        public CollisionBox(Mobile Owner, Rectangle Rectangle, Vector2 CollisionOffset)
        {
            owner           = Owner;
            collisionOffset = CollisionOffset;

            corner    = new Vector2[4];
            corner[0] = Rectangle.Location.ToVector2();
            corner[1] = Rectangle.Location.ToVector2() + new Vector2(Rectangle.Width, 0);
            corner[2] = Rectangle.Location.ToVector2() + new Vector2(Rectangle.Width, Rectangle.Height);
            corner[3] = Rectangle.Location.ToVector2() + new Vector2(0, Rectangle.Height);

            rotatedBoxCenter = boxCenter = (corner[0] + corner[1] + corner[2] + corner[3]) / 4f;

            rotatedCorner    = new Vector2[4];
            rotatedCorner[0] = Rectangle.Location.ToVector2();
            rotatedCorner[1] = Rectangle.Location.ToVector2() + new Vector2(Rectangle.Width, 0);
            rotatedCorner[2] = Rectangle.Location.ToVector2() + new Vector2(Rectangle.Width, Rectangle.Height);
            rotatedCorner[3] = Rectangle.Location.ToVector2() + new Vector2(0, Rectangle.Height);

#if DEBUG
            debugRectangle = new DebugRectangle(Color.Red);
            debugCrosshair = new DebugCrosshair(Color.Red);
            debugCircle    = new DebugCircle(Color.Black, 25);
            debugLine      = new DebugLine(Color.White);

            DebugHandler.Instance.Add(debugRectangle);
            DebugHandler.Instance.Add(debugCrosshair);
            DebugHandler.Instance.Add(debugCircle);
            DebugHandler.Instance.Add(debugLine);
#endif
        }
Beispiel #2
0
        /// <summary>
        /// Instances all Flipbooks in position and set it's animations
        /// </summary>
        public virtual void Initialize(string texturePath, Vector2 startingPosition, WeatherAnimationType animationType, int extraSpawns = 0, float layerDepth = DepthParameter.WeatherEffect)
        {
            Vector2 endingPosition = new Vector2(Topography.MapWidth, Topography.MapHeight) / 2;

            //Creates the initial offset and 'subtracts' the pivot influence of the element.
            Vector2 currentOffset = startingPosition + Vector2.Transform(new Vector2(0, flipbookPivot.Y), Matrix.CreateRotationZ(rotation)) * Scale;

            int     startingFrame   = 0;
            Vector2 temporaryOffset = Vector2.Zero;

            do
            {
                currentOffset += temporaryOffset;

                //FixedAnimationsFrames is used on random
                //VariableAnimationFrame is used on tornado, weakness and force
                AnimationInstance animation = new AnimationInstance()
                {
                    TimePerFrame = 1 / 15f
                };

                switch (animationType)
                {
                case WeatherAnimationType.FixedAnimationFrame:
                    animation.StartingFrame = animation.EndingFrame = startingFrame % numberOfFrames;
                    break;

                case WeatherAnimationType.VariableAnimationFrame:
                    animation.EndingFrame = numberOfFrames - 1;
                    break;
                }

                startingFrame++;

                Flipbook fb = new Flipbook(currentOffset, flipbookPivot, (int)flipbookPivot.X * 2, (int)flipbookPivot.Y * 2, texturePath, animation, DepthParameter.WeatherEffect, rotation);
                fb.Scale *= Scale;
                flipbookList.Add(fb);

                fb.SetCurrentFrame(startingFrame % numberOfFrames);

                if (temporaryOffset == Vector2.Zero)
                {
                    temporaryOffset = Vector2.Transform(new Vector2(0, fb.SpriteHeight), Matrix.CreateRotationZ(rotation)) * Scale;
                }

                //While it is inside the map boundaries and extraSpawns is not 0
            } while (Topography.IsInsideMapBoundaries(currentOffset) || extraSpawns-- > 0);

            //If the rotation isn't 0 it means there are no good reasons for collision boxes
            if (rotation == 0)
            {
                collisionRectangle = new Rectangle((int)(startingPosition.X - collisionRectangleOffset.X * Scale), (int)startingPosition.Y,
                                                   (int)(collisionRectangleOffset.X * 2 * Scale), (int)(endingPosition.Y - startingPosition.Y));

                outerCollisionRectangle = new Rectangle(collisionRectangle.X - (int)outerCollisionRectangleOffset.X, collisionRectangle.Y - (int)outerCollisionRectangleOffset.Y,
                                                        collisionRectangle.Width + (int)outerCollisionRectangleOffset.X * 2, collisionRectangle.Height + 10 * 2);

#if DEBUG
                debugRectangle = new DebugRectangle(Color.Blue);
                debugRectangle.Update(collisionRectangle);
                DebugHandler.Instance.Add(debugRectangle);
                outerDebugRectangle = new DebugRectangle(Color.Red);
                outerDebugRectangle.Update(outerCollisionRectangle);
                DebugHandler.Instance.Add(outerDebugRectangle);
#endif
            }
        }