- 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?