Sign in to follow this  
ecr0n

Delays?

Recommended Posts

ecr0n    120
y0 I have a problem. I was able to figure out how to draw bullets using an array. The bullets right now are currently pixels while i'm in the process in developing my game(Windows/C++). The problem i'm having is that when the key is pressed to shoot the computer draws many pixels making it form a straight line or a diagnol line if the player is moving. How could i fix this? Is there a way for me to put a delay on it? so the player can't hit the shoot button but a couple times a second or something?...

Share this post


Link to post
Share on other sites
Ravuya    135
I would use the Windows functionality to get the tick counter, and then update it every frame.

Pseudocode:
while(bGameIsRunning) {
...tickStart = get ticks from system counter
...// game stuff goes here
...bulletTimer += ticksElapsedLastFrame;
...if(player pushes fire and bulletTimer is over x number of ticks)
.....fire
.....bulletTimer = 0
...ticksElapsedLastFrame = get ticks from system counter - tickStart
}

I'm not sure of the exact syntax under Win32, otherwise I would have put it in there instead of pseudocode. Basically, you take a measure of how many "ticks" (ms) there are between frames, and then continuously update the timer. When the player mashes the button, you check the timer to see if it's over a certain number, and if it is, you reset it to zero and fire the bullet.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this