Exemplo n.º 1
0
        private void Process(object body, GenericMotionConfig config)
        {
            var sendEvent = false;
            var state     = _motion.GetState();
            var direction = state.GetDirection();
            var isJumping = state.GetJumping();
            var isFalling = state.GetFalling();

            // Check if we need to send an event?
            if ((_isFalling && !isFalling) || (!_isFalling && isFalling))
            {
                sendEvent  = true;
                _isFalling = isFalling;
            }
            else if ((_isJumping && !isJumping) || (!_isJumping && isJumping))
            {
                sendEvent  = true;
                _isJumping = isJumping;
            }
            else
            {
                var v  = SignOf(direction.Vertical);
                var vo = SignOf(_direction.Vertical);
                var h  = SignOf(direction.Horizontal);
                var ho = SignOf(_direction.Horizontal);
                if ((v != vo) || (h != ho))
                {
                    sendEvent  = true;
                    _direction = direction.Clone();
                }
            }

            // Send event
            if (sendEvent)
            {
                _eventHandler.Trigger(new GenericMotionEvent()
                {
                    IsFalling = isFalling,
                    IsJumping = isJumping,
                    Direction = direction.AsVector(body, config)
                });
            }
        }
Exemplo n.º 2
0
 public void Motion(GenericMotionValue value)
 {
     State.Direction.Horizontal = value.Horizontal;
     State.Direction.Vertical   = value.Vertical;
 }
Exemplo n.º 3
0
 public void Add(GenericMotionValue value)
 {
     Vertical   = Mathf.Clamp(Vertical + value.Vertical, -1f, 1f);
     Horizontal = Mathf.Clamp(Horizontal + value.Horizontal, -1f, 1f);
     Jump       = Mathf.Clamp(Jump + value.Jump, 0f, 1f);
 }
Exemplo n.º 4
0
 public GenericMotionTracker(IGenericMotion motion, EventHandler eventHandler)
 {
     _motion       = motion;
     _eventHandler = eventHandler;
     _direction    = new GenericMotionValue();
 }