Exemple #1
0
        public static LevelElementPlacement CreateSingleSynchro(LevelElementType type, float synchroTime)
        {
            LevelElementPlacement placement = new LevelElementPlacement(type);

            placement.SynchroStartTime = synchroTime;
            placement.SynchroEndTime   = synchroTime;

            if (type == LevelElementType.JumpObstacle)
            {
                placement.LevelElementStartTime = synchroTime;
                placement.LevelElementEndTime   = synchroTime + LevelGenerationValues.GetPlainJumpDuration();
            }
            if (type == LevelElementType.HighCollectible)
            {
                float halfJumpDuration = LevelGenerationValues.GetPlainJumpDuration() / 2.0f;

                placement.LevelElementStartTime = synchroTime - halfJumpDuration;
                placement.LevelElementEndTime   = synchroTime + halfJumpDuration;
            }
            if (type == LevelElementType.LowCollectible)
            {
                placement.LevelElementStartTime = synchroTime - 0.01f;
                placement.LevelElementEndTime   = synchroTime + 0.01f;
            }
            if (type == LevelElementType.SingleProjectile)
            {
                placement.LevelElementStartTime = synchroTime - LevelGenerationValues.ProjectileSafetyTime;
                placement.LevelElementEndTime   = synchroTime;
            }

            return(placement);
        }
        public Vector2 GetProjectilePosition(float time, float groundY)
        {
            float hitXPosition = GetPlayerRightEdgeXByTime(time);

            float startingXPosition = GeneralValues.MusicStartPositionX + hitXPosition + time *
                                      PhysicsValues.GetProjectileVelocity() + (PhysicsValues.ProjectileHitboxWidth / 2.0f);

            float startingYPosition = groundY + LevelGenerationValues.GetProjectileYOffset();

            return(new Vector2(startingXPosition, startingYPosition));
        }
        public Obstacle CreateDuckObstacle(LevelElementPlacement placement, float groundY)
        {
            float obstacleStartTime = placement.SynchroStartTime + LevelGenerationValues.DuckingObstacleEnteringSafetyTime;
            float obstacleEndtime   = placement.SynchroEndTime - LevelGenerationValues.DuckingObstacleLeavingSafetyTime;

            float leftX  = GetXPositionByTime(obstacleStartTime);
            float rightX = GetXPositionByTime(obstacleEndtime);

            float topY    = groundY + LevelGenerationValues.GetDuckObstacleGapHeight() + LevelGenerationValues.GetDuckObstacleHeight();
            float bottomY = groundY + LevelGenerationValues.GetDuckObstacleGapHeight();

            return(new Obstacle(new Vector2(leftX, topY), new Vector2(rightX, bottomY)));
        }
        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);
        }
        public Obstacle CreateJumpObstacle(LevelElementPlacement placement, float groundY)
        {
            float centerOfObstacle = GetXPositionByTime(placement.SynchroStartTime) +
                                     PhysicsValues.GetPlainJumpLength() / 2.0f;

            float halfObstacleWidth = LevelGenerationValues.GetJumpObstacleWidth() / 2.0f;

            float leftX  = centerOfObstacle - halfObstacleWidth;
            float rightX = centerOfObstacle + halfObstacleWidth;

            float topY = groundY + LevelGenerationValues.GetJumpObstacleHeight();

            return(new Obstacle(new Vector2(leftX, topY), new Vector2(rightX, groundY)));
        }
 public Vector2 GetHighCollectiblePosition(LevelElementPlacement placement, float groundY)
 {
     return(GetCollectiblePosition(placement, LevelGenerationValues.GetHighCollectibleYOffset(), groundY));
 }
 private float GetXPositionByTime(float time)
 {
     return(LevelGenerationValues.GetXPositionByTime(time));
 }
        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);
        }