void runGame(){
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);

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

x9 = x9 + 5;
putimage(0, 0, background, COPY_PUT);
x9 = x9 + 5;
putimage(0, 0, background, COPY_PUT);
x9 = x9 + 5;
putimage(0, 0, background, COPY_PUT);
x9 = x9 + 5;
putimage(0, 0, background, COPY_PUT);
break;

case 2://up

y9 = y9 - 5;
putimage(0, 0, background, COPY_PUT);
y9 = y9 - 5;
putimage(0, 0, background, COPY_PUT);
y9 = y9 - 5;
putimage(0, 0, background, COPY_PUT);
y9 = y9 - 5;
putimage(0, 0, background, COPY_PUT);
break;

case 3://right

x9 = x9 - 5;
putimage(0, 0, background, COPY_PUT);
x9 = x9 - 5;
putimage(0, 0, background, COPY_PUT);
x9 = x9 - 5;
putimage(0, 0, background, COPY_PUT);
x9 = x9 - 5;
putimage(0, 0, background, COPY_PUT);
break;

case 4://down

y9 = y9 + 5;
putimage(0, 0, background, COPY_PUT);
y9 = y9 + 5;
putimage(0, 0, background, COPY_PUT);
y9 = y9 + 5;
putimage(0, 0, background, COPY_PUT);
y9 = y9 + 5;
putimage(0, 0, background, COPY_PUT);
break;

default:
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
putimage(0, 0, background, COPY_PUT);
putimage(0, 0, background, COPY_PUT);
putimage(0, 0, background, COPY_PUT);
putimage(0, 0, background, COPY_PUT);
putimage(0, 0, background, COPY_PUT);
putimage(0, 0, background, COPY_PUT);
putimage(0, 0, background, COPY_PUT);
putimage(0, 0, background, COPY_PUT);
}
}


So this is the code I have at the moment. My issue is that it keeps thinking the left mouse button is being clicked constantly. Therefore it is constantly putting the animation in the top left corner and slowing down character movement. I have tried an enourmouse slew of things to stop this but have not been able to figure it out. Google has not helped either. I just don't get how it thinks I am constantly clicking left mouse button. I believe it is because of the if(WM_LBUTTONDOWN) statement. But even that, I have tried changing it, adding different specifications, moving it, getting rid of it, and nothing works out how I need it to. It just constantly thinks left button is being clicked (even when I got rid of if() statement it did this!).

Could anyone help me out on this?

THANKS!

2
Contributors
4
Replies
20
Views
4 Years
Discussion Span
Last Post by tyler.dahle

Somewhere in the windows code is a line like this:

#define WM_LBUTTONDOWN                  0x0201


So your code if(WM_LBUTTONDOWN) is essentially saying: if(0x0201) which is essentially if(true)

You're not checking to see if the left mouse button is currently being clicked - you're simply saying if(true)

Edited by Moschops

haha I don't really know what else to try... I tried using a switch statement (unsuccessful), I tried getting rid of if() statement and used registermousehandler(WM_LBUTTONDOWN, thunderClaw); and that seemingly works... it just doesn't do the animation. It produces the sound and will only produce the very last image. (registermousehandler() is in main btw.) I just don't get what needs to be done to tell the stupid program to only execute images when mouse is CLICKED! Lol why can't it just do what it needs to!

You haven't helped yourself by trying to do this directly with the Win32 API. The message pump is not a simple piece of code. I'd suggest you pick out one of the simple widget toolkits and start with that.

Lol... oh dear... Hmmm... I am in my first class ever of programming. I suppose I would nee to look up what widget toolkits are as I have no idea... But I might not even be able to use them? My professor has had us using this program he created for the entire class so far that has a graphics screen that we have done stuff with. We might have to use his program for this. This game is term project of our own choosing so me and partner decided to do this.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.