Exemple #1
0
        public Terrain generateRandomTerrain(float angle, Random rand)
        {
            Terrain lastTerrain = this.terrains[terrains.Count - 1];

            bool fly = false;
            int flyChance = rand.Next(0, 4);
            if (flyChance == 0)
            {
                fly = true;
            }

            double terrainHeight = lowestH;
            int terNum = rand.Next(0, 4);

            if (terNum == 1)
            {
                terrainHeight = secondH;
            }
            if (terNum == 2 && lastTerrain.tHeight != lowestH)
            {
                terrainHeight = thirdH;
            }
            if (terNum == 3 && lastTerrain.tHeight != lowestH && lastTerrain.tHeight != secondH)
            {
                terrainHeight = topH;
            }

            Terrain[] allTerrains = new Terrain[7];
            allTerrains[0] = new PlainTerrain(game, angle, terrainHeight, fly);
            allTerrains[1] = new AscentTerrain(game, angle, terrainHeight, fly);
            allTerrains[2] = new LavaPitTerrain(game, angle, terrainHeight, fly);
            allTerrains[3] = new LavaPitWideTerrain(game, angle, terrainHeight, fly);
            allTerrains[4] = new LoweredTerrain(game, angle, terrainHeight, fly);
            allTerrains[5] = new DescentTerrain(game, angle, terrainHeight, fly);

            // volcanos get too high..
            double volcanoHeight = lastTerrain.tHeight == topH || lastTerrain.tHeight == thirdH ? secondH : lastTerrain.tHeight;
            //Console.WriteLine("volcano height " + volcanoHeight);
            allTerrains[6] = new VolcanoTerrain(game, angle, volcanoHeight, fly);

            Terrain nextTerrain = allTerrains[rand.Next(0, 7)];
            if (lastTerrain is AscentTerrain)
            {
                if (lastTerrain.tHeight == lowestH)
                {
                    nextTerrain.tHeight = lowestH;
                }
                if (lastTerrain.tHeight == secondH)
                {
                    nextTerrain.tHeight = secondH;
                }
                if (lastTerrain.tHeight == thirdH)
                {
                    nextTerrain.tHeight = thirdH;
                }
                if (nextTerrain is AscentTerrain)
                {
                    nextTerrain = generateRandomTerrain(angle, rand);
                }
            }

            if (lastTerrain is DescentTerrain)
            {
                if (lastTerrain.tHeight == lowestH)
                {
                    nextTerrain.tHeight = lowestH;
                }
                if (lastTerrain.tHeight == secondH)
                {
                    nextTerrain.tHeight = secondH;
                }
                if (lastTerrain.tHeight == thirdH)
                {
                    nextTerrain.tHeight = thirdH;
                }
                if (nextTerrain is DescentTerrain)
                {
                    nextTerrain = generateRandomTerrain(angle, rand);
                }
            }

            return nextTerrain;
        }
Exemple #2
0
        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();

            if (this.terrains == null)
            {
                this.terrains = new List<Terrain>();
                float angle = 4.4f;
                Random rand = new Random();
                float uncoveredSurface = 2 * (float)Math.PI; // full circle

                // fist piece
                Terrain t = new PlainTerrain(game, angle, lowestH, true);
                this.terrains.Add(t);
                angle += t.offsetAngle;
                uncoveredSurface -= t.offsetAngle;

                // rest generated randomly to cover full circle
                while (uncoveredSurface > 0)
                {
                    t = generateRandomTerrain(angle, rand);
                    this.terrains.Add(t);
                    angle += t.offsetAngle;

                    uncoveredSurface -= t.offsetAngle;
                }

                Console.WriteLine("Covered in terrains: {0} rad, left uncovered: {1}", angle - 4.4f, 2 * Math.PI - angle + 4.4f);
            }
        }