public void Shutdown()
        {
            // Release the position object.
            Position = null;
            // Release the FPS object.
            FPS = null;
            // Release the camera object.
            Camera = null;

            // Release the foliage object.
            Foliage?.ShutDown();
            Foliage = null;
            // Release the ground model object.
            GroundModel?.Shutdown();
            GroundModel = null;
            // Release the user interface object.
            UserInterface?.ShutDown();
            UserInterface = null;
            // Release the shader manager object.
            ShaderManager?.ShutDown();
            ShaderManager = null;
            // Release the input object.
            Input?.Shutdown();
            Input = null;
            // Release the Direct3D object.
            D3D?.ShutDown();
            D3D = null;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Method creates an Actor from Xml Data
        /// </summary>
        /// <param name="tiledObject">Xml element that contains main information for an Actor</param>
        /// <returns></returns>
        private Actor XElementToActor(XElement tiledObject)
        {
            int     gid      = (int)tiledObject.Attribute("gid");
            Vector3 position = new Vector3((int)tiledObject.Attribute("x"), (int)tiledObject.Attribute("y"), 0);
            Vector3 size     = new Vector3((int)tiledObject.Attribute("width"), (int)tiledObject.Attribute("height"), 0);

            Texture2D image = GidToImage[gid];

            Actor actor;

            if (Name.Equals("Undergrowth"))
            {
                actor = new Foliage(new Sprite(image), scene, position);
            }
            else
            {
                actor = new Actor(new Sprite(image));
            }

            actor.SetPosition(position);
            actor.SetRotation(Vector3.Zero);
            actor.SetSize(size);

            return(actor);
        }
Exemplo n.º 3
0
 public void CopyTo(GTerrainData des)
 {
     Geometry.CopyTo(des.Geometry);
     Shading.CopyTo(des.Shading);
     Rendering.CopyTo(des.Rendering);
     Foliage.CopyTo(des.Foliage);
 }
        public bool Frame(float frameTime)
        {
            // Update the system stats.
            FPS.Frame();

            // Do the frame input processing.
            if (!HandleInput(frameTime))
            {
                return(false);
            }

            // Do the frame processing for the user interface.
            if (!UserInterface.Frame(FPS.FPS, Position.PositionX, Position.PositionY, Position.PositionZ, Position.RotationX, Position.RotationY, Position.RotationZ, D3D.DeviceContext))
            {
                return(false);
            }

            // Do the frame processing for the foliage.
            if (!Foliage.Frame(Camera.GetPosition(), D3D.DeviceContext))
            {
                return(false);
            }

            // Render the graphics.
            if (!Render())
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 5
0
        private void CreateLightningEffect()
        {
            float   startX = random.Next((int)baseScreenSize.X);
            Vector2 endPos = new Vector2(random.Next((int)baseScreenSize.X), baseScreenSize.Y - 10);

            int burnFoliageProb = random.Next(3);

            if (burnFoliageProb < 2 && foliages.Count > 0)
            {
                Foliage chosenFoliage = foliages[random.Next(foliages.Count)];
                chosenFoliage.StartBurning();
                Vector3 tmp  = chosenFoliage.GetPosition();
                Vector3 size = chosenFoliage.GetSize();
                if (chosenFoliage.Moving)
                {
                    endPos = new Vector2(tmp.X, tmp.Y + size.Y);
                }
                else
                {
                    endPos = new Vector2(tmp.X, tmp.Y);
                }
            }

            branchLightning = new BranchLightning(new Vector2(startX, -2),
                                                  endPos);
            scene.LightningManager.CurrentLightnings.Add(branchLightning);
        }
Exemplo n.º 6
0
        public static void Paint(Foliage foliage, int[] foliageTypesIndices, Vector3 brushPosition, float brushRadius, bool additive)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            Internal_Paint(Object.GetUnmanagedPtr(foliage), foliageTypesIndices, ref brushPosition, brushRadius, additive);
#endif
        }
Exemplo n.º 7
0
        public static bool Intersects(Foliage foliage, Ray ray, out float distance, out Vector3 normal, out int instanceIndex)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            return(Internal_Intersects(Object.GetUnmanagedPtr(foliage), ref ray, out distance, out normal, out instanceIndex));
#endif
        }
Exemplo n.º 8
0
    // Use this for initialization
    void Start()
    {
        foliage          = GetComponent <Foliage>();
        mainManager      = GetComponent <MainManager>();
        interfaceManager = GetComponent <InterfaceManager>();
        roots            = GetComponent <Roots>();

        fruitsCount = initialFruits;

        updateDisplay();
    }
Exemplo n.º 9
0
    public void SpawnFoliage(Foliage plant)
    {
        if (sandiness != 0)
        {
            return;
        }
        GameObject foliageObject = Instantiate(plant.gameObject);

        foliageObject.transform.parent   = transform;
        foliageObject.transform.position = new Vector3(
            transform.position.x,
            foliageObject.transform.position.y + transform.position.y,
            transform.position.z);
    }
Exemplo n.º 10
0
    // Use this for initialization
    void Start()
    {
        prefabBank = GetComponent <PrefabBank>();
        roots      = GetComponent <Roots>();
        foliage    = GetComponent <Foliage>();

        int len = spawningObjects.Count;

        for (int i = 0; i < len; i++)
        {
            spawningVectors.Add(spawningObjects[i].transform.position);
            slots.Add(true);
            spawningObjects[i].SetActive(false);
        }
    }
Exemplo n.º 11
0
 public void DecorateTerrain()
 {
     LandBlock[] blocks = GetComponentsInChildren <LandBlock>();
     foreach (LandBlock block in blocks)
     {
         block.baseLandMaterial = baseLandMaterial;
         block.sandLandMaterial = sandLandMaterial;
         block.sandBlock        = sandBlock;
         block.ApplySandiness();
         Foliage plant = foliage[Random.Range(0, foliage.Length)];
         if (block != null && ((Mathf.Round(Random.Range(0f, 1f) * 100) / 100) < (plant.concentration)))
         {
             block.SpawnFoliage(plant);
         }
     }
 }
Exemplo n.º 12
0
        private Foliage CreateMovingFoliage(Foliage currentFoliage)
        {
            RenderObject foliageSpritesheet = SpritesheetImporter.ImportSpritesheet(MainConfig.CONTENT_CHARACTERS_DIRECTORY + "UndergrowthAnimation.xml", director.Content, scene).Item1;
            Foliage      movingFoliage      = new Foliage(foliageSpritesheet, scene, currentFoliage.GetPosition());

            Vector3 currPos  = currentFoliage.GetPosition();
            Vector3 currRot  = currentFoliage.GetRotation();
            Vector3 currSize = currentFoliage.GetSize();

            movingFoliage.SetPosition(currentFoliage.Moving
                ? new Vector2(currPos.X, currPos.Y)
                : new Vector2(currPos.X, currPos.Y - currSize.Y - 1f));

            movingFoliage.SetRotation(currRot);
            movingFoliage.SetSize(currSize);

            return(movingFoliage);
        }
        private bool Render()
        {
            // Clear the scene.
            D3D.BeginScene(0.0f, 0.0f, 1.0f, 1.0f);

            // Generate the view matrix based on the camera's position.
            Camera.Render();

            // Get the world, view, projection, ortho, and base view matrices from the camera and Direct3D objects.
            Matrix worldMatrix      = D3D.WorldMatrix;
            Matrix viewCameraMatrix = Camera.ViewMatrix;
            Matrix projectionMatrix = D3D.ProjectionMatrix;
            Matrix orthoMatrix      = D3D.OrthoMatrix;
            Matrix baseViewMatrix   = Camera.BaseViewMatrix;

            // Render the ground model.
            GroundModel.Render(D3D.DeviceContext);
            ShaderManager.RenderTextureShader(D3D.DeviceContext, GroundModel.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, GroundModel.ColourTexture.TextureResource);

            // Turn on the alpha-to-coverage blending.
            D3D.EnableSecondBlendState();

            // Render the foliage.
            Foliage.Render(D3D.DeviceContext);
            if (!ShaderManager.RenderFoliageShader(D3D.DeviceContext, Foliage.VertexCount, Foliage.InstanceCount, viewCameraMatrix, projectionMatrix, Foliage.Texture.TextureResource))
            {
                return(false);
            }

            // Turn off the alpha blending.
            D3D.TurnOffAlphaBlending();

            // Render the user interface.
            UserInterface.Render(D3D, ShaderManager, worldMatrix, baseViewMatrix, orthoMatrix);

            // Present the rendered scene to the screen.
            D3D.EndScene();

            return(true);
        }
Exemplo n.º 14
0
        public void Dispose()
        {
            _player       = null;
            _frameCounter = null;
            _camera       = null;

            _frustrum = null;


            _skyPlane.ShurDown();
            _skyPlane = null;

            _skyDome.ShutDown();
            _skyDome = null;

            _quadTree?.Shutdown();
            _quadTree = null;

            _foliage?.Dispose();
            _foliage = null;

            _groundModel?.Dispose();
            _groundModel = null;

            _terrain?.Dispose();
            _terrain = null;

            _userInterface?.Dispose();
            _userInterface = null;

            _shaderManager?.Dispose();
            _shaderManager = null;

            _input?.Dispose();
            _input = null;

            _directX?.Dispose();
            _directX = null;
        }
Exemplo n.º 15
0
 void SetToMine()
 {
     if (Vector2.Distance(currTask.location, transform.position) < 1f)
     {
         Foliage foliage = currTask.obj.GetComponentInParent <Foliage>();
         if (foliage)
         {
             if (buildTimer < foliage.timeToChop)
             {
                 float speed = Time.deltaTime * (GetStat("Strength").value / 5);
                 speed /= 2;
                 tool   = inventory.CheckForTool(ToolTypes.Axe);
                 if (tool)
                 {
                     if (tool.toolType == ToolTypes.Axe)
                     {
                         speed *= 2;
                     }
                 }
                 buildTimer += speed;
             }
             else
             {
                 foliage.ChopDown();
                 EndTask();
             }
         }
     }
     else
     {
         if (!move)
         {
             Move();
             move = true;
         }
     }
 }
Exemplo n.º 16
0
        public override void Paint(Level level, Room room)
        {
            Fill(level, room, Terrain.WALL);
            Fill(level, room, 1, Terrain.HIGH_GRASS);
            Fill(level, room, 2, Terrain.GRASS);

            room.Entrance().Set(Room.Door.DoorType.REGULAR);

            var bushes = Random.Int(3) == 0 ? (Random.Int(5) == 0 ? 2 : 1) : 0;

            for (var i = 0; i < bushes; i++)
            {
                level.Plant(new Sungrass.Seed(), room.Random());
            }

            Foliage light;

            if (level.Blobs.ContainsKey(typeof(Foliage)))
            {
                light = (Foliage)level.Blobs[typeof(Foliage)];
            }
            else
            {
                light = new Foliage();
            }

            for (var i = room.Top + 1; i < room.Bottom; i++)
            {
                for (var j = room.Left + 1; j < room.Right; j++)
                {
                    light.Seed(j + Level.Width * i, 1);
                }
            }

            level.Blobs.Add(typeof(Foliage), light);
        }
Exemplo n.º 17
0
        public Tree(Program owner)
        {
            this.owner = owner;

            // Instantiate statics if needed
            if (trunkMesh == null)
            {
                trunkMesh = new TransparentXMesh("/data/tree_trunk.x");
            }
            if (foliageMesh == null)
            {
                foliageMesh = new SquareMesh(2f, 1, 1, 1.0f, new Vector3(0, 0, 1));
            }
            if (foliageTexture == null)
            {
                foliageTexture = new TextureBase("/data/leaves1.png");
            }

            trunk       = new GameObject();
            trunk.Mesh  = trunkMesh;
            trunk.Scale = new Vector3(1f, 1f, 1f);

            foliageMesh.Texture             = foliageTexture;
            foliageMesh.Texture.Transparent = true;

            foreach (Vector3 pos in foliagePositions)
            {
                Foliage foliage = new Foliage();
                foliage.RelativePosition = pos;
                foliage.Mesh             = foliageMesh;
                foliages.Add(foliage);
                owner.TransparentObjectManager.Objects.Add(foliage);
            }

            counter++;
        }
Exemplo n.º 18
0
        public bool Initialise(Dimension size, IntPtr windowHandle)
        {
            var result = true;

            try
            {
                _directX = new DirectX();
                result  &= _directX.Initialise(size, windowHandle);

                _input  = new Input();
                result &= _input.Initialise(size, windowHandle);

                _shaderManager = new ShaderManager();
                result        &= _shaderManager.Initialise(_directX, windowHandle);

                _player = new Player
                {
                    Position = new Coordinate3D <float>(31.0f, 18.0f, 7.0f),
                    Rotation = new Coordinate3D <float>(11.0f, 23.0f, 0.0f)
                };

                _camera = new Camera();
                _camera.SetPosition(new Coordinate3D <float>(0, 0, -10));
                _camera.Render();
                _camera.RenderBaseViewMatrix();

                _frameCounter = new FrameCounter();
                _frameCounter.Initialise();

                _userInterface = new UserInterface();
                result        &= _userInterface.Initialise(_directX, size);

                _terrain = new Terrain();
                result  &= _terrain.Initialise(_directX.Device, "heightmap01.bmp", "dirt03.bmp");

                _groundModel = new Object();
                result      &= _groundModel.Initialise(_directX.Device, "plane01.txt", "rock015.bmp");

                _quadTree = new QuadTree();
                result   &= _quadTree.Initialise(_terrain, _directX.Device);

                _foliage = new Foliage();
                result  &= _foliage.Initialise(_directX.Device, _quadTree, "grass01.bmp", 2500);

                _frustrum = new Frustrum();

                _skyDome = new SkyDome();
                result  &= _skyDome.Initialise(_directX.Device);

                _skyPlane = new SkyPlane();
                result   &= _skyPlane.Initialze(_directX.Device, "cloud001.bmp", "perturb001.bmp");

                return(result);
            }
            catch (Exception ex)
            {
                //Log.WriteToFile(ErrorLevel.Error, "Window.Initialise", ex, true);

                return(false);
            }
        }
 /// <summary>
 /// Removes the foliage instances using the given foliage types selection and the brush location.
 /// </summary>
 /// <param name="foliage">The foliage actor.</param>
 /// <param name="foliageTypesIndices">The foliage types indices to use for painting.</param>
 /// <param name="brushPosition">The brush position.</param>
 /// <param name="brushRadius">The brush radius.</param>
 public static void Remove(Foliage foliage, int[] foliageTypesIndices, Vector3 brushPosition, float brushRadius)
 {
     Internal_Remove(FlaxEngine.Object.GetUnmanagedPtr(foliage), foliageTypesIndices, ref brushPosition, brushRadius);
 }
Exemplo n.º 20
0
        public override void Initialize()
        {
            //************************* INIT TEXTURES(needs to be init before map) ************************//

            //Load in bullet texture
            ProjectileConfig.BULLET_TEXTURE =
                director.Content.Load <Texture2D>(MainConfig.PIPELINE_GRAPHICS_DIRECTORY + "Bullet");
            ProjectileConfig.BULLET_SIZE = new Vector3(ProjectileConfig.BULLET_TEXTURE.Width / 1.5f,
                                                       ProjectileConfig.BULLET_TEXTURE.Height / 1.5f, 0f);//new Vector3(ProjectileConfig.BULLET_TEXTURE.Width/2f, ProjectileConfig.BULLET_TEXTURE.Height/2f, 0);

            //Load in dart texture
            ProjectileConfig.DART_TEXTURE =
                director.Content.Load <Texture2D>(MainConfig.PIPELINE_GRAPHICS_DIRECTORY + "Dart");
            ProjectileConfig.DART_SIZE = new Vector3(ProjectileConfig.DART_TEXTURE.Width,
                                                     ProjectileConfig.DART_TEXTURE.Height, 0f);

            //Init all treasure and ammo crate textures into the ItemsConfig class
            ItemsConfig.LOOT_TEXTURE = new List <Texture2D>();
            string treasurePrefix = "Treasure0";

            for (var i = 0; i < numOfTreasureTypes; i++)
            {
                ItemsConfig.LOOT_TEXTURE.Add(
                    director.Content.Load <Texture2D>(MainConfig.PIPELINE_GRAPHICS_DIRECTORY + treasurePrefix + (i + 1)));
            }

            ItemsConfig.AMMO_CRATE_TEXTURE =
                director.Content.Load <Texture2D>(MainConfig.PIPELINE_GRAPHICS_DIRECTORY + "NewCrate");

            for (var i = 0; i < maxAmmoCount + 1; i++)
            {
                ItemsConfig.AMMO_COUNT_TEXTURES.Add(
                    director.Content.Load <Texture2D>(MainConfig.PIPELINE_GRAPHICS_DIRECTORY + "Ammo" + i));
            }

            ItemsConfig.TRAP_CLOSED_TEXTURE =
                director.Content.Load <Texture2D>(MainConfig.PIPELINE_GRAPHICS_DIRECTORY + "TrapClosed");

            ItemsConfig.TRAP_OPEN_TEXTURE =
                director.Content.Load <Texture2D>(MainConfig.PIPELINE_GRAPHICS_DIRECTORY + "TrapOpen");

            ParticleConfig.WHITE_CIRCLE =
                director.Content.Load <Texture2D>(MainConfig.PIPELINE_GRAPHICS_DIRECTORY + "whiteCircle");

            ParticleConfig.RAIN_DROP =
                director.Content.Load <Texture2D>(MainConfig.PIPELINE_GRAPHICS_DIRECTORY + "raindrop");

            int    numOfFootstepTextures = 3;
            string texturePrefix         = "FootstepParticle0";

            for (var i = 0; i < numOfFootstepTextures; i++)
            {
                ParticleConfig.FOOTSTEP_TEXTURE.Add(new Sprite(director.Content.Load <Texture2D>(MainConfig.PIPELINE_GRAPHICS_DIRECTORY + texturePrefix + i)));
            }

            int numOfFoliageTextures = 5;

            texturePrefix = "UndergrowthParticle0";
            for (var i = 0; i < numOfFoliageTextures; i++)
            {
                ParticleConfig.FOLIAGE_CUT_TEXTURE.Add(new Sprite(director.Content.Load <Texture2D>(MainConfig.PIPELINE_GRAPHICS_DIRECTORY + texturePrefix + (i + 1))));
            }

            LightningConfig.LIGHTNING_TEXTURES[0] = director.Content.Load <Texture2D>(MainConfig.PIPELINE_GRAPHICS_DIRECTORY + "Half Circle");
            LightningConfig.LIGHTNING_TEXTURES[1] = director.Content.Load <Texture2D>(MainConfig.PIPELINE_GRAPHICS_DIRECTORY + "Lightning Segment");

            //************************* INIT MAP(map needs to be initialized before player) ************************//

            //Import a simple test level
            TiledMap tiledMap = new TiledMap(MainConfig.CONTENT_MAP_DIRECTORY + "FinalLevel.xml", director.Content, MainConfig.PIPELINE_GRAPHICS_DIRECTORY, scene);

            this.BaseScreenSize = tiledMap.MapSize;


            //************************* INIT SHOP KEEPER ************************//
            Character shopkeeper = CharacterImporter.ImportCharacter(
                MainConfig.CONTENT_CHARACTERS_DIRECTORY + MainConfig.CONTENT_SHOPKEEPER_FILE, director.Content, scene);

            scene.RegisterObject(shopkeeper);



            //************************* INIT AI GRAPH ************************//
            NavGraph navGraph = new NavGraph(scene);

            //************************* INIT FOLIAGE (after the characters!!) ************************//


            // Initialize the foliage events
            // Initialize treasures and ammo crates
            int foliageCount    = scene.GetFoliage().Count;
            int treasureCount   = selectedPlayers.Length * MatchConfig.TreasuresPerPlayer;                    //(int)(foliageCount * MatchConfig.TreasureFactor);
            int ammoCrateCount  = (int)(foliageCount * MatchConfig.AmmoCrateFactor);
            int indigenousCount = (int)Math.Ceiling(selectedPlayers.Length * MatchConfig.IndPeoplePerPlayer); //(foliageCount * MatchConfig.IndigenousFactor);
            int snakeCount      = (int)(foliageCount * MatchConfig.SnakeSpawnFactor);

            scene.TreasuresLeft = treasureCount;

            List <Foliage> undecidedFoliage = new List <Foliage>();

            undecidedFoliage.AddRange(scene.GetFoliage());

            // Favor higher distances to the shopkeeper
            ProbabilityList <Foliage, double> undecidedFoliageProbabilityList =
                new ProbabilityList <Foliage, double>(MatchConfig.TreasureDistanceProbabilityMeanFactor, MatchConfig.TreasureDistanceProbabilityVarianceFactor, foliage =>
                                                      Math.Sqrt(
                                                          Math.Pow(foliage.GetPosition().X - shopkeeper.GetPosition().X, 2) +
                                                          Math.Pow(foliage.GetPosition().Y - shopkeeper.GetPosition().Y, 2) +
                                                          Math.Pow(foliage.GetPosition().Z - shopkeeper.GetPosition().Z, 2))
                                                      , scene.Random);


            Random random = scene.Random;


            // WARNING: Order of hiding matters! 1. AI, 2. Snakes, 3. Rest
            // This way, snakes can be hidden with other things.

            // Hide Indigenous AI
            for (int i = 0; i < indigenousCount; i++)
            {
                Foliage currentFoliage;
                SpawnAiPossessedCharacterEvent currentSpawnAiPossessedCharacterEvent;
                Character currentIndigenousCharacter;
                // Select one random foliage to put treasure inside
                currentFoliage = undecidedFoliage[random.Next(undecidedFoliage.Count)];
                undecidedFoliage.Remove(currentFoliage);
                currentIndigenousCharacter = CharacterImporter.ImportCharacter(MainConfig.CONTENT_CHARACTERS_DIRECTORY + "IndigenousChar.xml", director.Content, scene);
                currentIndigenousCharacter.InitCharacter(new Vector3(currentFoliage.PositionForContent.X, currentFoliage.PositionForContent.Y - 150, 0f));
                currentSpawnAiPossessedCharacterEvent = new SpawnAiPossessedCharacterEvent(currentIndigenousCharacter, scene);
                currentFoliage.CharacterCutEventList.EventList.Add(currentSpawnAiPossessedCharacterEvent);
            }

            //Hide snakes
            for (int i = 0; i < snakeCount; i++)
            {
                Foliage         currentFoliage;
                SpawnSnakeEvent currentSpawnSnakeEvent;
                currentFoliage = undecidedFoliage[random.Next(undecidedFoliage.Count)];

                // Don't remove currentfoliage from undecidedfoliage because snakes should appear in any foliage (except foliage with AI)

                Tuple <Spritesheet, Rectangle> snakeData = SpritesheetImporter.ImportSpritesheet(MainConfig.CONTENT_CHARACTERS_DIRECTORY + "Snake.xml", director.Content, scene);

                Snake snake = new Snake(snakeData.Item1, new Vector2(currentFoliage.PositionForContent.X, currentFoliage.PositionForContent.Y - 70), snakeData.Item2);
                scene.RegisterObject(snake);
                currentSpawnSnakeEvent = new SpawnSnakeEvent(snake, scene);
                //test
                var rand = random.Next(1, 4);                //1,2,3

                if (rand < 2)
                {
                    Foliage movingFoliage = CreateMovingFoliage(currentFoliage);

                    movingFoliage.CharacterCutEventList.EventList.Add(currentSpawnSnakeEvent);
                    scene.RegisterObject(movingFoliage);
                    scene.RemoveActor(currentFoliage);

                    // Make sure that things hidden later are hidden in foliage that is accessible and visible
                    undecidedFoliage.Remove(currentFoliage);
                    undecidedFoliage.Add(movingFoliage);
                }
                else
                {
                    currentFoliage.CharacterCutEventList.EventList.Add(currentSpawnSnakeEvent);
                }
            }


            // Hide treasures
            undecidedFoliageProbabilityList.AddRange(undecidedFoliage);
            undecidedFoliageProbabilityList.LockList(true);

            for (int i = 0; i < treasureCount; i++)
            {
                Foliage           currentFoliage;
                TreasureDropEvent currentTreasureDropEvent;
                // Select one random foliage to put treasure inside
                currentFoliage = undecidedFoliageProbabilityList.DrawItem();
                //test
                var rand = random.Next(1, 4);

                if (rand < 2)
                {
                    Foliage movingFoliage = CreateMovingFoliage(currentFoliage);

                    currentTreasureDropEvent = new TreasureDropEvent(random, currentFoliage.PositionForContent, scene);
                    movingFoliage.CharacterCutEventList.EventList.Add(currentTreasureDropEvent);
                    scene.RegisterObject(movingFoliage);
                    scene.RemoveActor(currentFoliage);
                }
                else
                {
                    currentTreasureDropEvent = new TreasureDropEvent(random, currentFoliage.PositionForContent, scene);
                    currentFoliage.CharacterCutEventList.EventList.Add(currentTreasureDropEvent);
                }

                undecidedFoliage.Remove(currentFoliage);
            }

            // Hide ammo crates
            for (int i = 0; i < ammoCrateCount; i++)
            {
                Foliage       currentFoliage;
                AmmoDropEvent currentAmmoDropEvent;
                // Select one random foliage to put an ammo crate inside
                currentFoliage = undecidedFoliage[random.Next(undecidedFoliage.Count)];
                undecidedFoliage.Remove(currentFoliage);
                currentAmmoDropEvent = new AmmoDropEvent(ItemsConfig.AMMO_CRATE_TEXTURE, currentFoliage.PositionForContent, scene);
                currentFoliage.CharacterCutEventList.EventList.Add(currentAmmoDropEvent);
            }



            //************************* INIT PLAYERS ************************//

            // Creating as many players, as there are connected gamepads (up to four)
            // Player 1 and 2 are always created.
            Character defaultCharacter = null;

            for (var i = 0; i < maxNumOfPlayers; i++)
            {
                if (!selectedPlayers[i])
                {
                    continue;
                }

                Player player;
                if (i == 1 || i == 2)
                {
                    player = new Player((PlayerIndex)i, new MatchInputMapper(true, i), scene);
                    scene.RegisterPlayer(player);
                }
                else
                {
                    player = new Player((PlayerIndex)i, new MatchInputMapper(false, -1), scene);
                    scene.RegisterPlayer(player);
                }


                defaultCharacter = CharacterImporter.ImportCharacter(
                    MainConfig.CONTENT_CHARACTERS_DIRECTORY + MainConfig.CONTENT_CHARACTER_FILE_XML(i + 1), director.Content, scene);
                player.Possess(defaultCharacter);
                //Character can only be initialized after the possesing player has been set.
                defaultCharacter.InitCharacter();
                scene.Characters.Add(defaultCharacter);
                //scene.RegisterObject(defaultCharacter);
            }

            //Correct walkable areas of each walkable polygons(MinX and MaxX may overlap)
            var character = (DefaultCharacter)defaultCharacter;

            if (character != null)
            {
                //TODO:DELTAY is only a crude approximation. Find better way
                float deltaY = 2 * character.HitboxOffset.Height;

                foreach (var c1 in scene.WalkableCollidables)
                {
                    foreach (var c2 in scene.WalkableCollidables)
                    {
                        if (c1 == c2)
                        {
                            continue;
                        }
                        float centerDistY = Math.Abs(c1.Center.Y - c2.Center.Y);
                        if (centerDistY > deltaY)
                        {
                            continue;
                        }
                        //If centerDistY < deltaY, then one walkable polygon may overlap another walkable
                        if (c1.WalkableMinMax.X < c2.WalkableMinMax.X && c1.WalkableMinMax.Y > c2.WalkableMinMax.X)
                        {
                            if (c1.Center.Y < c2.Center.Y)
                            {
                                //c1 is overlapping(above) c2 => adjust walkables positions of c2
                                c2.WalkableMinMax.X = c1.WalkableMinMax.Y;
                            }
                            else
                            {
                                //c2 is overlapping(above) c1 => adjust walkables positions of c2
                                c1.WalkableMinMax.Y = c2.WalkableMinMax.X;
                            }
                        }
                    }
                }
            }

            //************************* INIT SCORE ************************//

            // Initialize the score
            scene.Scores = new Dictionary <Player, Score>();
            foreach (Player p in scene.GetPlayers())
            {
                scene.Scores.Add(p, new Score());
            }


            //************************* INIT PARTICLE EFFECTS ************************//

            /*Rectangle startPosRec = scene.ShopKeeperStartPos[0];
             * Vector3 firePos = new Vector3(startPosRec.X, startPosRec.Y, 0f);
             * ParticleEffectFactory fireParticleEffectFactory = new FireParticleEffectFactory(FireParticleEffectType.Default, new Vector2(firePos.X, firePos.Y), 10);
             * //ParticleEffectFactory fireParticleEffectFactory = new FireParticleEffectFactory(new Vector2(firePos.X, firePos.Y), 10, 3000, new Vector2(0.5f,0f),
             * // new Vector2(0f, 200), 0.5f, -0.3f, Color.Red, Color.LightYellow, 2750);
             * ParticleEffectManager fireParticleEffectManager = new ParticleEffectManager(new Sprite(ParticleConfig.WHITE_CIRCLE),fireParticleEffectFactory, 10, 16, true, BlendState.Additive);
             * scene.RegisterParticleEffect(fireParticleEffectManager);*/


            weatherSystem           = new WeatherSystem(scene, BaseScreenSize);
            scene.CurrWeatherSystem = weatherSystem;

            //************************* PLAY INGAME THEME ************************//
            scene.MatchSoundManager.PlaySong(SongEnumeration.InGame);
        }
 /// <summary>
 /// Paints the foliage instances using the given foliage types selection and the brush location.
 /// </summary>
 /// <param name="foliage">The foliage actor.</param>
 /// <param name="foliageTypesIndices">The foliage types indices to use for painting.</param>
 /// <param name="brushPosition">The brush position.</param>
 /// <param name="brushRadius">The brush radius.</param>
 /// <param name="additive">True if paint using additive mode, false if remove foliage instances.</param>
 public static void Paint(Foliage foliage, int[] foliageTypesIndices, Vector3 brushPosition, float brushRadius, bool additive)
 {
     Internal_Paint(FlaxEngine.Object.GetUnmanagedPtr(foliage), foliageTypesIndices, ref brushPosition, brushRadius, additive);
 }