我是 map 创建和数组存储的新手,想知道是否可以在任务中获得一些帮助。我正在使用 Java 工作并使用 LWJGL 库(如果这有任何帮助的话)。
我并不是想抄袭任何其他游戏,所以它会与其他游戏有所不同。我基本上只需要不同的区域,比如水、草和泥土。我最终会添加山脉和丘陵以及攀岩等。
我需要知道如何实现这一点,如果可以的话,就像我说的那样,我对它很陌生,所以我没有任何代码可以让您了解我所处的级别。
如果您能提供帮助,请留下答案,我也希望得到尽可能多的帮助。
最佳答案
它的渲染方式(openGL、swing/awt、其他)与 map 本身无关。这就是它的渲染方式。我使用了我编写的一个特殊的 CooperativeMap 类,但它基本上只不过是 Map<Point,MapTile>
的包装器。 。
您想要的 map 样式对您在此处尝试执行的操作有很大影响。我想大多数算法都会使用这样的东西(假设是矩形):
for(int x = minx; x <= maxx; x++) {
for(int y = miny; y <= maxy; y++) {
map.put(new Point(x,y),generateRandomTile());
}
}
您可以做的另一个选择是传播。它的工作原理如下:
// pick 10 random points (10 is up to you)
MapTile[] seeds = new MapTile[10];
Point[] seedPoints = new Point[seeds.length];
for(int i = 0; i < seeds.length; i++) {
seeds[i] = generateRandomTile();
seedPoints[i] = generateRandomPoint();
}
int distance = 1;
while(true) {
boolean changed = false;
for(int i = 0; i < seedsPoints.length; i++) {
Point p = seedPoints[i];
for(int x = -distance; x <= distance; x++) {
Point here = new Point(x,p.y));
MapTile tile = tiles.get(here);
if(tile == null) {
tiles.put(here,new Tile(seeds[i].terrainType));
changed = true;
}
}
// that does the left edge of the square of distance away from
// the center. I'll leave the other edges of the square for you since they're boilerplate
} // end for seeds
if(!changed) break;
distance++;
}
关于java - 2D map 创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5776050/