#include <graphics.h>
#include <stdio.h>
#define I 15
int main()
{
initgraph(500, 500, 0);
//创建图片对象
PIMAGE pimg = newimage();
PIMAGE pimg2 = newimage();
getimage(pimg, "resource/background.jpg");
getimage(pimg2, "resource/block.jpg");
putimage(0, 0, pimg);
putimage(15, 15, pimg2);
for(;is_run();delay_fps(60))
{
while(kbmsg())
{
key_msg msg = getkey ();
if (msg.msg ==key_msg_down){
if (msg.key == 'D') {
for(int i=0;i<=120;i++){
cleardevice();
putimage(0, 0, pimg);
putimage(I + i, I, pimg2);
Sleep(1);}
}
else if (msg.key == 'S') {
for(int i=0;i<=120;i++){
cleardevice();
putimage(0, 0, pimg);
putimage(I , I + i, pimg2);
Sleep(1);}
}
else if (msg.key == 'A') {
for(int i=0;i<=120;i++){
cleardevice();
putimage(0, 0, pimg);
putimage(I - i , I, pimg2);
Sleep(1);}
}
else if (msg.key == 'W') {
for(int i=0;i<=120;i++){
cleardevice();
putimage(0, 0, pimg);
putimage(I , I - i , pimg2);
Sleep(1);}
}
}
}
}
// delimage(pimg);
getch();
closegraph();
return 0;
}