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 / Massive Amounts of Bullets! Any ideas how to handel? Game Design

Author
Message
Timidon
19
Years of Service
User Offline
Joined: 26th Jun 2005
Location: Bakersfield, Ca. USA.
Posted: 1st Apr 2006 07:50
Now that I got the camera placed for my starfighter game. I the ship sails across the cube starfield. Next step is to have the ship open it's gun ports and fire..

Todays Question: What is a good way to handle lots of bullets. In some games I see allot of bullets flying around

1) Would it be a good idea to make a big array just to hold bullet information? like speed, position try and guestimate how many I will have flying around at any one time? This is what I am kinda leaning at doing. Does Anybody got any other sudgestions?

There are many answers but just one question" ~ Jerilith the Mad
Mikey P
19
Years of Service
User Offline
Joined: 23rd May 2005
Location: Manchester, UK
Posted: 1st Apr 2006 16:21
How I do it in DarkBasic, which will probably be alot easier in C++, is have a big UDT array of bullets like you say, say the array is big enough to handle 300 bullets, and one of the fields in my UDT is Status, and when I make a bullet, I set the status of it to 1.
When creating the bullet, I loop though the array to find a slot where Status = 0, and stick my bullet there. I then loop through my array when I'm drawing everything and if Bullets(i).Status = 1 then I update/draw the bullet. If it collides I kill the bullet and set Status to 0 so that the slot can be used for another bullet later

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 1st Apr 2006 18:18
You could use a vector and include an 'active' flag in your bullet structure, or you could use a list and insert/delete elements.

Vector will allow you to increase the size at runtime if needed, but will use a fixed amount of space, while list will grow and shrink as needed, but memory allocation costs you in your main loop, and you might suffer from memory fragmentation.

You could also experiment with 2 lists - an active list and a free list, and move items between them. That would remove the allocation/fragmentation issues at the cost of a little more complexity.

For free Plug-ins and source code http://www.matrix1.demon.co.uk
Timidon
19
Years of Service
User Offline
Joined: 26th Jun 2005
Location: Bakersfield, Ca. USA.
Posted: 1st Apr 2006 21:12
Thanks, I will poke at both of these to see what happens. Good ideas!

There are many answers but just one question" ~ Jerilith the Mad

Login to post a reply

Server time is: 2024-11-19 05:39:00
Your offset time is: 2024-11-19 05:39:00