private void MoveToDestination() { //elementToMove.SetStatusMessage("Trying to move"); //Are we starting a move? if (!moveGoingOn && !associatedMap.getOccupied(destination)) { moveGoingOn = true; //set Destination As Occupied associatedMap.setOccupied(destination, true); associatedMap.setOccupyingElement(destination, elementToMove); } if (moveGoingOn && !this.GetShutdownSmoothly()) { //Process the move //Find direction of move elementToMove.SetStuck(false); float xMove = 0.0f; float yMove = 0.0f; if (elementToMove.getWorldPositionX() > destination.X) { xMove = -1.0f; } if (elementToMove.getWorldPositionX() < destination.X) { xMove = 1.0f; } if (elementToMove.getWorldPositionY() > destination.Y) { yMove = -1.0f; } if (elementToMove.getWorldPositionY() < destination.Y) { yMove = 1.0f; } Vector2 newAnimationOffset = new Vector2(0, 0); newAnimationOffset.X = elementToMove.GetAnimationOffset().X + (gameTime.ElapsedGameTime.Milliseconds * elementToMove.GetSpeed() * xMove); newAnimationOffset.Y = elementToMove.GetAnimationOffset().Y + (gameTime.ElapsedGameTime.Milliseconds * elementToMove.GetSpeed() * yMove); elementToMove.SetAnimationOffset(newAnimationOffset); //Has the move finished? if (Math.Abs(newAnimationOffset.X) > GlobalVariables.TILE_SIZE || Math.Abs(newAnimationOffset.Y) > GlobalVariables.TILE_SIZE) { associatedMap.setOccupied(new Vector2(elementToMove.getWorldPositionX(), elementToMove.getWorldPositionY()), false); associatedMap.setOccupyingElement(new Vector2(elementToMove.getWorldPositionX(), elementToMove.getWorldPositionY()), null); elementToMove.worldPositionX = (int)destination.X; elementToMove.worldPositionY = (int)destination.Y; elementToMove.SetAnimationOffset(new Vector2(0, 0)); if (this.GetCallingEvent() == null) { elementToMove.SetStatusMessage("I'm Here!"); } this.SetComplete(); } else { elementToMove.SetStatusMessage("Walking"); } } else { elementToMove.SetStuck(true); this.SetComplete(); } }