예제 #1
0
        public virtual void update(GameTime time)
        {
            performChunkManagement(time);
            windOffset += 1f;

            foreach (Entity entity in entities)
            {
                entity.update(1);
                if (entity is PlantWrapper)
                {
                    PlantWrapper tree = (PlantWrapper)entity;
                    float        effectiveWindOffset = windOffset + (tree.isBackground ? 0 : 15);

                    if ((tree.location.X + effectiveWindOffset) % windWaveWidth <= 1 && (tree.location.X + effectiveWindOffset) % windWaveWidth > 0)
                    {
                        tree.bendModifiers.Add(new SineAndHalfTimeModifier(220, .1f, .025f));
                    }
                }
            }

            lock (queuedEntities)
            {
                foreach (Entity entity in queuedEntities)
                {
                    entities.Add(entity);
                }
                queuedEntities.Clear();
            }
        }
예제 #2
0
        //returns a list of entities that need to be spawned into the world
        public List <Entity> generateProcedural()
        {
            List <Entity> spawnedEntities = new List <Entity>();

            //TODO: remove cast
            WorldBase world = (WorldBase)this.world;

            generated = true;

            random = new Random(location.X * 500 + location.Y);
            int   terrainMultipler = 250;
            float caveThreshold    = .585f;

            PerlinNoise perlin = world.noise;

            for (int x = 0; x < tilesPerChunk; x++)
            {
                float groundLevel = perlin.octavePerlin1D((float)(location.X * tilesPerChunk + x) / 25) * terrainMultipler;
                for (int y = 0; y < tilesPerChunk; y++)
                {
                    float height = (location.Y * tilesPerChunk + y);
                    if (height > groundLevel)
                    {
                        tiles[x, y] = TileTypeReferencer.DIRT;
                    }
                    else
                    {
                        if (height < groundLevel && height >= groundLevel - 1)
                        {
                            PlantWrapper wrapper = new PlantWrapper(Game1.grass.getTree(), world);

                            int nx = location.X * tilesPerChunk * tileDrawWidth + x * tileDrawWidth /* - tileDrawWidth / 2 - 10*/;
                            int ny = location.Y * tilesPerChunk * tileDrawWidth + y * tileDrawWidth /* - tileDrawWidth / 2*/;
                            wrapper.location = new Vector2(nx, ny);
                            spawnedEntities.Add(wrapper);

                            PlantWrapper wrapper_background = new PlantWrapper(Game1.grass.getTree(), world);
                            wrapper_background.location     = new Vector2(nx, ny);
                            wrapper_background.isBackground = true;
                            spawnedEntities.Add(wrapper_background);
                        }

                        tiles[x, y] = TileTypeReferencer.AIR;
                    }
                }
            }
            return(spawnedEntities);
        }