Path: chuka.playstation.co.uk!scea!greg_labrec@interactive.sony.com From: mperdue@iquest.net (Mario Perdue) Newsgroups: scea.yaroze.programming.2d_graphics Subject: Re: autofire Date: Sat, 14 Jun 1997 01:12:34 GMT Organization: SCEA Net Yaroze News Lines: 51 Message-ID: <33a1ea76.40137794@205.149.189.29> References: <33A08AD0.6C8F@concentric.net> NNTP-Posting-Host: firewall.hrtc.net X-Newsreader: Forte Free Agent 1.1/32.230 On Thu, 12 Jun 1997 19:48:32 -0400, djinn666 wrote: >hi, > > i'm writing a game but everytime the user holds the fire button it >keeps on shooting. i was wondering if anyone knows how i could make it >so when the user holds down the fire button the ship will only fire >once, making it so they must continuelly press the button to fire. >in the code the bullets are actually from "gsline" and go to the end of >the screen. > Djinn, If you look at the code for Spaceguy, you'll notice that I do what you're wanting to do. It looks something like this: void FireLaser() { static char button; int i; // Check to see if the 'fire' button is pressed if(contState & PADRdown) { // If button = 1 the fire button is still being held // down for the last time the laser was fired. - Abort if(button) return; // If button = 0, set it to 1 and continue processing button = 1; .... Do whatever you want here .... } else { // If the 'fire button is not pressed, button = 0 button = 0; } In this example, 'contState' contains the state of the controller buttons. The variable 'button' is a flag that is set whenever the the fire button is pressed and cleared when the fire button is released. Whenever the fire button is pressed AND 'button' is set the function returns without doing anything. Mario