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 Professional Discussion / Bullet data in arrays...

Author
Message
Soyuz
22
Years of Service
User Offline
Joined: 17th Dec 2002
Location:
Posted: 16th Jan 2003 00:44
I have made an array Type that will store bullet data as bullets are created when player shoots his weapon. As it stands the array will store data for up to 500 bullets. Now I don't want to have to have to check all 500 entries of the array if there are only say 5 bullets on the screen and hence only 5 entries being used. Problem is that as it stands I do not know how the program will know which entries are "alive" and which are "dead".

I thought maybe I could create an array whereby I always add new bullets to the top of the array and hence the old ones are pushed down. Then when a bullet is dead i remove it from the array and push the old ones back up. I thought that to do this I could use 'array insert at top' and 'array delete element', but when I tried this I ended up getting all sorts of weird stuf going down, duplicate entries and entries being overwritten. Is this the wrong use for these commands?

I'd post my code but I've messed it up so much trying to get this working!
Arrow
22
Years of Service
User Offline
Joined: 1st Jan 2003
Location: United States
Posted: 16th Jan 2003 01:33
Why are you using an array? Why not use something simplar.

This is Truth!
This is my Belief!
...at least for now.
Dr OcCuLt
22
Years of Service
User Offline
Joined: 27th Nov 2002
Location: a Dark Deep Dark pit, it dark in here
Posted: 16th Jan 2003 01:37
i trying to make one too but i can`t get it to work all the time i post the code a day or 2 ago on HELP ARRAYS !!!!!!!!!!!

--Dr 0--
Dr OcCuLt
22
Years of Service
User Offline
Joined: 27th Nov 2002
Location: a Dark Deep Dark pit, it dark in here
Posted: 16th Jan 2003 01:40
what is this simpla thing you talking about
Arrow
22
Years of Service
User Offline
Joined: 1st Jan 2003
Location: United States
Posted: 16th Jan 2003 01:49
I don't know the terms yet but something like:

clipA = 8
totalbulletsA = 100

when gunA fires then clipA = clipA - 1

if clipA = 0
if totalbulletsA > 0
if totalbulletsA >= 8
clipA = 8
totalbulletsA = totalbulletsA - 8
else clipA = totalbulletsA
totalbulletsA = 0
else print 'Damn, empty'

This is Truth!
This is my Belief!
...at least for now.
Arrow
22
Years of Service
User Offline
Joined: 1st Jan 2003
Location: United States
Posted: 16th Jan 2003 01:49
damn, it didn't space at all, let me try again

This is Truth!
This is my Belief!
...at least for now.
Arrow
22
Years of Service
User Offline
Joined: 1st Jan 2003
Location: United States
Posted: 16th Jan 2003 01:50


This is Truth!
This is my Belief!
...at least for now.
Dr OcCuLt
22
Years of Service
User Offline
Joined: 27th Nov 2002
Location: a Dark Deep Dark pit, it dark in here
Posted: 16th Jan 2003 02:06
i hate to say this but that code do`s bullets in the clip this is about bullets flying in the space
Arrow
22
Years of Service
User Offline
Joined: 1st Jan 2003
Location: United States
Posted: 16th Jan 2003 02:51
Ah ha ha ha... I'll shut-up now.

This is Truth!
This is my Belief!
...at least for now.
Soyuz
22
Years of Service
User Offline
Joined: 17th Dec 2002
Location:
Posted: 16th Jan 2003 02:56
I'll have a crack at a different approach tomorrow which I think may work, unless there's a solution posted here. If so, Occult, I'll let you know what I do - if it works!
Soyuz
22
Years of Service
User Offline
Joined: 17th Dec 2002
Location:
Posted: 16th Jan 2003 15:23
Well this may not be the best way of doing it and there are a few potentials for error, such as if there are more than 500 bullets in your scene at one time...but these can be ironed out withot too much bother. I guess if there are 32 ships in a scene each firing 10 rounds a second then it is highly likely you'd have more than 500 bullets pretty rapidly - except the game would probably slow down stupidly at this point so there'd need some way to prevent this...some kind of bullet cap. I don't know what yet.

Still this works hunky dory at the mo.



Obviously need to declare the array type.
Soyuz
22
Years of Service
User Offline
Joined: 17th Dec 2002
Location:
Posted: 16th Jan 2003 15:24
Hmmm I suggest copying this in to DBPro so it don't look quite so ugly!
Soyuz
22
Years of Service
User Offline
Joined: 17th Dec 2002
Location:
Posted: 16th Jan 2003 15:27
I guess you'd also want the bullet's initial velocity to match that of your aircraft plus the nozle velocity
Soyuz
22
Years of Service
User Offline
Joined: 17th Dec 2002
Location:
Posted: 16th Jan 2003 15:27
Well If it's an fps you're doing then this wouldn't be so relevant
the architect
22
Years of Service
User Offline
Joined: 6th Jan 2003
Location: United Kingdom
Posted: 16th Jan 2003 21:35
I know what you mean about the array stacks etc. I thought an array that what reduced or increased as required would be ideal but found that It seems to go pair shaped. I created routines to see how it would and to be honest.
The routine I wrote should have displayed 1-10 down screen.
ARRAY INSERT AT TOP() produces the same as ARRAY INSERT AT BOTTOM(). I expected it to reverse the result?????

Soyuz
22
Years of Service
User Offline
Joined: 17th Dec 2002
Location:
Posted: 16th Jan 2003 21:43
Yep I tried the 1-10 thing too. I ended up with:

array(0)=10
array(1)=6
array(2)=6
array(3)=7
array(4)=7
array(5)=8
array(6)=8 etc

Well something odd like that but it weren't right that's for sure!
Dr OcCuLt
22
Years of Service
User Offline
Joined: 27th Nov 2002
Location: a Dark Deep Dark pit, it dark in here
Posted: 17th Jan 2003 03:02
i got the code work white the array delete element and ARRAY INSERT AT BOTTOM



--Dr 0--
Dr OcCuLt
22
Years of Service
User Offline
Joined: 27th Nov 2002
Location: a Dark Deep Dark pit, it dark in here
Posted: 17th Jan 2003 18:27
i sorry but the code i`v just posted has an ERROR in it
but i`v fixt it now

Dr OcCuLt
22
Years of Service
User Offline
Joined: 27th Nov 2002
Location: a Dark Deep Dark pit, it dark in here
Posted: 18th Jan 2003 14:50
there is bug in ARRAY INSERT AT BOTTOM if the array moves thing in an array and then you add a bullet uesing ARRAY INSERT AT BOTTOM it loss sum data in the array for no good reson?

i got to test thing more be for posting them

--Dr 0--
Fluffy Paul
22
Years of Service
User Offline
Joined: 16th Dec 2002
Location: United Kingdom
Posted: 20th Jan 2003 19:17
A couple things to bear in mind is that you don't need to check every single bullet in the game in every frame.

What I advise is that you keep one array, one stack and one list:
The array is called BulletData(b) where b is the index of the bullet who's data you need to look up.

The stack is freeBullets(n,b) where b is the index of that bullet in the data array. When the game first runs ALL of the bulles will be in this stack.

The list is busyBullets(n,b) where n is the postion in the list and b refers to BulletData(b) where you go look up the bullet info.

Every frame (aka program cycle) you check to see if you need more bullets (e.g. a player has fired a gun or something) if so then you pop a bullet off the freeBullets stack and add the b it held to the list of bullets in use.
Update the bullets positional (and orientation data if required for any other purpose) data in the BulletData(b) array.

Once you have popped all the new bullets you loop through the busyBullets(n,b) list moving all the bullets and checking for collision. If any of the bullets are dead then hide the objects and delete them from the busyBullets list and push them back on the freeBullets(n,b) stack.

This way you will only ever have to perform one loop for the bullets and it will only deal with the ones that need attention - no pointless looping through unused bullets.

What do you reckon?

Ending a sentence with a French word is so passé
Fluffy Paul
22
Years of Service
User Offline
Joined: 16th Dec 2002
Location: United Kingdom
Posted: 20th Jan 2003 19:29
An additoinal note on BulletData(b)

BulletData(b) is an array of a user defined type. The type I recommend is "BulletInfo" defined below.



You loop through the active bullets looking up their BulletInfo(b).BulletObject and move it + check for collision. If there's a collision then you hide the bullet and delete its b value from the BusyBullets(n,b) list by deleting everything at index n. Then you push that same b value onto the freeBullets(n,b) stack etc... etc...

When you get a collision, for example, you look up the damage that bullet does with BulletInfo(b).Damage and it'll return the damage value.

I hope that's clearer.

Ending a sentence with a French word is so passé
Dr OcCuLt
22
Years of Service
User Offline
Joined: 27th Nov 2002
Location: a Dark Deep Dark pit, it dark in here
Posted: 21st Jan 2003 00:24
this is a bit of an odd way of doing it,i do`t now why u need a freeBullets stack it a bit of over kill if you ask me the best way of doing at the until the ARRAY INSERT AT bug get fix`t is to



this is simpla then uesing list and stack to track the bullets in the the array

--Dr 0--
Hilmi2k
22
Years of Service
User Offline
Joined: 29th Nov 2002
Location:
Posted: 21st Jan 2003 09:05
I am somehow not convinced of this system of loading 500 objects and having a limit of 500 bullets.

It feels primitive.

How do they do it in unreal tournament where you might have eveybody in the room firing away with mini guns? I am sure things quickly get out of hand the programers would run out of bullets in the code if they were doing it that way.

How do they creat bullets on demand? do they load a new bullet when required? doesnt that entail a performance hit?

Basicaly, I'm sure there is a better way out there.
Dr OcCuLt
22
Years of Service
User Offline
Joined: 27th Nov 2002
Location: a Dark Deep Dark pit, it dark in here
Posted: 21st Jan 2003 21:33
you coud make a template bullet then copy it in to the array when a shot is fired the true is that a lot of game like unreal ues INTERSECT OBJECT for most bullets and only ues the arrays for slow move easy to see bullet like Rockets and crossbow bots.

Login to post a reply

Server time is: 2025-05-19 04:34:25
Your offset time is: 2025-05-19 04:34:25