Ejemplo n.º 1
0
 public void Set(MapRogulikeGenerator newgameobject, WorldMapCell mapCell, Loader l)
 {
     gameObject.SetActive(true);
     Debug.LogWarning("New world key");
     generator = newgameobject;
     mapcell   = mapCell;
     loader    = l;
 }
Ejemplo n.º 2
0
    public void CreateWorldMapCell(Vector2 position)
    {
//        Debug.Log("GeneratingMapCell");
//        Debug.Log(position);
        position += new Vector2(StaticData.WorldCellSize / 2, StaticData.WorldCellSize / 2);
//        Debug.Log(position);
        position /= StaticData.WorldCellSize;
        //      Debug.Log(position);
        position.x = Mathf.FloorToInt(position.x);
        position.y = Mathf.FloorToInt(position.y);
        //    Debug.Log((int)position.x+","+(int)position.y);
        //  Debug.Log((int)-0.1);
        WorldMapCell worldMapCell = StaticData.MapData[(int)position.x + (int)ZeroPosition.x][(int)position.y + (int)ZeroPosition.y];

//        Debug.Log(worldMapCell.PosX+"  "+worldMapCell.PosY);
        for (int i = 0; i < MapCells.Length; i++)
        {
            if (MapCells[i] == null)
            {
                continue;
            }
            if (MapCells[i].ThisCell.PosX == worldMapCell.PosX && MapCells[i].ThisCell.PosY == worldMapCell.PosY)
            {
                return;
            }
        }
        Debug.Log(new Vector3((position.x * StaticData.WorldCellSize) - (float)StaticData.WorldCellSize / 2, (float)(position.y * StaticData.WorldCellSize) - (float)StaticData.WorldCellSize / 2, 1));
        MapRogulikeGenerator MapCell = Instantiate(WorldCellPerhub);

        MapCell.transform.SetParent(gameObject.transform);
        MapCell.transform.position = new Vector3((position.x * StaticData.WorldCellSize) - (float)StaticData.WorldCellSize / 2, (float)(position.y * StaticData.WorldCellSize) - (float)StaticData.WorldCellSize / 2, 1);

        MapCell.Setter(loader, worldMapCell);
        //Debug.Log($"Coordinate:{DY}, DX:{DX}");
        //Debug.Log($"ResultCoordinate:{tmpCell.PosY + DY},:{tmpCell.PosX + DX}");
        //Debug.Log($"MessageThis:{StaticData.MapData[tmpCell.PosY + DY][tmpCell.PosX + DX].Message}");
        //Debug.Log($"MessageThis:{StaticData.MapData[tmpCell.PosY + DY][tmpCell.PosX + DX].PosY}");
        AddMapCell(MapCell, position);
    }
Ejemplo n.º 3
0
    public void Setter(Loader loader, WorldMapCell thisscell, int UnBorder = 5)
    {
//        Debug.LogWarning("disablings");
        GetComponent <BoxCollider2D>().enabled = false;
        //Debug.Log("asdfghjkl;:"+loader.IsMapGenered);
        this.loader   = loader;
        ThisCell      = thisscell;
        this.UnBorder = UnBorder;
        //if (!loader.IsMapGenered)
        //{
        //    Debug.Log("coo");
        //    loader.LoadMap();
        //    StaticData.ActiveCell = StaticData.MapData[10][10];
        //    ThisCell = StaticData.ActiveCell;
        //}
        if (!ThisCell.Accesed)
        {
            return;
        }
        Map = loader.GetMap(ThisCell);
        if (Map == null)
        {
            Destroy(gameObject);
            return;
        }
        MapSet();
        Setted = true;
        GetComponent <Image>().sprite = Resources.Load <Sprite>("Grey Stones");
        //Debug.Log(StaticData.MapData[9][10].Message);
        //ThisCell = StaticData.ActiveCell;
        //Debug.Log(ThisCell.Message);

        //generator = new Generator();
        //Debug.Log($"{this.transform.position}CoordinateInside:{ThisCell.PosY},{ThisCell.PosX}");
        //Debug.Log($"{this.transform.position}MessageInside:{ThisCell.Message}");

        //if (generator.ResultMap == null)
        //{
        //    generator.Map = loader.GetNeighborWorldMapCell();
        //
        //    outer = Task.Factory.StartNew(() =>
        //    {
        //        Debug.Log("Stage1");
        //        generator.Build(UnBorder);
        //        Debug.Log("Stage2");
        //        generator.ConnectCaves();
        //        Debug.Log("Stage3");
        //        generator.ConnectCaves();
        //        Debug.Log("Stage4");
        //        generator.EmptyCellSet();
        //        Debug.Log("Stage5");
        //        generator.EndGeneration();
        //        Debug.Log("Stage6");
        //        return generator.ResultMap;
        //    });
        //    return;
        //}
        //else
        //{
        //    // Debug.Log("MapSet");
        //    MapSet();
        //}
    }
Ejemplo n.º 4
0
    async void MapBackgroundGenerator()
    {
        try
        {
//            Debug.Log("Task");
            while (true)
            {
                //Debug.Log("Stage-1");
                WorldMapCell worldMapCell = null;
                //  Debug.Log("Stage-0.5");
                try
                {
                    worldMapCell = GeneratorQuery[0];
                }
                catch (System.Exception ex)
                {
                    Debug.Log(ex.Message);
                }
                //Debug.Log("Stage-0.1");
                Generator generator1 = new Generator();
                //Debug.Log("Stage0");
                await Task.Run(() => {
                    generator1.Map = loader.GetNeighborWorldMapCell(new Vector2(worldMapCell.PosX, worldMapCell.PosY));
                    //  Debug.Log("Stage1");
                    generator1.Build(5);
                    //Debug.Log("Stage2");
                    generator1.ConnectCaves();
                    //Debug.Log("Stage3");
                    generator1.ConnectCaves();
                    //Debug.Log("Stage4");
                    generator1.EmptyCellSet();
                    //Debug.Log("Stage5");
                    generator1.EndGeneration();
                    loader.MapGenered(worldMapCell, generator1.ResultMap);
                    //       loader.MapAccess(worldMapCell);
                });

                GeneratorQuery.Remove(worldMapCell);
                if (GeneratorQuery.Count == 0)
                {
                    GeneratorQuery.Add(GetCell());
                }
                if (GeneratorQuery[0] == null)
                {
                    //Debug.Log("QWERTYUIOP");
                    return;
                }
                if (OnGenerationEnded != null)
                {
                    GenerationCallback callback = new GenerationCallback();
                    callback.Map     = generator1.ResultMap;
                    callback.mapCell = worldMapCell;
                    OnGenerationEnded(callback);
                }
                cellcount = GeneratorQuery.Count;


                //   Debug.Log("Stage6");
                if (Stop)
                {
                    return;
                }
            }
        }
        catch (System.Exception ex)
        {
            Debug.Log(ex.Message);
        }
    }
Ejemplo n.º 5
0
    public void CreateWorldMapCell(int DX, int DY, MapRogulikeGenerator myCanvas, Vector3 position)
    {
        //Debug.Log("HOLHELL");

        //if (X < 0 || Y < 0 || X > 100 || Y > 100)
        //{
        //    Debug.Log("ERROR:CreateWorldMapCell Uncorrect (WorldState.css)");
        //    return;
        //}
        WorldMapCell tmpCell    = myCanvas.ThisCell;
        WorldMapCell targetCell = StaticData.MapData[tmpCell.PosY + DY][tmpCell.PosX + DX];

        for (int i = 0; i < MapCells.Length; i++)
        {
            if (MapCells[i] == null)
            {
                continue;
            }
            if (MapCells[i].transform.position == myCanvas.transform.position + new Vector3(DX * StaticData.WorldCellSize, DY * -StaticData.WorldCellSize))
            {
                if (!MapCells[i].Setted)
                {
                    return;
                }
                if (!MapCells[i].Setted && targetCell.Accesed)
                {
                    MapCells[i].Setter(loader, targetCell);
                }
                else if (!MapCells[i] && targetCell.Generated && !tmpCell.GetKey(DX, DY).gameObject.active)
                {
                    tmpCell.GetKey(DX, DY).gameObject.SetActive(true);
                    tmpCell.GetKey(DX, DY).Set(MapCells[i], targetCell, loader);
                }
                return;
            }
        }

        //Debug.Log("Creating new cell");
        MapRogulikeGenerator MapCell = Instantiate(WorldCellPerhub);

        MapCell.transform.SetParent(gameObject.transform);
        MapCell.transform.position = myCanvas.transform.position + new Vector3(DX * StaticData.WorldCellSize, DY * -StaticData.WorldCellSize);
        if (StaticData.MapData[tmpCell.PosY + DY][tmpCell.PosX + DX].Accesed)
        {
            MapCell.Setter(loader, StaticData.MapData[tmpCell.PosY + DY][tmpCell.PosX + DX]);
        }
        else if (StaticData.MapData[tmpCell.PosY + DY][tmpCell.PosX + DX].Generated)
        {
            Debug.Log("yy .gg");
            if (tmpCell.GetKey(DX, DY) != null)
            {
                Debug.Log("pesda1 .gg");
                tmpCell.GetKey(DX, DY).gameObject.SetActive(true);
                tmpCell.GetKey(DX, DY).Set(MapCell, StaticData.MapData[tmpCell.PosY + DY][tmpCell.PosX + DX], loader);
            }
        }
        else if (!StaticData.MapData[tmpCell.PosY + DY][tmpCell.PosX + DX].Generated)
        {
            //Debug.LogWarning("Adding to list " + tmpCell.PosY + DY + "  " + tmpCell.PosX + DX);
            GeneratorQuery.Add(StaticData.MapData[tmpCell.PosY + DY][tmpCell.PosX + DX]);
            OnGenerationEnded += (x) =>
            {
                Debug.Log("genered .gg");
                GenerationCallback callback = (GenerationCallback)x;
                if (callback.mapCell == StaticData.MapData[tmpCell.PosY + DY][tmpCell.PosX + DX])
                {
                    //MapCell.Setter(loader, StaticData.MapData[tmpCell.PosY + DY][tmpCell.PosX + DX]);
                    if (tmpCell.GetKey(DX, DY) != null)
                    {
                        Debug.Log("pesda2 .gg");
                        tmpCell.GetKey(DX, DY).gameObject.SetActive(true);
                        tmpCell.GetKey(DX, DY).Set(MapCell, StaticData.MapData[tmpCell.PosY + DY][tmpCell.PosX + DX], loader);
                    }
                }
            };
        }
        //Debug.Log($"Coordinate:{DY}, DX:{DX}");
        //Debug.Log($"ResultCoordinate:{tmpCell.PosY + DY},:{tmpCell.PosX + DX}");
        //Debug.Log($"MessageThis:{StaticData.MapData[tmpCell.PosY + DY][tmpCell.PosX + DX].Message}");
        //Debug.Log($"MessageThis:{StaticData.MapData[tmpCell.PosY + DY][tmpCell.PosX + DX].PosY}");
        AddMapCell(MapCell, position);
    }