예제 #1
0
        public void CreateRandomLeaf()
        {
            // Very slight random offset for leaves so that there's no z-fighting.
            double minY = Constants.FLOOR_HEIGHT;
            double maxY = Constants.FLOOR_HEIGHT + 0.2f;

            float minX = matchHandler.GetMatch().NoMansLand.leftX + Constants.TREE_RADIUS;
            float maxX = matchHandler.GetMatch().NoMansLand.rightX - Constants.TREE_RADIUS;
            float minZ = matchHandler.GetMatch().NoMansLand.downZ + (2 * Constants.TREE_RADIUS);
            float maxZ = matchHandler.GetMatch().NoMansLand.upZ - (2 * Constants.TREE_RADIUS);

            // Get random doubles for position.
            double randX = rnd.NextDouble();
            double randY = rnd.NextDouble();
            double randZ = rnd.NextDouble();

            // Bind random doubles to our range.
            randX = (randX * (maxX - minX)) + minX;
            randY = (randY * (maxY - minY)) + minY;
            randZ = (randZ * (maxZ - minZ)) + minZ;

            // Get the new position
            Vector3 pos      = new Vector3((float)randX, (float)randY, (float)randZ);
            float   rotation = rnd.NextFloat() * 360.0f;

            // Create a new leaf
            LeafServer newLeaf = new LeafServer();

            // Set the leaf's initial position.
            newLeaf.Transform.Position = pos;

            // Set the leaf's initial rotation.
            newLeaf.Transform.Rotation.Y = rotation;

            newLeaf.EnsureSafePosition();

            // Add this leaf to the leaf list and object dictionary.
            newLeaf.Register();

            // Send this object to the other objects.
            networkServer.SendNewObjectToAll(newLeaf);
        }
예제 #2
0
        /// <summary>
        /// Gets all of the leaves that are within specified bounds.
        /// </summary>
        /// <param name="leaves"> List of all leaves in the game. </param>
        /// <param name="leftBound"> Leftmost bound of the area to check. </param>
        /// <param name="rightBound"> Rightmost bound of the area to check. </param>
        /// <param name="lowBound"> Low (bottom) bound of the area to check. </param>
        /// <param name="highBound"> High (upper) bound of the area to check. </param>
        /// <returns>Number of leaves in the area.</returns>
        public int GetLeavesInBounds(List <LeafServer> leaves, float leftBound, float rightBound, float lowBound, float highBound)
        {
            // Keep track of number of leaves.
            int count = 0;

            // Iterate through all leaves.
            for (int i = 0; i < leaves.Count; i++)
            {
                // Current leaf.
                LeafServer leaf = leaves[i];

                // Check if it's in bounds.
                if (IsInBounds(leaf.Transform.Position, leftBound, rightBound, lowBound, highBound))
                {
                    // If so, increment count.
                    count++;
                }
            }

            // Return result.
            return(count);
        }