|
@@ -10,47 +10,73 @@ public class TileMapGenerator
|
|
|
static
|
|
|
{
|
|
|
GRASS_MAP.put(0, Tiles.GRASS);
|
|
|
- GRASS_MAP.put(70, Tiles.GRASS_WITH_STONE);
|
|
|
- GRASS_MAP.put(75, Tiles.GRASS_WITH_6_BUSHES);
|
|
|
- GRASS_MAP.put(80, Tiles.GRASS_WITH_3_BUSHES);
|
|
|
- GRASS_MAP.put(85, Tiles.GRASS_WITH_FLOWERS);
|
|
|
- GRASS_MAP.put(90, Tiles.GRASS_WITH_HILL);
|
|
|
- GRASS_MAP.put(95, Tiles.GRASS_WITH_EARTH);
|
|
|
+ GRASS_MAP.put(76, Tiles.GRASS_WITH_STONE);
|
|
|
+ GRASS_MAP.put(80, Tiles.GRASS_WITH_6_BUSHES);
|
|
|
+ GRASS_MAP.put(84, Tiles.GRASS_WITH_3_BUSHES);
|
|
|
+ GRASS_MAP.put(88, Tiles.GRASS_WITH_FLOWERS);
|
|
|
+ GRASS_MAP.put(92, Tiles.GRASS_WITH_HILL);
|
|
|
+ GRASS_MAP.put(96, Tiles.GRASS_WITH_EARTH);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ private static long seed = 1;
|
|
|
+
|
|
|
+
|
|
|
+ *
|
|
|
+ * @param width the width of the map
|
|
|
+ * @param height the height of the map
|
|
|
+ * @return a random generated map
|
|
|
+ */
|
|
|
+ public static TileMap getMap(int width, int height)
|
|
|
+ {
|
|
|
+ return getMap(width, height, seed++);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
*
|
|
|
* @param width the width of the map
|
|
|
* @param height the height of the map
|
|
|
- * @return a random test map
|
|
|
+ * @param seed the seed for the random number generator
|
|
|
+ * @return a random generated map
|
|
|
*/
|
|
|
public static TileMap getMap(int width, int height, long seed)
|
|
|
{
|
|
|
Random r = new Random(seed);
|
|
|
|
|
|
- HighMap highMap = HighMap.generate(seed, width, height, Math.min(width, height) * 0.125f);
|
|
|
+ HighMap highMap = HighMap.generate(seed, width, height);
|
|
|
|
|
|
TileMap map = new TileMap(width, height);
|
|
|
for(int x = 0; x < width; x++)
|
|
|
{
|
|
|
for(int y = 0; y < height; y++)
|
|
|
{
|
|
|
- switch((int) (highMap.get(x, y) * 5))
|
|
|
+ if(highMap.get(x, y) < 0.15f)
|
|
|
+ {
|
|
|
+ map.setTile(x, y, Tiles.DEEP_WATER);
|
|
|
+ }
|
|
|
+ else if(highMap.get(x, y) < 0.3f)
|
|
|
+ {
|
|
|
+ map.setTile(x, y, Tiles.SHALLOW_WATER);
|
|
|
+ }
|
|
|
+ else if(highMap.get(x, y) < 0.7f)
|
|
|
{
|
|
|
- case 0: map.setTile(x, y, Tiles.DEEP_WATER); break;
|
|
|
- case 1: map.setTile(x, y, Tiles.SHALLOW_WATER); break;
|
|
|
- case 2: map.setTile(x, y, randomGrass(r)); break;
|
|
|
- case 3: map.setTile(x, y, Tiles.HILL); break;
|
|
|
- case 4: map.setTile(x, y, Tiles.MOUNTAIN); break;
|
|
|
+ map.setTile(x, y, randomGrass(r));
|
|
|
+ }
|
|
|
+ else if(highMap.get(x, y) < 0.85f)
|
|
|
+ {
|
|
|
+ map.setTile(x, y, Tiles.HILL);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ map.setTile(x, y, Tiles.MOUNTAIN);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- int forestSize = ((width + height) / 2) / 5;
|
|
|
+ int forestSize = ((width + height) / 2) / 10;
|
|
|
forestSize *= forestSize;
|
|
|
|
|
|
- generateForest(map, r, forestSize, 10, 1);
|
|
|
+ generateForest(map, r, forestSize, 10, 2, Tiles.FOREST);
|
|
|
+ generateForest(map, r, forestSize, 5, 2, Tiles.SWAMP);
|
|
|
return map;
|
|
|
}
|
|
|
|
|
@@ -59,7 +85,7 @@ public class TileMapGenerator
|
|
|
return GRASS_MAP.floorEntry(r.nextInt(100)).getValue();
|
|
|
}
|
|
|
|
|
|
- private static void generateForest(TileMap map, Random r, int depth, int placements, int jumpRadius)
|
|
|
+ private static void generateForest(TileMap map, Random r, int depth, int placements, int jumpRadius, Tile t)
|
|
|
{
|
|
|
for(int i = 0; i < placements; i++)
|
|
|
{
|
|
@@ -83,7 +109,11 @@ public class TileMapGenerator
|
|
|
|
|
|
if(r.nextFloat() < map.getTile(x, y).getForestReplaceChance())
|
|
|
{
|
|
|
- map.setTile(x, y, Tiles.FOREST);
|
|
|
+ map.setTile(x, y, t);
|
|
|
+ placeForest(map, r, x - 1, y, t);
|
|
|
+ placeForest(map, r, x + 1, y, t);
|
|
|
+ placeForest(map, r, x, y - 1, t);
|
|
|
+ placeForest(map, r, x, y + 1, t);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -93,4 +123,15 @@ public class TileMapGenerator
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private static void placeForest(TileMap map, Random r, int x, int y, Tile t)
|
|
|
+ {
|
|
|
+ if(x >= 0 && x < map.getWidth() && y >= 0 && y < map.getHeight())
|
|
|
+ {
|
|
|
+ if(r.nextFloat() * 2 < map.getTile(x, y).getForestReplaceChance())
|
|
|
+ {
|
|
|
+ map.setTile(x, y, t);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|