Stop Any Key Down even from triggerring once for each key

Non-platform specific questions.

Stop Any Key Down even from triggerring once for each key

Postby motorollin » Mon Aug 13, 2007 4:53 pm

My game features a ship which fires continuously while the fire button is held down. Simply creating the bullet actor on the key down event of the ship actor fired to quickly, so I wrote this script for the key down:

Code: Select all
char *key = GetKeyState(); //Get keyboard state
if ( shootcount == 100 )
{
    //Create a bullet actor
    shootcount=0;
}
else
{
    if ( key[KEY_UP] | key[KEY_DOWN] | key[KEY_LEFT] | key[KEY_RIGHT] )
    {
        shootcount += 10;
    }
}


This works well while the ship is stationary. But if the ship is moving and firing at the same time, the script is triggered once for each key which is held down, so shootcount increments too quickly and the shooting rate goes up.

One solution would be to use a key down event just for the fire button to trigger the firing script. But I can't do this since I'm using GP2X keys, which means I need to use an any key event.

Any ideas how I can get the script to run just once for all keys instead of once for each key held down?
motorollin
 
Posts: 54
Joined: Sun Aug 12, 2007 8:05 am
Score: 1 Give a positive score

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest