예제 #1
0
        private void ControlByKeyboard()
        {
            RigidBody body = GameObj.GetComponent <RigidBody>();

            if (KeyPressed(Key.A, Key.D, Key.Left, Key.Right))
            {
                MoveLaterally(body);
            }

            // deal with jumping
            bool jumpKeyHit =
                (DualityApp.Keyboard.KeyHit(Key.Space) || DualityApp.Keyboard.KeyHit(Key.Up));

            bool inCollision = _isInCollision;

            EventAggregator.AnnounceEvent(new DebugMessageEvent($"In Collision?: {inCollision}"));

            if (jumpKeyHit && inCollision)
            {
                body.LinearVelocity = new Vector2(body.LinearVelocity.X, -JumpUnits * Time.TimeMult);
            }

            body.ApplyLocalForce(new Vector2(0, FallUnits * Time.TimeMult));

            EventAggregator.AnnounceEvent(new PlayerMovedEvent(GameObj.Transform.Pos));
        }
예제 #2
0
        void ICmpUpdatable.OnUpdate()
        {
            switch (ControlMethod)
            {
            case PlayerControlMethod.Keyboard:
                ControlByKeyboard();
                break;
                //case PlayerControlMethod.Mouse:
                //    ControlByMouse();
                //    break;
            }

            if (_collisionEndTime.HasValue && DateTime.Now > _collisionEndTime.Value)
            {
                _collisionEndTime = null;
                _isInCollision    = false;
            }

            var body = GameObj.GetComponent <RigidBody>();
            //if (_collisionData != null)
            //{
            //    var playerVelocityVector = body.LinearVelocity;
            //    var angle = Vector2.AngleBetween(_collisionData.Tangent, playerVelocityVector);
            //    //angle = ((angle * 360) / (float)Math.PI);
            //    EventAggregator.AnnounceEvent(new DebugMessageEvent($"Angle: Normal: {angle}"));
            //}

            string msg = String.Format("Velocity: ({0:0,000.00}, {1:0,000.00})", body.LinearVelocity.X, body.LinearVelocity.Y);

            EventAggregator.AnnounceEvent(new DebugMessageEvent(msg));
        }