Exemple #1
0
        /// <summary>
        /// Create ball randomly. Used in spawning in menu
        /// </summary>
        /// <returns></returns>
        public static List <Ball> CreateRandomBalls()
        {
            List <Ball> balls     = new List <Ball>();
            int         numOfBall = RandomMath.RandomBetween(1, 4);     // Random spawn 1-3 balls

            var ballSize     = RandomMath.RandomEnum <BallSize>();
            var ballStrength = RandomMath.RandomEnum <BallStrength>();

            foreach (int i in Enumerable.Range(1, numOfBall))
            {
                Vector2 position = new Vector2()
                {
                    X = RandomMath.RandomBetween(0, GlobalData.Screen.Width - Ball.RadiusDict[ballSize] * 2),
                    Y = RandomMath.RandomBetween(0, GlobalData.Screen.Height - Ball.RadiusDict[ballSize] * 2),
                };

                Ball ball = new Ball(EntryPoint.Game.Scene, position);

                ball.Size     = ballSize;
                ball.Strength = ballStrength;
                ball.Angle    = RandomMath.RandomBetween(0, 360);

                balls.Add(ball);
            }

            return(balls);
        }
Exemple #2
0
        private void UpdateTimers()
        {
            Timer.Count.Update(deltaTime);
            IncreaseBallVelocityTimer += deltaTime;
            SpawnPowerUpTimer         += deltaTime;

            if (IncreaseBallVelocityTimer >= IncreaseBallVelocityInterval)
            {
                BallVelocity += 10;
                Balls.ForEach(b => { b.BaseVelocity = BallVelocity; b.Velocity = BallVelocity; });

                IncreaseBallVelocityTimer = 0;
            }

            if (SpawnPowerUpTimer >= SpawnPowerUpInterval)
            {
                var randPowerup  = new PowerUp(this, RandomMath.RandomEnum <PowerUpType>());
                var randPosition = new Vector2()
                {
                    X = RandomMath.RandomBetween(0, GlobalData.Screen.Width - SpriteData.PackageWidth),
                    Y = 0 - SpriteData.PackageHeight,
                };

                Packages.AddIfNotNull(ModelFactory.CreatePowerUpPackage(randPowerup, randPosition));
                SpawnPowerUpTimer = 0;
            }
        }
Exemple #3
0
        private PowerUpPackage SpawnPowerUpPackage()
        {
            // TODO: remove
            //PowerUp pu = null;

            //if (RandomMath.RandomBoolean())
            //	pu = new PowerUp(scene, PowerUpType.Magnetize);
            //else
            //	pu = new PowerUp(scene, PowerUpType.Triple);

            //return ModelFactory.CreatePowerUpPackage(pu, this.Position);


            if (!RandomMath.RandomPercent(powerUpSpawnChance))
            {
                return(null);
            }

            PowerUp powerUp = null;
            var     randNum = RandomMath.RandomBetween(0, 100);

            if (0 <= randNum && randNum < 30 && favoredPowerUp != PowerUpType.Nothing)
            {
                powerUp = new PowerUp(scene, favoredPowerUp);
            }

            else if (30 <= randNum && randNum < 50 && secondaryfavoredPowerUp != PowerUpType.Nothing)
            {
                powerUp = new PowerUp(scene, secondaryfavoredPowerUp);
            }

            else
            {
                powerUp = new PowerUp(scene, RandomMath.RandomEnum <PowerUpType>());
            }

            if (powerUp.PowerUpType == PowerUpType.Nothing)
            {
                return(null);
            }

            return(ModelFactory.CreatePowerUpPackage(powerUp, this.Position));
        }