当前位置: 首页>>代码示例>>C#>>正文


C# Vector2.ToCompassDirection方法代码示例

本文整理汇总了C#中Microsoft.Xna.Framework.Vector2.ToCompassDirection方法的典型用法代码示例。如果您正苦于以下问题:C# Vector2.ToCompassDirection方法的具体用法?C# Vector2.ToCompassDirection怎么用?C# Vector2.ToCompassDirection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Xna.Framework.Vector2的用法示例。


在下文中一共展示了Vector2.ToCompassDirection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleInput

        protected override void HandleInput(GameTime gameTime)
        {
            base.HandleInput(gameTime);

            var mouseX = (int)(MouseState.X * ClientWidth);
            var mouseY = (int)(MouseState.Y * ClientHeight);
            _ui.MouseMove(mouseX, mouseY);
            //_dummy = string.Format("MouseMove X:{0} Y:{1}", mouseX, mouseY);
            //_dummy = MouseState.X.ToString();
            if (MouseState.LeftButton == ButtonState.Pressed)
            {
                _ui.MouseDown(mouseX, mouseY);
                //_dummy = string.Format("MouseDownLeft X:{0} Y:{1}", mouseX, mouseY);
            }
            if (MouseState.LeftButton == ButtonState.Released)
            {
                _ui.MouseUp(mouseX, mouseY);
                //_dummy = string.Format("MouseUpLeft X:{0} Y:{1}", mouseX, mouseY);
            }

            var playerWantsToMove = false;

            var targetDirection = Vector2.Zero;

            if (KeyboardState.IsKeyUp(Keys.NumPad8) || (GamepadState.DPad.Up == ButtonState.Pressed && OldGamepadState.DPad.Up == ButtonState.Released))
            {
                targetDirection += new Vector2(0, -1);
                playerWantsToMove = true;
            }
            if (KeyboardState.IsKeyUp(Keys.NumPad2) || (GamepadState.DPad.Down == ButtonState.Pressed && OldGamepadState.DPad.Down == ButtonState.Released))
            {
                targetDirection += new Vector2(0, 1);
                playerWantsToMove = true;
            }
            if (KeyboardState.IsKeyUp(Keys.NumPad4) || (GamepadState.DPad.Left == ButtonState.Pressed && OldGamepadState.DPad.Left == ButtonState.Released))
            {
                targetDirection += new Vector2(-1, 0);
                playerWantsToMove = true;
            }
            if (KeyboardState.IsKeyUp(Keys.NumPad6) || (GamepadState.DPad.Right == ButtonState.Pressed && OldGamepadState.DPad.Right == ButtonState.Released))
            {
                targetDirection += new Vector2(1, 0);
                playerWantsToMove = true;
            }
            if (KeyboardState.IsKeyUp(Keys.NumPad7))
            {
                targetDirection += new Vector2(-1, -1);
                playerWantsToMove = true;
            }
            if (KeyboardState.IsKeyUp(Keys.NumPad9))
            {
                targetDirection += new Vector2(1, -1);
                playerWantsToMove = true;
            }
            if (KeyboardState.IsKeyUp(Keys.NumPad1))
            {
                targetDirection += new Vector2(-1, 1);
                playerWantsToMove = true;
            }
            if (KeyboardState.IsKeyUp(Keys.NumPad3))
            {
                targetDirection += new Vector2(1, 1);
                playerWantsToMove = true;
            }

            var leftThumb = new Vector2(GamepadState.ThumbSticks.Left.X / 32768f, -GamepadState.ThumbSticks.Left.Y / 32768f); // X[-1..0..1] Y[-1..0..1]
            Vector2 compassDir = Vector2.Zero;
            if (leftThumb.Length() >= 0.5f)
            {
                targetDirection = leftThumb.ToCompassDirection();
                playerWantsToMove = (gameTime.TotalGameTime.TotalMilliseconds > (_previousMilliseconds + 250)); //TODO(philipp): add option for speedruns ;)
            }

            if (!playerWantsToMove)
            {
                return;
            }
            else
            {
                _previousMilliseconds = gameTime.TotalGameTime.TotalMilliseconds;
            }

            var targetPosition = _world.Player.Position.ToVector2() + targetDirection;
            if (targetPosition.X >= 0 && targetPosition.Y >= 0 && targetPosition.X < _world.CurrentMap.Width && targetPosition.Y < _world.CurrentMap.Height)
            {
                var targetPositionPoint = new Point((int)targetPosition.X, (int)targetPosition.Y);
                var targetTile = _world.CurrentMap.Tiles.ElementAt(_world.CurrentMap.PointToIndex(targetPositionPoint));
                if (!targetTile.IsSolid)
                {
                    _world.Player.Position = targetPositionPoint;
                    if (targetTile.IsTeleporter)
                    {
                        targetTile.DoStepOn(targetPositionPoint, _world.CurrentMap);
                    }
                    _world.Player.Step();
                }
            }
        }
开发者ID:deccer,项目名称:ValhallaClone,代码行数:98,代码来源:MainGame.cs


注:本文中的Microsoft.Xna.Framework.Vector2.ToCompassDirection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。