Ejemplo n.º 1
0
        public void importSeedGrowthData()
        {
            string filePath = _view.getImportFilePath();

            if (filePath != null)
            {
                IFormatter formatter = new BinaryFormatter();
                try
                {
                    Stream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);

                    var data   = formatter.Deserialize(stream) as SeedGrowthDo;
                    var width  = data.seeds.GetLength(0);
                    var height = data.seeds.GetLength(1);

                    _seedGrowth = SeedGrowthFactory.Create(width, height, _neighbourhoodType, _boundoryConditionType);
                    _seedGrowth.setSeeds(data.seeds);
                    _seedGrowth.setGrainMap(data.grainMap);
                    if (isGBCType)
                    {
                        _seedGrowth.useGBC(true);
                        _seedGrowth._activationThreshold = _activationThreshold;
                    }
                    _seedGrowth.OnGrainChange += _seedGrowth_OnIterationComplette;
                    _seedGrowth.init();
                }
                catch (Exception ex)
                {
                    _view.showExceptionMessage(ex.Message);
                }
            }
        }
Ejemplo n.º 2
0
    private void GenerateProcedualLevel()
    {
        if (useGraphicAsBase)
        {
            elevationMap = ProcessBaseGraphicIntoArray();
            moistureMap  = ProcessBaseGraphicIntoArray();
            float[] perlinElevation = PerlinMapGenerator.GeneratePerlinMap(mapDimensions.width, mapDimensions.height, elevationSettings, false);
            float[] perlinMoisture  = PerlinMapGenerator.GeneratePerlinMap(mapDimensions.width, mapDimensions.height, moistureSettings, false);
            elevationMap = Utility.AddSameLengthArrays(elevationMap, perlinElevation, perlinWeightOnBaseGrafic);
            elevationMap = Utility.ClampPerlinValues(elevationMap);
            moistureMap  = Utility.AddSameLengthArrays(moistureMap, perlinMoisture, perlinWeightOnBaseGrafic);
            moistureMap  = Utility.ClampPerlinValues(moistureMap);
        }
        else
        {
            elevationMap = PerlinMapGenerator.GeneratePerlinMap(mapDimensions.width, mapDimensions.height, elevationSettings);
            moistureMap  = PerlinMapGenerator.GeneratePerlinMap(mapDimensions.width, mapDimensions.height, moistureSettings);
        }
        terrainMap = CombinePerlinMaps();

        terrainMap = SeedGrowth.PopulateGrid(terrainMap, forestParam, mapDimensions);
        terrainMap = SeedGrowth.PopulateGrid(terrainMap, citiesParam, mapDimensions);

        terrainMap = RoadGenerator.GenerateRoads(terrainMap, riversParam);
        terrainMap = RoadGenerator.GenerateRoads(terrainMap, roadParam);

        InitializePerlinMap();
    }
Ejemplo n.º 3
0
        public static SeedGrowth Create(int domainWidth, int domainHeight, Neighbourhood neighbourhoodType, BoundaryConditions boundaryConditionsType)
        {
            SeedGrowth sd = new SeedGrowth(domainWidth, domainHeight);

            sd.setNeighbourhoodType(getNeigbhourhoodType(neighbourhoodType, boundaryConditionsType));
            return(sd);
        }
Ejemplo n.º 4
0
 void CheckForClick()
 {
     if (Input.GetButtonDown("Fire1"))
     {
         //Check if a UI button was clicked on
         Vector2      clickPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         RaycastHit2D hit           = Physics2D.Raycast(new Vector2(clickPosition.x, clickPosition.y), Vector2.zero, 0);
         Ray          ray           = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (InventoryManager.instance.PlantableSelected() && World.instance.GetTileAt(Mathf.FloorToInt(clickPosition.x), Mathf.FloorToInt(clickPosition.y)).type == Tile.Type.Till)
         {
             InventoryManager.instance.ReduceSelectedItem();
             SeedGrowth seed = Instantiate(basicSeed, new Vector2(Mathf.FloorToInt(clickPosition.x) + 0.5f, Mathf.FloorToInt(clickPosition.y) + 0.5f), Quaternion.identity);
             seed.setPlanted();
         }
         if (!hit && PlayerMovement.instance.InPlayerReach(clickPosition))
         {
             if (Equipment.instance.handheld != null)
             {
                 WorldChangeClick(Mathf.FloorToInt(clickPosition.x), Mathf.FloorToInt(clickPosition.y), Equipment.instance.handheld.getClickType());
             }
             WorldChangeClick(Mathf.FloorToInt(clickPosition.x), Mathf.FloorToInt(clickPosition.y), WorldClickType.Break);
         }
         else if (Equipment.instance.handheld != null && Equipment.instance.handheld.getClickType() == WorldClickType.Chop && hit && PlayerMovement.instance.InPlayerReach(clickPosition) && hit.transform.gameObject.CompareTag("Tree"))
         {
             TreeBreak hitTree = hit.transform.gameObject.GetComponent <TreeBreak>();
             hitTree.SpawnWood();
         }
     }
 }
Ejemplo n.º 5
0
 public void OnSeedBreak(int x, int y, SeedGrowth prefab)
 {
     if (Random.Range(-1, 5) == 2)
     {
         Instantiate(prefab, new Vector3(x + 0.5f, y + 0.5f), Quaternion.identity);
     }
 }
Ejemplo n.º 6
0
 public void initializeDomain()
 {
     _seedGrowth = SeedGrowthFactory.Create(_width, _height, _neighbourhoodType, _boundoryConditionType);
     setInitialSeeds();
     if (_numberOfInclusions != 0)
     {
         _seedGrowth.setInclusions(_numberOfInclusions, _inclusionMinRadius, _inclusionMaxRadius);
     }
     if (isGBCType)
     {
         _seedGrowth.useGBC(true);
         _seedGrowth._activationThreshold = _activationThreshold;
     }
     _seedGrowth.OnGrainChange += _seedGrowth_OnIterationComplette;
     _seedGrowth.init();
 }
Ejemplo n.º 7
0
    public void plantSeed(seedTypes type)
    {
        bool haveSeeds = false;

        switch (type)
        {
        case seedTypes.hogweed:
            if (hogweedSeeds > 0)
            {
                haveSeeds = true;
                hogweedSeeds--;
            }
            break;

        case seedTypes.potato:
            if (potatoSeeds > 0)
            {
                haveSeeds = true;
                potatoSeeds--;
            }
            break;

        case seedTypes.cherry:
            if (cherrySeeds > 0)
            {
                haveSeeds = true;
                cherrySeeds--;
            }
            break;
        }

        if (haveSeeds)
        {
            Vector3    newLocation = transform.position + new Vector3(0, -.5f, 0);
            SeedGrowth sg          = Instantiate(growthPrefab, newLocation, Quaternion.identity).GetComponent <SeedGrowth>();
            sg.seedType = type;
        }
    }