Esempio n. 1
0
        //Function that generates a new platform
        private void regenPlatform(Platform p)
        {
            //Remove the platform that is off the screen
            platforms.Remove(p);
            //Get the platform from the end of the list
            Platform temp = platforms[platforms.Count - 1];
            //New random number generator
            Random rand = new Random();
            //This is the amount of Y distance that you will add between the platform currently being generated
            //and the one before it.
            int yDist = rand.Next(-200, 100 + p.Bounds.Height);
            //The x Location of the new platform
            //This should generate a platform 100 - 200 pixels behind the rightmost edge of the previous platform
            int xVal = temp.Bounds.X + temp.Bounds.Width + rand.Next(100, 200);
            //Where the platform will be vertically.
            int yVal = temp.Bounds.Y + yDist;

            //If the platform will be off the screen, move it to the bottom of the screen.
            if (yVal >= graphics.PreferredBackBufferHeight - temp.Bounds.Height || yVal <= 0)
            {
                yVal = graphics.PreferredBackBufferHeight - temp.Bounds.Height - 15;
            }

            //Set the bounds of the new platform
            p.Bounds = new Rectangle(xVal, yVal, rand.Next(150, 350), 25);

            int isFalling = rand.Next(35);

            if (isFalling == 1)
            {
                p = new FallingPlatform(p.Bounds, p.Texture);
            }

            int hasTorch = 1;

            if (hasTorch == 1)
            {
                p.HasTorch = true;
            }
            //Add the new platform to the screen
            platforms.Add(p);
        }
Esempio n. 2
0
        //Function that generates a new platform
        private void regenPlatform(Platform plat)
        {
            int index = platforms.IndexOf(plat);
            int prevIndex = index - 1;
            if (prevIndex == -1)
            {
                prevIndex = platforms.Count - 1;
            }

            Platform p = platforms[index];
            //Remove the platform that is off the screen
            //platforms.Remove(p);
            //Get the platform from the end of the list
            Platform temp = platforms[prevIndex];
            //New random number generator
            Random rand = new Random();
            //This is the amount of Y distance that you will add between the platform currently being generated
            //and the one before it.
            int yDist = rand.Next(-200, 90 + p.Bounds.Height);
            //The x Location of the new platform
            //This should generate a platform 100 - 200 pixels behind the rightmost edge of the previous platform
            int xVal = temp.Bounds.X + temp.Bounds.Width + rand.Next(200, 300) + this.distTraveled / 100;
            //Where the platform will be vertically.
            int yVal = temp.Bounds.Y + yDist;

            //If the platform will be off the screen, move it to the bottom of the screen.
            if (yVal >= graphics.PreferredBackBufferHeight - temp.Bounds.Height || yVal <= 0 + player.Body.Height)
            {
                yVal = graphics.PreferredBackBufferHeight - temp.Bounds.Height - 35;
            }

            //Set the bounds of the new platform
            p.Bounds = new Rectangle(xVal, yVal, rand.Next(150, 350), 25);

            int isFalling = rand.Next(26);
            if (isFalling == 1 && p.Bounds.Y < graphics.PreferredBackBufferHeight - 150)
            {
                p = new FallingPlatform(p.Bounds, p.Texture, p.Textures, p.rand);
            }
            else
            {
                p = new Platform(p.Bounds, p.Texture, p.Textures, p.rand);
            }

            int hasTorch = rand.Next(20);
            //int hasTorch = 1;
            p.HasTorch = false;
            if (hasTorch == 1)
            {
                p.HasTorch = true;
            }
            //Add the new platform to the screen
            //platforms.Add(p);
            platforms[index] = p;
        }