コード例 #1
0
ファイル: Game1.cs プロジェクト: vantos3001/ClickShooter
        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);
            }
        }
コード例 #2
0
ファイル: Game1.cs プロジェクト: vantos3001/ClickShooter
        // maybe spawn big and little circle
        // сделать перегрузку функций
        private void SpawnLittleCircle()
        {
            //random x and y
            int randomLocationX = GetRandomLocation(GameConstants.SPAWN_BORDER_SIZE, GameConstants.WINDOW_WIDTH - 2 * GameConstants.SPAWN_BORDER_SIZE);
            // generate outside window
            int randomLocationY = GameConstants.SPAWN_OUTSIDE_WINDOW + GetRandomLocation(GameConstants.SPAWN_BORDER_SIZE, GameConstants.WINDOW_HEIGHT - 2 * GameConstants.SPAWN_BORDER_SIZE);

            //random velocity
            float speedLittleCircle = GameConstants.SPEED_MIN_LITTLE_CIRCLE + RandomNumberGerator.NextFloat(GameConstants.SPEED_RANGE_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);
        }