📄 map.java
字号:
import java.io.IOException;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
public class MAP
{
Image dim , djim ;
int iw , ih ;
byte[][] map ;
int[][] pd ; // 图片信息 ix iy w h zh(遮罩的搞)
int [][]dj; // 道具 x,y,ID
int[][] cs; // 传送点的位置信息 x y w h ievel px py cx cy
public MAP()
{
try {
dim=Image.createImage( "/map01.png");
djim=Image.createImage( "/fangzi12.png");
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
pd = new int[][]
{
{ 0 , 3 , 82 , 81,50 } ,
{ 85 , 1 , 78 , 79 ,40} ,
{ 170 , 3 , 64 , 64 ,50} ,
{ 261 , 0 , 9 , 30 ,30} ,
{ 237 , 0 , 23 , 15 ,20} ,
{ 238 , 38 , 33 , 31,60 } ,
{ 271 , 1 , 20 , 40,20 } ,
{ 273 , 45 , 16 , 15,10 } ,
{ 295 , 1 , 77 , 82 ,50} ,
{ 377 , 0 , 124 , 114,30 } ,
{ 16 , 90 , 131 , 85 ,20} ,
{ 187 , 76 , 97 , 105 ,20} ,
{ 295 , 84 , 75 , 76 ,50} ,
{ 4 , 212 , 73 , 57 ,50} ,
{ 81 , 181 , 81 , 74 ,20} ,
{ 170 , 185 , 98 , 105,10 } ,
{ 277 , 162 , 97 , 104 ,20} ,
{ 378 , 116 , 123 , 113,20 } ,
{ 8 , 276 , 16 , 16 ,20} ,
{ 127 , 275 , 10 , 24,20 } ,
{ 144 , 268 , 24 , 31,20 } ,
} ;
iw = ih =40 ;
isHitmap(1 ) ;
}
public void isHitmap(int level)
{
switch(level)
{
case 1:
map=new byte[][]{{ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 1, 1, 1, 1, 1, 11,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12 },
{ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 1, 1, 1, 1, 1, 11,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 1, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12 },
{ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 1, 1, 1, 1, 1, 11,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 1, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12 },
{ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 1, 1, 1, 1, 1, 11,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 1, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12 },
{ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 1, 1, 1, 1, 1, 11,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 1, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12 },
{ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 1, 1, 1, 1, 1, 11,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 1, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12 },
{ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 1, 1, 1, 1, 1, 11,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 1, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12 },
{ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 1, 1, 1, 1, 1, 11,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12 },
{ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 1, 1, 1, 1, 1, 11,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12 },
{ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 1, 1, 1, 1, 1, 11,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12 },
{ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 1, 1, 1, 1, 1, 11,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12 },
{ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 1, 1, 1, 1, 1, 11,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12 },
{ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 1, 1, 1, 1, 1, 11,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12 },
{ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 1, 1, 1, 1, 1, 11,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12 },
{ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 1, 1, 1, 1, 1, 11,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12 },
{ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 1, 1, 1, 1, 1, 11,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12 }
};
// 道具 x,y,ID
dj=new int[][]{
{ 50, 81,1 } ,
{ 185, 78 , 2 } ,
{170,64, 3 } ,
{ 261,81,0 }
};
// 传送点的位置信息 x y w h ievel px py cx cy
cs=new int[][]{
{500,630,20,20,2,100,100,0,0}
};
break;
case 2:
map=new byte[][]{{ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 },
{ 10, 10, 10, 11, 11, 10, 10, 10, 10, 10 },
{ 10, 10, 10, 11, 11, 10, 10, 10, 10, 10 },
{ 10, 10, 10, 11, 11, 10, 10, 10, 10, 10 },
{ 10, 10, 10, 11, 11, 10, 10, 10, 10, 10 },
{ 10, 10, 10, 11, 11, 10, 10, 10, 10, 10 },
{ 10, 10, 10, 11, 11, 10, 10, 10, 10, 10 },
{ 10, 10, 10, 11, 11, 10, 10, 10, 10, 10 },
{ 10, 10, 10, 11, 11, 10, 10, 10, 10, 10 },
{ 10, 10, 10, 11, 11, 10, 10, 10, 10, 10 }
};
// 道具 x,y,ID
dj=new int[][]{
{ 50, 81,1 } ,
{ 185, 78 , 2 } ,
{170,64, 3 } ,
{ 261,81,0 }
};
// 传送点的位置信息 x y w h ievel px py cx cy
cs=new int[][]{
{25,25,20,20,1,100,100,0,0}
};
break;
}
}
public void renderDown(Graphics g , int cx , int cy) //绘制上面;
{
byte t ;
for(int i = 0 ; i <240/ih +2 ; i++)
{
for (int j = 0 ; j <320/iw +2 ; j++)
{
if(cy/ih + i >= 0 && cy/ih + i < map.length &&
cx/iw+ j >= 0 && cx/iw + j < map[0].length)
{
t =map[cy/ih + i][cx/iw + j] ;
if(t > 0)
{
Tools.paintImage(g , dim ,
j*iw-(cx % iw) , i*ih-(cy % ih) ,(t-1)*iw, 0,
iw , ih ) ;
}
}
}
}
for(int i = 0 ; i < dj.length ; i++)
{
if(dj[i][0] - cx > - pd[dj[i][2]][2] &&
dj[i][0] - cx < 240 &&
dj[i][1] - cy > - pd[dj[i][2]][3] &&
dj[i][1] - cy < 320)
{
Tools.paintImage(g , djim , dj[i][0] - cx , dj[i][1] - cy ,pd[dj[i][2]][0] , pd[dj[i][2]][1],
pd[dj[i][2]][2] ,pd[dj[i][2]][3]
) ;
}
}
}
public void renderUp(Graphics g , int cx , int cy)
{
for(int i = 0 ; i < dj.length ; i++)
{
if(dj[i][0] - cx > - pd[dj[i][2]][2] &&
dj[i][0] - cx <240 &&
dj[i][1] - cy > - pd[dj[i][2]][3] &&
dj[i][1] - cy <320)
{
Tools.paintImage(g , djim , dj[i][0] - cx , dj[i][1] - cy ,pd[dj[i][2]][0] , pd[dj[i][2]][1],
pd[dj[i][2]][2] ,pd[dj[i][2]][4]
) ;
}
}
}
public boolean isHit(int x , int y)
{
for(int i = 0 ; i < dj.length ; i++)
{
if(x > dj[i][0] && x < dj[i][0] + pd[dj[i][2]][2] &&
y > dj[i][1] + pd[dj[i][2]][4] && y < dj[i][1] + pd[dj[i][2]][3])
{
return true ;
}
}
return false ;
}
public void isHitcs(MC mc)
{
for(int i = 0 ; i < cs.length ; i++)
{
if(mc.pl.x > cs[i][0] &&
mc.pl.x < cs[i][0] + cs[i][2] &&
mc.pl.y > cs[i][1] &&
mc.pl.y < cs[i][1] + cs[i][3])
{
mc.pl.x = cs[i][5] ;
mc.pl.y = cs[i][6] ;
mc.cx = cs[i][7] ;
mc.cy = cs[i][8] ;
isHitmap(cs[i][4] ) ;
System.out.println("***********");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -