-2

I'm creating an island for my game and i have a map middle point where its land and all other is water. How to make a chance calculator for the tile to be land (if close to center 100% chance and lowering the further it's from it)?

so far what I only can do for one side of map:

float centerx=r.mapsize/2*r.tilesize, centery=centerx;
    if(position.x<centerx&&position.y<centery){
        float distancex = centerx-position.x, distancey = centerx-position.y;
        boolean chancex = rr.nextInt((int)distancex)/5==0; boolean chancey=rr.nextInt((int)distancey)/5==0;
        if(chancex&&chancey){sprite=AssetLoader.grass;}
    }

enter image description here

But it doent look like an island side. Its like tiles exploded from the center.

  • There seems to be a problem with the different segments of your map (because of that `if` check), but even with that the "island" will consist of many many small specks of land. – tobias_k Dec 21 '14 at 20:41
  • use `distancex = Math.abs(centerx - position.x);`, same for y, and get rid of `if (positionx < centerx && ...` – ryanpattison Dec 21 '14 at 20:49
  • 1
    Place one land tile in the center of the map. The odds are 100% close to the center and decrease as you get further away **if and only if** there's a land tile as one of your 8 neighbors. The odds increase the more land neighbors you have. – Gilbert Le Blanc Dec 21 '14 at 21:34

1 Answers1

0

To get your approach to work for all quadrants, you should probably ensure that distanceX and distanceY are never negative, for instance with Math.abs(centerx - positionX).

To get a smoother, more realistic looking terrain, you should choose another algorithm, see http://en.wikipedia.org/wiki/Scenery_generator for common choices.

BTW, questions specific to game design may receive a better reception over at https://gamedev.stackexchange.com/, though they, too, generally expect a bit more research on your part.

Community
  • 1
  • 1
meriton
  • 68,356
  • 14
  • 108
  • 175