public virtual void Update(WorldParameters parameters)
 {
     foreach (IGraphicalItem curItem in graphicalItems)
     {
         curItem.Update(parameters);
     }
 }
        public void Update(WorldParameters parameters)
        {
            if (Velocity != previousVelocity && Velocity.Y == 0 && Falling)
            {
                int startSpeed = parameters.WorldRandom.Next(2, 5);
                Velocity.X = (1 - parameters.WorldRandom.Next(0, 2) * 2) * startSpeed;
                Falling    = false;
            }

            if (parameters.WorldRandom.Next(0, 100) % 10 == 0)
            {
                int whichArm = parameters.WorldRandom.Next(0, 2);
                if (whichArm == 0)
                {
                    RaiseLeftArm = !RaiseLeftArm;
                }
                else
                {
                    RaiseRightArm = !RaiseRightArm;
                }
            }

            int gravityDirection = 1;

            if (ReverseGravity)
            {
                gravityDirection = -1;
            }
            Velocity.Y      += (parameters.Gravity * gravityDirection);
            Position        += Velocity;
            previousVelocity = new Vector2(Velocity);

            Rectangle stickRectangle = CalculateBoundingBox();
            Rectangle boundary       = parameters.Boundary;

            if (stickRectangle.X < boundary.X)
            {
                Velocity.X = Math.Abs(Velocity.X) * parameters.Damping;
                Position.X = boundary.X + Width / 2;
            }
            if (stickRectangle.X + stickRectangle.Width > boundary.Width)
            {
                Velocity.X = -Math.Abs(Velocity.X) * parameters.Damping;
                Position.X = boundary.Width - Width / 2;
            }
            if (stickRectangle.Y < boundary.Y)
            {
                Velocity.Y = Math.Abs(Velocity.Y) * parameters.Damping;
                Position.Y = boundary.Y + Height / 2;
            }
            if (stickRectangle.Y + stickRectangle.Height > boundary.Height)
            {
                Velocity.Y = 0;
                Position.Y = boundary.Height - Height / 2;
            }
        }
Beispiel #3
0
        public void Update(WorldParameters parameters)
        {
            if (EnableGravity)
            {
                Velocity.Y += parameters.Gravity;
            }
            Position += Velocity;

            Rectangle ballRectangle = CalculateBoundingBox();
            Rectangle boundary      = parameters.Boundary;
            Random    random        = parameters.WorldRandom;

            if (ballRectangle.X < boundary.X)
            {
                Velocity.X = Math.Abs(Velocity.X) * parameters.Damping;
                Position.X = boundary.X + Radius;
            }
            if (ballRectangle.X + ballRectangle.Width > boundary.Width)
            {
                Velocity.X = -Math.Abs(Velocity.X) * parameters.Damping;
                Position.X = boundary.Width - Radius;
            }
            if (ballRectangle.Y < boundary.Y)
            {
                Velocity.Y = Math.Abs(Velocity.Y) * parameters.Damping;
                Position.Y = boundary.Y + Radius;
            }
            if (ballRectangle.Y + ballRectangle.Height > boundary.Height)
            {
                Velocity.Y = -Math.Abs(Velocity.Y) * parameters.Damping;
                double jitterVel = Velocity.Y / 2;
                if (jitterVel < -1)
                {
                    Velocity.X += random.NextDouble() * jitterVel - random.NextDouble() * jitterVel;
                }
                Position.Y = boundary.Height - Radius;
            }
        }