Exemple #1
0
        public static void GenerateTranslatedMaps(int amountToGenerate, int seedStart)
        {
            var sw = new Stopwatch();

            for (var i = seedStart; i < seedStart + amountToGenerate; i++)
            {
                sw.Restart();
                var random123 = new Random(i);
                var ca        = new CellularAutomata(64, 64, Enums.Half.Top, maxRangeToGroupPoint: 7, r: random123);
                ca.RunGenerations();
                ca.CreateImpassableTerrain(maxLength: 25, maxPathNoiseDisplacement: 1, maxWidth: 2);

                var map = new MapPhenotype(ca.Map, new Enums.Item[64, 64]);
                map.SmoothTerrain();

                var newMap = MapHelper.IncreaseSizeOfMap(map, 2);
                newMap.SmoothTerrain(random: random123);
                newMap.PlaceCliffs();

                newMap.SmoothCliffs();
                newMap.UpdateCliffPositions(Enums.Half.Top);
                newMap.SaveMapToPngFile(string.Format("map {0}_4_translated_post_smooth_cliffs", i), itemMap: false);
                Console.WriteLine(sw.ElapsedMilliseconds);
            }

            Console.ReadKey();
        }
        public void TestLangtonIterate()
        {
            bool[,] StartingContent = new bool[8, 8]
            {
                { false, false, false, false, false, false, false, false },
                { false, false, false, false, false, false, false, false },
                { false, false, false, false, false, false, false, false },
                { false, false, false, false, false, false, false, false },
                { true, false, false, false, false, false, false, false },
                { false, false, false, false, false, false, false, false },
                { false, false, false, false, false, false, false, false },
                { false, false, false, false, false, false, false, false }
            };

            CircularArray2D <bool>         StartingArray     = new CircularArray2D <bool>(StartingContent);
            CellularAutomata <LangtonsAnt> _CellularAutomata = new CellularAutomata <LangtonsAnt>(StartingArray);

            bool[,] IteratedContent = _CellularAutomata.Iterate();

            bool[,] ModelContent = new bool[8, 8]
            {
                { false, false, false, false, true, false, false, false },
                { false, false, false, false, false, false, false, false },
                { false, true, false, false, false, true, false, false },
                { false, false, false, false, false, false, false, false },
                { false, false, true, false, false, false, true, false },
                { false, false, false, false, false, false, false, false },
                { false, false, false, true, false, false, false, true },
                { false, false, false, false, false, false, false, false }
            };

            Assert.AreEqual(IteratedContent, ModelContent);
        }
Exemple #3
0
        /// <summary> Initializes this Room. </summary>
        internal void Init(int index)
        {
            this.Index = index;

            if (!this.IsGenerated)
            {
                if (!CheckDoors())
                {
                    return;
                }

                this.upperDoor.Init(this, this.Up);
                this.lowerDoor.Init(this, this.Down);
                this.leftDoor.Init(this, this.Left);
                this.rightDoor.Init(this, this.Right);
                this.Grid = null;
            }
            else
            {
                CellularAutomata ca = new CellularAutomata(15);
                ca.GeneratePattern(30);
                this.Grid = ca.GetPattern();
            }

            this.doors   = new List <GameObject>();
            this.walls   = new List <GameObject>();
            this.floors  = new List <GameObject>();
            this.holes   = new List <GameObject>();
            this.enemies = new List <Enemy>();
            Deactivate();
        }
Exemple #4
0
    void SetupLevel()
    {
        bool laddarSpawned = false; // bool will control if a ladder has already been spawned
        bool playerSpawned = false;

        cellularAutomata = GameObject.Find("MeshGenerator").GetComponent <CellularAutomata>();                                      // finds the cellular automata script in the scene
        aStarGrid        = GameObject.Find("A*").GetComponent <AStarGrid>();                                                        // finds the AStarGrid

        for (int x = 0; x < cellularAutomata.gridWidth; x++)                                                                        // loops through the grids x
        {
            for (int y = 0; y < cellularAutomata.gridHeight; y++)                                                                   // loops through the grids y
            {
                if (x != 0 && x != cellularAutomata.grid.GetLength(0) - 2 && y != 0 && y != cellularAutomata.grid.GetLength(1) - 2) // if we are within the bounds the array
                {
                    if (cellularAutomata.GetAmountOfNeighbours(x, y, 2) == 0 && aStarGrid.grid[x, y].walkable)                      // using the overloaded methoed of get neighbours to have a larger search area to stop things from spawning on walls and checks if the tile is walkable in the AStarGrid
                    {                                                                                                               //
                        if (GetRandomNumber() <= probabilityToSpawnEnemy)                                                           // generate a random number and if it is within probabilty
                        {
                            Instantiate(enemy, aStarGrid.grid[x, y].worldPosition, Quaternion.identity);                            // spawn an enemy
                        }
                        else if (!laddarSpawned)
                        {
                            laddarSpawned = Instantiate(ladder, aStarGrid.grid[x, y].worldPosition, Quaternion.identity); // if no spawn a ladder and set the ladderspawned varaible to true
                        }
                        else if (!playerSpawned && (x == (cellularAutomata.grid.GetLength(0) / 2) || y == (cellularAutomata.grid.GetLength(1) / 2)))
                        {
                            playerSpawned = Instantiate(player, aStarGrid.grid[x, y].worldPosition, Quaternion.identity);
                        }
                    }
                }
            }
        }
    }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        CellularAutomata Automata = (CellularAutomata)target;

        if (GUILayout.Button("Generate Room"))
        {
            Automata.GenerateRoom();
        }

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Restart"))
        {
            Automata.FillRandom();
            Automata.DrawRoom();
        }
        if (GUILayout.Button("Iterate"))
        {
            Automata.Iterate();
        }
        if (GUILayout.Button("Change States"))
        {
            Automata.ChangeStates();
            Automata.DrawRoom();
        }
        GUILayout.EndHorizontal();
    }
Exemple #6
0
        public T CreateMap()
        {
            var cave      = CellularAutomata.GenerateCaves(_width, _height, _density);
            var regionMap = MapFeatureDetector.GetRegions(cave);

            // Pick a random room to start and dig a tunnel to a random other room.
            // Go from there to another random room until all are connected.
            var roomCenters = GetRoomCenters(regionMap).ToList();
            var startPoint  = roomCenters[random.Next(roomCenters.Count)];

            roomCenters.Remove(startPoint);

            while (roomCenters.Count > 0)
            {
                var nextPoint = roomCenters[random.Next(roomCenters.Count)];
                roomCenters.Remove(nextPoint);
                cave       = CreatePath(cave, startPoint.X, startPoint.Y, nextPoint.X, nextPoint.Y);
                startPoint = nextPoint;
            }
            var map = new RogueSharp.Map(_width, _height);

            foreach (var cell in map.GetAllCells())
            {
                var open = cave[cell.X, cell.Y] == 0;
                map.SetCellProperties(cell.X, cell.Y, isTransparent: open, isWalkable: open, false);
            }

            return((T)(object)map);
        }
Exemple #7
0
    void inizializeLandscapeMatrix()
    {
        for (int j = 0; j < lenght; j++)
        {
            for (int i = 0; i < heights[j]; i++)
            {
                landscape[i + LAND_START_Y, j] = GROUND;
            }
        }
        for (int j = 0; j < lenght; j++)
        {
            for (int i = 0; i < caveDownHeights[j]; i++)
            {
                landscape[i, j] = GROUND;
            }
        }
        for (int j = 0; j < lenght; j++)
        {
            for (int i = 0; i < caveUpHeights[j]; i++)
            {
                landscape[CAVE_START_Y - i, j] = GROUND;
            }
        }
        CellularAutomata generator = new CellularAutomata();

        int[,] caveSystem = generator.getMatrix();
        for (int i = 0; i < LAND_START_Y - CAVE_START_Y; i++)
        {
            for (int j = 0; j < lenght; j++)
            {
                landscape[i + CAVE_START_Y, j] = caveSystem[i, j];
            }
        }
    }
        private void ImportBitmap_Click(object sender, RoutedEventArgs e)
        {
            RectangleCanvas.Visibility = Visibility.Hidden;
            currRange = new Range();
            currRange = InitStructures.InitCellularAutomata(properties);
            SetProperties();
            OpenFileDialog openfiledialog = new OpenFileDialog();

            openfiledialog.Title  = "Open Image";
            openfiledialog.Filter = "Image File|*.bmp; *.gif; *.jpg; *.jpeg; *.png;";

            if (openfiledialog.ShowDialog() == true)
            {
                Image.Source = Converters.BitmapToImageSource(new Bitmap(openfiledialog.FileName));
                currRange.StructureBitmap = new Bitmap(openfiledialog.FileName);

                CellularAutomata.UpdateGrainsArray(currRange);
                for (int i = 0; i < currRange.Width; i++)
                {
                    for (int j = 0; j < currRange.Height; j++)
                    {
                        currRange.StructureBitmap.SetPixel(i, j, currRange.GrainsArray[i, j].Color);
                    }
                }
            }

            dispatcher.Stop();
            Clear_Selected_Grains_Click(sender, e);
            SetEnableSubStrAndBoundCheckBoxs();
        }
Exemple #9
0
    private void GetRandomMap()
    {
        // Dont run another mesh if another render is still running
        renderDone = false;

        // Map dimensions
        width  = mapDimensions.width;
        height = mapDimensions.height;

        // ProcGen settings
        fillPercent     = proceduralGeneration.randomFill;
        resolution      = proceduralGeneration.resolution;
        smoothingPasses = proceduralGeneration.smoothing;
        seed            = proceduralGeneration.seed;
        useRandom       = proceduralGeneration.randomSeed;
        threadCount     = proceduralGeneration.threads;

        // Inversely proportional to resolution; same size but more complex meshes
        squareSize = 1 / (float)resolution;

        // Generates random 2d array of booleans
        randomMap = new CellularAutomata(fillPercent, resolution, smoothingPasses, width, height, seed, useRandom);
        map       = randomMap.GenerateMap();

        // Creates contoured mesh from bool array
        meshGenerator = new ThreadedContourMesh(RecieveMeshData, threadCount, map, squareSize, meshSettings.drawContours, meshSettings.drawSimple, meshSettings.uniqueVertcies);
        meshGenerator.StartThreads();
    }
 private void Clear_Content_Click(object sender, RoutedEventArgs e)
 {
     CellularAutomata.UpdateBitmap(boundaries.ClearBoundaries);
     currRange    = boundaries.ClearBoundaries;
     Image.Source = Converters.BitmapToImageSource(currRange.StructureBitmap);
     Clear_Selected_Grains_Click(sender, e);
 }
Exemple #11
0
        public void Apply(GeneratorParameter param, Tile[,] tiles)
        {
            if (param.forestSize <= 0f)
            {
                return;
            }

            float paramValue = 1 - param.forestSize;
            int   perc       = (int)(BLOCKING_PERC_MIN + (BLOCKING_PERC_MAX - BLOCKING_PERC_MIN) * paramValue);

            bool[,] automata = CellularAutomata.Generate(param.size, SMOOTH_ITERATIONS, perc, true, random.Next());

            for (int x = 0; x < param.size.X; x++)
            {
                for (int y = 0; y < param.size.Y; y++)
                {
                    Tile t = tiles[x, y];
                    if (!automata[x, y] && t.type == TileType.Nothing)
                    {
                        t.type       = TileType.Forest;
                        t.onTopIndex = param.tileset.GetRandomIndex(TileType.Forest, random);
                    }
                }
            }
        }
Exemple #12
0
    public void AddTile(Coordinates tileCoords)
    {
        try
        {
            if (mapData.cellMap[tileCoords.X, tileCoords.Y] == 1 || chunkTiles[tileCoords.X, tileCoords.Y] != null)
            {
                return;
            }
        }
        catch (System.Exception e)
        {
            Debug.LogError(e);
        }

        mapData.cellMap[tileCoords.X, tileCoords.Y] = 1;
        mapData.groundMap = CellularAutomata.GenerateGroundMap(mapData.cellMap);
        mapData.airMap    = CellularAutomata.GenerateCaveMap(mapData.cellMap);
        chunkTiles[tileCoords.X, tileCoords.Y] = CreateTile(tileCoords);
        if (gizmo)
        {
            debugGameObject.GetComponent <MeshRenderer>().material.mainTexture = TextureGenerator.GenerateTexture(mapData.cellMap, mapData.groundMap, mapData.airMap, mapData.waterMap);
        }
        Collider2D tempCollider = chunkTiles[tileCoords.X, tileCoords.Y].GetComponent <EdgeCollider2D>();

        if (tempCollider != null)
        {
            chunkTiles[tileCoords.X, tileCoords.Y].GetComponent <EdgeCollider2D>().enabled     = true;
            chunkTiles[tileCoords.X, tileCoords.Y].GetComponent <PlatformEffector2D>().enabled = true;
        }

        IterateTileToUpdate(tileCoords);
    }
Exemple #13
0
    public static Dictionary <GridPosition, MazeNode> Create(ECAVariant Variant, GridPosition Origin, int Width, int Height)
    {
        CellularAutomata Generator = new CellularAutomata(Variant, Origin, Width, Height);

        Generator.BuildMaze();

        return(Generator.m_NodeList);
    }
Exemple #14
0
 public static void Main(String[] args)
 {
     CellularAutomata automata = new CellularAutomata(this.size);
     automata.RandomSeed = this.LevelSeed;
     automata.InitializeMap();
     for (int i = 0; i < 6; i++)
         automata.DoStep();
 }
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.B))
     {
         CreatePlanet();
         CellularAutomata.IterateHexaSphere(ref hexaSphere, birth, death, iterationCount);
     }
 }
        private void CreateStones(GeneratorParameter param, Tile[,] tiles)
        {
            float[,] heatMap = CreateStoneHeatMap(param.size, tiles);

            List <Room> rooms = null;

            while (rooms == null || rooms.Count < MIN_RES_ROOMS)
            {
                int block = (int)(BLOCKING_PERC - BLOCKING_PERC_DELTA / 2 + ((1 - param.resourceSize) * BLOCKING_PERC_DELTA));

                bool[,] automata = CellularAutomata.Generate(param.size, SMOOTH_ITERATIONS, block, false, random.Next());

                for (int y = 0; y < param.size.Y; y++)
                {
                    for (int x = 0; x < param.size.X; x++)
                    {
                        if (automata[x, y] || heatMap[x, y] < 0.5f || !tiles[x, y].AllHeightsAreSame())
                        {
                            automata[x, y] = true;
                        }
                    }
                }

                rooms = GeneratorHelper.GetCellularAutomataAsRooms(automata);
            }

            rooms.Shuffle(random);

            int coalIndex = (int)(STONE_PERCENTAGE * rooms.Count);
            int oreIndex  = (int)((STONE_PERCENTAGE + COAL_PERCENTAGE) * rooms.Count);
            int oilIndex  = (int)((STONE_PERCENTAGE + COAL_PERCENTAGE + ORE_PERCENTAGE) * rooms.Count);

            for (int i = 0; i < rooms.Count; ++i)
            {
                TileType res = TileType.Stone;
                if (i >= oilIndex)
                {
                    res = TileType.Oil;
                }
                else if (i >= oreIndex)
                {
                    res = TileType.Ore;
                }
                else if (i >= coalIndex)
                {
                    res = TileType.Coal;
                }

                foreach (Point p in rooms[i].Tiles)
                {
                    if (tiles[p.X, p.Y].type == TileType.Nothing)
                    {
                        tiles[p.X, p.Y].type       = res;
                        tiles[p.X, p.Y].onTopIndex = param.tileset.GetRandomIndex(res);
                    }
                }
            }
        }
Exemple #17
0
	public static int[,] CreateCAMap(int mapSize, MapInfo mapInfo)
	{
		PseudoRandom rnd = mapInfo.GetSeededPsuedoRnd ();
		CellularAutomata ca = new CellularAutomata();
		int[,] start = ca.InitialiseMap (0.4f, mapSize, rnd);
		int[,] map = ca.CreateCellularAutomataFromMap (start, rnd);
		map = MapEdges.CreateSurrounding (map, mapInfo);
		return map; 
	}
 public override void ApplyModification(CellularAutomata automata)
 {
     if (_colours.Length == automata.Colours.Length)
     {
         _colours.CopyTo(automata.Colours, 0);
     }
     else
     {
         throw new ArgumentOutOfRangeException(nameof(_colours), _colours, "New colours array should have contained " + automata.Colours.Length + " colours");
     }
 }
 public override void ApplyModification(CellularAutomata automata)
 {
     if (_colourPosition < automata.Colours.Length)
     {
         automata.Colours[_colourPosition] = _colour;
     }
     else
     {
         throw new ArgumentOutOfRangeException(nameof(_colourPosition), _colourPosition, "Colour at position " + _colourPosition + " does not exist");
     }
 }
Exemple #20
0
    public void Setup(ViewData viewData)
    {
        if (ca != null)
        {
            return;
        }

        view = viewData;

        ca = new CellularAutomataDefault(view.width, view.height);

        mapWeights = new int[view.width, view.height];
    }
Exemple #21
0
        /// <summary>
        /// initialize the Cellular Automata
        /// </summary>
        private void InitiateCellularAutomata()
        {
            _CellularAutomata = new List <CellularAutomata <LangtonsAnt> >();

            for (short z = 0; z < NumberOfGrids; z++)
            {
                CellularAutomata <LangtonsAnt> _CA
                    = new CellularAutomata <LangtonsAnt>(new CircularArray2D <bool>(CellValues[z]));
                _CellularAutomata.Add(_CA);
            }

            CurrentColumn = 0;
        }
    /// <summary>
    /// Generates the DungeonLevel and writes it to the map 2d array
    /// </summary>
    private void GenerateDungeon()
    {
        DungeonMst    dungeonMst    = new DungeonMst();
        RoomGenerator roomGenerator = new RoomGenerator();

        rooms = roomGenerator.GenerateRooms(
            DungeonLevel.InitialRoomDensity,
            DungeonLevel.Width,
            DungeonLevel.Height,
            new Vector2Int(DungeonLevel.MinRoomHeight, DungeonLevel.MaxRoomHeight),
            new Vector2Int(DungeonLevel.MinRoomWidth, DungeonLevel.MaxRoomWidth)
            );
        links = dungeonMst.GetDungeonMap(rooms.Keys.ToList(), DungeonLevel.RoomConnectedness);
        LinksIntoHallways();
        dungeonExits = dungeonMst.dungeonExits;

        // Adds hubs
        foreach (var room in rooms.Values)
        {
            WriteRoomToMap(room);
        }

        foreach (var edge in hallways)
        {
            WriteEdgeToMap(edge);
        }

        CellularAutomata          caveGen   = new CellularAutomata(DungeonLevel);
        List <List <Vector2Int> > caveRooms = caveGen.Generate();

        foreach (var caveRoom in caveRooms)
        {
            foreach (var tile in caveRoom)
            {
                map[tile.x, tile.y] = Tiles.caveTile;
            }
        }

        // Place the physical objects into the world
        PlaceExits();
        AddFloorsAndWalls();
        PlaceDoors();
        foreach (WeightedGeneratedStructure type in DungeonLevel.generatedStructures)
        {
            PlaceGeneratedStructures(type.structure, type.amountPerLevel);
        }
        PlaceObjects(PlaceChest, DungeonLevel.ChestsPerLevel);
        PlaceObjects(PlaceDecorObjects, DungeonLevel.FreeStandingDecorationCount);
        PlaceObjects(PlaceEnemy, DungeonLevel.EnemiesPerLevel);
        PlaceObjects(PlaceDestrucibleObjects, DungeonLevel.DestructibleObjectCount);
    }
        private void Previous_Structure_Button_Click(object sender, RoutedEventArgs e)
        {
            prevRange = new Range();
            prevRange = InitStructures.InitCellularAutomata(properties);

            CellularAutomata.UpdateBitmap(currRange);

            prevRange.StructureBitmap = currRange.StructureBitmap;
            CellularAutomata.UpdateGrainsArray(prevRange);
            CellularAutomata.UpdateBitmap(prevRange);
            prevRange = nucleons.EnergyDistributor(currRange, nucleons);

            CellularAutomata.UpdateBitmap(currRange);
            Image.Source = Converters.BitmapToImageSource(currRange.StructureBitmap);
        }
        private void Energy_Vizualization_Button_Click(object sender, RoutedEventArgs e)
        {
            currRange = new Range();
            currRange = InitStructures.InitCellularAutomata(properties);

            CellularAutomata.UpdateBitmap(prevRange);

            currRange.StructureBitmap = prevRange.StructureBitmap;
            CellularAutomata.UpdateGrainsArray(currRange);
            CellularAutomata.UpdateBitmap(currRange);
            nucleons.EnergyDistributor(prevRange, nucleons);
            nucleons.EnergyVisualization(ref prevRange, nucleons);
            CellularAutomata.UpdateBitmap(prevRange);
            Image.Source = Converters.BitmapToImageSource(prevRange.StructureBitmap);
        }
    // Start is called before the first frame update
    void Start()
    {
        cellsWithin      = GameObject.Find("Space"); //The "Space" object has a "Volume" component and a "CellularAutomata" component
        cellularAutomata = cellsWithin.GetComponent <CellularAutomata>();

        for (int i = 0; i < 150; i++)
        {
            //Lets spawn a bunch of random cells in a 23x23x23 volume.
            var randX = Random.RandomRange(0, 23);
            var randY = Random.RandomRange(0, 23);
            var randZ = Random.RandomRange(0, 23);
            AddCell(new Vector3(randX, randY, randZ));
        }
        return;
    }
    // Use this for initialization
    void Start()
    {
        //Service locator needs to know about this object.
        ServiceLocator.Provide(this);

        tree = new Quadtree(new Rect(0, 0, Width, Height));
        generator = new CellularAutomata(Width, Height);
        GenerateLevel();

        if (DEBUGCAMERA)
        {
            Camera.main.gameObject.SetActive(false);

            GameObject.Instantiate(DebugCamera, new Vector3(0, 1, -10), transform.rotation);
        }
    }
Exemple #27
0
    public void EvaluateFitness()
    {
        //DebugLogPopulation();

        //testPop = new List<Chromossome>();

        /**
         * for (int i = 0; i < population.Count; i++)
         * {
         *  testPop.Add(population[i]);
         * }
         * /**/

        for (int i = 0; i < population.Count; i++)
        {
            float       __tempFitness     = 0;
            Chromossome __tempChromossome = population[i];
            int[][]     __simulatedMap    = CellularAutomata.SimulateMap(__tempChromossome.GetMap(), 5);
            __simulatedMap = CellularAutomata.FillExclaves(__simulatedMap); //by doing this we end up having only the largest cave area

            //first we calculate the fitness from Fill Ratio
            float __fill = CellularAutomata.GetFilledPercentage(__simulatedMap);
            __tempFitness += (1 - (Mathf.Abs(fillTarget - __fill))) * fitnessBaseValue;

            //now we calculate the fitness based on points
            for (int j = 0; j < fitnessPoints.Length; j++)
            {
                if (__simulatedMap[(int)fitnessPoints[j].y][(int)fitnessPoints[j].x] == 0)
                {
                    __tempFitness += fitnessBaseValue * fitnessPointsWeight;
                }
            }

            __tempChromossome.fitness = __tempFitness;

            population[i] = __tempChromossome;
        }

        /**
         * for (int i = 0; i < population.Count; i++)
         * {
         *  Debug.Log(testPop[i] == population[i]);
         * }
         * /**/

        //DebugLogPopulation();
    }
Exemple #28
0
    public static void printMap(CellularAutomata automata) 
    {
    #if UNITY
        int maxX = automata.size.x, maxY = automata.size.y;
#else
        int maxX = automata.length, maxY = automata.width;
#endif
        for (int x = 0; x < maxX; x++) 
        {
            for (int y = 0; y < maxY - 1; y++) 
            {
                Console.Write(Convert.ToString(automata.map[x,y]) + ", ");
            }
            Console.WriteLine(Convert.ToString(automata.map[x, maxY - 1]));
        }
        Console.WriteLine();
    }
Exemple #29
0
    private void Start()
    {
        //The "Space" object has a "Volume" component and a "CellularAutomata" component
        _cellsWithin      = GameObject.Find("Space");
        _cellularAutomata = _cellsWithin.GetComponent <CellularAutomata>();

        System.Random rand = new System.Random();

        for (int i = 0; i < 150; i++)
        {
            // Spawns a bunch of random cells in a 23x23x23 volume.
            int randX = rand.Next(0, 23);
            int randY = rand.Next(0, 23);
            int randZ = rand.Next(0, 23);
            AddCell(new Vector3(randX, randY, randZ));
        }
    }
Exemple #30
0
    public void RemoveTile(Tile tile)
    {
        Coordinates tileCoords = tile.Coords;

        chunkTiles[tileCoords.X, tileCoords.Y]      = null;
        mapData.cellMap[tileCoords.X, tileCoords.Y] = 0;
        mapData.groundMap = CellularAutomata.GenerateGroundMap(mapData.cellMap);
        mapData.airMap    = CellularAutomata.GenerateCaveMap(mapData.cellMap);
        if (gizmo)
        {
            debugGameObject.GetComponent <MeshRenderer>().material.mainTexture = TextureGenerator.GenerateTexture(mapData.cellMap, mapData.groundMap, mapData.airMap, mapData.waterMap);
        }
        chunkColliders.Remove(tile.gameObject.GetComponent <EdgeCollider2D>());
        GameObject.Destroy(tile.gameObject);

        IterateTileToUpdate(tileCoords);
    }
 private void AddInclusionsButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         SetProperties();
         currRange.IsFull = true;
         if (inclusions.IsEnable && (inclusions.CreationTime == InclusionsCreationTime.After))
         {
             CellularAutomata.UpdateGrainsArray(currRange);
             currRange = inclusions.AddInclusionsAfter(currRange);
             CellularAutomata.UpdateBitmap(currRange);
             prevRange    = currRange;
             Image.Source = Converters.BitmapToImageSource(currRange.StructureBitmap);
         }
     }
     catch (Exception) { }
 }
Exemple #32
0
    void Start()
    {
        bool[,] map = CellularAutomata.Generate(cellularAutomataArgs);
        Tilemap tilemap = FindObjectOfType <Tilemap>();

        for (int x = 0; x < map.GetLength(0); x++)
        {
            for (int y = 0; y < map.GetLength(1); y++)
            {
                if (map[x, y])
                {
                    Vector2Int pos = new Vector2Int(
                        x - cellularAutomataArgs.width / 2,
                        y - cellularAutomataArgs.height / 2);
                    tilemap.Instantiate(floorTile, pos);
                }
            }
        }
    }
Exemple #33
0
	void CreateCAMap()
	{
		PseudoRandom rnd = new PseudoRandom(seedX, seedY, seedZ); 
		CellularAutomata ca = new CellularAutomata();
		int[,] start = ca.InitialiseMap (0.4f, mapSize, rnd);
		map = ca.CreateCellularAutomataFromMap (start, rnd);
		map = MapEdges.CreateSurrounding (map, seedX, seedY, seedZ);
		CreateMap (map);
		toggle = true; 
	}
Exemple #34
0
	void CreateGraphCAMap()
	{
		Graph grph = Graph.CreateGraphMaxSize(1000, 40);
		DisplayGraph (grph);


		PseudoRandom rnd = new PseudoRandom(seedX, seedY, seedZ); 
		CellularAutomata ca = new CellularAutomata();
		GraphGenCA grCa = new GraphGenCA (grph, rnd, 0.385f);
		int[,] start = grCa.CreateInitalMapFromGraph (grph, 16, 4);
		map = ca.CreateBasicCellularAutomataFromMap (start, rnd);


		mainCam.transform.position = new Vector3 ((map.GetLength(1)+3)/2, (map.GetLength(0)+3)/2, -10 );
		mainCam.orthographicSize = 90f;
		CreateMap (map);
		toggle = true; 
	}