Why isn't my If statement working?

Ok, so I'm making an asteroids game in C++ and I'm trying to make the ship shoot, but it's not really working.
1st when the game starts it automatically shoots once and when I try to limit the shooting using an integer or a boolean, it doesn't work
Here's the important part of my code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
	 int key=0;
	 int steerKey=0;
	 int moveKey=0;

	 bool gameExit=false;
     int shoot=false;


	 char p1char='-';

	 for(;;)
	 {

		int p1oldx=p1x;
		int p1oldy=p1y;
		
        int bOldX=bX;
        int bOldY=bY;
		
		if (_kbhit())
			key = _getch();
		
		if (key==KEY_ARROWLEFT || key==KEY_ARROWRIGHT)
			steerKey = key;
		 
		if (key==KEY_ARROWDOWN)
			moveKey = key;

        if (key==KEY_S && shoot==false){ //This is what's not working
            shoot=true;
            bX=p1x;
            bY=p1y;
            bdirection=pdirection;
            key=0;
            } 


Also, just so you know

KEY_S = 0x73,
Last edited on
"int shoot=false;"
i dont know if thats wrong but shoudlnt it be bool or sumting? (or is it same as 0 and 1?)
Oh yes that is wrong, but that's not the reason it's not working, it was left like that because I was messing with it.
I'll take a stab in the dark here and say that key never equals KEY_S.

What lib is this anyway? is that conio? Wouldn't the S key be 'S' or 's' and not 0x73?

*checks*

oh wait, 0x73 is 's'

Try 'S' instead?

*shrug*

try printing the key after you call _getch() and see what you get.
Topic archived. No new replies allowed.