Hey, I've trying to detect if a key was pressed. Currently my code detects if a key is down but in the case of the game I'm making where the player can shoot a bullet, the bullet will disappear if the button is let go rather than continue on regardless of the state of the key now. Heres my code,its just a small part so you can see what I'm currently doing:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
switch (message)
{
case WM_KEYDOWN:
keys[wParam]=true;
break;
case WM_KEYUP:
keys[wParam]=false;
break;
}
if(keys[VK_SPACE])
{
drawSprite(Bullet);
Bullet.x += bulletV;
}
The current method checks if the key is held down, so if you keep it held down the bullet will go all the way off screen, but if you let go of the key, then the bullet would disappear . I need it to check if the key was pressed so that once its been pressed even if its let go, the bullet will keep going off the screen.
Then add a new variable that you don't reset when the button is released. Plus code to detect when the bullet disappears off screen, and resets the variable.
Actually, you will prob want an array/vector of such variables, if you want to support multiple bullets?