Exemplo n.º 1
0
        /// <summary>
        /// Generates the interactuable blocks by random
        /// </summary>
        private void GenerateInteractuableBlocks()
        {
            int i;

            foreach (var node in Graph.Nodes)
            {
                i = Int32.Parse(node.name);

                if (PositionTools.IsSide(node.name, widthAndHeight))
                {
                    continue;
                }
                if (PositionTools.IsAForgivenOne(node.name, forgivenPositions))
                {
                    setRelations(i, normalCost, normalCost, true);
                    continue;
                }
                GameObject newBlock;
                var        groundBlockInfo = node.GetComponent <GroundBlock>();


                if (Random.Range(0, 100) < 70)
                {
                    newBlock = Instantiate(blocksPrefab[Random.Range(0, 3)], node.transform, true);
                    setRelations(i, closedCost, blockedCost, true);
                    walkableBlocks++;
                }
                else
                {
                    newBlock = Instantiate(indestructibleBlockPrefab, node.transform, true);
                    newBlock.transform.GetChild(0).gameObject.SetActive(false);
                    setRelations(i, closedCost, closedCost, true);
                }



                groundBlockInfo.Reset();

                newBlock.transform.position = node.transform.position + new Vector3(0, 2, 0);
                groundBlockInfo.block       = newBlock.GetComponent <Block>();
                groundBlockInfo.blockObject = newBlock;
            }

            //Debug.Log("cantidad de bloques caminables : " + walkableBlocks);
            //Debug.Log(message: "cantidad de bloques NOcaminables : " +(int) (Math.Pow(widthAndHeight - 2, 2) - walkableBlocks));
            //Debug.Log("tiene areas cerradas : " + !BackTracking());
            if (BackTracking())
            {
                return;
            }
            walkableBlocks = 28;
            Invoke(nameof(GenerateInteractuableBlocks), 0.1F);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Explores all nodes recursively , ask if it is a walkable one, if true, the counter increases
        /// </summary>
        /// <param name="blockNumber"></param>
        /// <param name="cont"></param>
        /// <returns> int how many nodes it visited</returns>
        private int BackTrackingAux(int blockNumber, int cont)
        {
            if (PositionTools.IsSide(blockNumber, widthAndHeight))
            {
                return(cont);
            }
            var blockInfo = Graph.getNode(blockNumber).GetComponent <GroundBlock>();

            if (visitedNodes.Contains(blockNumber))
            {
                return(cont);
            }
            if (blockInfo.block != null)
            {
                if (!blockInfo.block.isDestructible)
                {
                    return(cont);
                }
            }

            visitedNodes[cont] = blockNumber;
            cont++;

            var blockUp    = PositionTools.DetectWalkable(blockNumber, PositionTools.Up, widthAndHeight);
            var blockDown  = PositionTools.DetectWalkable(blockNumber, PositionTools.Down, widthAndHeight);
            var blockLeft  = PositionTools.DetectWalkable(blockNumber, PositionTools.Left, widthAndHeight);
            var blockRight = PositionTools.DetectWalkable(blockNumber, PositionTools.Right, widthAndHeight);

            if (blockUp > 0)
            {
                cont = BackTrackingAux(blockUp, cont);
            }
            if (blockDown > 0)
            {
                cont = BackTrackingAux(blockDown, cont);
            }
            if (blockLeft > 0)
            {
                cont = BackTrackingAux(blockLeft, cont);
            }
            if (blockRight > 0)
            {
                cont = BackTrackingAux(blockRight, cont);
            }



            return(cont);
        }
Exemplo n.º 3
0
/// <summary>
/// generates a new map
/// </summary>
/// <returns></returns>
        public DGraph <GameObject> GenerateNewMap()
        {
            if (MapConfig.Side != 0)
            {
                widthAndHeight = MapConfig.Side;
            }


            Graph             = new DGraph <GameObject>(widthAndHeight * widthAndHeight);
            otherGraph        = new DGraph <GameObject>(widthAndHeight * widthAndHeight);
            forgivenPositions = PositionTools.DetermineForgivenPositions(widthAndHeight);

            GenerateGround();
            if (generateMap)
            {
                GenerateInteractuableBlocks();
            }
            CharacterGenerator.GenerateAllPlayers(widthAndHeight, Graph);
            //justAPrint();
            return(Graph);
        }