public Vector2 GetLowCollectiblePosition(LevelElementPlacement placement, float groundY)
 {
     return(GetCollectiblePosition(placement, LevelGenerationValues.GetLowCollectibleYOffset(), groundY));
 }
示例#2
0
        public Level GenerateLevel(LevelPlan levelPlan)
        {
            Level level = new Level();

            level.PlayerStartingPosition = LevelGenerationValues.PlayerStartPosition;

            level.GoalLineX = 99999;

            List <LevelElementPlacement> chasmsPlacements    = levelPlan.GetChasms();
            List <LevelElementPlacement> nonChasmsPlacements = levelPlan.GetNonChasms();

            float currentLeftX = LevelGenerationValues.FirstGroundLeftX;
            float currentY     = LevelGenerationValues.PlayerStartPosition.Y;

            foreach (LevelElementPlacement placement in chasmsPlacements)
            {
                float currentRightX = LevelGenerationValues.GetXPositionByTime(placement.LevelElementStartTime +
                                                                               LevelGenerationValues.SuggestedChasmJumpTimingOffset);

                level.AddGround(new Ground(currentLeftX, currentRightX, currentY));

                if (placement.Type == LevelElementType.ChasmWithCollectibles)
                {
                    foreach (float synchroTime in placement.SynchroTimes)
                    {
                        float collectibleXPosition = LevelGenerationValues.GetXPositionByTime(synchroTime);

                        float timeAfterJump = synchroTime - placement.LevelElementStartTime;

                        float collectibleYPosition = currentY + LevelGenerationValues.GetYDifferenceAfterJump(timeAfterJump)
                                                     + LevelGenerationValues.GetLowCollectibleYOffset();

                        level.AddCollectibleByPosition(new Vector2(collectibleXPosition, collectibleYPosition));
                    }
                }

                //float hangTime = placement.GetSynchroDuration();
                float hangTime = placement.LevelElementEndTime - placement.LevelElementStartTime;

                currentLeftX = currentRightX + LevelGenerationValues.GetChasmXDifference(hangTime);

                currentY = currentY + LevelGenerationValues.GetChasmYDifference(hangTime);
            }

            float lastRightX = LevelGenerationValues.GetXPositionByTime(9999);

            level.AddGround(new Ground(currentLeftX, lastRightX, currentY));


            LevelElementCreator levelElementGenerator = new LevelElementCreator();

            foreach (LevelElementPlacement placement in nonChasmsPlacements)
            {
                float groundY = GetGroundY(level, placement.SynchroStartTime);

                if (placement.Type == LevelElementType.DuckObstacle)
                {
                    Obstacle obstacle = levelElementGenerator.CreateDuckObstacle(placement, groundY);

                    level.AddObstacle(obstacle);
                }
                if (placement.Type == LevelElementType.JumpObstacle)
                {
                    Obstacle obstacle = levelElementGenerator.CreateJumpObstacle(placement, groundY);

                    level.AddObstacle(obstacle);
                }
                if (placement.Type == LevelElementType.LowCollectible)
                {
                    Vector2 collectiblePosition = levelElementGenerator.GetLowCollectiblePosition(placement, groundY);

                    level.AddCollectibleByPosition(collectiblePosition);
                }
                if (placement.Type == LevelElementType.HighCollectible)
                {
                    Vector2 collectiblePosition = levelElementGenerator.GetHighCollectiblePosition(placement, groundY);

                    level.AddCollectibleByPosition(collectiblePosition);
                }
                if (placement.Type == LevelElementType.SingleProjectile)
                {
                    Vector2 projectilePosition = levelElementGenerator.GetProjectilePosition(placement.SynchroStartTime, groundY);

                    level.AddProjectileByPosition(projectilePosition);
                }
                if (placement.Type == LevelElementType.MultipleProjectiles)
                {
                    foreach (float synchroTime in placement.SynchroTimes)
                    {
                        Vector2 projectilePosition = levelElementGenerator.GetProjectilePosition(synchroTime, groundY);

                        level.AddProjectileByPosition(projectilePosition);
                    }
                }
            }

            return(level);
        }