2011-04-25 81 views
2

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

我并不是试图从其他任何游戏中剥离,所以它会与其他任何游戏不同。我基本上只需要不同的区域,比如水,草和泥土。我最终会加山,爬山等。

我需要知道如何做到这一点,如果可以的话,我是新来的,就像我说的,所以我没有任何代码可以给给你任何关于我在什么级别的想法。

如果你可以帮忙,请留下一个答案,会尽可能多的帮助,因为我可以得到。

+0

还有另一个栈处理这些类型的问题;)http://gamedev.stackexchange.com/questions/4031/methods-for-generating-a-map – 2011-04-25 07:04:42

+1

不用担心,现在看看。非常感谢您的帮助。 – Shannon 2011-04-25 07:07:15

回答

2

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

既然你想使用lwjgl,你会发现很难做2d游戏。还有其他的框架可以为你简化这一点,answers in this question会给你一些建议。

这里有可能会激发你让2D贴图一些链接:

您还应该尝试使用game development stackexchange网站。他们也可以帮助您进行游戏编程。

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++; 
} 
+0

这是很棒的帮助glowcoder。然而,我需要进一步的解释,并想知道我能否与外界联系一些如何? 像MSN这样的东西将是适当的,并可以很容易地传输代码等。 – Shannon 2011-04-25 07:33:51