工具:
VS-2010版,注册密钥点击它
图库工具:EasyX
效果显示:
全部代码:
#include
#include
#include
#include
#include
/*道具表示:
墙:0,地板:1,箱子目的地:2,小人:3,箱子:4,箱子命中目标:5
*/
using namespace std;
#define RATIO 61//一个格子的宽度
#define LINE 9//数组成员9,相当于是坐标y轴
#define COLUMN 12//每个成员有12个元素,相当于x轴
#define HEIGHT 768//相当于是坐标y轴
#define WIDTH 960//相当于x轴
/*热键控制方向*/
#define KEY_UP 'w'
#define KEY_LEFT 'a'
#define KEY_RIGHT 'd'
#define KEY_DOWN 's'
#define KEY_QUIT 'q'
#define isVaild(pos) pos.x>=0 && pos.x=0 && pos.yx][man->y] = prop;
putimage((man->y)*RATIO+(WIDTH-COLUMN*RATIO)/2,(man->x)*RATIO+(HEIGHT-LINE*RATIO)/2,&images[prop]);
}
/********************************
*实现游戏四个方向(上,下,左,右)的控制
*输入:
* direct - 人前进的方向
* man - 人对应的道具视图
* hit - 箱子是否命中目的地
*输出:无
*********************************/
void gameControl(enum _DIRECTION direct){
struct Man next_Man = man;
struct Man next_Man_pos = man;
switch(direct){
case UP:
next_Man.x--;
next_Man_pos.x-=2;
break;
case DOWN:
next_Man.x++;
next_Man_pos.x+=2;
break;
case LEFT:
next_Man.y--;
next_Man_pos.y-=2;
break;
case RIGHT:
next_Man.y++;
next_Man_pos.y+=2;
break;
}
if(isVaild(next_Man) && (map[next_Man.x][next_Man.y]==FLOOR)){//人的前方是地板
changMap(&next_Man,MAN);//人的前进一个格子
changMap(&man,FLOOR);
man=next_Man;
}else if(isVaild(next_Man_pos) && (map[next_Man.x][next_Man.y]==BOX)){//人的前方是箱子
if(isVaild(next_Man_pos) && (map[next_Man_pos.x][next_Man_pos.y]==FLOOR)){//两种情况,箱子前面是地板,
changMap(&next_Man_pos,BOX);
changMap(&next_Man,MAN);
changMap(&man,FLOOR);
man=next_Man;
}else if(isVaild(next_Man_pos) && (map[next_Man_pos.x][next_Man_pos.y]==BOX_DES)){//箱子前面是目的地
changMap(&next_Man_pos,HIT);
changMap(&next_Man,MAN);
changMap(&man,FLOOR);
man=next_Man;
}
}
}
int main(void){
//搭台
IMAGE bg_img;
initgraph(WIDTH,HEIGHT);
loadimage(&bg_img,_T("blackground.bmp"),WIDTH,HEIGHT,true);
putimage(0,0,&bg_img);
//加载道具图标
loadimage(&images[WALL],_T("wall_right.bmp"),RATIO,RATIO,true);
loadimage(&images[FLOOR],_T("floor.bmp"),RATIO,RATIO,true);
loadimage(&images[BOX_DES],_T("des.bmp"),RATIO,RATIO,true);
loadimage(&images[MAN],_T("man.bmp"),RATIO,RATIO,true);
loadimage(&images[BOX],_T("box.bmp"),RATIO,RATIO,true);
loadimage(&images[HIT],_T("box.bmp"),RATIO,RATIO,true);
for(int i=0;i