Exemplo n.º 1
0
    public void buildBoardFoundationOnLayer(mapData mapData, mapGfx mapGfx, string layerName)
    {
        if (mapData == null || mapGfx == null)
        {
            if (gamemanager.instance.debug)
            {
                Debug.LogWarning("(mapGenerator:buildBoardFoundation) Could not build foundation because the mapData/Gfx is a nullptr.");
            }

            return;
        }

        for (int positionX = 0; positionX < mapData.mapSize; ++positionX)
        {
            for (int positionY = 0; positionY < mapData.mapSize; ++positionY)
            {
                switch (layerName)
                {
                case "ground":
                    rangeHelper range = mapGfx.getPrefixedObjectRange("ground");
                    if (range != null)
                    {
                        mapData.setTileOnLayer(positionX, positionY, layerName, Random.Range(range.begin, range.end + 1));
                    }
                    else
                    {
                        if (gamemanager.instance.debug)
                        {
                            Debug.LogError("(mapGenerator:buildBoardFoundation) Ground ID range is null.");
                        }
                        mapData.setTileOnLayer(positionX, positionY, layerName, 0);
                    }
                    break;

                case "path":
                    if (positionX == 0 || positionY == 0 || positionY == mapData.mapSize - 1 || positionX == mapData.mapSize - 1)
                    {
                        mapData.setTileOnLayer(positionX, positionY, layerName, 1);
                    }
                    else
                    {
                        mapData.setTileOnLayer(positionX, positionY, layerName, 0);
                    }
                    break;

                case "waypoint":
                    break;

                default:
                    mapData.setTileOnLayer(positionX, positionY, layerName, 0);
                    break;
                }
            }
        }
    }
Exemplo n.º 2
0
    private void setupBuiltPath(mapData mapData, mapGfx mapGfx)
    {
        triggerWaypoint lastWaypoint  = null;
        int             waypointCount = 0;

        mapData.setTileOnLayer(_spawnX, _spawnY, "path", mapGfx.getPrefixedObjectRange("spawn").getRandom());
        mapData.setTileOnLayer(_baseX, _baseY, "path", mapGfx.getPrefixedObjectRange("basis").getRandom());

        lastWaypoint = createWaypoint(_baseX, _baseY, mapGfx, lastWaypoint, waypointCount++);

        mapData.setTileOnLayer(_baseX, _baseY, "tower", 1);

        for (int pathtileIndex = _pathList.Count - 1; pathtileIndex >= 1; pathtileIndex--)
        {
            int positionX        = _pathList[pathtileIndex].positionX;
            int positionY        = _pathList[pathtileIndex].positionY;
            int currentDirection = _pathList[pathtileIndex].direction;
            int nextDirection    = _pathList[pathtileIndex - 1].direction;

            if (gamemanager.instance.debug)
            {
                Debug.Log("(mapGenerator:setupBuiltPath) Pathtile on " + positionX + "|" + positionY + ".");
            }

            if (currentDirection != nextDirection)
            {
                if ((currentDirection == 0 && nextDirection == 2) || (currentDirection == 3 && nextDirection == 1))
                {
                    mapData.setTileOnLayer(positionX, positionY, "path", mapGfx.getPrefixedObjectRange("upperLeftPath").getRandom());
                }
                else if ((currentDirection == 1 && nextDirection == 2) || (currentDirection == 3 && nextDirection == 0))
                {
                    mapData.setTileOnLayer(positionX, positionY, "path", mapGfx.getPrefixedObjectRange("bottomLeftPath").getRandom());
                }
                else if ((currentDirection == 0 && nextDirection == 3) || (currentDirection == 2 && nextDirection == 1))
                {
                    mapData.setTileOnLayer(positionX, positionY, "path", mapGfx.getPrefixedObjectRange("upperRightPath").getRandom());
                }
                else if ((currentDirection == 1 && nextDirection == 3) || (currentDirection == 2 && nextDirection == 0))
                {
                    mapData.setTileOnLayer(positionX, positionY, "path", mapGfx.getPrefixedObjectRange("bottomRightPath").getRandom());
                }

                lastWaypoint = createWaypoint(positionX, positionY, mapGfx, lastWaypoint, waypointCount++);
            }
            else
            {
                if (currentDirection == 0 || currentDirection == 1)
                {
                    mapData.setTileOnLayer(positionX, positionY, "path", mapGfx.getPrefixedObjectRange("verticalPath").getRandom());
                }
                else if (currentDirection == 2 || currentDirection == 3)
                {
                    mapData.setTileOnLayer(positionX, positionY, "path", mapGfx.getPrefixedObjectRange("horizontalPath").getRandom());
                }
            }

            mapData.setTileOnLayer(positionX, positionY, "tower", 1);
        }

        lastWaypoint   = createWaypoint(_spawnX, _spawnY, mapGfx, lastWaypoint, waypointCount++);
        _startWaypoint = lastWaypoint;

        mapData.setTileOnLayer(_spawnX, _spawnY, "tower", 1);
    }