Posted by Epitaph64 on Sun 31 May 02:33
report abuse | download | new post
- private void generateLand()
- {
- for (int x = 0; x < 100; x++)
- {
- for (int y = 0; y < 100; y++)
- {
- terrain[x][y] = 1;
- terrainDone[x][y] = 0;
- }
- }
- int amountOfSeeds = mt.nextInt(3)+1;
- for (int i = 0; i < amountOfSeeds; i++)
- {
- int sX = mt.nextInt(50)+25;
- int sY = mt.nextInt(50)+25;
- int amount = mt.nextInt(50)+100;
- growWater(sX, sY, amount);
- }
- for (int i = 0; i < mt.nextInt(50)+10; i++)
- {
- int LX = mt.nextInt(100);
- int LY = mt.nextInt(100);
- if (terrain[LX][LY] != 0)
- {
- growLand(LX, LY, mt.nextInt(500)+100);
- }
- }
- for (int x = 0; x < 100; x++)
- {
- for (int y = 0; y < 100; y++)
- {
- if (terrain[x][y] <= 0)
- {
- terrain[x][y] = 0;
- }
- else
- {
- if (terrain[x][y] < 5)
- {
- terrain[x][y] += mt.nextInt(5);
- }
- else
- {
- terrain[x][y] /= 5;
- }
- }
- }
- }
- for (int i = 0; i < 3; i++)
- {
- for (int x = 0; x < 100; x++)
- {
- for (int y = 0; y < 100; y++)
- {
- if (terrain[x][y] > 0)
- {
- int ticks = 0;
- float amount = 0;
- if (x + 1 < 100)
- {
- ticks ++;
- amount += terrain[x+1][y];
- }
- if (y + 1 < 100)
- {
- ticks ++;
- amount += terrain[x][y+1];
- }
- if (x + 1 < 100 && y + 1 < 100)
- {
- ticks ++;
- amount += terrain[x+1][y+1];
- }
- if (x - 1 >= 0)
- {
- ticks ++;
- amount += terrain[x-1][y];
- }
- if (y - 1 >= 0)
- {
- ticks ++;
- amount += terrain[x][y-1];
- }
- if (x - 1 >= 0 && y - 1 >= 0)
- {
- ticks ++;
- amount += terrain[x-1][y-1];
- }
- if (x - 1 >= 0 && y + 1 < 100)
- {
- ticks ++;
- amount += terrain[x-1][y+1];
- }
- if (x + 1 < 100 && y - 1 >= 0)
- {
- ticks ++;
- amount += terrain[x+1][y-1];
- }
- }
- }
- }
- }
- for (int i = 0; i < 4; i++)
- {
- for (int x = 0; x < 100; x++)
- {
- for (int y = 0; y < 100; y++)
- {
- if (terrain[x][y] > 0)
- {
- int ticks = 0;
- if (x + 1 < 100)
- {
- if (terrain[x+1][y] == 0)
- {
- ticks ++;
- }
- }
- if (y + 1 < 100)
- {
- if (terrain[x][y+1] == 0)
- {
- ticks ++;
- }
- }
- if (x + 1 < 100 && y + 1 < 100)
- {
- if (terrain[x+1][y+1] == 0)
- {
- ticks ++;
- }
- }
- if (x - 1 >= 0)
- {
- if (terrain[x-1][y] == 0)
- {
- ticks ++;
- }
- }
- if (y - 1 >= 0)
- {
- if (terrain[x][y-1] == 0)
- {
- ticks ++;
- }
- }
- if (x - 1 >= 0 && y - 1 >= 0)
- {
- if (terrain[x-1][y-1] == 0)
- {
- ticks ++;
- }
- }
- if (x - 1 >= 0 && y + 1 < 100)
- {
- if (terrain[x-1][y+1] == 0)
- {
- ticks ++;
- }
- }
- if (x + 1 < 100 && y - 1 >= 0)
- {
- if (terrain[x+1][y-1] == 0)
- {
- ticks ++;
- }
- }
- if (ticks > 4)
- {
- terrain[x][y] = 0;
- }
- }
- }
- }
- }
- for (int i = 0; i < 4; i++)
- {
- for (int x = 0; x < 100; x++)
- {
- for (int y = 0; y < 100; y++)
- {
- if (terrain[x][y] == 0)
- {
- int ticks = 0;
- if (x + 1 < 100)
- {
- if (terrain[x+1][y] > 0)
- {
- ticks ++;
- }
- }
- if (y + 1 < 100)
- {
- if (terrain[x][y+1] > 0)
- {
- ticks ++;
- }
- }
- if (x + 1 < 100 && y + 1 < 100)
- {
- if (terrain[x+1][y+1] > 0)
- {
- ticks ++;
- }
- }
- if (x - 1 >= 0)
- {
- if (terrain[x-1][y] > 0)
- {
- ticks ++;
- }
- }
- if (y - 1 >= 0)
- {
- if (terrain[x][y-1] > 0)
- {
- ticks ++;
- }
- }
- if (x - 1 >= 0 && y - 1 >= 0)
- {
- if (terrain[x-1][y-1] > 0)
- {
- ticks ++;
- }
- }
- if (x - 1 >= 0 && y + 1 < 100)
- {
- if (terrain[x-1][y+1] > 0)
- {
- ticks ++;
- }
- }
- if (x + 1 < 100 && y - 1 >= 0)
- {
- if (terrain[x+1][y-1] > 0)
- {
- ticks ++;
- }
- }
- if (ticks > 4)
- {
- terrain[x][y] = 1;
- }
- }
- }
- }
- }
- for (int x = 0; x < 100; x++)
- {
- for (int y = 0; y < 100; y++)
- {
- if (terrain[x][y] > 0)
- {
- terrain[x][y] += mt.nextInt(10);
- }
- }
- }
- }
- private void growWater(int x, int y, int amount)
- {
- if (amount > 0 && terrain[x][y] == 1)
- {
- terrain[x][y] = 0;
- boolean up = false;
- boolean down = false;
- boolean left = false;
- boolean right = false;
- if (y - 1 >= 0 && mt.nextInt(100) > 50)
- {
- if (terrain[x][y-1] == 1)
- {
- up = true;
- }
- }
- if (x + 1 < 100 && mt.nextInt(100) > 50)
- {
- if (terrain[x+1][y] == 1)
- {
- right = true;
- }
- }
- if (y + 1 < 100 && mt.nextInt(100) > 50)
- {
- if (terrain[x][y+1] == 1)
- {
- down = true;
- }
- }
- if (x - 1 >= 0 && mt.nextInt(100) > 50)
- {
- if (terrain[x-1][y] == 1)
- {
- left = true;
- }
- }
- int directionAmount = 0;
- if (up) directionAmount ++;
- if (right) directionAmount ++;
- if (down) directionAmount ++;
- if (left) directionAmount ++;
- if (amount - directionAmount >= 0)
- {
- if (up)
- {
- growWater(x, y-1, amount - 1);
- }
- if (right)
- {
- growWater(x+1, y, amount - 1);
- }
- if (down)
- {
- growWater(x, y+1, amount - 1);
- }
- if (left)
- {
- growWater(x-1, y, amount - 1);
- }
- }
- }
- }
- private void growLand(int x, int y, int height)
- {
- if (terrainDone[x][y] < 1)
- {
- terrain[x][y] = height;
- terrainDone[x][y] ++;
- if (mt.nextBoolean())
- {
- if (y - 1 >= 0 && height - 1 > 0)
- {
- if (terrain[x][y-1] > 0)
- {
- growLand(x, y - 1, height - 1);
- }
- }
- }
- else
- {
- if (y + 1 < 100 && height - 1 > 0)
- {
- if (terrain[x][y+1] > 0)
- {
- growLand(x, y + 1, height - 1);
- }
- }
- }
- if (mt.nextBoolean())
- {
- if (x + 1 < 100 && height - 1 > 0)
- {
- if (terrain[x+1][y] > 0)
- {
- growLand(x + 1, y, height - 1);
- }
- }
- }
- else
- {
- if (x - 1 >= 0 && height - 1 > 0)
- {
- if (terrain[x-1][y] > 0)
- {
- growLand(x - 1, y, height - 1);
- }
- }
- }
- }
- }
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.