代码如下
char map1[]={
0x0,0x4,0x4,0x0,0x20,0x10,0x0,0x0,0x0,0x0,0x11,0x2,0x0,0x20,0x80,0x0,0x2,0x0,0x8,0x2,0x0,0x0,0x1,0x20,0x8,0x0,0x80,0x0,0x0,0x4,0x2,0x0};
char mapdata[]={
0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,
0,0,0,0,0,0,1,1,1,1,2,5,5,11,7,0,
0,0,0,1,1,1,96,97,1,1,1,1,1,0,5,0,
0,1,1,1,6,5,98,99,5,13,5,10,10,5,9,0,
1,1,3,1,5,1,1,1,1,1,1,1,0,0,0,0,
1,1,5,1,8,10,5,5,10,10,14,10,7,0,0,0,
1,1,17,1,1,1,1,1,1,1,1,1,5,1,1,0,
1,6,11,18,12,10,5,10,12,5,7,1,8,11,7,0,
1,5,1,1,1,1,1,1,1,1,5,1,1,1,5,0,
1,15,1,1,1,1,1,86,87,1,5,1,6,5,9,0,
1,10,1,1,4,5,16,88,89,5,16,10,9,1,1,0,
1,10,1,1,1,1,1,1,19,1,1,1,1,1,1,0,
1,8,5,5,10,10,10,10,9,1,1,1,1,1,0,0,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0};
void drawmap(int x,int y,int px,int py)
{
int dx,dy;
int ttx,tty;
ClearScreen();
for (dx=2;dx<14;dx++)
{for (dy=2;dy<9;dy++)
{if (px-8+dx<0||py-5+dy<0||px-8+dx>16||py-5+dy>13){continue;}
ttx=(dx-2)*16+x-8;
tty=(dy-2)*16+y-16;
WriteBlock(ttx,tty,16,16,1,map1);
}
}
Rectangle(73,16,88,31,1);
Refresh();
}
void main()
{
int p_x,p_y;
int tx,ty;
char key;
char i;
p_x=1;
p_y=1;
drawmap(1,0,p_x,p_y);
getchar();
for (;;)
{
tx=1;
ty=0;
key=getchar();
if (key==20){
for (i=1;i<17;i++)
{
ty=ty+1;
Delay(5);
drawmap(tx,ty,p_x,p_y);
}
p_y=p_y-1;
}
if (key==21){
for (i=1;i<17;i++)
{
ty=ty-1;
Delay(5);
drawmap(tx,ty,p_x,p_y);
}
p_y=p_y+1;
}
if (key==23){
for (i=1;i<17;i++)
{
tx=tx+1;
Delay(5);
drawmap(tx,ty,p_x,p_y);
}
p_x=p_x-1;
}
if (key==22){
for (i=1;i<17;i++)
{
tx=tx-1;
Delay(5);
drawmap(tx,ty,p_x,p_y);
}
p_x=p_x+1;
}
}
getchar();
}
效果是
按下箭头,地图图片向下移动
按上箭头,地图图片向上移动
按左箭头,地图图片向左移动
按下箭头,地图图片向下移动
|