本文整理汇总了C#中Microsoft.Xna.Framework.Point.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# Point.Equals方法的具体用法?C# Point.Equals怎么用?C# Point.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Xna.Framework.Point
的用法示例。
在下文中一共展示了Point.Equals方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
/// <summary>Function to update the view.</summary>
/// <param name="gameTime">Provides a snapshot of timing values</param>
public override void Update(GameTime gameTime)
{
Point panDirection = new Point(0,0);
Vector2 panDisplacement = Vector2.Zero;
timeSinceLastDraw += gameTime.ElapsedGameTime.Milliseconds;
if (timeSinceLastDraw > msBetweenFrames)
{
timeSinceLastDraw = 0;
// Poll input
MouseState mouseState = Mouse.GetState();
int mouseX = mouseState.X;
int mouseY = mouseState.Y;
// check for clicking
if (prevMouseState.LeftButton == ButtonState.Pressed &&
mouseState.LeftButton == ButtonState.Released)
{
Vector3 nearSource = new Vector3((float)mouseX, (float)mouseY, 0f);
Vector3 farSource = new Vector3((float)mouseX, (float)mouseY, 1f);
}
// check for panning
if (panningAllowed)
{
// determine direction
if (mouseState.X <= panBuffer)
{
panDirection.X = 1;
}
if (mouseState.X >= (clientBounds.Width - panBuffer))
{
panDirection.X = -1;
}
if (mouseState.Y <= panBuffer)
{
panDirection.Y = 1;
}
if (mouseState.Y >= (clientBounds.Height - panBuffer))
{
panDirection.Y = -1;
}
// execute pan
if (!panDirection.Equals(Point.Zero))
tacticalView.Pan(panDirection);
}
// update children
//gameWindow.Update(gameTime);
// record old input state
prevMouseState = mouseState;
}
}
示例2: HasMouseMoved
private bool HasMouseMoved(Point position)
{
return !position.Equals(this.oldPosition);
}
示例3: Update
public void Update(TimeSpan elapsedTime, bool deviceActive)
{
#if WINDOWS_PHONE
TouchCollection touches = TouchPanel.GetState();
if (touches.Count > 0)
{
Point mouseLocation = new Point((int)touches[0].Position.X, (int)touches[0].Position.Y);
// We only care about the primary touch for MouseInput implementation
switch (touches[0].State)
{
case TouchLocationState.Pressed:
if(MousePressEvent != null)
MousePressEvent(LeftButton, mouseLocation);
mousePressed = true;
// Handle drag start
startDraggingPos = mouseLocation;
prevDraggingPos = mouseLocation;
dragButton = LeftButton;
break;
case TouchLocationState.Released:
// RELEASE
if (MouseReleaseEvent != null)
MouseReleaseEvent(dragButton, mouseLocation);
// CLICK
if (MouseClickEvent != null)
MouseClickEvent(dragButton, mouseLocation);
mousePressed = false;
break;
case TouchLocationState.Moved:
if (!prevDraggingPos.Equals(mouseLocation))
{
if (MouseDragEvent != null)
MouseDragEvent(dragButton, startDraggingPos, mouseLocation);
if(MouseMoveEvent != null)
MouseMoveEvent(mouseLocation);
prevDraggingPos = mouseLocation;
}
break;
}
}
#elif WINDOWS
if (onlyTrackWhenFocused && !deviceActive)
return;
// Get the current state of the mouse
mouseState = Mouse.GetState();
// If only want to track inside of window, then ignore any mouse events
// triggered outside of the window
if (onlyTrackInsideWindow && (mouseState.X < 0 || mouseState.X >= State.Width
|| mouseState.Y < 0 || mouseState.Y >= State.Height))
{
return;
}
// HANDLE MOUSE PRESS
if (!mousePressed)
{
if (MouseLeftButtonPressed || MouseRightButtonPressed || MouseMiddleButtonPressed)
{
int button = LeftButton;
if (MouseRightButtonPressed)
button = RightButton;
else if (MouseMiddleButtonPressed)
button = MiddleButton;
if(MousePressEvent != null)
MousePressEvent(button, MouseLocation);
mousePressed = true;
// Handle drag start
startDraggingPos = MouseLocation;
dragButton = button;
}
}
else
{
// HANDLE MOUSE RELEASE & CLICK
if ((dragButton == RightButton && MouseRightButtonReleased) ||
(dragButton == MiddleButton && MouseMiddleButtonPressed) ||
(dragButton == LeftButton && MouseLeftButtonReleased))
{
// RELEASE
if(MouseReleaseEvent != null)
MouseReleaseEvent(dragButton, MouseLocation);
// CLICK
if(MouseClickEvent != null)
MouseClickEvent(dragButton, MouseLocation);
//.........这里部分代码省略.........
示例4: tilesConnected
private bool tilesConnected(Point start, Point goal)
{
if (start.Equals(goal))
{
return true;
}
Queue<Point> queue = new Queue<Point>();
bool[,] connected = new bool[tileGrid.Height, tileGrid.Width];
connected[start.Y - tileGrid.MinY, start.X - tileGrid.MinX] = true;
queue.Enqueue(start);
while (queue.Count != 0)
{
Point p = queue.Dequeue();
if (tilesConnectedHelper(queue, connected, new Point(p.X, p.Y + 1), goal) || // east
tilesConnectedHelper(queue, connected, new Point(p.X + 1, p.Y), goal) || // north
tilesConnectedHelper(queue, connected, new Point(p.X, p.Y - 1), goal) || // west
tilesConnectedHelper(queue, connected, new Point(p.X - 1, p.Y), goal)) // south
{
return true;
}
}
return false;
}
示例5: Step
private void Step()
{
if (state == GameState.Dying)
{
snakeBlocks.RemoveAt(snakeBlocks.Count - 1);
if (snakeBlocks.Count == 0)
{
Vector2 expVec = ScreenVec(nextBlock);
expVec.X += (float)blockSize / 2.0f;
expVec.Y += (float)blockSize / 2.0f;
boom.Play(0.5f, RandomPitch(0.5f), 0.0f);
explode.Trigger(ref expVec);
state = GameState.Splash;
InitSnake();
DoHighScore();
foreach (HighScore s in highScores)
Console.WriteLine(s);
}
return;
}
KeyboardState keyState = Keyboard.GetState();
keysDown.Clear();
keysDown.AddRange(keyState.GetPressedKeys());
snakeDirection = nextSnakeDirection;
Point head = snakeBlocks[0];
Point next = new Point(head.X + (snakeDirection == Direction.Right ? 1 : 0) -
(snakeDirection == Direction.Left ? 1 : 0),
head.Y + (snakeDirection == Direction.Down ? 1 : 0) -
(snakeDirection == Direction.Up ? 1 : 0));
// check for constrict
if (!constrictBlocks.Except(snakeBlocks).Any())
{
score += 5;
stepTime -= 3;
Vector2 screenExp = ScreenVec(nextBlock);
Vector2 expVec = new Vector2(screenExp.X + (blockSize / 2.0f),
screenExp.Y + (blockSize / 2.0f));
explode.Trigger(ref expVec);
boom.Play(0.5f, RandomPitch(0.5f), 0.0f);
GenerateBlock();
}
snakeBlocks.Insert(0, next);
if (next.Equals(nextBlock))
{
crunch.Play(1.0f, RandomPitch(0.3f), 0.0f);
score++;
stepTime -= 3;
GenerateBlock();
}
else // Pop the last block off
{
snakeBlocks.RemoveAt(snakeBlocks.Count - 1);
}
}
示例6: direction
private ArrowDirection direction(Point p1, Point p2, bool finished)
{
if (!finished)
{
Point p3 = new Point(p2.X + p1.X, p2.Y + p1.Y);
if (p1.Equals(new Point(1, 0)) && p2.Equals(new Point(1, 0)) || p1.Equals(new Point(-1, 0)) && p2.Equals(new Point(-1, 0)))
{
return ArrowDirection.Horizontal;
}
if (p1.Equals(new Point(0, 1)) && p2.Equals(new Point(0, 1)) || p1.Equals(new Point(0, -1)) && p2.Equals(new Point(0, -1)))
{
return ArrowDirection.Vertical;
}
if (p1.Equals(new Point(0, -1)) && p2.Equals(new Point(1, 0)) || p1.Equals(new Point(-1, 0)) && p2.Equals(new Point(0, 1)))
{
return ArrowDirection.BottomRight;
}
if (p1.Equals(new Point(0, -1)) && p2.Equals(new Point(-1, 0)) || p1.Equals(new Point(1, 0)) && p2.Equals(new Point(0, 1)))
{
return ArrowDirection.BottomLeft;
}
if (p1.Equals(new Point(-1, 0)) && p2.Equals(new Point(0, -1)) || p1.Equals(new Point(0, 1)) && p2.Equals(new Point(1, 0)))
{
return ArrowDirection.TopRight;
}
if (p1.Equals(new Point(1, 0)) && p2.Equals(new Point(0, -1)) || p1.Equals(new Point(0, 1)) && p2.Equals(new Point(-1, 0)))
{
return ArrowDirection.TopLeft;
}
}
else
{
if (p1.Equals(new Point(1, 0)))
{
return ArrowDirection.Right;
}
if (p1.Equals(new Point(-1, 0)))
{
return ArrowDirection.Left;
}
if (p1.Equals(new Point(0, 1)))
{
return ArrowDirection.Up;
}
if (p1.Equals(new Point(0, -1)))
{
return ArrowDirection.Down;
}
}
return ArrowDirection.None;
}
示例7: getAdjacentTiles
private List<Point> getAdjacentTiles(Point start, ushort room, Point target)
{
// check all 4 sides to see if the tiles on them:
// 1. are not blocked by a wall
// 2. do not contain any collidable objects
// TODO: optimise by remembering what certain tiles return for their collidable status, as this will not change.
var adj = new List<Point>();
Point test;
test = new Point(start.X, start.Y + 1);
if (!TileSolid(test.X, test.Y, room) || test.Equals(target)) adj.Add(test); //todo, check for wall between
test = new Point(start.X + 1, start.Y);
if (!TileSolid(test.X, test.Y, room) || test.Equals(target)) adj.Add(test); //todo, check for wall between
test = new Point(start.X, start.Y - 1);
if (!TileSolid(test.X, test.Y, room) || test.Equals(target)) adj.Add(test); //todo, check for wall between
test = new Point(start.X - 1, start.Y);
if (!TileSolid(test.X, test.Y, room) || test.Equals(target)) adj.Add(test); //todo, check for wall between
return adj;
}
示例8: PixelsBetweenPoints
/// <summary>
/// Gets the pixels between points.
/// </summary>
/// <param name="p1">Point one</param>
/// <param name="p2">Point two</param>
/// <param name="spacing">The pixel spacing between the points (default should be 1). Lower than 1 will use 1.</param>
/// <returns></returns>
public Point[] PixelsBetweenPoints(Point p1, Point p2, int spacing)
{
if (spacing < 1) spacing = 1;
int xDiff = p2.X - p1.X;
int yDiff = p2.Y - p1.Y;
double maxWidth = Math.Max(Math.Abs(xDiff) , Math.Abs(yDiff));
double xDelta = (xDiff / maxWidth) * spacing;
// Console.Out.WriteLine("xDelta: " + xDelta);
double yDelta = (yDiff / maxWidth) * spacing;
// Console.Out.WriteLine("yDelta: " + yDelta);
LinkedList<Point> pointList = new LinkedList<Point>();
Point currentPoint = p1;
Point previousPoint = new Point(-100, -100);
double currentX = p1.X, currentY = p1.Y;
for( int i = 0; i < maxWidth / spacing; i++ ) {
currentX += xDelta;
currentY += yDelta;
currentPoint.X = (int)currentX;
currentPoint.Y = (int)currentY;
Point newPoint = new Point( currentPoint.X, currentPoint.Y );
if ( previousPoint != null && !previousPoint.Equals(newPoint) ) {
// Console.Out.WriteLine(i + ". Adding point to list: " + newPoint);
pointList.AddLast(newPoint);
}
previousPoint = newPoint;
}
return pointList.ToArray<Point>();
}
示例9: MoveEntity
public bool MoveEntity(Entity entity, Point start, Point end)
{
if (start == null || end == null || !InBounds(end) || start.Equals(end)) {
return false;
}
// Retrieve the list of entities at the start position
List<Entity> entitiesAtStart;
if (entityTable.ContainsKey(start)) {
entitiesAtStart = entityTable[start];
} else {
// Add a new list for empty positions
entitiesAtStart = new List<Entity>();
entityTable.Add(start, entitiesAtStart);
}
// Remove the entity from the start bucket
if (entitiesAtStart.Remove(entity)) {
entity.Position = end;
// Retrieve the list of entities at the end position
List<Entity> entitiesAtEnd;
if (entityTable.ContainsKey(end)) {
entitiesAtEnd = entityTable[end];
} else {
// Adds a new list for empty positions
entitiesAtEnd = new List<Entity>();
entityTable.Add(end, entitiesAtEnd);
}
// Add the entity to the end bucket
entitiesAtEnd.Add(entity);
// Move successful
return true;
}
// Move failed
return false;
}
示例10: GenerateMatrix
private void GenerateMatrix(Node Prev, Point Aqui, Path Path)
{
if (CheckedBoard == null)
{
CheckedBoard = new bool[Board.Width, Board.Height];
}
CheckedBoard[Aqui.X, Aqui.Y] = true;
if (Path == null)
{
Path = new Path(this, null);
}
if (All.ContainsKey(Aqui) && (!Prev.Location.Equals(Aqui) || Path.Points.Count > 1))
{
Node node;
All.TryGetValue(Aqui, out node);
Path.AddEnd(node);
Prev.Paths.Add(Path);
node.Paths.Add(Path.Reverse());
//foreach (Point Point in Path.Points)
//{
// UI.RegisterSprite(new StaticSprite(new Element { X = Point.X, Y = Point.Y }, "fruit/banana", 20));
//}
return;
}
if (SurroundingFreeSpaces(Aqui) > 2 && !Path.Start.Location.Equals(Aqui) && !All.ContainsKey(Aqui))
{
//UI.RegisterSprite(new StaticSprite(new Element { X = Aqui.X, Y = Aqui.Y }, "fruit/orange", 20));
Node End = new Node(Aqui);
All.Add(Aqui, End);
//Path.AddEnd(End);
//Prev.Paths.Add(Path);
//End.Paths.Add(Path.Reverse());
//foreach (Point Point in Path.Points)
//{
// UI.RegisterSprite(new StaticSprite(new Element { X = Point.X, Y = Point.Y }, "fruit/cherry", 20));
//}
End.GenerateMatrix(End, End.Location, null);
return;
}
for (double i = 0; i < 2 * MathHelper.Pi; i+= MathHelper.Pi/2)
{
Point Next = new Point(Aqui.X + (int)Math.Round(Math.Sin(i)), Aqui.Y + (int)Math.Round(Math.Cos(i)));
if(IsInBounds(Next) && !Board.IsType(Enum.ElementTypes.Wall, Next) && !CheckedBoard[Next.X, Next.Y]){
GenerateMatrix(Prev, Next, Aqui.Equals(Location)?Path.Diverge():Path.Diverge(Aqui));
}
}
}
示例11: Update
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
var currentState = Mouse.GetState();
LeftButton.Update(currentState.LeftButton);
RightButton.Update(currentState.RightButton);
MiddleButton.Update(currentState.MiddleButton);
var newPoint = new Point(currentState.X, currentState.Y);
if (!newPoint.Equals(lastPosition))
{
MouseMove(newPoint);
lastPosition = newPoint;
}
}