设计地图
新建map包创建Maptile类
package map;
import util.MyUtil;
import java.awt.*;
public class MapTile {
//地图块的宽度
public static int tileW = 40;
private static Image tileImg;
static {
tileImg = MyUtil.createImage("res/tile.png");
if(tileW <= 0){
tileW = tileImg.getWidth(null);
}
}
//砖块左上角坐标
private int x,y;
private boolean visible = true;
public MapTile(int x, int y) {
this.x = x;
this.y = y;
if(tileW <= 0){
tileW = tileImg.getWidth(null);
}
}
public void draw(Graphics g){
if(!visible)
return;
if(tileW <= 0){
tileW = tileImg.getWidth(null);
}
g.drawImage(tileImg,x,y,null);
}
public boolean isVisible() {
return visible;
}
public void setVisible(boolean visible) {
this.visible = visible;
}
public static int getTileW() {
return tileW;
}
public static void setTileW(int tileW) {
MapTile.tileW = tileW;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}