public IEnumerator GenerateTiles() { int i = 0; for (int x = 0; x < world.Border_X; x++) { for (int y = 0; y < world.Border_Y; y++) { Ground_tile gt = world.map[x, y]; if (gt.type == ground_type.world_grass) { continue; } tile_typ2e type = GetType(x, y, gt.type); SelectTileSprite(type, gt.type, gt.pos); i++; if (i % 10 == 0) { yield return(new WaitForSeconds(Time.deltaTime)); } } } yield return(null); }
public Ground_tile ChanceChoose(int _x, int _y, Vector2 worldPos) { int chance = 80; Ground_tile ret = new Ground_tile(worldPos, _x, _y); for (int x = -2; x < 1; x++) { for (int y = -2; y < 1; y++) { if (x == 0 && y == 0) { continue; } int xt = _x + x; int yt = _y + y; xt = Mathf.Clamp(xt, 0, world.Border_X - 1); yt = Mathf.Clamp(yt, 0, world.Border_Y - 1); ground_type temp = (world.map[xt, yt] != null) ? world.map[xt, yt].type: ground_type.world_grass; if (temp == ground_type.world_grass) { continue; } int chance_t = random_int(0, 100); if (chance_t > chance) { chance = chance_t; ret.type = temp; } } } if (ret.type != ground_type.world_grass) { return(ret); } chance = random_int(0, 100); if (chance < ChanceWood) { ret.type = ground_type.wood; //ret.sprite = wood[random_int(0, wood.Length)]; //ret.type = ground_type.wood; } else if (chance < ChanceBlocks + ChanceWood) { ret.type = ground_type.blocks; //ret.type = ground_type.blocks; //ret.sprite = blocks[random_int(0, blocks.Length)]; } else if (chance < ChanceBlocks + ChanceWood + ChanceSand) { ret.type = ground_type.sand; //ret.type = ground_type.grass_s; //ret.sprite = grass_Special[random_int(0, grass_Special.Length)]; } return(ret); }
public IEnumerator GenerateWorld() { int i = 0; yield return(DeleteOld(trees_t)); yield return(DeleteOld(plants_t)); yield return(DeleteOld(ground)); int xm = 0; int ym = 0; for (int x = -x_zero; xm < Border_Y; x += pixels * (int)scale, xm++) { for (int y = -y_zero; ym < Border_Y; y += pixels * (int)scale, ym++) { Ground_tile get = self.ChanceChoose(xm, ym, new Vector2(x, y)); //if (get == ground_type.world_grass) //{ // self.GeneratePlants(x, y); // continue; //} //self.CreateTexture(x, y, get.sprite, get.type); //Debug.Log(" / x / " + xm + " / y / " + ym + " // ; // / x / " // + (x + x_zero)/pixels + " / y / " + (y + y_zero)/pixels); map[xm, ym] = get; i++; if (i > 500) { yield return(new WaitForSeconds(Time.deltaTime)); i = 0; } } ym = 0; } yield return(self.GenerateTiles()); self.CreatedEveryTHing = true; CreateWorld.Fully_loaded = true; }