Exemple #1
0
        public void InitPath()
        {
            int startSectionId = 0;

            sectionIndex = 0;
            ClearPath();

            SectionModel firstCornerSection = new SectionModel(
                startSectionId,
                SectionType.corner,
                Direction.right,
                new Node(0, 0),
                pathWidth, pathWidth, MapManager.Instance.verticalCornerSectionContent.terrains);

            int unitLength = Random.Range(3, 6);

            unitLength = 2;
            int            firstStraightSectionLength = unitLength * 3;
            SectionContent sectionContent             = MapManager.Instance.GetSectionContentByUnitLength(unitLength);
            SectionModel   firstStraightSection       = new SectionModel(
                firstCornerSection.sectionId + 1,
                SectionType.straight,
                Direction.right,
                new Node(3, 0),
                firstStraightSectionLength, pathWidth);

            Direction secondCornerSectionDirection = Random.Range(0, 100) < 50 ? Direction.up : Direction.down;

            secondCornerSectionDirection = pm.playMode == PlayMode.campaign ? Direction.up : Direction.down;
            SectionModel secondCornerSection = new SectionModel(
                firstStraightSection.sectionId + 1,
                SectionType.corner,
                secondCornerSectionDirection,
                new Node(3 + firstStraightSectionLength, 0),
                pathWidth, pathWidth, secondCornerSectionDirection == Direction.up ? MapManager.Instance.decreaseCornerSectionContent.terrains : MapManager.Instance.increaseCornerSectionContent.terrains);

            SectionComponent firstCornerSectionComponent = MakeSection(firstCornerSection, firstStraightSection);

            PutSectionComponent(firstCornerSectionComponent);
            SectionComponent firstStraightSectionComponent = MakeSection(firstStraightSection, secondCornerSection);

            PutSectionComponent(firstStraightSectionComponent);
            SectionComponent secondCornerSectionComponent = MakeSection(secondCornerSection);

            PutSectionComponent(secondCornerSectionComponent);

            firstCornerSectionComponent.nextSectionComponent     = firstStraightSectionComponent;
            firstStraightSectionComponent.beforeSectionComponent = firstCornerSectionComponent;
            firstStraightSectionComponent.nextSectionComponent   = secondCornerSectionComponent;
            secondCornerSectionComponent.beforeSectionComponent  = firstStraightSectionComponent;
            currentSectionComponent = firstCornerSectionComponent;


            for (int i = 0; i < 5; i++)
            {
                AddSection(pm.playMode);
            }
        }
Exemple #2
0
        public List <SectionContent> GetSectionContents(TextAsset[] textAssets)
        {
            List <SectionContent> returnData = new List <SectionContent>();

            foreach (TextAsset textAsset in textAssets)
            {
                SectionContent sectionContent = GetSectionContentFromTextAsset(textAsset);
                returnData.Add(sectionContent);
            }

            return(returnData);
        }
Exemple #3
0
        void Init()
        {
            tilesetList.Clear();
            tilesetDictionary.Clear();
            tileObjectDictionary.Clear();
            for (int i = 0; i < tilesets.Length; i++)
            {
                TextAsset textAsset = tilesets[i];
                Tileset   tileset   = JsonConvert.DeserializeObject <Tileset>(textAsset.text);
                if (tileset.tileproperties != null && tileset.tileproperties.Count > 0)
                {
                    foreach (KeyValuePair <int, TileProperty> kv in tileset.tileproperties)
                    {
                        tileObjectDictionary.Add(tileset.firstgid + kv.Key, kv.Value);
                    }
                }
                tilesetList.Add(tileset);
                tilesetDictionary.Add(i, tileset);
            }

            campaignSectionContent = GetSectionContents(campaign);
            finishSectionContent   = GetSectionContentFromTextAsset(finish);

            sectionContentList.Clear();
            sectionContentList.Add(2, GetSectionContents(unit_2));
            sectionContentList.Add(3, GetSectionContents(unit_3));
            sectionContentList.Add(4, GetSectionContents(unit_4));
            sectionContentList.Add(5, GetSectionContents(unit_5));
            sectionContentList[2].Shuffle();
            sectionContentList[3].Shuffle();
            sectionContentList[4].Shuffle();
            sectionContentList[5].Shuffle();

            sectionContentQueue.Clear();
            sectionContentQueue.Add(2, new Queue <SectionContent>(sectionContentList[2]));
            sectionContentQueue.Add(3, new Queue <SectionContent>(sectionContentList[3]));
            sectionContentQueue.Add(4, new Queue <SectionContent>(sectionContentList[4]));
            sectionContentQueue.Add(5, new Queue <SectionContent>(sectionContentList[5]));

            verticalCornerSectionContent   = GetSectionContentFromTextAsset(verticalCorner);
            horizontalCornerSectionContent = GetSectionContentFromTextAsset(horizontalCorner);
            decreaseCornerSectionContent   = GetSectionContentFromTextAsset(decreaseCorner);
            increaseCornerSectionContent   = GetSectionContentFromTextAsset(increaseCorner);
        }
Exemple #4
0
        public void AddSection(PlayMode playMode)
        {
            SectionContent sectionContent        = null;
            int            unitLength            = -1;
            int            straightSectionLength = -1;

            if (playMode == PlayMode.infinity)
            {
                unitLength            = Random.Range(2, 6);
                straightSectionLength = unitLength * 3; //6, 9, 12, 15
                sectionContent        = MapManager.Instance.GetSectionContentByUnitLength(unitLength);
            }
            else if (playMode == PlayMode.campaign)
            {
                sectionContent = MapManager.Instance.GetSectionContentBySectionIndex(sectionIndex++);
                if (sectionContent == null)
                {
                    // Debug.Log("sectionContent is null, sectionIndex : " + sectionIndex.ToString());
                    return;
                }
                unitLength            = sectionContent.unitLength;
                straightSectionLength = unitLength * 3;
            }

            Node straightSectionOrigin = lastSectionComponent.sectionData.origin;
            int  straightSectionWidth  = 0;
            int  straightSectionHeight = 0;

            if (lastSectionComponent.sectionData.direction == Direction.up)
            {
                straightSectionOrigin += new Node(0, pathWidth);
                straightSectionWidth   = pathWidth;
                straightSectionHeight  = straightSectionLength;
            }
            else if (lastSectionComponent.sectionData.direction == Direction.right)
            {
                straightSectionOrigin += new Node(pathWidth, 0);
                straightSectionWidth   = straightSectionLength;
                straightSectionHeight  = pathWidth;
            }
            else if (lastSectionComponent.sectionData.direction == Direction.down)
            {
                straightSectionOrigin += new Node(0, -straightSectionLength);
                straightSectionWidth   = pathWidth;
                straightSectionHeight  = straightSectionLength;
            }
            int[,] terrains = new int[straightSectionHeight, straightSectionWidth];
            Dictionary <Node, TiledObject> objects = new Dictionary <Node, TiledObject>();

            if (lastSectionComponent.sectionData.direction == Direction.right)
            {
                terrains = sectionContent.terrains;

                foreach (KeyValuePair <Node, TiledObject> kv in sectionContent.objects)
                {
                    Node node = new Node(kv.Key.y, kv.Key.x);
                    objects.Add(node, kv.Value);
                }
            }
            else if (lastSectionComponent.sectionData.direction == Direction.up)
            {
                for (int i = 0; i < sectionContent.terrains.GetLength(0); i++)
                {
                    for (int j = 0; j < sectionContent.terrains.GetLength(1); j++)
                    {
                        terrains[j, sectionContent.terrains.GetLength(0) - 1 - i] = sectionContent.terrains[i, j];
                    }
                }

                foreach (KeyValuePair <Node, TiledObject> kv in sectionContent.objects)
                {
                    Node node = new Node(sectionContent.terrains.GetLength(0) - 1 - kv.Key.x, kv.Key.y);
                    objects.Add(node, kv.Value);
                }
            }
            else if (lastSectionComponent.sectionData.direction == Direction.down)
            {
                for (int i = 0; i < sectionContent.terrains.GetLength(0); i++)
                {
                    for (int j = 0; j < sectionContent.terrains.GetLength(1); j++)
                    {
                        terrains[sectionContent.terrains.GetLength(1) - 1 - j, i] = sectionContent.terrains[i, j];
                    }
                }

                foreach (KeyValuePair <Node, TiledObject> kv in sectionContent.objects)
                {
                    objects.Add(new Node(kv.Key.x, sectionContent.terrains.GetLength(1) - 1 - kv.Key.y), kv.Value);
                }
            }

            SectionModel addStraightSection = new SectionModel(
                lastSectionComponent.sectionData.sectionId + 1,
                SectionType.straight,
                lastSectionComponent.sectionData.direction,
                straightSectionOrigin,
                straightSectionWidth, straightSectionHeight,
                terrains,
                objects);


            Direction cornerSectionDirection = Direction.none;
            Node      cornerSectionOrigin    = addStraightSection.origin;

            if (addStraightSection.direction == Direction.up)
            {
                cornerSectionDirection = Direction.right;
                cornerSectionOrigin   += new Node(0, addStraightSection.height);
            }
            else if (addStraightSection.direction == Direction.right)
            {
                cornerSectionDirection = Random.Range(0, 100) < 50 ? Direction.up : Direction.down;
                cornerSectionOrigin   += new Node(addStraightSection.width, 0);
            }
            else if (addStraightSection.direction == Direction.down)
            {
                cornerSectionDirection = Direction.right;
                cornerSectionOrigin   += new Node(0, -pathWidth);
            }
            SectionContent cornerSectionContent = null;

            if (playMode == PlayMode.campaign && sectionIndex == MapManager.Instance.campaignSectionContent.Count)
            {
                cornerSectionContent = MapManager.Instance.finishSectionContent;
            }
            else if (cornerSectionDirection == Direction.up)
            {
                cornerSectionContent = MapManager.Instance.decreaseCornerSectionContent;
            }
            else if (cornerSectionDirection == Direction.down)
            {
                cornerSectionContent = MapManager.Instance.increaseCornerSectionContent;
            }
            else if (cornerSectionDirection == Direction.right)
            {
                if (addStraightSection.direction == Direction.up)
                {
                    cornerSectionContent = MapManager.Instance.decreaseCornerSectionContent;
                }
                else if (addStraightSection.direction == Direction.down)
                {
                    cornerSectionContent = MapManager.Instance.increaseCornerSectionContent;
                }
            }

            bool         isLastSection    = playMode == PlayMode.campaign && sectionIndex == MapManager.Instance.campaignSectionContent.Count;
            SectionModel addCornerSection = new SectionModel(
                addStraightSection.sectionId + 1,
                SectionType.corner,
                isLastSection ? addStraightSection.direction : cornerSectionDirection,
                cornerSectionOrigin,
                pathWidth, pathWidth, cornerSectionContent.terrains);

            SectionComponent straightSectionComponent = MakeSection(addStraightSection, addCornerSection);

            lastSectionComponent.nextSectionComponent       = straightSectionComponent;
            straightSectionComponent.beforeSectionComponent = lastSectionComponent;
            PutSectionComponent(straightSectionComponent);
            SectionComponent cornerSectionComponent = MakeSection(addCornerSection, null, isLastSection);

            straightSectionComponent.nextSectionComponent = cornerSectionComponent;
            cornerSectionComponent.beforeSectionComponent = straightSectionComponent;
            PutSectionComponent(cornerSectionComponent);

            if (sectionList.Count > maxMaintainSectionCount)
            {
                SectionComponent firstStraightSection = sectionList[0];
                SectionComponent firstCornerSection   = sectionList[1];
                RemoveSectionComponent(firstStraightSection);
                RemoveSectionComponent(firstCornerSection);
                firstStraightSection.RemoveSection();
                firstCornerSection.RemoveSection();
            }
        }