public void setColorsTriadic(ChunkDecorator decorator)
        {
            Color start = getRandomStartColor(decorator);

            float h;
            float s;
            float v;

            RGBtoHSV(start, out h, out s, out v);
            Color triad1 = HSVtoRGB((h + 120) % 360, s, v);
            Color triad2 = HSVtoRGB((h + 360 - 120) % 360, s, v);

            groundColor   = start;
            skyColorDay   = Color.Lerp(triad1, Color.White, .3f);
            skyColorNight = Color.Lerp(triad2, Color.Black, .5f);


            if (decorator.world.difficulty < 1 || decorator.rand.NextDouble() < .9)
            {
                groundColor = Color.Lerp(groundColor, Color.Black, .85f);
            }
            else
            {
                skyColorDay   = Color.Lerp(skyColorDay, Color.Black, .9f);
                skyColorNight = Color.Lerp(skyColorNight, Color.Black, .9f);
            }
        }
        public ColorManager(ChunkDecorator decorator)
        {
            this.decorator = decorator;
            if (primaries == null)
            {
                primaries = new Color[] { Color.Blue, Color.Red, Color.Yellow };
            }


            int chosenColorScheme = decorator.rand.Next(4);

            switch (chosenColorScheme)
            {
            case 0:
                setColorsComplimentary(decorator);
                break;

            case 1:
                setColorsTriadic(decorator);
                break;

            case 2:
                setColorsAnalagous(decorator);
                break;

            case 3:
                setColorsSplitCompliment(decorator);
                break;
            }
        }
        public Color getRandomStartColor(ChunkDecorator decorator)
        {
            int   startPoint = decorator.rand.Next(3);
            float spin       = (float)decorator.rand.NextDouble();
            Color start      = Color.Lerp(primaries[startPoint], primaries[(startPoint + 1 + decorator.rand.Next(3)) % 3], spin);

            return(start);
        }
예제 #4
0
 private void selectEasyMonster(ChunkDecorator decorator)
 {
     if (decorator.worldGenSubtype == World.WorldGenSubtype.CENOTE)
     {
         decorator.monsters.Add(easyMonstersCave[decorator.rand.Next(easyMonstersCave.Length)]);
     }
     else
     {
         decorator.monsters.Add(easyMonsters[decorator.rand.Next(easyMonsters.Length)]);
     }
 }
예제 #5
0
        public AmbientSoundManager(ChunkDecorator decorator)
        {
            this.decorator = decorator;
            string selectedDaySound   = null;
            string selectedNightSound = null;

            if (decorator.worldGenSubtype != World.WorldGenSubtype.CENOTE)
            {
                switch (decorator.weatherManager.weather)
                {
                case WeatherManager.Weather.NONE:
                    selectedDaySound = daySoundsNoWeather[decorator.rand.Next(daySoundsNoWeather.Length)];
                    break;

                case WeatherManager.Weather.WINDY:
                    selectedDaySound = daySoundsWind[decorator.rand.Next(daySoundsWind.Length)];
                    break;

                case WeatherManager.Weather.FOGGY:
                    selectedDaySound = daySoundsNoWeather[decorator.rand.Next(daySoundsNoWeather.Length)];
                    break;

                case WeatherManager.Weather.RAINY:
                    selectedDaySound = daySoundsRain[decorator.rand.Next(daySoundsRain.Length)];
                    break;
                }
                selectedNightSound = nightSounds[decorator.rand.Next(nightSounds.Length)];
            }
            else
            {
                selectedDaySound   = caveSounds[decorator.rand.Next(caveSounds.Length)];
                selectedNightSound = caveSounds[decorator.rand.Next(caveSounds.Length)];
            }



            SoundEffect daySound   = decorator.content.Load <SoundEffect>(baseAmbienceString + selectedDaySound);
            SoundEffect nightSound = decorator.content.Load <SoundEffect>(baseAmbienceString + selectedNightSound);

            daySoundInstance            = daySound.CreateInstance();
            nightSoundInstance          = nightSound.CreateInstance();
            daySoundInstance.IsLooped   = true;
            nightSoundInstance.IsLooped = true;
            daySoundInstance.Play();
            nightSoundInstance.Play();

            SoundManager.addSoundToManagement(daySoundInstance);
            SoundManager.addSoundToManagement(nightSoundInstance);

            worldSongIndex = decorator.rand.Next(songs.Length);
            manageAmbientSound(decorator.world.timeOfDay);
        }
예제 #6
0
        private void selectDifficultMonster(ChunkDecorator decorator)
        {
            float subSelectedCritter = (float)decorator.rand.NextDouble();

            if (subSelectedCritter < .5f)
            {
                decorator.chanceCritterIsMonster *= .1f;
                decorator.monsters.Add(typeof(EntityOwl));
            }
            else
            {
                decorator.chanceCritterIsMonster *= .1f;
                decorator.monsters.Add(typeof(EntityAntlion));
            }
        }
예제 #7
0
        public CritterManager(ChunkDecorator decorator)
        {
            Type decorativeCritter = null;
            Type smallCritter      = null;
            Type mediumCritter     = null;

            if (decorator.worldGenSubtype == World.WorldGenSubtype.CENOTE)
            {
                decorativeCritter = decorativeCrittersCave[decorator.rand.Next(decorativeCrittersCave.Length)];
                smallCritter      = smallPreyCrittersCave[decorator.rand.Next(smallPreyCrittersCave.Length)];
                mediumCritter     = medPreyCrittersCave[decorator.rand.Next(medPreyCrittersCave.Length)];
            }
            else
            {
                decorativeCritter = decorativeCritters[decorator.rand.Next(decorativeCritters.Length)];
                smallCritter      = smallPreyCritters[decorator.rand.Next(smallPreyCritters.Length)];
                mediumCritter     = medPreyCritters[decorator.rand.Next(medPreyCritters.Length)];
            }

            decorator.decorativeCritters.Add(decorativeCritter);
            decorator.critters.Add(mediumCritter);
            decorator.critters.Add(smallCritter);
            decorator.critters.Add(smallCritter);

            if (decorator.isCity)
            {
                decorator.monsters.Add(typeof(EntityConstable));
            }
            else
            {
                if (decorator.metaDifficulty >= 4)
                {
                    if (decorator.rand.NextDouble() < .8f)
                    {
                        selectEasyMonster(decorator);
                    }
                    else
                    {
                        selectDifficultMonster(decorator);
                    }
                }
                else
                {
                    selectEasyMonster(decorator);
                }
            }
        }
        public void setColorsComplimentary(ChunkDecorator decorator)
        {
            Color start = getRandomStartColor(decorator);

            float h;
            float s;
            float v;

            RGBtoHSV(start, out h, out s, out v);
            Color compliment = HSVtoRGB((h + 180) % 360, s, v);

            skyColorDay = Color.Lerp(start, Color.White, .75f);
            groundColor = compliment;

            if (decorator.world.difficulty < 1 || decorator.rand.NextDouble() < .9)
            {
                groundColor = Color.Lerp(groundColor, Color.Black, .85f);
            }
            else
            {
                skyColorDay   = Color.Lerp(skyColorDay, Color.Black, .9f);
                skyColorNight = Color.Lerp(skyColorNight, Color.Black, .9f);
            }
        }
        public DecorationManager(ChunkDecorator decorator)
        {
            for (int i = 0; i < 1 + decorator.rand.Next((Math.Max(decorator.metaDifficulty, 1)) * 8); i++)
            {
                decorator.foliage.Add(new Decoration(new Point(0, 0), new TileType[, ] {
                    { TileTypeReferencer.STONES }
                }));
                decorator.foliageBiome2.Add(new Decoration(new Point(0, 0), new TileType[, ] {
                    { TileTypeReferencer.STONES }
                }));
            }

            for (int i = 0; i < 5; i++)
            {
                decorator.subTerranianFoliage.Add(new Decoration(new Point(0, 0), new TileType[, ] {
                    { TileTypeReferencer.MUSHROOMS }
                }));
                decorator.subTerranianFoliage.Add(new Decoration(new Point(0, 0), new TileType[, ] {
                    { TileTypeReferencer.STONES }
                }));
            }
            decorator.subTerranianFoliage.Add(new Decoration(new Point(0, 0), new TileType[, ] {
                { TileTypeReferencer.CHEST }
            }));

            if (decorator.metaDifficulty >= 1)
            {
                TileType[] potentialTotems = new TileType[] { TileTypeReferencer.TOTEM_RABBIT, TileTypeReferencer.TOTEM_TAPIR, TileTypeReferencer.TOTEM_CROCODILE, TileTypeReferencer.TOTEM_CONDOR, TileTypeReferencer.TOTEM_FALCON, };
                TileType   chosenTotem     = potentialTotems[decorator.rand.Next(potentialTotems.Length)];
                decorator.foliage.Add(new Decoration(new Point(0, 0), new TileType[, ] {
                    { chosenTotem }
                }));
                decorator.foliageBiome2.Add(new Decoration(new Point(0, 0), new TileType[, ] {
                    { chosenTotem }
                }));
            }

            decorator.subTerranianFoliage.Add(new Decoration(new Point(0, 0), new TileType[, ] {
                { TileTypeReferencer.CHARMSTONE }
            }));
            decorator.subTerranianFoliage.Add(new Decoration(new Point(0, 0), new TileType[, ] {
                { TileTypeReferencer.CHARMSTONE }
            }));

            decorator.subTerranianFoliage.Add(new Decoration(new Point(0, 0), new TileType[, ] {
                { TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER }
            }));
            decorator.subTerranianFoliage.Add(new Decoration(new Point(0, -6), new TileType[, ] {
                { TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER }
            }));
            decorator.subTerranianFoliage.Add(new Decoration(new Point(0, -9), new TileType[, ] {
                { TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER }
            }));

            if (decorator.worldGenSubtype == World.WorldGenSubtype.CENOTE)
            {
                decorator.foliage.Add(new Decoration(new Point(0, 0), new TileType[, ] {
                    { TileTypeReferencer.LAMP }
                }));
                decorator.foliageBiome2.Add(new Decoration(new Point(0, 0), new TileType[, ] {
                    { TileTypeReferencer.LAMP }
                }));
                decorator.foliage.Add(new Decoration(new Point(0, 0), new TileType[, ] {
                    { TileTypeReferencer.LAMP }
                }));
                decorator.foliageBiome2.Add(new Decoration(new Point(0, 0), new TileType[, ] {
                    { TileTypeReferencer.LAMP }
                }));

                decorator.foliage.Add(new Decoration(new Point(0, 0), new TileType[, ] {
                    { TileTypeReferencer.ALTAR }
                }));
                decorator.foliageBiome2.Add(new Decoration(new Point(0, 0), new TileType[, ] {
                    { TileTypeReferencer.ALTAR }
                }));
                decorator.foliage.Add(new Decoration(new Point(0, 0), new TileType[, ] {
                    { TileTypeReferencer.LAMP }
                }));
                decorator.foliageBiome2.Add(new Decoration(new Point(0, 0), new TileType[, ] {
                    { TileTypeReferencer.ALTAR }
                }));
            }


            if (decorator.isCity)
            {
                decorator.foliage.Add(DecorationReader.readDecorationFromContent("Decorations/testdecoration.map"));
                decorator.foliageBiome2.Add(DecorationReader.readDecorationFromContent("Decorations/testdecoration.map"));
                decorator.foliage.Add(DecorationReader.readDecorationFromContent("Decorations/city_segment_0"));
                decorator.foliageBiome2.Add(DecorationReader.readDecorationFromContent("Decorations/city_segment_0"));
                decorator.foliage.Add(DecorationReader.readDecorationFromContent("Decorations/city_segment_1"));
                decorator.foliageBiome2.Add(DecorationReader.readDecorationFromContent("Decorations/city_segment_1"));

                decorator.foliage.Add(DecorationReader.readDecorationFromContent("Decorations/city_segment_2"));
                decorator.foliageBiome2.Add(DecorationReader.readDecorationFromContent("Decorations/city_segment_2"));
                decorator.foliage.Add(DecorationReader.readDecorationFromContent("Decorations/city_segment_3"));
                decorator.foliageBiome2.Add(DecorationReader.readDecorationFromContent("Decorations/city_segment_3"));
                decorator.foliage.Add(DecorationReader.readDecorationFromContent("Decorations/city_segment_4"));
                decorator.foliageBiome2.Add(DecorationReader.readDecorationFromContent("Decorations/city_segment_4"));
                decorator.foliage.Add(DecorationReader.readDecorationFromContent("Decorations/city_segment_5"));
                decorator.foliageBiome2.Add(DecorationReader.readDecorationFromContent("Decorations/city_segment_5"));
                decorator.foliage.Add(DecorationReader.readDecorationFromContent("Decorations/city_segment_6"));
                decorator.foliageBiome2.Add(DecorationReader.readDecorationFromContent("Decorations/city_segment_6"));
                decorator.foliage.Add(DecorationReader.readDecorationFromContent("Decorations/city_segment_7"));
                decorator.foliageBiome2.Add(DecorationReader.readDecorationFromContent("Decorations/city_segment_7"));

                corpseTableRare = new HashSet <Item>();
                corpseTableRare.Add(new Item_Bullet(1));
                corpseTableRare.Add(new Item_Laser_Gun(15));

                corpseTableCommon = new HashSet <Item>();
                corpseTableCommon.Add(new Item_Bullet(1));
                decorator.critters.Add(typeof(prePopulatedCorpseRare));
                decorator.critters.Add(typeof(prePopulatedCorpseCommon));
                decorator.critters.Add(typeof(prePopulatedCorpseCommon));
            }
        }
예제 #10
0
        public WeatherManager(ChunkDecorator decorator)
        {
            if (decorator.world is World)
            {
                World wd      = ((World)decorator.world);
                float windDir = 0;
                if (decorator.metaDifficulty > 0 && decorator.world.difficulty != Game1.findGirlWorld && decorator.worldGenSubtype != WorldGenSubtype.CENOTE)
                {
                    Weather selectedWeather = weatherByProbability[decorator.rand.Next(weatherByProbability.Length)];
                    weather    = selectedWeather;
                    cloudyness = (3 + decorator.rand.Next(6)) * (3 + decorator.rand.Next(6));

                    switch (selectedWeather)
                    {
                    case Weather.NONE:
                        if (decorator.rand.NextDouble() <= .5)
                        {
                            windDir = .2f;
                        }
                        else
                        {
                            windDir = -.2f;
                        }
                        windStrength = (float)(decorator.rand.NextDouble() * .1f) + windDir;
                        break;

                    case Weather.WINDY:
                        if (decorator.rand.NextDouble() <= .5)
                        {
                            windDir = 1;
                        }
                        else
                        {
                            windDir = -1f;
                        }
                        windStrength = (float)(decorator.rand.NextDouble() * .07f) + windDir;

                        if (windStrength > .9f)
                        {
                            windStrength = .9f;
                        }
                        else if (windStrength < -.9f)
                        {
                            windStrength = -.9f;
                        }

                        break;

                    case Weather.FOGGY:
                        windStrength = 0;
                        break;

                    case Weather.RAINY:
                        if (decorator.rand.NextDouble() <= .5)
                        {
                            windDir = .05f;
                        }
                        else
                        {
                            windDir = -.05f;
                        }
                        windStrength = windDir;
                        cloudyness  += cloudyness / 2;
                        break;
                    }
                }
                else
                {
                    weather = Weather.NONE;
                    if (decorator.rand.NextDouble() <= .5)
                    {
                        windDir = .2f;
                    }
                    else
                    {
                        windDir = -.2f;
                    }
                    windStrength = (float)(decorator.rand.NextDouble() * .1f) + windDir;
                    cloudyness   = (3 + decorator.rand.Next(6)) * (3 + decorator.rand.Next(6));
                }
            }
        }
        private void generateTreeTrunk(ChunkDecorator decorator, out TileType treeTrunk, out TileType treeTop)
        {
            //we want to generate an appropriate variety of trunk images.
            int numGeneratedTrunks = 9;

            //set up the texture array and spritebatch
            RenderTarget2D[] trunks   = new RenderTarget2D[numGeneratedTrunks];
            RenderTarget2D[] treeTops = new RenderTarget2D[numGeneratedTrunks];
            SpriteBatch      batch    = new SpriteBatch(Game1.instance.GraphicsDevice);

            //numPrimitives represents the number of different "basic shapes" used to generate the tree trunk.
            int numPrimitives = 1 + decorator.rand.Next(2);

            //each primitive gets N different "strings" of drawings.
            int[] branches = new int[numPrimitives];
            //each primitive gets to move N distance each pass along its "string".
            float[] jumpHeight = new float[numPrimitives];
            //each primitive can change direction N amount each pass along its string.
            float[] rotationRange = new float[numPrimitives];
            //each primitive can start rotated an arbitrary amount.
            float[] startDisplayRotation = new float[numPrimitives];
            float[] displayRotationRange = new float[numPrimitives];

            Texture2D[] primitives = new Texture2D[numPrimitives];

            for (int i = 0; i < numPrimitives; i++)
            {
                //select a random primitive texture
                primitives[i] = Game1.instance.primitives[decorator.rand.Next(Game1.instance.primitives.Count)];
                //select a random number of times for the primitive to draw a string on the texture.
                branches[i] = 2 + decorator.rand.Next(3);
                //select a random distance for the primitive to jump through each pass.
                jumpHeight[i] = 7 + decorator.rand.Next(5);
                //select a random rotation for each primitive to use on each pass.
                rotationRange[i] = (float)(decorator.rand.NextDouble() / 2);
                //select a random display rotation for each primitive to use
                startDisplayRotation[i] = (float)(decorator.rand.NextDouble() * Math.PI * 2);
                displayRotationRange[i] = (float)(decorator.rand.NextDouble() * Math.PI * 2);
            }

            //make the texture size a bit bigger than the normal block, so that
            //the generation has room to work without ugly cut-offs on the final texture.
            int texSizeTrunk = (int)(Chunk.tileDrawWidth * 1.5);

            for (int i = 0; i < numGeneratedTrunks; i++)
            {
                RenderTarget2D trunkImages = new RenderTarget2D(
                    Game1.instance.GraphicsDevice,
                    texSizeTrunk,
                    texSizeTrunk,
                    false,
                    Game1.instance.GraphicsDevice.PresentationParameters.BackBufferFormat,
                    DepthFormat.Depth24);


                Game1.instance.GraphicsDevice.SetRenderTarget(trunkImages);
                Game1.instance.GraphicsDevice.Clear(Color.Transparent);
                batch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, null);

                for (int k = 0; k < numPrimitives; k++)
                {
                    for (int j = 0; j < branches[k]; j++)
                    {
                        //set up the start position and rotations.
                        Vector2 lastLocation = new Vector2((texSizeTrunk * .66f) - decorator.rand.Next((int)(texSizeTrunk * .33f)), 10);
                        float   lastRotation = (float)((Math.PI * -1.5) + decorator.rand.NextDouble() * rotationRange[k] - rotationRange[k] / 2); //turns out that this number is more-or-less vertically aligned for some reason.

                        //stop drawing when we've reached the other side of the texture
                        while (lastLocation.Y < texSizeTrunk - 15)
                        {
                            //find the rotation location and rotation after a jump
                            float   nextRotation = lastRotation + (float)(decorator.rand.NextDouble() * rotationRange[k] - rotationRange[k] / 2);
                            Vector2 nextLocation = lastLocation + vectorFromAngle(nextRotation) * jumpHeight[k];

                            //50% chance to flip the sprite
                            SpriteEffects effect = SpriteEffects.None;
                            if (decorator.rand.NextDouble() < .5f)
                            {
                                effect = SpriteEffects.FlipHorizontally;
                            }

                            //calculate the overall location of the primitive given the parameters
                            Rectangle rect = new Rectangle((int)(nextLocation.X), (int)(nextLocation.Y), 20, 20);

                            //draw onto the trunk texture
                            batch.Draw(primitives[k], rect, null, Color.White, nextRotation + startDisplayRotation[k] + (float)decorator.rand.NextDouble() * displayRotationRange[k], Vector2.Zero, effect, 0);

                            lastLocation = nextLocation;
                            lastRotation = nextRotation;
                        }
                    }
                }


                batch.End();
                Game1.instance.GraphicsDevice.SetRenderTarget(null);

                trunks[i] = trunkImages;
            }

            //lastly, generate a texture for the branches.
            //make the texture size a bit bigger than the normal block, so that
            //the generation has room to work without ugly cut-offs on the final texture.
            int texSizeTop = (int)(Chunk.tileDrawWidth * 3);

            for (int i = 0; i < numGeneratedTrunks; i++)
            {
                RenderTarget2D treeTopImages = new RenderTarget2D(
                    Game1.instance.GraphicsDevice,
                    texSizeTop,
                    texSizeTop,
                    false,
                    Game1.instance.GraphicsDevice.PresentationParameters.BackBufferFormat,
                    DepthFormat.Depth24);

                //blah blah blah
                Game1.instance.GraphicsDevice.SetRenderTarget(treeTopImages);
                Game1.instance.GraphicsDevice.Clear(Color.Transparent);
                batch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, null);

                for (int k = 0; k < numPrimitives; k++)
                {
                    for (int j = 0; j < branches[k]; j++)
                    {
                        //set up the start position and rotations.
                        //Vector2 lastLocation = new Vector2((texSize / 2) + rand.Next(texSize / 4) - texSize / 8, 10);
                        Vector2 lastLocation = new Vector2((texSizeTop * .66f) - decorator.rand.Next((int)(texSizeTop * .33f)), texSizeTop - 15);
                        float   lastRotation = (float)((Math.PI * -1.5) + decorator.rand.NextDouble() * rotationRange[k] - rotationRange[k] / 2); //turns out that this number is more-or-less vertically aligned for some reason.

                        //stop drawing when we've reached the other side of the texture
                        while (lastLocation.Y > 15 && lastLocation.X > 15 && lastLocation.X < texSizeTop - 15)
                        {
                            //find the rotation location and rotation after a jump
                            float   nextRotation = lastRotation + (float)(decorator.rand.NextDouble() * rotationRange[k] - rotationRange[k] / 2);
                            Vector2 nextLocation = lastLocation - vectorFromAngle(nextRotation) * jumpHeight[k];

                            //50% chance to flip the sprite
                            SpriteEffects effect = SpriteEffects.None;
                            if (decorator.rand.NextDouble() < .5f)
                            {
                                effect = SpriteEffects.FlipHorizontally;
                            }

                            //calculate the overall location of the primitive given the parameters
                            Rectangle rect = new Rectangle((int)(nextLocation.X), (int)(nextLocation.Y), 20, 20);

                            //draw onto the trunk texture
                            batch.Draw(primitives[k], rect, null, Color.White, nextRotation + startDisplayRotation[k] + (float)decorator.rand.NextDouble() * displayRotationRange[k], Vector2.Zero, effect, 0);

                            lastLocation = nextLocation;
                            lastRotation = nextRotation;
                        }
                    }
                }


                batch.End();
                Game1.instance.GraphicsDevice.SetRenderTarget(null);

                treeTops[i] = treeTopImages;
            }

            //TODO: randomize parameters
            //treeTrunk = new RandomImageTile(new TileTag[] { TagReferencer.AIR, TagReferencer.Climbeable, TagReferencer.DRAWOUTSIDEOFBOUNDS }, trunks, false);
            //trunk.friction += .03f;

            //TODO: randomize parameters
            //treeTop = new RandomImageTile(new TileTag[] { TagReferencer.AIR, TagReferencer.Climbeable, TagReferencer.DRAWOUTSIDEOFBOUNDS }, treeTops, false);
            //treeTop.friction += .03f;

            treeTrunk = new RandomImageTileFromSpritesheet(new TileTag[] { TagReferencer.AIR, TagReferencer.Climbeable, TagReferencer.Harvest, TagReferencer.DRAWOUTSIDEOFBOUNDS }, trunks, texSizeTrunk, batch, false);
            treeTrunk.harvestTicks = 5 + getRandValuePlusOrMinus(decorator.rand, Math.Max(decorator.metaDifficulty, 1));
            treeTop = new RandomImageTileFromSpritesheet(new TileTag[] { TagReferencer.AIR, TagReferencer.Climbeable, TagReferencer.DRAWOUTSIDEOFBOUNDS }, treeTops, texSizeTop, batch, false);

            batch.Dispose();
        }
        private List <Decoration> generateTrees(ChunkDecorator decorator, TileType trunk, TileType treeTop, TileType leaves)
        {
            List <Decoration> generatedTrees = new List <Decoration>();

            int MODE_BULB    = 0;
            int MODE_CONE    = 1;
            int MODE_POCKETS = 2;

            int minTrunkHeight       = 1 + decorator.rand.Next(8);
            int trunkHeightVariation = 1 + decorator.rand.Next(6);

            int minLeafWidth       = decorator.rand.Next(8);
            int leafWidthVariation = decorator.rand.Next(6);

            int minLeafHeight       = 1 + decorator.rand.Next(8);
            int leafHeightVariation = decorator.rand.Next(6);
            int mode = decorator.rand.Next(3);

            //used only in cone generation
            int coneMod = 1 + decorator.rand.Next(minLeafHeight);
            //used only in pocket generation
            int minPockets       = 2 + decorator.rand.Next(4);
            int pocketsVariation = decorator.rand.Next(4);

            float minLeafFullness       = .4f + (float)decorator.rand.NextDouble() * .6f;
            float leafFullnessVariation = (float)decorator.rand.NextDouble() * .6f;

            for (int i = 0; i < 12; i++)
            {
                int   trunkHeight  = minTrunkHeight + decorator.rand.Next(trunkHeightVariation);
                int   leafWidth    = minLeafWidth + decorator.rand.Next(leafWidthVariation);
                int   leafHeight   = minLeafHeight + decorator.rand.Next(leafHeightVariation);
                float leafFullness = minLeafFullness + (float)decorator.rand.NextDouble() * leafFullnessVariation;

                if (leafWidth % 2 == 0)
                {
                    leafWidth++;
                }

                TileType[,] tiles = new TileType[leafWidth, trunkHeight + leafHeight];

                for (int n = 0; n < trunkHeight + leafHeight; n++)
                {
                    tiles[leafWidth / 2, n] = trunk;
                }
                mode = MODE_BULB;
                if (mode == MODE_BULB)
                {
                    for (int x = 0; x < leafWidth; x++)
                    {
                        for (int y = 0; y < leafHeight; y++)
                        {
                            if (decorator.rand.NextDouble() < leafFullness)
                            {
                                tiles[x, y] = leaves;
                            }
                        }
                    }
                    tiles[leafWidth / 2, leafHeight] = treeTop;
                }
                else if (mode == MODE_CONE)
                {
                    int expansionIX = leafHeight / leafWidth;
                    int currentW    = 0;
                    for (int y = 0; y < leafHeight + trunkHeight - 1; y++)
                    {
                        if (y % coneMod == 0)
                        {
                            currentW++;
                        }

                        for (int x = 0; x < currentW; x++)
                        {
                            if (decorator.rand.NextDouble() < leafFullness)
                            {
                                tiles[Math.Min(leafWidth - 1, leafWidth / 2 + x), y] = leaves;
                            }
                            if (decorator.rand.NextDouble() < leafFullness)
                            {
                                tiles[Math.Max(0, leafWidth / 2 - x), y] = leaves;
                            }
                        }
                    }

                    for (int n = 0; n < trunkHeight + leafHeight; n++)
                    {
                        if (decorator.rand.NextDouble() < .7)
                        {
                            tiles[leafWidth / 2, n] = trunk;
                        }
                    }
                }
                else if (mode == MODE_POCKETS)
                {
                    int pockets = minPockets + decorator.rand.Next(pocketsVariation);
                    for (int z = 0; z < pockets; z++)
                    {
                        int thisPocketWidth  = (minLeafHeight + decorator.rand.Next(leafHeightVariation)) / 2;
                        int thisPocketHeight = (minLeafHeight + decorator.rand.Next(leafHeightVariation)) / 2;
                        int pocketX          = leafWidth / 2 + (decorator.rand.Next(leafWidth) - decorator.rand.Next(leafWidth));
                        int pocketY          = decorator.rand.Next(trunkHeight + leafHeight);
                        for (int x = 0; x < thisPocketWidth; x++)
                        {
                            for (int y = 0; y < thisPocketHeight; y++)
                            {
                                if (decorator.rand.NextDouble() < leafFullness)
                                {
                                    tiles[Math.Max(0, Math.Min(pocketX + x, leafWidth - 1)), Math.Max(0, Math.Min(pocketY + y, trunkHeight + leafHeight - 1))] = leaves;
                                }
                            }
                        }
                    }

                    for (int n = leafHeight; n < trunkHeight + leafHeight; n++)
                    {
                        if (decorator.rand.NextDouble() < .7)
                        {
                            tiles[leafWidth / 2, n] = trunk;
                        }
                    }
                }



                generatedTrees.Add(new Decoration(new Point(leafWidth / 2, trunkHeight + leafHeight - 1), tiles));
            }
            return(generatedTrees);
        }
        public TreeManager(ChunkDecorator decorator)
        {
            if (decorator.worldGenSubtype != World.WorldGenSubtype.CENOTE)
            {
                //build leaves
                Texture2D leafTexOne = decorator.content.Load <Texture2D>("Blocks/Variety/" + decorator.rand.Next(50));
                Texture2D leafTexTwo = decorator.content.Load <Texture2D>("Blocks/Variety/" + decorator.rand.Next(50));

                leaves = new TileType(new TileTag[] { TagReferencer.AIR, TagReferencer.Harvest, }, leafTexOne, false);
                leaves.harvestTicks  = 5 + getRandValuePlusOrMinus(decorator.rand, Math.Max(decorator.metaDifficulty, 1));
                leaves2              = new TileType(new TileTag[] { TagReferencer.AIR, TagReferencer.Harvest, }, leafTexTwo, false);
                leaves2.harvestTicks = 5 + getRandValuePlusOrMinus(decorator.rand, Math.Max(decorator.metaDifficulty, 1));


                //build trunks
                generateTreeTrunk(decorator, out trunk, out treeTop);
                generateTreeTrunk(decorator, out trunk2, out treeTop2);
                decorator.foliage.AddRange(generateTrees(decorator, trunk, treeTop, leaves));
                decorator.foliageBiome2.AddRange(generateTrees(decorator, trunk2, treeTop2, leaves2));

                TileType.replaceTileInDictionary(TileTypeReferencer.REACTIVE_LEAVES_0.TILEID, leaves);
                TileType.replaceTileInDictionary(TileTypeReferencer.REACTIVE_LEAVES_1.TILEID, leaves2);
                TileType.replaceTileInDictionary(TileTypeReferencer.REACTIVE_TRUNK_0.TILEID, trunk);
                TileType.replaceTileInDictionary(TileTypeReferencer.REACTIVE_TRUNK_1.TILEID, trunk2);

                ItemDropper dropSticks = new ItemDropper();
                dropSticks.registerNewDrop(new Item_Stick(0), null, 1, .1f);
                dropSticks.registerNewDrop(new Item_Stick(0), new Item_Axe(1), 1, .2f);

                if (decorator.metaDifficulty == 0)
                {
                    dropSticks.registerNewDrop(new Item_Stick(0), null, 1, .4f);
                    dropSticks.registerNewDrop(new Item_Stick(0), new Item_Axe(1), 1, .4f);
                }

                HarvestDictionary.registerNewHarvestWithGhost(trunk, new ItemDropper[] { dropSticks });
                HarvestDictionary.registerNewHarvestWithGhost(trunk2, new ItemDropper[] { dropSticks });
            }
            else
            {
                decorator.foliage.Add(new Decoration(new Point(0, -6), new TileType[, ] {
                    { TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER }
                }));
                decorator.foliage.Add(new Decoration(new Point(0, -9), new TileType[, ] {
                    { TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER }
                }));
                decorator.foliage.Add(new Decoration(new Point(0, 6), new TileType[, ] {
                    { TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER }
                }));
                decorator.foliage.Add(new Decoration(new Point(0, 9), new TileType[, ] {
                    { TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER, TileTypeReferencer.LADDER }
                }));

                for (int i = 0; i < 3; i++)
                {
                    decorator.foliage.Add(new Decoration(new Point(0, 2), new TileType[, ] {
                        { TileTypeReferencer.STALAGMITE_TOP, TileTypeReferencer.STALAGMITE_MIDDLE, TileTypeReferencer.STALAGMITE_BOTTOM }
                    }));
                    decorator.foliageBiome2.Add(new Decoration(new Point(0, 2), new TileType[, ] {
                        { TileTypeReferencer.STALAGMITE_TOP, TileTypeReferencer.STALAGMITE_MIDDLE, TileTypeReferencer.STALAGMITE_BOTTOM }
                    }));
                }
            }
        }
예제 #14
0
        public TileType generateGrass(ChunkDecorator decorator)
        {
            //we want to generate an appropriate variety of trunk images.
            int numGeneratedGrasses = 16;

            //set up the texture array and spritebatch
            RenderTarget2D[] grasses = new RenderTarget2D[numGeneratedGrasses];
            SpriteBatch      batch   = new SpriteBatch(Game1.instance.GraphicsDevice);

            //numPrimitives represents the number of different "basic shapes" used to generate the tree trunk.
            //int numPrimitives = 1 + rand.Next(2);
            //each primitive gets N different "strings" of drawings.
            //int[] branches = new int[numPrimitives];
            //each primitive gets to move N distance each pass along its "string".
            float jumpHeight = 1 + decorator.rand.Next(1);
            float bumpiness  = 1 + decorator.rand.Next(7);
            //each primitive can change direction N amount each pass along its string.
            //each primitive can start rotated an arbitrary amount.
            float startDisplayRotation = (float)(decorator.rand.NextDouble() * Math.PI * 2);
            float displayRotationRange = (float)(decorator.rand.NextDouble() * Math.PI * 2);

            Texture2D primitives = Game1.instance.primitives[decorator.rand.Next(Game1.instance.primitives.Count)];

            //make the texture size a bit bigger than the normal block, so that
            //the generation has room to work without ugly cut-offs on the final texture.
            int texSize = (int)(Chunk.tileDrawWidth * 1.7);

            for (int i = 0; i < numGeneratedGrasses; i++)
            {
                RenderTarget2D grassImage = new RenderTarget2D(
                    Game1.instance.GraphicsDevice,
                    texSize,
                    texSize,
                    false,
                    Game1.instance.GraphicsDevice.PresentationParameters.BackBufferFormat,
                    DepthFormat.Depth24);

                //blah blah blah
                Game1.instance.GraphicsDevice.SetRenderTarget(grassImage);
                Game1.instance.GraphicsDevice.Clear(Color.Transparent);
                batch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, null);


                //set up the start position and rotations.
                //Vector2 lastLocation = new Vector2((texSize / 2) + rand.Next(texSize / 4) - texSize / 8, 10);
                Vector2 lastLocation = new Vector2(15, Chunk.tileDrawWidth + 19);

                //stop drawing when we've reached the other side of the texture
                for (int z = 0; z < 10; z++)
                {
                    while (lastLocation.X < texSize - 20)
                    {
                        //find the rotation location and rotation after a jump
                        Vector2 nextLocation = lastLocation + new Vector2(jumpHeight, 0);

                        //50% chance to flip the sprite
                        SpriteEffects effect = SpriteEffects.None;
                        if (decorator.rand.NextDouble() < .5f)
                        {
                            effect = SpriteEffects.FlipHorizontally;
                        }

                        //calculate the overall location of the primitive given the parameters
                        Rectangle rect = new Rectangle((int)(nextLocation.X), (int)(nextLocation.Y + decorator.rand.NextDouble() * bumpiness), 7, 7);

                        //draw onto the trunk texture
                        batch.Draw(primitives, rect, null, Color.White, startDisplayRotation + (float)decorator.rand.NextDouble() * displayRotationRange, Vector2.Zero, effect, 0);

                        lastLocation = nextLocation;
                    }
                }

                batch.End();
                Game1.instance.GraphicsDevice.SetRenderTarget(null);

                grasses[i] = grassImage;
            }

            //TODO: randomize parameters
            //return new RandomImageTile(new TileTag[] { TagReferencer.AIR, TagReferencer.DRAWOUTSIDEOFBOUNDS }, grasses, false);
            RandomImageTileFromSpritesheet tile = new RandomImageTileFromSpritesheet(new TileTag[] { TagReferencer.AIR, TagReferencer.DRAWOUTSIDEOFBOUNDS }, grasses, texSize, batch, false);

            batch.Dispose();
            return(tile);
        }
예제 #15
0
        public ShrubManager(ChunkDecorator decorator)
        {
            if (decorator.worldGenSubtype != World.WorldGenSubtype.CENOTE)
            {
                //build grass and bushes
                grass              = generateGrass(decorator);
                bush               = generateBush(decorator);
                bush.harvestTicks += getRandValuePlusOrMinus(decorator.rand, Math.Max(decorator.metaDifficulty, 1) * 8);

                grass2              = generateGrass(decorator);
                bush2               = generateBush(decorator);
                bush2.harvestTicks += getRandValuePlusOrMinus(decorator.rand, Math.Max(decorator.metaDifficulty, 1) * 8);

                TileType.replaceTileInDictionary(TileTypeReferencer.REACTIVE_GRASS.TILEID, grass);
                TileType.replaceTileInDictionary(TileTypeReferencer.REACTIVE_BUSH_0.TILEID, bush);
                TileType.replaceTileInDictionary(TileTypeReferencer.REACTIVE_BUSH_1.TILEID, bush2);

                ItemDropper bushDrops = new ItemDropper();
                bushDrops.registerNewDrop(new Item_Grass(0), null, 1, 1f);
                ItemDropper bushDrops2 = new ItemDropper();
                bushDrops2.registerNewDrop(new Item_Grass(0), null, 1, 1f);

                if (decorator.world is World)
                {
                    if (decorator.rand.NextDouble() < .15)//chance to give the bush an interesting drop.
                    {
                        Item_Berry bushBerry = UniverseProperties.availableBerries[decorator.rand.Next(3)];

                        bushDrops.registerNewDrop(bushBerry, null, 1 + decorator.rand.Next(4), (float)(.05 + decorator.rand.NextDouble() * .3));
                    }
                    if (decorator.rand.NextDouble() < .15)//chance to give the bush an interesting drop.
                    {
                        Item_Berry bushBerry = UniverseProperties.availableBerries[decorator.rand.Next(3)];

                        bushDrops2.registerNewDrop(bushBerry, null, 1 + decorator.rand.Next(4), (float)(.05 + decorator.rand.NextDouble() * .3));
                    }
                }



                HarvestDictionary.registerNewHarvest(bush, new ItemDropper[] { bushDrops });
                HarvestDictionary.registerNewHarvest(bush2, new ItemDropper[] { bushDrops2 });

                for (int i = 0; i < 7 + decorator.rand.Next(7); i++)
                {
                    decorator.foliage.Add(new Decoration(new Point(0, 0), new TileType[, ] {
                        { bush },
                    }));
                    decorator.foliageBiome2.Add(new Decoration(new Point(0, 0), new TileType[, ] {
                        { bush2 },
                    }));
                }
            }
            else
            {
                for (int i = 0; i < 7 + decorator.rand.Next(7); i++)
                {
                    decorator.foliage.Add(new Decoration(new Point(0, 0), new TileType[, ] {
                        { TileTypeReferencer.STALAGMITE_TINY },
                    }));
                    decorator.foliageBiome2.Add(new Decoration(new Point(0, 0), new TileType[, ] {
                        { TileTypeReferencer.STALAGMITE_TINY },
                    }));
                }
            }

            //
        }