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.

Dark GDK / Help with Making Something Fire at a Cretin rate

Author
Message
negi
13
Years of Service
User Offline
Joined: 16th Feb 2011
Location:
Posted: 13th Dec 2011 01:08
Hay I have been making my own version of Asteroids and cannot seem to find a way to make the ship fire a bullet every so often. It only ever makes a sprite continuously, not at all or every 10 seconds.

I also have tryed to use a timer.

Here is the code I am using now.




Any help witht this would be great.

All is revealed with time.
Hassan
14
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 13th Dec 2011 18:20 Edited at: 13th Dec 2011 18:21


find someway else for that, you will want "Fireing" stay true until the bullet hit something or it goes out of screen, so set that as the condition instead of this "else", you might as well have this somewhere else in your code

negi
13
Years of Service
User Offline
Joined: 16th Feb 2011
Location:
Posted: 13th Dec 2011 20:32
Hmm ok but how should I go about making something fire at a certain rate like 5 times a second? I have tried to use a timer but it ether does not fire or fires too fast. And thanks so much for your help

All is revealed with time.
Wizz
14
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 13th Dec 2011 21:29 Edited at: 13th Dec 2011 21:29
To make something fire at a certain rate with timers you will need 2 variables, the first of which has the value of the current time in each frame, and the second of which only updates to the current time when you start measuring the time pause (between shots fired).
The code should look something like this:


negi
13
Years of Service
User Offline
Joined: 16th Feb 2011
Location:
Posted: 13th Dec 2011 22:34
I tryed what you said and now the sprite I have for the Player disappears.

here is the code


All is revealed with time.
Wizz
14
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 13th Dec 2011 23:37
You have to switch the CurrBulletTime - BulletTime around:
if ( BulletTime - CurrBulletTime >= FireRate)

Also, time is measured in miliseconds so one second is 1000.

The sprite disappears because you are using the same ID for all the bullet sprites. First you spawn a sprite with ID=50 at certain coordinates, and then you make it move. But when you fire the second bullet you make the same sprite again (cause you told the system to use the sprite with ID=50. Each time you make a sprite it needs a different ID.

negi
13
Years of Service
User Offline
Joined: 16th Feb 2011
Location:
Posted: 13th Dec 2011 23:52
I have a varialble that holds a sprite number for the bullet but its the Ship that the player controls that disaperes.

here is the code for the whole game


and thanks so much for your help

All is revealed with time.
negi
13
Years of Service
User Offline
Joined: 16th Feb 2011
Location:
Posted: 22nd Dec 2011 22:07
I figured it out I just had to make a class to manage the sprites for the bullets.

Thanks for your help

All is revealed with time.

Login to post a reply

Server time is: 2024-03-29 12:07:42
Your offset time is: 2024-03-29 12:07:42