Example #1
0
        public MotionPoint(RectangleF originBounds, MotionDirection direction, MotionSpeed speed, Color color, MotionPointCollection owner)
        {
            this._owner     = owner;
            this._orgBounds = originBounds;
            this._mDir      = direction;
            this._mSpd      = speed;
            this._clr       = color;
            this._bubble    = false;
            this._life      = 0;
            this._aFade     = AlphaFade.None;
            this._drwBounds = originBounds;
            this._xCen      = originBounds.Width / 2;
            this._yCen      = originBounds.Height / 2;

            if (owner != null)
            {
                rnd = this._owner.rnd;
            }
            else
            {
                rnd = new Random(Convert.ToInt32((DateTime.Now.Ticks / 20) + (DateTime.Now.Millisecond * (DateTime.Now.TimeOfDay.Ticks / 10))));
            }

            if (direction > MotionDirection.FromLeft)
            {
                // Calculate for Left/Right/Top/Bottom movement types.

                if (direction > MotionDirection.FromTop)
                {
                    // Top/Bottom
                    _xPos = rnd.Next((int)originBounds.Left, (int)originBounds.Right);
                    if (direction == MotionDirection.FromTop)
                    {
                        _yPos = originBounds.Top;
                    }
                    else
                    {
                        _yPos = originBounds.Bottom;
                    }
                }
                else
                {
                    // Left/Right
                    if (direction == MotionDirection.FromLeft)
                    {
                        _xPos = originBounds.Left;
                    }
                    else
                    {
                        _xPos = originBounds.Right;
                    }
                    _yPos = rnd.Next((int)originBounds.Top, (int)originBounds.Bottom);
                }
                _xSpd = rnd.Next(1, 10);
                _ySpd = rnd.Next(1, 10);
            }
            else
            {
                // For free-random origin types

                _xPos = rnd.Next((int)originBounds.Left, (int)originBounds.Right);
                _yPos = rnd.Next((int)originBounds.Top, (int)originBounds.Bottom);

                if (direction == MotionDirection.Zoom)
                {
                    _xSpd = (_xPos - _xCen) / 2;
                    _ySpd = (_yPos - _yCen) / 2;
                }
                else if (direction == MotionDirection.Bounce)
                {
                    _xSpd = rnd.Next(10) - 5;
                    if (_xSpd == 0)
                    {
                        _xSpd = 1 * System.Math.Sign((originBounds.Width / 2) - _xPos);
                    }

                    _ySpd = rnd.Next(10) - 5;
                    if (_ySpd == 0)
                    {
                        _ySpd = 1 * System.Math.Sign((originBounds.Height / 2) - _yPos);
                    }
                }
                else if (direction == MotionDirection.Snow)
                {
                    _xSpd = rnd.Next(1, 5);
                    _ySpd = rnd.Next(1, 5);
                }
                else if (direction == MotionDirection.Rotate)
                {
                    this.RotationPrecesion = 2;
                    _rad    = rnd.Next(2, (int)(originBounds.Width / 2));
                    _offset = rnd.Next(_rotPrec * 2);
                }
            }
        }
Example #2
0
 //***************************************************************************
 // Class Constructors
 //
 public MotionPoint(Rectangle drawBounds, MotionDirection direction, MotionSpeed speed, Color color, MotionPointCollection owner)
     : this(new RectangleF((float)drawBounds.Left, (float)drawBounds.Top, (float)drawBounds.Width, (float)drawBounds.Height), direction, speed, color, owner)
 {
 }