Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Automatic Gun Sounds Problem

Author
Message
Malith
20
Years of Service
User Offline
Joined: 12th Mar 2005
Location: nowhere
Posted: 31st May 2005 20:38
I have an automatic gun in my FPS I am making with some buddies in DarkBASIC. My code ends up, the closer the bullet is to the object it collides with, the faster the automatic weapon's sound plays, as the farther away the bullet is (I.E. shooting the sky), it plays one shot, and waits until the bullet gets a certain distance before hiding itself and being able to shoot again. any ideas?
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 1st Jun 2005 03:53 Edited at: 1st Jun 2005 03:57
Malith,

You need to create more than just one bullet object as your projectile. Instead, create enough bullets that you will not cycle through them all before the last bullet shot runs out of 'life'. Let's say that each bullet's life will last to 300 units out, and their speed will be 5 units each frame(game loop). Let's also say that you wish to shoot a bullet every 5 frames, as long as the 'trigger' is held down. Let's do some math.

Simply, divide the bullets' lifes by the distance they will travel each frame. 300 / 5 = 60. So, we need 60 bullets to make this loop fluent.

Now, there is a need for an array to control all the properties of each bullets. What do we need to record? In the 2D program I need to record the bullets' x and y coordinates. In 3D, you may need to record their z coordinates. Also, their bulletlife, in which this value will also be used to make the bullet move if it is above 0 bulletlife. Lastly, bulletangle.

There is no way to correct the sound problem the way you are writing the code, because you are only using one bullet, and AS SOON as it dies, it is reset and the sound is played again.

The code snippet below is a small program made in order to show this loop working. It is all in 2D, however, we're not focusing on the graphics, but the loop. The code is heavily commented to guide you through it processes. Watch for the "THIS IS WHERE YOU PLAY THE SOUND" comment. Enjoy!




+NanoBrain+

Login to post a reply

Server time is: 2025-05-22 23:58:25
Your offset time is: 2025-05-22 23:58:25