private float GetGroundY(Level level, float time) { float x = LevelGenerationValues.GetXPositionByTime(time); Ground ground = LevelAnalysis.GetGroundBelowVector(level, new Vector2(x, 999)); if (ground == null) { ground = LevelAnalysis.GetGroundLeftFromVector(level, new Vector2(x, 999)); } return(ground.TopY); }
private Vector2 GetVisualCenter(LevelProgression levelProgression) { Vector2 playerPosition = levelProgression.CurrentPlayerPosition; Ground groundBelowPlayer = LevelAnalysis.GetGroundBelowVector(level, playerPosition); if (hasPlayerLeftCurrentGround) { if (groundBelowPlayer != null) { if (Math.Abs(playerPosition.Y - groundBelowPlayer.TopY) < 0.001f) { hasPlayerLeftCurrentGround = false; } } return(new Vector2(playerPosition.X, Math.Min(lastGroundTopY, playerPosition.Y))); } if (groundBelowPlayer != null) { return(new Vector2(playerPosition.X, groundBelowPlayer.TopY)); } if (!hasPlayerLeftCurrentGround) { hasPlayerLeftCurrentGround = true; } Ground groundLeftFromPlayer = LevelAnalysis.GetGroundLeftFromVector(level, playerPosition); lastGroundTopY = groundLeftFromPlayer.TopY; if (groundLeftFromPlayer == null) { return(playerPosition); } return(new Vector2(playerPosition.X, Math.Min(groundLeftFromPlayer.TopY, playerPosition.Y))); }