public void tileMove(List <SimpleSprite> collisionSet) { DIRECTION oldDirection = Direction; // remember the old TilePosition in case we need to move back Vector2 PreviousTilePosition = TilePosition; // Rotate toward the site if sight is moving if (InputEngine.CurrentPadState.ThumbSticks.Right.LengthSquared() > 0) { // reset the original direction facing Direction = DIRECTION.LEFT; followPosition(Site.PixelPosition); } // Rotate with the mouse if (InputEngine.PreviousMouseState.Position.ToVector2() != InputEngine.MousePosition) { // reset the original direction facing Direction = DIRECTION.LEFT; followPosition(Site.PixelPosition); } if (InputEngine.IsKeyHeld(Keys.Right) || InputEngine.IsKeyHeld(Keys.D) || InputEngine.GetDirection(InputEngine.CurrentPadState.ThumbSticks.Left) == Engine.Engines.Direction.Right) { angleOfRotation = 0f; TilePosition += new Vector2(1, 0) * speed; _direction = DIRECTION.RIGHT; MovingState = STATE.MOVING; } if (InputEngine.IsKeyHeld(Keys.Left) || InputEngine.IsKeyHeld(Keys.A) || InputEngine.GetDirection(InputEngine.CurrentPadState.ThumbSticks.Left) == Engine.Engines.Direction.Left) { angleOfRotation = 0f; TilePosition += new Vector2(-1, 0) * speed; _direction = DIRECTION.LEFT; MovingState = STATE.MOVING; } if (InputEngine.IsKeyHeld(Keys.Up) || InputEngine.IsKeyHeld(Keys.W) || InputEngine.GetDirection(InputEngine.CurrentPadState.ThumbSticks.Left) == Engine.Engines.Direction.Up) { angleOfRotation = 0f; TilePosition += new Vector2(0, -1) * speed; _direction = DIRECTION.UP; MovingState = STATE.MOVING; } if (InputEngine.IsKeyHeld(Keys.Down) || InputEngine.IsKeyHeld(Keys.S) || InputEngine.GetDirection(InputEngine.CurrentPadState.ThumbSticks.Left) == Engine.Engines.Direction.Down) { angleOfRotation = 0f; TilePosition += new Vector2(0, 1) * speed; _direction = DIRECTION.DOWN; MovingState = STATE.MOVING; } foreach (SimpleSprite item in collisionSet) { if (item.BoundingRect.Intersects(DrawRectangle)) { TilePosition = PreviousTilePosition; MovingState = STATE.STILL; item.tint = Color.Red; break; } else { item.tint = Color.White; } } if (Direction != oldDirection && _directionFrames[(int)_direction].Count() > 0) { Frames = _directionFrames[(int)_direction]; CurrentFrame = 0; } // Keep the Player in the tile map TilePosition = Vector2.Clamp(TilePosition, Vector2.Zero, TileBound - Vector2.One); // keep the site in view of the player if (MovingState == STATE.MOVING) { Site.TilePosition += TilePosition - PreviousTilePosition; } else { Site.TilePosition -= TilePosition - PreviousTilePosition; } // Keep the Site in the TileMap Site.TilePosition = Vector2.Clamp(Site.TilePosition, Vector2.Zero, TileBound - Vector2.One); }