2

我是地图创建和数组存储的新手,想知道是否可以在任务中获得一些帮助。如果有任何帮助,我正在使用 Java 并使用 LWJGL 库。

我并不想抄袭任何其他游戏,所以它会与任何其他游戏不同。我基本上只需要不同的区域,比如水、草和泥土。我最终会添加山脉和丘陵以及攀爬等。

我需要知道如何实现这一点,如果可以的话,就像我说的那样,我是新手,所以我没有任何代码可以让你知道我的水平。

如果您可以提供帮助,请留下答案,我也希望得到尽可能多的帮助。

4

2 回答 2

4

它的渲染方式(openGL、swing/awt 等)与地图本身无关。这就是它的渲染方式。我使用自己编写的特殊 CoordinateMap 类,但它基本上只是Map<Point,MapTile>.

你希望你的地图如何对你在这里尝试做的事情有很大的影响。我想大多数算法都会使用这样的东西(假设是矩形):

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++;
}
于 2011-04-25T07:30:12.200 回答
2

有几种方法可以在 Java 中创建游戏。创建基于图块的关卡也可以通过多种方式完成。您可能想在互联网上搜索一些用于创建 2d Java 游戏的教程,并找到一些关于如何这样做的想法。

既然你想使用lwjgl,你会发现做基于2d的游戏很困难。您可以使用其他框架来为您简化此过程,并且此问题中的答案将为您提供一些建议。

以下是一些可能会激发您制作 2​​d 地图的链接:

您还应该尝试使用游戏开发 stackexchange站点。他们也可以帮助您进行游戏编程工作。

于 2011-04-25T07:25:29.743 回答