本文整理汇总了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();
}
}
}