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)); }