private void SetNewPlayerPosition() { Vector2 oldPosition = GetLevelProgression().CurrentPlayerPosition; Vector2 newPosition = gamePhysics.DoPlayerPhysics(oldPosition); if (!LevelAnalysis.IsVectorOnGround(levelAttempt.Level, newPosition)) { bool isPlayerStanding = GetLevelProgression().IsPlayerStanding; Ground groundCollidedWith = collisions.GetPlayerGroundCollision(newPosition, isPlayerStanding); if (groundCollidedWith != null) { Vector2 rightFoot = PhysicsValues.GetRightFootPosition(newPosition); float deltaX = Math.Abs(rightFoot.X - groundCollidedWith.LeftX); float deltaY = Math.Abs(groundCollidedWith.TopY - rightFoot.Y); if (deltaY > deltaX) { AddPlayerFail(); } newPosition = new Vector2(newPosition.X, groundCollidedWith.TopY); gamePhysics.ResetVerticalVelocity(); } } GetLevelProgression().CurrentPlayerPosition = newPosition; }
private bool IsPlayerOnGround(Vector2 playerPosition) { Vector2 leftFoot = PhysicsValues.GetLeftFootPosition(playerPosition); Vector2 rightFoot = PhysicsValues.GetRightFootPosition(playerPosition); return(LevelAnalysis.IsVectorOnGround(level, leftFoot) || LevelAnalysis.IsVectorOnGround(level, rightFoot)); }
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))); }