Ejemplo n.º 1
0
        private void SpawnLittleCircle(Rectangle drawRectangleBigCircle)
        {
            //random x and y
            // i>1 because RandomNumberGerator.Next() spawn from 1 to max
            // possibility that loop does not work
            for (int i = RandomNumberGerator.Next(GameConstants.MAX_COUNT_LITTLE_CIRCLE_AFTER_KILL_BIG_CIRCLE); i >= 1; i--)
            {
                int randomLocationX = GetRandomLocation(drawRectangleBigCircle.X, 60);
                // generate outside window
                int randomLocationY = GetRandomLocation(drawRectangleBigCircle.Y, 60);

                //random velocity
                float speedLittleCircle = GameConstants.SPEED_MIN_LITTLE_CIRCLE_AFTER_KILL_BIG_CIRCLE + RandomNumberGerator.NextFloat(GameConstants.SPEED_RANGE_CIRCLE_AFTER_KILL_BIG_CIRCLE);
                float angleLittleCircle = RandomNumberGerator.NextFloat((float)(2 * Math.PI));

                // use sin for x and don't use for y
                Vector2 velocity = new Vector2(speedLittleCircle * (float)Math.Sin((double)angleLittleCircle), speedLittleCircle);

                if (velocity.Y == 0)
                {
                    velocity.Y = velocity.X;
                }

                if (velocity.Y < 0)
                {
                    velocity.Y *= -1;
                }

                string       spriteName      = @"graphics\littleCircle\" + player.ColorEnamy + "LittleCircle";
                LittleCircle newLittleCircle = new LittleCircle(Content, spriteName, randomLocationX, randomLocationY, velocity);
                littleCircles.Add(newLittleCircle);
            }
        }
Ejemplo n.º 2
0
 // get random location(int)
 private int GetRandomLocation(int min, int range)
 {
     return(min + RandomNumberGerator.Next(range + 1));
 }