Beispiel #1
0
        public override ProgrammingElement Clone()
        {
            DirectionFilter clone = new DirectionFilter();

            CopyTo(clone);
            return(clone);
        }
Beispiel #2
0
        public override bool MatchAction(Reflex reflex, out object param)
        {
            bool result = false;

            param = null;

            GamePadStickFilter stickFilt = reflex.Data.GetFilterByType(typeof(GamePadStickFilter)) as GamePadStickFilter;
            TouchGestureFilter touchFilt = reflex.Data.GetFilterByType(typeof(TouchGestureFilter)) as TouchGestureFilter;

            int        directFiltCount   = 0;
            Directions combinedDirection = 0;

            if (stickFilt != null)
            {
                Vector2 stick = stickFilt.stickPosition;
                stick.Normalize();

                for (int i = 0; i < reflex.Filters.Count; ++i)
                {
                    Filter filter = reflex.Filters[i];

                    if (!(filter is DirectionFilter))
                    {
                        continue;
                    }

                    DirectionFilter directFilt = filter as DirectionFilter;

                    // The first filter will handle all direction filters present, so if we are not
                    // the first filter, just bail with a "true" result.
                    if (directFiltCount > 0 && directFilt == this)
                    {
                        return(true);
                    }

                    // Is the stick in the correct quadrant for this direction?
                    if (!directFilt.IsStickPositionValid(stick))
                    {
                        return(false);
                    }

                    combinedDirection |= directFilt.direction;

                    directFiltCount += 1;
                }

                // If we've gotten here we're good.  The stick is in the
                // right quadrant for the filter so return true.

                result = true;
            }
            else if (touchFilt != null)
            {
                for (int i = 0; i < reflex.Filters.Count; ++i)
                {
                    Filter filter = reflex.Filters[i];

                    if (!(filter is DirectionFilter))
                    {
                        continue;
                    }

                    DirectionFilter directFilt = filter as DirectionFilter;

                    // The first filter will handle all direction filters present, so if we are not
                    // the first filter, just bail with a "true" result.
                    if (directFiltCount > 0 && directFilt == this)
                    {
                        return(true);
                    }

                    combinedDirection |= directFilt.direction;

                    directFiltCount += 1;
                }

                if (combinedDirection == touchFilt.Direction)
                {
                    result = true;
                }
            }

            return(result);
        }
Beispiel #3
0
 protected void CopyTo(DirectionFilter clone)
 {
     base.CopyTo(clone);
     clone.direction = this.direction;
 }