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;
}
这将呈现如下:
然而,我想要达到的目标就是这样。
为了实现这一目标,我需要做出哪些改变?
感谢。
答案 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;
}
结果: