public void Move(GameTime gameTime) { if (Health <= 0) { return; } var timeElapsed = Math.Min(gameTime.ElapsedGameTime.Milliseconds / 1000f, 0.2f); var movement = Velocity * timeElapsed; mLastVelocities[mCurrentLastVelocitiesIndex] = Velocity; mCurrentLastVelocitiesIndex++; mCurrentLastVelocitiesIndex %= mLastVelocities.Length; var averageVelocity = mLastVelocities.Aggregate(Vector2.Zero, (current, velocity) => current + velocity); Position += movement; if (CurrentQuadTree == null) { Position -= movement; } else { Position += QuadTree.ClampPosition(this); CurrentQuadTree.UpdateGameObjectPosition(this); } if (Math.Abs(averageVelocity.Y) > 2 * Math.Abs(averageVelocity.X) && !mOnlyLeftRightDirection) { if (averageVelocity.Y > 0) { mDirection = (int)Directions.Down; } else { mDirection = (int)Directions.Up; } } else if (2 * Math.Abs(averageVelocity.Y) < Math.Abs(averageVelocity.X)) { if (averageVelocity.X > 0) { mDirection = (int)Directions.Right; } else { mDirection = (int)Directions.Left; } } else { if (mDirection == (int)Directions.Down && averageVelocity.Y < 0 || mDirection == (int)Directions.Up && averageVelocity.Y > 0 || mDirection == (int)Directions.Right && averageVelocity.X < 0 || mDirection == (int)Directions.Left && averageVelocity.X > 0) { mDirection = (int)GetDirection(averageVelocity); } } }