Beispiel #1
0
        public Obstacle PerformSpawn()
        {
#if DEBUG
            var screen = FlatRedBall.Screens.ScreenManager.CurrentScreen;
            LastTwoSpawnTimes[0] = LastTwoSpawnTimes[1];
            LastTwoSpawnTimes[1] = screen.PauseAdjustedCurrentTime;

            SpawnRollingAverage.AddValue((float)(LastTwoSpawnTimes[1] - LastTwoSpawnTimes[0]));
#endif
            var newObstacle = ObstacleFactory.CreateNew();

            if (FlatRedBallServices.Random.Between(0, 1) < RatioOfGold)
            {
                newObstacle.CurrentBonusCategoryState = Obstacle.BonusCategory.Bonus;
            }

            int repositionsSoFar = 0;
            while (repositionsSoFar <= NumberOfTimesToRepositionCrates)
            {
                PositionNewObstacle(newObstacle);

                var distanceFromCenterOfPath = Math.Abs(newObstacle.X - pathX) - newObstacle.Width;

                bool isOnPath = distanceFromCenterOfPath < PathWidth / 2.0f;

                if (!isOnPath)
                {
                    break;
                }

                repositionsSoFar++;
            }



            lastSpawnY = this.Y;

            return(newObstacle);
        }