Esempio n. 1
0
        /// <summary>
        /// Spawns a new teddy bear at a random location
        /// </summary>
        private void SpawnBear()
        {
            // generate random location
            int randomLocationX = GetRandomLocation(GameConstants.SpawnBorderSize, (GameConstants.WindowWidth - GameConstants.SpawnBorderSize));
            int randomLocationY = GetRandomLocation(GameConstants.SpawnBorderSize, (GameConstants.WindowHeight - GameConstants.SpawnBorderSize));

            // generate random velocity
            float   randomSpeed    = GameConstants.MinBearSpeed + RandomNumberGenerator.NextFloat(GameConstants.BearSpeedRange);
            float   randomAngle    = RandomNumberGenerator.NextFloat(2 * (float)Math.PI);
            Vector2 randomVelocity = new Vector2((float)(randomSpeed * Math.Cos(randomAngle)), (float)(randomSpeed * Math.Sin(randomAngle)));

            // create new bear
            TeddyBear newBear = new TeddyBear(Content, @"BuildGraphics\teddybear", randomLocationX, randomLocationY, randomVelocity, teddyBounce, teddyShot);

            // make sure we don't spawn into a collision
            List <Rectangle> otherRectangles = GetCollisionRectangles();

            while (CollisionUtils.IsCollisionFree(newBear.DrawRectangle, otherRectangles) == false)
            {
                newBear.X = GetRandomLocation(GameConstants.SpawnBorderSize, (GameConstants.WindowWidth - GameConstants.SpawnBorderSize));
                newBear.Y = GetRandomLocation(GameConstants.SpawnBorderSize, (GameConstants.WindowHeight - GameConstants.SpawnBorderSize));
            }

            // add new bear to list
            bears.Add(newBear);
        }
Esempio n. 2
0
        /// <summary>
        /// Spawns a new teddy bear at a random location
        /// </summary>
        private void SpawnBear()
        {
            // generate random location
            int xBear = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowWidth - GameConstants.SpawnBorderSize * 2);
            int yBear = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowHeight - GameConstants.SpawnBorderSize * 2);

            // generate random velocity

            float randVel = GameConstants.MinBearSpeed + RandomNumberGenerator.NextFloat(GameConstants.BearSpeedRange - GameConstants.MinBearSpeed);

            float randAng = RandomNumberGenerator.NextFloat((float)Math.PI / 2);

            Vector2 velBear = new Vector2(randVel * (float)Math.Cos(randAng), randVel * (float)Math.Sin(randAng));

            // create new bear

            TeddyBear newBear = new TeddyBear(Content, "graphics/teddybear", xBear, yBear, velBear, teddyBounce, teddyShot);

            // make sure we don't spawn into a collision
            List <Rectangle> otherCollisionRectangles = GetCollisionRectangles();

            while (!CollisionUtils.IsCollisionFree(newBear.CollisionRectangle, otherCollisionRectangles))
            {
                newBear.X = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowWidth - GameConstants.SpawnBorderSize * 2);
                newBear.Y = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowHeight - GameConstants.SpawnBorderSize * 2);
            }

            // add new bear to list
            bears.Add(newBear);
        }
Esempio n. 3
0
        /// <summary>
        /// Spawns a new teddy bear at a random location
        /// </summary>
        private void SpawnBear()
        {
            // generate random location
            int bearRndLocX  = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowWidth - GameConstants.SpawnBorderSize);
            int bearRandLoxY = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowHeight - GameConstants.SpawnBorderSize);

            // generate random velocity, angle and Vector for the bear velocity
            float bearRndSpeed = GameConstants.MinBearSpeed + RandomNumberGenerator.NextFloat(GameConstants.BearSpeedRange);
            float bearRndAngle = RandomNumberGenerator.NextFloat((float)Math.PI);
            //float bearRndAngle = (float)Math.PI/3;
            Vector2 bearVelocityVector = new Vector2((float)(bearRndSpeed * Math.Cos(Convert.ToDouble(bearRndAngle))), (float)(bearRndSpeed * Math.Sin(Convert.ToDouble(bearRndAngle))));

            // create new bear
            TeddyBear newBear = new TeddyBear(Content, @"graphics\teddybear", bearRndLocX, bearRandLoxY, bearVelocityVector, teddyBounce, teddyShot);


            // make sure we don't spawn into a collision
            List <Rectangle> collisionRectangles = GetCollisionRectangles();

            while (!CollisionUtils.IsCollisionFree(newBear.CollisionRectangle, collisionRectangles))
            {
                newBear.X = GetRandomLocation(0, GameConstants.WindowWidth);
                newBear.Y = GetRandomLocation(0, GameConstants.WindowHeight);
            }

            // add new bear to list
            bears.Add(newBear);
        }
Esempio n. 4
0
        /// <summary>
        /// Spawns a new teddy bear at a random location
        /// </summary>
        private void SpawnBear()
        {
            // generate random location
            int x = GetRandomLocation(GameConstants.SpawnBorderSize,
                                      graphics.PreferredBackBufferWidth - 2 * GameConstants.SpawnBorderSize);
            int y = GetRandomLocation(GameConstants.SpawnBorderSize,
                                      graphics.PreferredBackBufferHeight - 2 * GameConstants.SpawnBorderSize);
            // generate random velocity
            float   speed    = GameConstants.MinBearSpeed + RandomNumberGenerator.NextFloat(GameConstants.BearSpeedRange);
            float   angle    = RandomNumberGenerator.NextFloat(2 * (float)Math.PI);
            Vector2 velocity = new Vector2(
                (float)(speed * Math.Cos(angle)), (float)(speed * Math.Sin(angle)));
            // create new bear
            TeddyBear newBear = new TeddyBear(Content, @"graphics\teddybear", x, y, velocity, null, null);
            // make sure we don't spawn into a collision
            List <Rectangle> rects = GetCollisionRectangles();

            while (!CollisionUtils.IsCollisionFree(newBear.DrawRectangle, rects))
            {
                x         = GetRandomLocation(GameConstants.SpawnBorderSize, graphics.PreferredBackBufferWidth - 2 * GameConstants.SpawnBorderSize);
                y         = GetRandomLocation(GameConstants.SpawnBorderSize, graphics.PreferredBackBufferHeight - 2 * GameConstants.SpawnBorderSize);
                newBear.X = x;
                newBear.Y = y;
            }
            // add new bear to list
            bears.Add(newBear);
        }
Esempio n. 5
0
        /// <summary>
        /// Spawns a new teddy bear at a random location
        /// </summary>
        private void SpawnBear()
        {
            // generate random location
            //Vector2 bearLocation = new Vector2(GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowWidth - GameConstants.SpawnBorderSize),
            //                                   GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowHeight - GameConstants.SpawnBorderSize));
            int bearLocationX = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowWidth - GameConstants.SpawnBorderSize);
            int bearLocationY = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowHeight - GameConstants.SpawnBorderSize);


            // generate random velocity
            float bearSpeed = GameConstants.MinBearSpeed + RandomNumberGenerator.NextFloat(GameConstants.BearSpeedRange);
            float bearAngle = RandomNumberGenerator.NextFloat(2) * (float)Math.PI; // Radians

            // Using Math.Sin to calculate the 'y' component and Math.Cos for the 'x' component
            Vector2 bearVelocity = new Vector2((float)Math.Cos(bearAngle) * bearSpeed, (float)Math.Sin(bearAngle) * bearSpeed);

            // create new bear
            TeddyBear newBear = new TeddyBear(Content, @"graphics\teddybear", bearLocationX, bearLocationY, bearVelocity, teddyBounce, teddyShot);

            // make sure we don't spawn into a collision
            List <Rectangle> collisionRectangles = GetCollisionRectangles();

            while (!CollisionUtils.IsCollisionFree(newBear.CollisionRectangle, collisionRectangles))
            {
                newBear.X = GetRandomLocation(0, GameConstants.WindowWidth);
                newBear.Y = GetRandomLocation(0, GameConstants.WindowHeight);
            }

            // add new bear to list
            bears.Add(newBear);
        }
Esempio n. 6
0
        /// <summary>
        /// Spawns a new teddy bear at a random location
        /// </summary>
        private void SpawnBear()
        {
            // generate random location, note the location might be in border since we use it's center as (x,y)
            int x = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowWidth - GameConstants.SpawnBorderSize);
            int y = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowHeight - GameConstants.SpawnBorderSize);

            // generate random velocity
            float   v        = GameConstants.MinBearSpeed + RandomNumberGenerator.NextFloat(GameConstants.BearSpeedRange - GameConstants.MinBearSpeed);
            float   angle    = RandomNumberGenerator.NextFloat(2 * (float)Math.PI);
            Vector2 velocity = new Vector2((float)(v * Math.Cos(angle)), (float)(v * Math.Sin(angle)));

            // create new bear
            TeddyBear newBear = new TeddyBear(Content, @"graphics\teddybear", x, y, velocity, teddyBounce, teddyShot);

            // make sure we don't spawn into a collision
            while (!CollisionUtils.IsCollisionFree(newBear.CollisionRectangle, GetCollisionRectangles()))
            {
                x       = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowWidth - GameConstants.SpawnBorderSize);
                y       = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowHeight - GameConstants.SpawnBorderSize);
                newBear = new TeddyBear(Content, @"graphics\teddybear", x, y, velocity, teddyBounce, teddyShot);
            }

            // add new bear to list
            bears.Add(newBear);
        }
Esempio n. 7
0
        /// <summary>
        /// Spawns a new teddy bear at a random location
        /// </summary>
        private void SpawnBear()
        {
            // generate random location
            int x = GetRandomLocation(GameConstants.SPAWN_BORDER_SIZE,
                                      graphics.PreferredBackBufferWidth - 2 * GameConstants.SPAWN_BORDER_SIZE);
            int y = GetRandomLocation(GameConstants.SPAWN_BORDER_SIZE,
                                      graphics.PreferredBackBufferHeight - 2 * GameConstants.SPAWN_BORDER_SIZE);

            // generate random velocity
            float speed = GameConstants.MIN_BEAR_SPEED +
                          RandomNumberGenerator.NextFloat(GameConstants.BEAR_SPEED_RANGE);
            float   angle    = RandomNumberGenerator.NextFloat(2 * (float)Math.PI);
            Vector2 velocity = new Vector2(
                (float)(speed * Math.Cos(angle)), (float)(speed * Math.Sin(angle)));

            // create new bear
            TeddyBear newBear = new TeddyBear(Content, "teddybear", x, y, velocity,
                                              null, null);

            // make sure we don't spawn into a collision
            List <Rectangle> CollisionRectangles = new List <Rectangle>(GetCollisionRectangles());

            while (CollisionUtils.IsCollisionFree(newBear.CollisionRectangle, CollisionRectangles) == false)
            {
                newBear.X = GetRandomLocation(GameConstants.SPAWN_BORDER_SIZE, GameConstants.WINDOW_WIDTH - (2 * GameConstants.SPAWN_BORDER_SIZE));
                newBear.Y = GetRandomLocation(GameConstants.SPAWN_BORDER_SIZE, GameConstants.WINDOW_HEIGHT - (2 * GameConstants.SPAWN_BORDER_SIZE));
            }
            // add new bear to list
            bears.Add(newBear);
        }
Esempio n. 8
0
        /// <summary>
        /// Spawns a new teddy bear at a random location
        /// </summary>
        private void SpawnBear()
        {
            // generate random location
            int xLoc = GetRandomLocation(GameConstants.SPAWN_BORDER_SIZE, GameConstants.WINDOW_WIDTH - 2 * GameConstants.SPAWN_BORDER_SIZE);
            int yLoc = GetRandomLocation(GameConstants.SPAWN_BORDER_SIZE, GameConstants.WINDOW_HEIGHT - 2 * GameConstants.SPAWN_BORDER_SIZE);

            // generate random velocity
            float   speed    = GameConstants.MIN_BEAR_SPEED + RandomNumberGenerator.NextFloat(GameConstants.BEAR_SPEED_RANGE);
            float   angle    = RandomNumberGenerator.NextFloat(2 * (float)Math.PI);
            Vector2 velocity = new Vector2(speed * (float)Math.Cos(angle), speed * (float)Math.Sin(angle));

            // create new bear
            TeddyBear newBear = new TeddyBear(Content, "teddybear", xLoc, yLoc, velocity, teddyBounce, teddyShot);

            // make sure we don't spawn into a collision
            List <Rectangle> rectangles = GetCollisionRectangles();

            while (!CollisionUtils.IsCollisionFree(newBear.CollisionRectangle, rectangles))
            {
                newBear.X = GetRandomLocation(GameConstants.SPAWN_BORDER_SIZE, GameConstants.WINDOW_WIDTH - 2 * GameConstants.SPAWN_BORDER_SIZE);
                newBear.Y = GetRandomLocation(GameConstants.SPAWN_BORDER_SIZE, GameConstants.WINDOW_HEIGHT - 2 * GameConstants.SPAWN_BORDER_SIZE);
            }


            // add new bear to list
            bears.Add(newBear);
        }
Esempio n. 9
0
        /// <summary>
        /// Spawns a new teddy bear at a random location
        /// </summary>
        private void SpawnBear()
        {
            // generate random location
            int start_x = GetRandomLocation(GameConstants.SPAWN_BORDER_SIZE, GameConstants.WINDOW_WIDTH - 2 * GameConstants.SPAWN_BORDER_SIZE);
            int start_y = GetRandomLocation(GameConstants.SPAWN_BORDER_SIZE, GameConstants.WINDOW_HEIGHT - 2 * GameConstants.SPAWN_BORDER_SIZE);

            // generate random velocity
            //float v_random=GameConstants.MIN_BEAR_SPEED+RandomNumberGenerator.NextFloat(RandomNumberGenerator.NextFloat((GameConstants.BEAR_SPEED_RANGE)));
            float v_random = GameConstants.MIN_BEAR_SPEED + RandomNumberGenerator.NextFloat(GameConstants.BEAR_SPEED_RANGE);

            //float angle_random = (float)Math.PI * RandomNumberGenerator.NextFloat(2);
            float angle_random = RandomNumberGenerator.NextFloat((float)Math.PI * 2);

            Vector2 velocity = new Vector2(v_random * (float)Math.Cos(angle_random), v_random * (float)Math.Sin(angle_random));

            // create new bear
            TeddyBear NewBear = new TeddyBear(Content, "teddybear", start_x, start_y, velocity, teddyBounce, teddyShot);

            // make sure we don't spawn into a collision
            List <Rectangle> collisionRectangles = GetCollisionRectangles();

            while (!CollisionUtils.IsCollisionFree(NewBear.CollisionRectangle, collisionRectangles))
            {
                NewBear.X = GetRandomLocation(GameConstants.SPAWN_BORDER_SIZE,
                                              graphics.PreferredBackBufferWidth - 2 * GameConstants.SPAWN_BORDER_SIZE);
                NewBear.Y = GetRandomLocation(GameConstants.SPAWN_BORDER_SIZE,
                                              graphics.PreferredBackBufferHeight - 2 * GameConstants.SPAWN_BORDER_SIZE);
            }
            // add new bear to list
            bears.Add(NewBear);
        }
        /// <summary>
        /// Spawns a new teddy bear at a random location
        /// </summary>
        private void SpawnBear()
        {
            // generate random location

            int x = GetRandomLocation(GameConstants.SpawnBorderSize,
                                      GameConstants.WindowWidth - 2 * GameConstants.SpawnBorderSize);
            int y = GetRandomLocation(GameConstants.SpawnBorderSize,
                                      GameConstants.WindowHeight - 2 * GameConstants.SpawnBorderSize);

            // generate random velocity

            float   speed    = RandomNumberGenerator.NextFloat(GameConstants.BearSpeedRange) + GameConstants.MinBearSpeed;
            float   angle    = RandomNumberGenerator.NextFloat(2.0f * (float)Math.PI);
            Vector2 velocity = new Vector2(speed * (float)Math.Cos(angle), speed * (float)Math.Sin(angle));

            // create new bear
            TeddyBear newBear = new TeddyBear(Content, @"graphics\teddybear", x, y, velocity, teddyBounce, teddyShot);

            // make sure we don't spawn into a collision
            List <Rectangle> collisionRectangles = GetCollisionRectangles();

            while (!CollisionUtils.IsCollisionFree(newBear.CollisionRectangle, collisionRectangles))
            {
                newBear.X = GetRandomLocation(GameConstants.SpawnBorderSize,
                                              GameConstants.WindowWidth - 2 * GameConstants.SpawnBorderSize);
                newBear.Y = GetRandomLocation(GameConstants.SpawnBorderSize,
                                              GameConstants.WindowHeight - 2 * GameConstants.SpawnBorderSize);
            }

            // add new bear to list
            bears.Add(newBear);
        }
        /// <summary>
        /// Spawns a new teddy bear at a random location
        /// </summary>
        private void SpawnBear()
        {
            // generate random location
            int bx = GetRandomLocation(GameConstants.SpawnBorderSize, graphics.PreferredBackBufferWidth - 2 * GameConstants.SpawnBorderSize);
            int by = GetRandomLocation(GameConstants.SpawnBorderSize, graphics.PreferredBackBufferWidth - 2 * GameConstants.SpawnBorderSize);

            // generate random velocity
            float   vel = GameConstants.MinBearSpeed + RandomNumberGenerator.NextFloat(GameConstants.BearSpeedRange);
            float   ang = RandomNumberGenerator.NextFloat((float)Math.PI);
            Vector2 vec = new Vector2((float)Math.Cos(ang) * vel, -1 * (float)Math.Sin(ang) * vel);

            // create new bear
            TeddyBear newbear = new TeddyBear(Content, @"graphics/teddybear", bx, by, vec, teddyBounce, teddyShot);

            // make sure we don't spawn into a collision
            List <Rectangle> collisionRectangules = GetCollisionRectangles();

            while (!CollisionUtils.IsCollisionFree(newbear.DrawRectangle, collisionRectangules))
            {
                newbear.X = GetRandomLocation(GameConstants.SpawnBorderSize, graphics.PreferredBackBufferWidth - 2 * GameConstants.SpawnBorderSize);
                newbear.Y = GetRandomLocation(GameConstants.SpawnBorderSize, graphics.PreferredBackBufferWidth - 2 * GameConstants.SpawnBorderSize);
            }

            // add new bear to list
            bears.Add(newbear);
        }
Esempio n. 12
0
        /// <summary>
        /// Spawns a new teddy bear at a random location
        /// </summary>
        private void SpawnBear()
        {
            // generate random location
            int locationX = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowWidth);
            int locationY = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowHeight);

            // generate random velocity
            float speed1 = RandomNumberGenerator.NextFloat(GameConstants.BearSpeedRange);

            float speed2 = RandomNumberGenerator.NextFloat(GameConstants.BearSpeedRange);

            /*     -------  Vidi za angle generator --------------
             * RandomNumberGenerator.NextFloat(GameConstants.BearSpeedRange);
             * // generate random angle            float angle = (float)Math.PI * RandomNumberGenerator.NextFloat(360.0f) / 180.0f;
             * // generate vector velocity            Vector2 velocity = new Vector2((float)Math.Cos(angle) * speed, -(float)Math.Sin(angle) * speed);
             */

            Vector2 vector = new Vector2(speed1, speed2);
            // create new bear
            TeddyBear newBear = new TeddyBear(Content, @"graphics/teddybear", locationX, locationY, vector, teddyBounce, teddyShot);

            // make sure we don't spawn into a collision
            List <Rectangle> collisionsList = GetCollisionRectangles();

            while (!CollisionUtils.IsCollisionFree(newBear.DrawRectangle, collisionsList))
            {
                newBear.X = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowWidth);
                newBear.Y = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowHeight);
            }

            // add new bear to list
            bears.Add(newBear);
        }
        /// <summary>
        /// Spawns a new teddy bear at a random location
        /// </summary>
        private void SpawnBear()
        {
            // generate random location
            int locationX = GetRandomLocation(GameConstants.SPAWN_BORDER_SIZE, graphics.PreferredBackBufferWidth - 2 * GameConstants.SPAWN_BORDER_SIZE);
            int locationY = GetRandomLocation(GameConstants.SPAWN_BORDER_SIZE, graphics.PreferredBackBufferHeight - 2 * GameConstants.SPAWN_BORDER_SIZE);

            // generate random velocity
            float   speed    = GameConstants.MIN_BEAR_SPEED + RandomNumberGenerator.NextFloat(GameConstants.BEAR_SPEED_RANGE);
            float   angle    = RandomNumberGenerator.NextFloat((float)(Math.PI * 2));
            Vector2 velocity = new Vector2(speed * (float)Math.Cos((double)angle), speed * (float)Math.Sin((double)angle));

            // create new bear
            TeddyBear newBear = new TeddyBear(Content, "teddybear", locationX, locationY, velocity, teddyBounce, teddyShot);

            // make sure we don't spawn into a collision
            List <Rectangle> collisionRectangles = GetCollisionRectangles();

            while (!CollisionUtils.IsCollisionFree(newBear.DrawRectangle, collisionRectangles))
            {
                newBear.X = GetRandomLocation(GameConstants.SPAWN_BORDER_SIZE, graphics.PreferredBackBufferWidth - 2 * GameConstants.SPAWN_BORDER_SIZE);
                newBear.Y = GetRandomLocation(GameConstants.SPAWN_BORDER_SIZE, graphics.PreferredBackBufferHeight - 2 * GameConstants.SPAWN_BORDER_SIZE);
            }

            // add new bear to list
            bears.Add(newBear);
        }
Esempio n. 14
0
        /// <summary>
        /// Spawns a new teddy bear at a random location
        /// </summary>
        private void SpawnBear()
        {
            // generate random location
            int X = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowWidth - GameConstants.SpawnBorderSize);
            int Y = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowHeight - GameConstants.SpawnBorderSize);

            // generate random velocity
            float XVelocity = GameConstants.MinBearSpeed + RandomNumberGenerator.NextFloat(GameConstants.BearSpeedRange);
            float YVelocity = GameConstants.MinBearSpeed + RandomNumberGenerator.NextFloat(GameConstants.BearSpeedRange);

            float   angle        = (float)((RandomNumberGenerator.NextFloat(360)) / (2 * Math.PI));
            Vector2 bearVelocity = new Vector2((float)(XVelocity * Math.Sin(angle)), (float)(YVelocity * Math.Cos(angle)));

            // create new bear
            TeddyBear newBear = new TeddyBear(Content, "Graphics//teddyBear", X, Y, bearVelocity, teddyBounce, teddyShot);
            // make sure we don't spawn into a collision
            List <Rectangle> collisionRectangles = GetCollisionRectangles();

            while (!CollisionUtils.IsCollisionFree(newBear.CollisionRectangle, collisionRectangles))
            {
                newBear.X = GetRandomLocation(0, GameConstants.WindowWidth);
                newBear.Y = GetRandomLocation(0, GameConstants.WindowHeight);
            }
            bears.Add(newBear);


            // add new bear to list
        }
Esempio n. 15
0
        /// <summary>
        /// Spawns a new teddy bear at a random location
        /// </summary>
        private void SpawnBear()
        {
            // generate random location
            int x = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowWidth - GameConstants.SpawnBorderSize);
            int y = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowHeight - GameConstants.SpawnBorderSize);
            // generate random velocity
            float BearSpeed = GameConstants.MinBearSpeed + RandomNumberGenerator.NextFloat(GameConstants.BearSpeedRange);
            //random angle
            float BearAngle = RandomNumberGenerator.NextFloat((float)Math.PI);
            //new vector2 object
            Vector2 Velocity = new Vector2((float)Math.Cos(BearAngle) * BearSpeed, ((float)Math.Sin(BearAngle) * BearSpeed));
            // create new bear
            TeddyBear newBear = new TeddyBear(Content, @"graphics\teddybear", x,
                                              y, Velocity, teddyBounce, teddyShot);
            // make sure we don't spawn into a collision
            List <Rectangle> collisionList = GetCollisionRectangles();

            while (!CollisionUtils.IsCollisionFree(newBear.CollisionRectangle, collisionList))
            {
                newBear.X = GetRandomLocation(0, GameConstants.WindowWidth);
                newBear.Y = GetRandomLocation(0, GameConstants.WindowHeight);
            }

            // add new bear to list
            bears.Add(newBear);
        }
Esempio n. 16
0
        /// <summary>
        /// Spawns a new teddy bear at a random location
        /// </summary>
        private void SpawnBear()
        {
            // generate random location : SpawnBorderSize is subtracted twice, one for left/top side and one for right/bottom side

            int randomXLocation = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowWidth - (GameConstants.SpawnBorderSize * 2));
            int randomYLocation = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowHeight - (GameConstants.SpawnBorderSize * 2));

            // generate random velocity

            //create random speeds
            float randomSpeed = GameConstants.MinBearSpeed + RandomNumberGenerator.NextFloat(GameConstants.BearSpeedRange);

            //create random angle
            float randomAngle = 2 * (float)Math.PI * RandomNumberGenerator.NextFloat(1);

            //create Vector2
            Vector2 randomVelocity = new Vector2((float)Math.Cos(randomAngle) * randomSpeed, (float)Math.Sin(randomAngle) * randomSpeed);


            // create new bear
            TeddyBear newBear = new TeddyBear(Content, @"graphics\teddybear", randomXLocation, randomYLocation, randomVelocity, teddyBounce, teddyShot);

            // make sure we don't spawn into a collision
            while (CollisionUtils.IsCollisionFree(newBear.CollisionRectangle, GetCollisionRectangles()) == false)
            {
                //change x and y values
                newBear.X = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowWidth - (GameConstants.SpawnBorderSize * 2));
                newBear.Y = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowHeight - (GameConstants.SpawnBorderSize * 2));
            }


            // add new bear to list
            bears.Add(newBear);
        }
Esempio n. 17
0
        /// <summary>
        /// Spawns a new teddy bear at a random location
        /// </summary>
        private void SpawnBear()
        {
            // generate random location
            int bearX = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowWidth - GameConstants.SpawnBorderSize);
            int bearY = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowHeight - GameConstants.SpawnBorderSize);

            // generate random velocity
            float velMagnitude = RandomNumberGenerator.NextFloat(GameConstants.BearSpeedRange);
            if(velMagnitude < GameConstants.MinBearSpeed)
            {
                velMagnitude = GameConstants.MinBearSpeed;
            }
            float velAngle = RandomNumberGenerator.NextFloat(2 * (float)Math.PI);
            Vector2 bearVelocity = new Vector2((float)(velMagnitude * Math.Cos((double)velAngle)), (float)(velMagnitude * Math.Sin((double)velAngle)));

            // create new bear
            TeddyBear newBear = new TeddyBear(Content, @"graphics\teddyBear", bearX, bearY, bearVelocity, teddyBounce, teddyShot);

            // make sure we don't spawn into a collision
            List<Rectangle> collisionRectangles = GetCollisionRectangles();
            while(CollisionUtils.IsCollisionFree(newBear.DrawRectangle, collisionRectangles))
            {
                bearX = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowWidth - GameConstants.SpawnBorderSize);
                bearY = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowHeight - GameConstants.SpawnBorderSize);

                newBear.X = bearX;
                newBear.Y = bearY;
            }

            // add new bear to list
            bears.Add(newBear);
        }
        /// <summary>
        /// Spawns a new teddy bear at a random location
        /// </summary>
        private void SpawnBear()
        {
            // generate random location
            int y = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowHeight - GameConstants.SpawnBorderSize * 2);
            int x = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowWidth - GameConstants.SpawnBorderSize * 2);

            // generate random velocity
            float   speed    = GameConstants.MinBearSpeed + RandomNumberGenerator.NextFloat(GameConstants.BearSpeedRange);
            float   angle    = RandomNumberGenerator.NextFloat((float)Math.PI * 2);
            Vector2 velocity = new Vector2((float)(speed * Math.Cos(angle)), (float)(speed * Math.Sin(angle)));

            // create new bear
            TeddyBear bear = new TeddyBear(Content, @"graphics/teddybear", x, y, velocity, null, null);

            // make sure we don't spawn into a collision

            List <Rectangle> rectangles = GetCollisionRectangles();

            while (!CollisionUtils.IsCollisionFree(bear.CollisionRectangle, rectangles))
            {
                y = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowHeight - GameConstants.SpawnBorderSize * 2);
                x = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowWidth - GameConstants.SpawnBorderSize * 2);

                bear.X = x;
                bear.Y = y;
            }

            // add new bear to list
            bears.Add(bear);
        }
        /// <summary>
        /// Spawns a new teddy bear at a random location
        /// </summary>
        private void SpawnBear()
        {
            // generate random location
            int X = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowWidth - (2 * GameConstants.SpawnBorderSize));
            int Y = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowHeight - (2 * GameConstants.SpawnBorderSize));

            // generate random velocity
            float   angle      = RandomNumberGenerator.NextFloat((float)Math.PI * 2);
            float   velocity   = GameConstants.MinBearSpeed + RandomNumberGenerator.NextFloat(GameConstants.BearSpeedRange);
            Vector2 bearVector = new Vector2(velocity * (float)Math.Cos(angle), velocity * (float)Math.Sin(angle));

            // create new bear
            TeddyBear newBear = new TeddyBear(Content, @"graphics\teddybear", X, Y, bearVector, null, null);

            // make sure we don't spawn into a collision
            List <Rectangle> collisionRectangles = GetCollisionRectangles();

            while (CollisionUtils.IsCollisionFree(newBear.CollisionRectangle, collisionRectangles) == false)
            {
                newBear.X = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowWidth -
                                              (2 * GameConstants.SpawnBorderSize));
                newBear.Y = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowWidth -
                                              (2 * GameConstants.SpawnBorderSize));
            }

            // add new bear to list
            bears.Add(newBear);
        }
Esempio n. 20
0
        /// <summary>
        /// Spawns a new teddy bear at a random location
        /// </summary>
        private void SpawnBear()
        {
            // generate random location (bear sprite size = 46 x 64)
            int randomLocationX = GetRandomLocation(GameConstants.SpawnBorderSize,
                                                    GameConstants.WindowWidth - 2 * GameConstants.SpawnBorderSize);
            int randomLocationY = GetRandomLocation(GameConstants.SpawnBorderSize,
                                                    GameConstants.WindowHeight - 2 * GameConstants.SpawnBorderSize);

            // generate random velocity
            float bearRandomSpeed = GameConstants.MinBearSpeed + RandomNumberGenerator.NextFloat(GameConstants.BearSpeedRange);
            float randomAngle     = RandomNumberGenerator.NextFloat((float)Math.PI * 2);
            float speedX          = bearRandomSpeed * (float)Math.Cos(randomAngle);
            float speedY          = bearRandomSpeed * (float)Math.Sin(randomAngle);

            Vector2 bearVelocity = new Vector2(speedX, speedY);

            // create new bear
            TeddyBear newBear;

            newBear = new TeddyBear(Content, @"graphics\teddybear", randomLocationX, randomLocationY, bearVelocity, teddyBounce, teddyShot);

            // make sure we don't spawn into a collision

            while (!CollisionUtils.IsCollisionFree(newBear.DrawRectangle, GetCollisionRectangles()))
            {
                newBear.X = GetRandomLocation(GameConstants.SpawnBorderSize,
                                              GameConstants.WindowWidth - 2 * GameConstants.SpawnBorderSize);
                newBear.Y = GetRandomLocation(GameConstants.SpawnBorderSize,
                                              GameConstants.WindowHeight - 2 * GameConstants.SpawnBorderSize);
            }

            // add new bear to list
            bears.Add(newBear);
        }
Esempio n. 21
0
        /// <summary>
        /// Spawns a new teddy bear at a random location
        /// </summary>
        private void SpawnBear()
        {
            // generate random location
            int x = GetRandomLocation(GameConstants.SPAWN_BORDER_SIZE, GameConstants.WINDOW_WIDTH - 2 * GameConstants.SPAWN_BORDER_SIZE);
            int y = GetRandomLocation(GameConstants.SPAWN_BORDER_SIZE, GameConstants.WINDOW_HEIGHT - 2 * GameConstants.SPAWN_BORDER_SIZE);

            // generate random velocity
            float   bearSpeedValue = GameConstants.MIN_BEAR_SPEED + RandomNumberGenerator.NextFloat(GameConstants.BEAR_SPEED_RANGE);
            float   angle          = RandomNumberGenerator.NextFloat((float)Math.PI * 2);
            Vector2 bearVelocity   = new Vector2(bearSpeedValue * (float)Math.Cos(angle), (float)bearSpeedValue * (float)Math.Sin(angle));

            // create new bear
            TeddyBear newBear = new TeddyBear(Content, "teddybear", x, y, bearVelocity, teddyBounce, teddyShot);

            // make sure we don't spawn into a collision

            //Get list of collision rectangles
            List <Rectangle> collisionRectangles = GetCollisionRectangles();

            //Reset spawn location until collision free location is chosen
            while (!CollisionUtils.IsCollisionFree(newBear.CollisionRectangle, collisionRectangles))
            {
                newBear.X = GetRandomLocation(0, GameConstants.WINDOW_WIDTH);
                newBear.Y = GetRandomLocation(0, GameConstants.WINDOW_HEIGHT);
            }


            // add new bear to list
            bears.Add(newBear);
        }
Esempio n. 22
0
        /// <summary>
        /// Spawns a new teddy bear at a random location
        /// </summary>
        private void SpawnBear()
        {
            // generate random location
            int x = GetRandomLocation(GameConstants.SPAWN_BORDER_SIZE,
                                      GameConstants.WINDOW_WIDTH - 2 * GameConstants.SPAWN_BORDER_SIZE);
            int y = GetRandomLocation(GameConstants.SPAWN_BORDER_SIZE,
                                      GameConstants.WINDOW_HEIGHT - 2 * GameConstants.SPAWN_BORDER_SIZE);
            // generate random velocity
            float Rand_Speed = RandomNumberGenerator.NextFloat(GameConstants.BEAR_SPEED_RANGE);

            if (Rand_Speed < GameConstants.MIN_BEAR_SPEED)
            {
                Rand_Speed += GameConstants.MIN_BEAR_SPEED;
            }
            float   Rand_Angle    = RandomNumberGenerator.NextFloat((float)Math.PI * 2);
            Vector2 Rand_Velocity = new Vector2(Rand_Speed * (float)Math.Cos(Rand_Angle),
                                                Rand_Speed * (float)Math.Sin(Rand_Angle));

            // create new bear
            TeddyBear newBear = new TeddyBear(Content, "teddybear", x, y, Rand_Velocity, teddyBounce, teddyShot);

            // make sure we don't spawn into a collision
            while (CollisionUtils.IsCollisionFree(newBear.CollisionRectangle, GetCollisionRectangles()) == false)
            {
                newBear.X = GetRandomLocation(GameConstants.SPAWN_BORDER_SIZE,
                                              GameConstants.WINDOW_WIDTH - 2 * GameConstants.SPAWN_BORDER_SIZE);
                newBear.Y = GetRandomLocation(GameConstants.SPAWN_BORDER_SIZE,
                                              GameConstants.WINDOW_WIDTH - 2 * GameConstants.SPAWN_BORDER_SIZE);
            }
            // add new bear to list
            bears.Add(newBear);
        }
Esempio n. 23
0
        /// <summary>
        /// Spawns a new teddy bear at a random location
        /// </summary>
        private void SpawnBear()
        {
            // generate random location
            int xBearRandom = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowWidth - GameConstants.SpawnBorderSize * 2 - Content.Load <Texture2D>(@"graphics\teddybear").Width);
            int yBearRandom = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowHeight - GameConstants.SpawnBorderSize * 2 - Content.Load <Texture2D>(@"graphics\teddybear").Height);


            //GameConstants.SpawnBorderSize + RandomNumberGenerator.Next(GameConstants.WindowWidth - GameConstants.SpawnBorderSize * 2 + 1);

            // generate random velocity
            float speedBear = RandomNumberGenerator.NextFloat(GameConstants.BearSpeedRange);

            if (speedBear < GameConstants.MinBearSpeed)
            {
                speedBear = GameConstants.MinBearSpeed;
            }

            // a random angle using Math.PI and the RandomNumberGenerator NextFloat method
            float angleInRadians = RandomNumberGenerator.NextFloat(2 * (float)Math.PI); //360 = 2*Pi
            float angleInDegree  = angleInRadians * (180 / (float)Math.PI);

            //random speed and angles you generated and the appropriate trigonometry: speed as the length of hypotenuse of a right triangle
            float   xVelocity    = speedBear * (float)Math.Cos(angleInRadians);
            float   yVelocity    = speedBear * (float)Math.Sin(angleInRadians);
            Vector2 velocityBear = new Vector2(xVelocity, yVelocity);

            // create new bear  be speed * cos(angle) and the Y component would be speed * sin(angle)
            TeddyBear newBear = new TeddyBear(Content, @"graphics\teddybear", xBearRandom, yBearRandom, velocityBear, teddyBounce, teddyShot);

            // make sure we don't spawn into a collision
            List <Rectangle> collisions = GetCollisionRectangles();

            while (!CollisionUtils.IsCollisionFree(newBear.DrawRectangle, collisions))
            {
                int newXBearRandom = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowWidth - GameConstants.SpawnBorderSize * 2 - Content.Load <Texture2D>(@"graphics\teddybear").Width);
                int newYBearRandom = GetRandomLocation(GameConstants.SpawnBorderSize, GameConstants.WindowHeight - GameConstants.SpawnBorderSize * 2 - Content.Load <Texture2D>(@"graphics\teddybear").Height);
                newBear.X = newXBearRandom;
                newBear.Y = newYBearRandom;

                //alternate way ()instead of 2 above statements:
                //newBear = new TeddyBear(Content, @"graphics\teddybear", newXBearRandom, newYBearRandom, velocityBear, null, null);
            }


            // add new bear to list
            bears.Add(newBear);
        }
Esempio n. 24
0
        /// <summary>
        /// Spawns a new teddy bear at a random location
        /// </summary>
        private void SpawnBear()
        {
            // generate random location
            int xLocation = GetRandomLocation(0 + GameConstants.SpawnBorderSize,
                                              GameConstants.WindowWidth - GameConstants.SpawnBorderSize);
            int yLocation = GetRandomLocation(0 + GameConstants.SpawnBorderSize,
                                              GameConstants.WindowHeight - GameConstants.SpawnBorderSize);

            // generate random speed
            float speed = GameConstants.MinBearSpeed + RandomNumberGenerator.NextFloat(GameConstants.BearSpeedRange);

            // generate random angle
            float angle = RandomNumberGenerator.NextFloat((float)Math.PI);

            // generate random velocity
            // sine angle * speed = y velocity
            // cos angle * speed = x velocity
            float   xVelocity = (float)Math.Sin(angle) * speed;
            float   yVelocity = (float)Math.Cos(angle) * speed;
            Vector2 velocity  = new Vector2(xVelocity, yVelocity);

            // create new bear
            // make sure we don't spawn into a collision
            TeddyBear newBear = new TeddyBear(Content, @"graphics\teddybear", xLocation, yLocation, velocity, teddyBounce, teddyShot);

            // ensure teddy bears don't spawn into collisions
            List <Rectangle> allCollisions = GetCollisionRectangles();

            while (!CollisionUtils.IsCollisionFree(newBear.CollisionRectangle, allCollisions))
            {
                int newXLocation = GetRandomLocation(0 + GameConstants.SpawnBorderSize, GameConstants.WindowWidth -
                                                     GameConstants.SpawnBorderSize);
                int newYLocation = GetRandomLocation(0 + GameConstants.SpawnBorderSize, GameConstants.WindowHeight -
                                                     GameConstants.SpawnBorderSize);
                newBear.X = newXLocation;
                newBear.Y = newYLocation;
            }

            // add new bear to list
            bears.Add(newBear);
        }
Esempio n. 25
0
        /// <summary>
        /// Spawns a new teddy bear at a random location
        /// </summary>
        private void SpawnBear()
        {
            // generate random location
            int randX = RandomNumberGenerator.Next(GameConstants.SpawnBorderSize);
            int randY = RandomNumberGenerator.Next(GameConstants.SpawnBorderSize);
            // generate random velocity
            float   randSpeed    = GameConstants.MinBearSpeed + RandomNumberGenerator.NextFloat(GameConstants.BearSpeedRange);
            float   randAngle    = RandomNumberGenerator.NextFloat(2 * (float)Math.PI);
            Vector2 randVelocity = new Vector2(randSpeed * (float)Math.Cos(randAngle), randSpeed * (float)Math.Sin(randAngle));
            // create new bear
            TeddyBear newBear = new TeddyBear(Content, @"graphics\teddybear", randX, randY, randVelocity, teddyBounce, teddyShot);
            // make sure we don't spawn into a collision
            List <Rectangle> CollisionRectangles = GetCollisionRectangles();

            while (CollisionUtils.IsCollisionFree(newBear.CollisionRectangle, CollisionRectangles) != true)
            {
                newBear.X = GetRandomLocation(GameConstants.SpawnBorderSize, graphics.PreferredBackBufferWidth - 2 * GameConstants.SpawnBorderSize);
                newBear.Y = GetRandomLocation(GameConstants.SpawnBorderSize, graphics.PreferredBackBufferHeight - 2 * GameConstants.SpawnBorderSize);
            }
            // add new bear to list
            bears.Add(newBear);
        }