void runGame(){
readimagefile("PIX\\Landscape.jpg", 0, 0, 800, 800);
while(1 == 1){
moveCharacter();
//moveMonster();
}
}
void moveCharacter(){
int move = 0;
int size = imagesize(0, 0, 800, 800);
void *background = malloc(size);
getimage(0, 0, 800, 800, background);
readimagefile("PIX\\Character\\down_still.gif",x9,y9,x9+50,y9+50);
thunderClaw();
//specialAttack();
//thunderball();
if(kbhit()){
if(getch()== 'd'){
move = 1;
}
if(getch()== 'a'){
move = 3;
}
if(getch()== 'w'){
move = 2;
}
if(getch()== 's'){
move = 4;
}
}
switch (move){
case 1://left
readimagefile("PIX\\Character\\left_r.gif",x9,y9,x9+50,y9+50);Sleep(15);
x9 = x9 + 5;
putimage(0, 0, background, COPY_PUT);
readimagefile("PIX\\Character\\left_still.gif",x9,y9,x9+50,y9+50);Sleep(15);
x9 = x9 + 5;
putimage(0, 0, background, COPY_PUT);
readimagefile("PIX\\Character\\left_l.gif",x9,y9,x9+50,y9+50);Sleep(15);
x9 = x9 + 5;
putimage(0, 0, background, COPY_PUT);
readimagefile("PIX\\Character\\left_still.gif",x9,y9,x9+50,y9+50);Sleep(15);
x9 = x9 + 5;
putimage(0, 0, background, COPY_PUT);
break;
case 2://up
readimagefile("PIX\\Character\\up_r.gif",x9,y9,x9+50,y9+50);Sleep(15);
y9 = y9 - 5;
putimage(0, 0, background, COPY_PUT);
readimagefile("PIX\\Character\\up_still.gif",x9,y9,x9+50,y9+50);Sleep(15);
y9 = y9 - 5;
putimage(0, 0, background, COPY_PUT);
readimagefile("PIX\\Character\\up_l.gif",x9,y9,x9+50,y9+50);Sleep(15);
y9 = y9 - 5;
putimage(0, 0, background, COPY_PUT);
readimagefile("PIX\\Character\\up_still.gif",x9,y9,x9+50,y9+50);Sleep(15);
y9 = y9 - 5;
putimage(0, 0, background, COPY_PUT);
break;
case 3://right
readimagefile("PIX\\Character\\right_r.gif",x9,y9,x9+50,y9+50);Sleep(15);
x9 = x9 - 5;
putimage(0, 0, background, COPY_PUT);
readimagefile("PIX\\Character\\right_still.gif",x9,y9,x9+50,y9+50);Sleep(15);
x9 = x9 - 5;
putimage(0, 0, background, COPY_PUT);
readimagefile("PIX\\Character\\right_l.gif",x9,y9,x9+50,y9+50);Sleep(15);
x9 = x9 - 5;
putimage(0, 0, background, COPY_PUT);
readimagefile("PIX\\Character\\right_still.gif",x9,y9,x9+50,y9+50);Sleep(15);
x9 = x9 - 5;
putimage(0, 0, background, COPY_PUT);
break;
case 4://down
readimagefile("PIX\\Character\\down_l.gif",x9,y9,x9+50,y9+50);Sleep(15);
y9 = y9 + 5;
putimage(0, 0, background, COPY_PUT);
readimagefile("PIX\\Character\\down_still.gif",x9,y9,x9+50,y9+50);Sleep(15);
y9 = y9 + 5;
putimage(0, 0, background, COPY_PUT);
readimagefile("PIX\\Character\\down_r.gif",x9,y9,x9+50,y9+50);Sleep(15);
y9 = y9 + 5;
putimage(0, 0, background, COPY_PUT);
readimagefile("PIX\\Character\\down_still.gif",x9,y9,x9+50,y9+50);Sleep(15);
y9 = y9 + 5;
putimage(0, 0, background, COPY_PUT);
break;
default:
readimagefile("PIX\\Character\\down_still.gif", x9, y9, x9+50, y9+50);
putimage(0, 0, background, COPY_PUT);
}
}//end function
void thunderClaw(){
int mx = mousex();
int my = mousey();
int size = imagesize(0, 0, 800, 800);
void *background = malloc(size);
getimage(0, 0, 800, 800, background);
getmouseclick(WM_LBUTTONDOWN, mx, my);
if(WM_LBUTTONDOWN){
printf("Left mouse button was clicked!\n");
#ifdef SOUNDfx
PlaySound("SOUNDS\\Electricity_Shock_Sound_Effect.wav", NULL, SND_ASYNC);
#endif
readimagefile("PIX\\Thunderclaw\\thunderclaw00.gif", mx-25, my-25, mx+25, my+25);Sleep(80);
putimage(0, 0, background, COPY_PUT);
readimagefile("PIX\\Thunderclaw\\thunderclaw01.gif", mx-25, my-25, mx+25, my+25);Sleep(80);
putimage(0, 0, background, COPY_PUT);
readimagefile("PIX\\Thunderclaw\\thunderclaw0.gif", mx-25, my-25, mx+25, my+25);Sleep(80);
putimage(0, 0, background, COPY_PUT);
readimagefile("PIX\\Thunderclaw\\thunderclaw.gif", mx-25, my-25, mx+25, my+25);Sleep(80);
putimage(0, 0, background, COPY_PUT);
readimagefile("PIX\\Thunderclaw\\thunderclaw2.gif", mx-25, my-25, mx+25, my+25);Sleep(80);
putimage(0, 0, background, COPY_PUT);
readimagefile("PIX\\Thunderclaw\\thunderclaw3.gif", mx-25, my-25, mx+25, my+25);Sleep(80);
putimage(0, 0, background, COPY_PUT);
readimagefile("PIX\\Thunderclaw\\thunderclaw4.gif", mx-25, my-25, mx+25, my+25);Sleep(80);
putimage(0, 0, background, COPY_PUT);
readimagefile("PIX\\Thunderclaw\\thunderclaw5.gif", mx-25, my-25, mx+25, my+25);Sleep(80);
putimage(0, 0, background, COPY_PUT);
}
}
所以这是我目前拥有的代码。我的问题是它一直认为鼠标左键不断被点击。因此,它不断地将动画放在左上角并减慢角色移动。我已经尝试了很多方法来阻止这种情况,但无法弄清楚。谷歌也没有帮助。我只是不明白它是如何认为我不断单击鼠标左键的。我相信这是因为 if(WM_LBUTTONDOWN) 语句。但即便如此,我也尝试过改变它,添加不同的规格,移动它,摆脱它,但没有什么能解决我的需要。它只是不断地认为左按钮被单击(即使我摆脱了 if() 语句它也这样做了!)。
谁能帮我解决这个问题?
谢谢!
PS 我在 Visual Studio 2012 和 graphics.h 库中。
void getmouseclick( int kind, int& x, int& y )
{
WindowData *pWndData = BGI__GetWindowDataPtr( );
POINTS where; // POINT (short) to tell where mouse event happened.
// Check if mouse event is in range
if ( !MouseKindInRange( kind ) )
return;
// Set position variables to mouse location, or to NO_CLICK if no event occured
if ( MouseKindInRange( kind ) && pWndData->clicks[kind - WM_MOUSEFIRST].size( ) )
{
where = pWndData->clicks[kind - WM_MOUSEFIRST].front( );
pWndData->clicks[kind - WM_MOUSEFIRST].pop( );
x = where.x;
y = where.y;
}
else
{
x = y = NO_CLICK;
}
}
这是您在代码中所指的getmouseclick()
吗?这不是我写的东西哈哈只是我正在使用的东西。