public void initiate()
    {
        poolmanager.instance.initiate();
        elementaryAffection.instance.initiate();

        if (_map == null)
        {
            _map = new GameObject("(" + mapSize + "x" + mapSize + ") map");
            mapData      data      = _map.AddComponent <mapData>();
            mapGfx       gfx       = _map.AddComponent <mapGfx>();
            mapGenerator generator = _map.AddComponent <mapGenerator>();

            List <string> layerNames = new List <string>()
            {
                "ground", "path", "decoration", "tower"
            };

            data.mapSize = mapSize;
            data.layers  = layerNames;
            data.initiate();

            layerNames.Add("waypoint");

            gfx.prefixIdentifier = new List <string>()
            {
                "basis",
                "ground",
                "spawn",
                "bottomLeftPath",
                "bottomRightPath",
                "horizontalPath",
                "upperLeftPath",
                "upperRightPath",
                "verticalPath"
            };

            gfx.initiate(layerNames);

            generator.buildBoardFoundation(data, gfx);
            generator.buildRandomBoard(data, gfx);

            gfx.instantiateBoard(data.getBoard(), data.mapSize);

            createWavesystem(generator.startWaypoint);
        }
        else
        {
            Destroy(_map);
            _map = null;

            Destroy(_wavesystem);
            _wavesystem = null;

            elementaryAffection.instance.reset();

            initiate();
        }
    }
Ejemplo n.º 2
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;
                }
            }
        }
    }
Ejemplo n.º 3
0
    /*(random generation)waypoint functions*/
    private triggerWaypoint createWaypoint(int positionX, int positionY, mapGfx mapGfx, triggerWaypoint connectWith, int identification)
    {
        GameObject newWaypoint = new GameObject("waypoint " + identification);

        triggerWaypoint triggerWaypoint = newWaypoint.AddComponent <triggerWaypoint>();

        newWaypoint.transform.position = new Vector3(positionX, positionY);

        mapGfx.addGameObject(newWaypoint, "waypoint");

        if (connectWith != null)
        {
            triggerWaypoint.nextWaypoint = connectWith;
        }

        return(triggerWaypoint);
    }
    /*(random generation)waypoint functions*/
    private waypoint createWaypoint(int positionX, int positionY, mapGfx mapGfx, waypoint connectWith, int identification)
    {
        GameObject newWaypoint = new GameObject("waypoint " + identification);

        waypoint waypoint = newWaypoint.AddComponent <waypoint>();

        BoxCollider2D boxCollider2D = newWaypoint.AddComponent <BoxCollider2D>();

        boxCollider2D.size = new Vector2(0.32f, 0.32f);

        newWaypoint.transform.position = new Vector3(positionX, positionY);

        mapGfx.addGameObject(newWaypoint, "waypoint");

        if (connectWith != null)
        {
            connectWith.nextwaypoint = waypoint;
        }

        return(waypoint);
    }
Ejemplo n.º 5
0
    public void buildRandomBoard(mapData mapData, mapGfx mapGfx)
    {
        int pathBuildTryCount = 1;

        do
        {
            if (gamemanager.instance.debug)
            {
                Debug.LogWarning("(mapGenerator:buildRandomBoard) " + pathBuildTryCount + ". try to build path.");
            }

            buildBoardFoundationOnLayer(mapData, mapGfx, "path");
            buildBoardFoundationOnLayer(mapData, mapGfx, "tower");
            initiate(mapData.mapSize, _pathLengthReduktion);

            mapData.setTileOnLayer(_baseX, _baseY, "path", 2);

            ++pathBuildTryCount;
            _pathLengthReduktion += 5;
        }while (!buildPath(_baseX, _baseY, 1, -1, mapData));

        setupBuiltPath(mapData, mapGfx);
    }
Ejemplo n.º 6
0
    void Update()
    {
        Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        if (mousePosition.x < -0.5f || mousePosition.y < -0.5f)
        {
            mousePosition.x = -2;
            mousePosition.y = -2;
        }

        int mousePositionX = (int)(mousePosition.x + 0.5f);
        int mousePositionY = (int)(mousePosition.y + 0.5f);

        mapData mapData = gamemanager.instance.mapData;
        mapGfx  mapGfx  = gamemanager.instance.mapGfx;

        if (mapData == null || mapGfx == null)
        {
            return;
        }

        int tileOnMousePosition = mapData.getTileOnLayer(mousePositionX, mousePositionY, "tower");

        if (_buildTower == true && tileOnMousePosition != -1 && tileOnMousePosition != 1)
        {
            _mouseOverObject.SetActive(true);
            _mouseOverObject.transform.position = new Vector2(mousePositionX, mousePositionY);

            if (Input.GetMouseButtonDown(0) && _towers.ContainsKey(_towerTag))
            {
                mapData.setTileOnLayer(mousePositionX, mousePositionY, "tower", 1);
                GameObject newTower = Instantiate(_towers[_towerTag], new Vector2(mousePositionX, mousePositionY), Quaternion.identity) as GameObject;
                mapGfx.addGameObject(newTower, "tower");

                switch (_towerTag)
                {
                case "waterTower":
                    elementaryAffection.instance.waterLevel++;
                    break;

                case "fireTower":
                    elementaryAffection.instance.fireLevel++;
                    break;

                case "airTower":
                    elementaryAffection.instance.airLevel++;
                    break;

                case "earthTower":
                    elementaryAffection.instance.earthLevel++;
                    break;
                }

                elementaryAffection.instance.updateOnChange();
            }
        }
        else
        {
            _mouseOverObject.SetActive(false);
        }

        if (Input.GetMouseButtonDown(1))
        {
            _buildTower = false;
        }
    }
Ejemplo n.º 7
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);
    }