示例#1
0
        public void Update(Random rand)
        {
            if (Game1.GetDistance(pos, Target) < 1)
            {
                pos = Target;
            }
            else
            {
                movement.X = (Target.X - pos.X) * World.cameraSpeed;
                movement.Y = (Target.Y - pos.Y) * World.cameraSpeed;

                pos += movement;
            }

            if (Math.Abs(rotation - RotationTarget) < 0.001f)
            {
                rotation = RotationTarget;
            }
            else
            {
                rotation += (RotationTarget - rotation) * World.cameraTorque;
            }

            shakeOffset = Vector2.Zero;

            for (int i = 0; i < shakes.Count; i++)
            {
                shakeOffset += new Vector2(shakes[i].X * ((float)rand.NextDouble() * 2 - 1), shakes[i].Y * ((float)rand.NextDouble() * 2 - 1));
                shakeDurations[i]--;
                if (shakeDurations[i] <= 0)
                {
                    shakeDurations.RemoveAt(i);
                    shakes.RemoveAt(i);
                }
            }

            pos += shakeOffset;

            if (pos.X == float.NaN)
            {
                pos.X = posPrev.X;
            }
            if (pos.Y == float.NaN)
            {
                pos.Y = posPrev.Y;
            }

            rectangle = new Rectangle(Game1.CeilAdv(pos.X - zoom * World.screenWidth / 2) - 32, Game1.CeilAdv(pos.Y - zoom * World.screenHeight / 2) - 32, Game1.CeilAdv(World.screenWidth * zoom) + 64, Game1.CeilAdv(World.screenHeight * zoom) + 64);
            //rectangle = new Rectangle(Game1.CeilAdv(pos.X), Game1.CeilAdv(pos.Y), Game1.CeilAdv(World.screenWidth * zoom), Game1.CeilAdv(World.screenHeight * zoom));

            posPrev = pos;
        }
示例#2
0
        /// <summary>
        /// Draw a line between two Vector2 positions in a chosen color
        /// </summary>
        /// <param name="spriteBatch"></param>
        /// <param name="point0"></param>
        /// <param name="point1"></param>
        /// <param name="color"></param>
        public static void DrawLine(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, Vector2 point0, Vector2 point1, Color color)
        {
            float length   = Game1.GetDistance(point0, point1);
            float deg      = 0;
            bool  possible = true;

            if (point0 == point1)
            {
                possible = false;
            }

            deg = (float)Math.Atan2(point1.Y - point0.Y, point1.X - point0.X);

            if (possible)
            {
                spriteBatch.Draw(pixel, point0, null, color, deg, Vector2.Zero, new Vector2(length, 2), SpriteEffects.None, 0f);
            }
        }