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 / Gun Fire Problem

Author
Message
BENOJ
19
Years of Service
User Offline
Joined: 17th Mar 2006
Location: UK
Posted: 30th Mar 2006 15:38
hi, here is a section of firing code for the fps i am making

there is one problem though, if you hold down the mouse button, the bullets keep on going down bu the bullet does not fire, i would liek to make it so that there is multiple firing bullets preferably. is there a more efficient way of doing this, like making new objects when the mouseclick()=1 or soemthing like that, all help will be appreciated thanks for looking

abit fatal1ty an8 sli mobo, ati radeon 1800 XT, 1.5GB RAM
250GB SATA HDD, AMD Athlon 64 x2 4200 (overclocked further)
BENOJ
19
Years of Service
User Offline
Joined: 17th Mar 2006
Location: UK
Posted: 30th Mar 2006 15:43
sorry forgot to mention object 99 is a sphere

abit fatal1ty an8 sli mobo, ati radeon 1800 XT, 1.5GB RAM
250GB SATA HDD, AMD Athlon 64 x2 4200 (overclocked further)
SimSmall
20
Years of Service
User Offline
Joined: 7th Aug 2004
Location: United Kingdom
Posted: 30th Mar 2006 16:41
Currently: bullet using object 99 is never deleted. you need to delete object 99 before the player tries to fire again, otheriwse object 99 will be reset before it has chance to hit a target...

you'll need to set aside a range of range of objects to use as bullets (5 should be enough), number them 100 - 105.

When the player tries to fire, check if bullet 100 is being used, if it is, try 101, and so on. if a bullet exists, move it as normal.

Also make a little system to track how long a bullet has existed for, when that reaches something like 2 seconds (or if the bullet has moved something like 20 times). delete that bullet as it will cause slow performance.
Profit
19
Years of Service
User Offline
Joined: 19th Feb 2006
Location: United States
Posted: 30th Mar 2006 16:44 Edited at: 30th Mar 2006 16:59
ok, since i posted to slow simsmall said what i was going to say. so now i will talk about a way to make this system


that is untested, sorry if it doesn't work completely
like simsmall suggested, you might want to do something with the bullets not in use. another thing is before you use this, you need to create the spheres 99-120.

you can do it like this



common people are walking in line.
BENOJ
19
Years of Service
User Offline
Joined: 17th Mar 2006
Location: UK
Posted: 30th Mar 2006 17:37 Edited at: 30th Mar 2006 17:41
thanks guys, i think i know what you mean. this is what i have came up with, havent had time to test it yet but do you think this is about right?



abit fatal1ty an8 sli mobo, ati radeon 1800 XT, 1.5GB RAM
250GB SATA HDD, AMD Athlon 64 x2 4200 (overclocked further)
BENOJ
19
Years of Service
User Offline
Joined: 17th Mar 2006
Location: UK
Posted: 30th Mar 2006 17:39 Edited at: 30th Mar 2006 17:42
code error realised after reading heres how i think it should be



abit fatal1ty an8 sli mobo, ati radeon 1800 XT, 1.5GB RAM
250GB SATA HDD, AMD Athlon 64 x2 4200 (overclocked further)
SimSmall
20
Years of Service
User Offline
Joined: 7th Aug 2004
Location: United Kingdom
Posted: 31st Mar 2006 10:45 Edited at: 31st Mar 2006 10:49
almost right, at the moment all bullets are sharing the same timer, each time a new bullet is created, the timer is reset.

Suggested changes to some lines have been underlined.

dim bulletlife(100)

for n = 100 to 200
if mouseclick()=1 and bullets>0 and object exist(n) = 0 then fire=1
bulletlife(n - 100) = timer()
`Only create bulletlife if a bullet was created, otherwise it throws a spanner in the works - in its old position, the 2000 milliseconds time was never going to be reached, since it was constantly being reset. It now cannot be changed while its corresponding bullet exists. This is why I've suggested moving it inside the fire section.
`The rest of the code is right, up to...
if object exist(n)
if bulletlife(n - 100) - timer() < 2000
`not been around for 2 seconds yet, lets move it
move object n,30
else
'Bullet's been around too long, time to get rid of it, to allow another one to be fired...
delete object n
endif
endif
next n

Edit: oops - missed off the for and next, although they were already in the right place...
BENOJ
19
Years of Service
User Offline
Joined: 17th Mar 2006
Location: UK
Posted: 31st Mar 2006 14:50 Edited at: 31st Mar 2006 14:51
i think i understand what you mean so basicaly the code has to say:

it makes the bullets
and the bullet life
if mouseclick =1 and the bullet chamber has more than 0 bullets and the object is existing then shoot.
while the timer is les than 2 seconds move the object at a speed of 30
but if the time is more than 2 seconds, deletd the bullet.

is that what it all means?
one question though, why is bullet life an array?

here is what i think it should be written like, may be wrong though


abit fatal1ty an8 sli mobo, ati radeon 1800 XT, 1.5GB RAM
250GB SATA HDD, AMD Athlon 64 x2 4200 (overclocked further)
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 31st Mar 2006 15:27
Bullet life is an array because you have more than one bullet, and each bullet needs a seperate time code.

BENOJ
19
Years of Service
User Offline
Joined: 17th Mar 2006
Location: UK
Posted: 31st Mar 2006 15:31 Edited at: 31st Mar 2006 15:35
Quote: "dim bulletlife(100)"

ok then, so it is 100 because there are 100 bullets right?

Quote: "if bulletlife(n - 100)"
so why does it change to n-100 later on in the code?

abit fatal1ty an8 sli mobo, ati radeon 1800 XT, 1.5GB RAM
250GB SATA HDD, AMD Athlon 64 x2 4200 (overclocked further)
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 31st Mar 2006 15:40
He counts from 100 to 200, must have something to do with your object numbers. You make your objects starting at 100, so the code needs to jump back 100 at times to do 2 things at the same time.


n = 100,101,102,103
n-100 = 0,1,2,3

BENOJ
19
Years of Service
User Offline
Joined: 17th Mar 2006
Location: UK
Posted: 31st Mar 2006 16:56
AHH ok thanks a lot m8 i get ya.

abit fatal1ty an8 sli mobo, ati radeon 1800 XT, 1.5GB RAM
250GB SATA HDD, AMD Athlon 64 x2 4200 (overclocked further)

Login to post a reply

Server time is: 2025-05-23 19:05:36
Your offset time is: 2025-05-23 19:05:36