Ejemplo n.º 1
0
        /// <summary>
        /// 射线检测
        /// </summary>
        /// <param name="hit">检测的结果</param>
        /// <param name="ray">射线</param>
        /// <param name="dist">距离</param>
        /// <param name="checkType">类型</param>
        /// <returns>是否发生碰撞</returns>
        public bool RayCheck(out NCheckResult hit, Ray ray, float dist, LineCheckType checkType)
        {
            NLevel  mainLv  = NLevelEditorEngine.Instance.MainLevel;
            Vector3 lineEnd = ray.Position + ray.Direction * dist;

            return(mainLv.LineCheck(out hit, ray.Position, lineEnd, checkType));
        }
 void PlayerInput_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Space)
     {
         PressJump = true;
         Jump();
     }
     else if (e.KeyCode == Keys.T && e.Modifiers == Keys.Control)
     {
         NCamera      camera   = Program.game.GameWindow.ViewportControl.Viewport.Camera;
         Ray          mouseRay = camera.GetMouseRay(PlayerInput.MouseValueX, PlayerInput.MouseValueY);
         NCheckResult hit      = new NCheckResult();
         if (GameEngine.EngineInstance.CurrentLevel.LineCheck(out hit, mouseRay.Position, mouseRay.Position + mouseRay.Direction * camera.ZFar, LineCheckType.World))
         {
             this.Transport(GameEngine.EngineInstance.GameLevel, hit.location, true);
         }
     }
     else if (e.KeyCode == Keys.D1)
     {
         // todo: 测试释放技能
         ClientUseSkill(1909162191);
     }
     else if (e.KeyCode == Keys.D2)
     {
         ClientUseSkill(4020073455);
     }
     else if (e.KeyCode == Keys.D3)
     {
         ClientUseSkill(1525076748);
     }
     else if (e.KeyCode == Keys.D4)
     {
         ClientUseSkill(3299876908);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 鼠标射线检测
        /// </summary>
        /// <param name="hit">检测的结果</param>
        /// <param name="mousePosition">鼠标位置的屏幕坐标</param>
        /// <param name="dist">射线检测的长度</param>
        /// <param name="checkType">检测碰撞类型</param>
        /// <returns>如何发生碰撞则返回true</returns>
        public void MouseRayCheck(out NCheckResult hit, Point mousePosition, float dist, LineCheckType checkType)
        {
            //Point clientPt = this.PointToClient(mousePosition);
            Point clientPt = mousePosition;
            Ray   ray      = m_view.Camera.GetMouseRay(clientPt.X, clientPt.Y);

            if (!RayCheck(out hit, ray, dist, checkType))
            {
                hit.dist     = 500;
                hit.location = ray.Position + ray.Direction * hit.dist;
            }
        }
        public void ClientUseSkill(UInt32 spellId)
        {
            NCamera      camera   = Program.game.GameWindow.ViewportControl.Viewport.Camera;
            Ray          mouseRay = camera.GetMouseRay(PlayerInput.MouseValueX, PlayerInput.MouseValueY);
            NCheckResult hit      = new NCheckResult();

            if (GameEngine.EngineInstance.CurrentLevel.LineCheck(out hit, mouseRay.Position, mouseRay.Position + mouseRay.Direction * camera.ZFar, LineCheckType.World))
            {
                C2S_CastSpell msg;
                msg.MessageId = C2S_CastSpell.Id;
                msg.SpellID   = spellId;
                msg.TargetId  = 0;
                msg.TargetPos = hit.location;
                msg.TimeStamp = NativeEngineHelper.GetTimeSeconds();
                msg.CastCount = 1;
                GameFrameManager.SendNetMessage <C2S_CastSpell>(msg);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 执行陆地行走
        /// </summary>
        /// <param name="deltaTime">时间</param>
        virtual protected void PerformWalking(GameEngine engine, float deltaTime)
        {
            // 限制速度
            Vector3 currentVel    = this.Velocity;
            Vector3 currentAccDir = Vector3.Normalize(this.Acceleration);

            currentVel.y    = 0;
            currentAccDir.y = -1.0f;

            CalcVelocity(deltaTime, currentAccDir, this.MaxGroundSpeed);

            Vector3      OldLocation  = this.TargetActor.Location;
            Vector3      deltaLoation = deltaTime * Velocity;
            NCheckResult hit          = new NCheckResult();

            if (!engine.MoveActor(this, deltaLoation, ref hit))
            {
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        // 执行飞行移动
        /// </summary>
        virtual protected void PerformFlying(GameEngine engine, float deltaTime)
        {
            // 已经飞出世界范围
            if (!CheckStillInWorld())
            {
                return;
            }

            Vector3 oldAcceleration = Acceleration;

            CalcVelocity(deltaTime, oldAcceleration, this.MaxFlySpeed);

            Vector3 deltaLoation = deltaTime * Velocity;

            NCheckResult hit = new NCheckResult();

            if (!engine.MoveActor(this, deltaLoation, ref hit))
            {
            }
        }
        /// <summary>
        /// 鼠标移动
        /// </summary>
        private void MouseMove(NCamera camera)
        {
            // 取鼠标射线点击Level中的Hit点
            if ((PlayerInput.ClickLocationX != 0 || PlayerInput.ClickLocationY != 0) && PlayerInput.IsKeyPressed(Keys.LButton))
            {
                Ray          mouseRay = camera.GetMouseRay(PlayerInput.ClickLocationX, PlayerInput.ClickLocationY);
                NCheckResult hit      = new NCheckResult();
                if (GameEngine.EngineInstance.CurrentLevel.LineCheck(out hit, mouseRay.Position, mouseRay.Position + mouseRay.Direction * camera.ZFar, LineCheckType.World))
                {
                    MoveTargetLocation = new Vector3(hit.location.x,
                                                     GameEngine.EngineInstance.CurrentLevel.GetWorldHeight(MoveTargetLocation.x, MoveTargetLocation.z),
                                                     hit.location.z);
                    moveTargetDirect = Vector3.Normalize(MoveTargetLocation - this.TargetActor.Location);
                    reachTarget      = false;
                }
            }

#if DEBUG
            GameViewportControl.debugInfos.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture,
                                                             "MoveTargetLocation: {0}\r\n", MoveTargetLocation.ToString()));
#endif

            if (!reachTarget)
            {
                // 朝向目标移动
                Vector3 dir = Vector3.Normalize(MoveTargetLocation - this.TargetActor.Location);
                if (ReachedDestination(this.TargetActor.Location, MoveTargetLocation) ||
                    Vector3.Dot(moveTargetDirect, dir) < 0)
                {
                    this.Acceleration = Vector3.Zero;
                    reachTarget       = true;
                }
                else
                {
                    this.Acceleration = dir;
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 鼠标移动
        /// </summary>
        private void MouseMove(GamePlayerInput playerInput, NCamera camera, GameEngine engine)
        {
            // 取鼠标射线点击Level中的Hit点
            if (playerInput.ClickLocationX != 0 || playerInput.ClickLocationY != 0)
            {
                Ray          mouseRay = camera.GetMouseRay(playerInput.ClickLocationX, playerInput.ClickLocationY);
                NCheckResult hit      = new NCheckResult();
                if (engine.CurrentLevel.LineCheck(out hit, mouseRay.Position, mouseRay.Position + mouseRay.Direction * camera.ZFar, LineCheckType.World))
                {
                    MoveTargetLocation = hit.location;
                    moveTargetDirect   = Vector3.Normalize(MoveTargetLocation - this.TargetActor.Location);
                    reachTarget        = false;
                }
            }

#if DEBUG
            GameViewportControl.debugInfos.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture,
                                                             "MoveTargetLocation: {0}\r\n", MoveTargetLocation.ToString()));
#endif

            if (!reachTarget)
            {
                // 朝向目标移动
                Vector3 dir = Vector3.Normalize(MoveTargetLocation - this.TargetActor.Location);
                if (ReachedDestination(this.TargetActor.Location, MoveTargetLocation) ||
                    Vector3.Dot(moveTargetDirect, dir) < 0)
                {
                    this.Acceleration = Vector3.Zero;
                    //this.Velocity = Vector3.Zero;
                    reachTarget = true;
                }
                else
                {
                    this.Acceleration = dir;
                }
            }
        }