2013-10-01 174 views
0

嗨产生的,所以我想到了一个主意,到目前为止,我已经取得了一些进展。我希望能够改变我的水平地形基础上的坐标。该坐标基于您单击的位置和积分的ArrayList添加选择。这些点然后由他们的x值排序,然后得出如下:2D“地形”通过使用坐标

public Image renderTerrain() throws SlickException { 

    Image image = new Image(MAP_WIDTH, MAP_HEIGHT); 

    Graphics gr = image.getGraphics(); 

    int startx = 0; 
    int starty = 0; 

    for(Point point : points) { 

     starty = (int) point.getY(); 

     int tox = (int) point.getX(); 
     int toy = (int) point.getY(); 


     for(int x = startx; x < tox; x++) { 
      for(int y = starty; y < MAP_HEIGHT; y++) { 
       gr.drawLine(x,y,x,y); 
      } 
     } 

     startx = tox; 

    } 

    gr.flush(); 

    return image; 
} 

这将使像这样:

enter image description here

但是我想实现的是像这样。

enter image description here

我需要什么样的变化,以实现这一目标做什么呢?

谢谢。

+0

对我来说,你的代码似乎完全不能胜任。你似乎可以用'line'其中'fillRect'将是有效的...只是说 – MadProgrammer

+0

是的,我意识到,检查我的解决方案。 –

回答

0

我在等待答案时回答了我自己的问题。

这里是我的解决方案:

public Image renderTerrain() throws SlickException { 

    Image image = new Image(MAP_WIDTH, MAP_HEIGHT); 

    Graphics gr = image.getGraphics(); 

    int startx = 0; 
    int starty = (int)points.get(0).getY(); 

    for(Point point : points) { 


     int tox = (int) point.getX(); 
     int toy = (int) point.getY(); 

     gr.setColor(Color.pink);//line 
     gr.drawLine(startx,starty,tox,toy); 
     gr.setColor(Color.green); //height 
     gr.drawLine(tox, toy, tox, MAP_HEIGHT); 
     gr.setColor(Color.yellow); //base 
     gr.drawLine(tox, MAP_HEIGHT-1, startx, MAP_HEIGHT-1); 
     gr.drawLine(tox, MAP_HEIGHT-2, startx, MAP_HEIGHT-2); 

     startx = tox; 
     starty = toy; 
    } 

    gr.flush(); 

    return image; 
} 

结果:

enter image description here