J2me手机游戏编程初体验
作者: 来源: 添加时间:2006-5-24 13:00:30BoxMaps类
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
public class BoxMaps
{
private static final int[][] map1 = {
{0,0,0,0,1,1,1,0,0,0,0,0},
{0,0,0,0,4,0,2,0,0,0,0,0},
{0,0,0,0,4,0,2,0,0,0,0,0},
{0,0,0,0,4,0,1,1,1,1,1,2},
{0,0,0,0,4,0,0,0,0,0,0,2},
{4,1,1,1,1,0,0,0,3,3,3,2},
{4,0,0,0,0,0,0,0,2,0,0,0},
{4,3,3,3,3,3,3,0,2,0,0,0},
{0,0,0,0,0,0,4,0,2,0,0,0},
{0,0,0,0,0,0,4,0,2,0,0,0},
{0,0,0,0,0,0,4,0,2,0,0,0},
{0,0,0,0,0,0,3,3,3,0,0,0}
};
private static final int TILE_WIDTH = 16;
private static final int TILE_HEIGHT = 16;
private int[][] currentMap;
private TiledLayer tl_BoxGround;
private int groundColor;
public BoxMaps() throws Exception{
setMap(1);
}
public void setMap(int level) throws Exception {
Image tileImages = Image.createImage("/wall.png");
switch(level)
{
case 1:
currentMap = map1;
groundColor = 0xF8DDBE;
break;
default:
groundColor = 0xF8DDBE;
break;
}
tl_BoxGround = new TiledLayer(12,12,tileImages,TILE_WIDTH,TILE_HEIGHT);
for (int row=0; row<12; row++) {
for (int col=0; col<12; col++) {
tl_BoxGround.setCell(col,row,currentMap[row][col]);
}
}
}
public TiledLayer getTiled() {
return tl_BoxGround;
}
public int getGroundColor() {
return groundColor;
}
}
运行一下,看看效果,哈哈,效果出来了,怎么样?比较简单吧
第 2 页,共 2 页 [1] [2]
站内搜索