2D 地图创建

发布于 2024-11-03 01:59:53 字数 259 浏览 7 评论 0原文

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

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

我需要知道如何实现这一点,如果可以的话,我对它很陌生,就像我说的,所以我没有任何代码可以给你任何知道我处于什么水平。

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

I am new to Map Creation and array storing and was wondering if I could get some assistance in the task. I am working in Java and using the LWJGL library if that is any help at all.

I'm not trying to make a rip off of any other game, so it's going to be different from any other game. I will basically just need different areas, like water, grass and dirt. I'll eventually add mountains and hills and climbing etc.

I need to know how this can be achieved, if it can be, I'm new to it like I said so I don't have any code to give to give you any idea of what level I am at.

If you can help, please leave an answer, would love as much help as I can get too.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

昔日梦未散 2024-11-10 01:59:53

它的渲染方式(openGL、swing/awt、其他任何东西)与地图本身无关。这就是它的渲染方式。我使用了自己编写的一个特殊的 CooperativeMap 类,但它基本上只不过是 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++;
}

How it's rendered (openGL, swing/awt, anything else) isn't related to the map itself. That's just how it's rendered. I use a special CoordinateMap class that I wrote, but it's basically nothing more than a wrapper for Map<Point,MapTile>.

How you want your map to be has a big impact on what you're trying to do here. I imagine most of the algorithms will use something like this (assuming rectangular):

for(int x = minx; x <= maxx; x++) {
    for(int y = miny; y <= maxy; y++) {
        map.put(new Point(x,y),generateRandomTile());
    }
}

Another option you can do is spreading. It works like this:

// 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++;
}
寻找我们的幸福 2024-11-10 01:59:53

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

既然你想用lwjgl,你会发现做基于2d的游戏很难。您还可以使用其他框架来简化此操作,此问题的答案将建议你一些。

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

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

There are several ways to create games in Java. Creating tile-based levels can also be done in several ways. You may want to do an internet search on some tutorials for creating 2d java games and find some ideas on how to do so.

Since you want to use lwjgl, you will find it difficult to do 2d-based games. There are other frameworks you could use that simplify this for you and the answers in this question will suggest you some.

Here are some links that may inspire you for making 2d maps:

You should also try to use the game development stackexchange site. They might help you with your game programming efforts as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文