managing bullets

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
WSPSNIPER
Chaos Rift Regular
Chaos Rift Regular
Posts: 145
Joined: Sun Jan 03, 2010 6:19 pm
Current Project: top down shooter
Favorite Gaming Platforms: ps3
Programming Language of Choice: c++

managing bullets

Post by WSPSNIPER »

hi i was thinking about how i was going to handle bullets in a game im writing. i use to just do a for loop checking every bullet against every entity and i was wondering if you had a faster method of doing this. it is going to be a top down shooter so the bullets will be traveling in different directions. thanks for your time :)
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: managing bullets

Post by Ginto8 »

look up quadtrees. That is all.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
hurstshifter
ES Beta Backer
ES Beta Backer
Posts: 713
Joined: Mon Jun 08, 2009 8:33 pm
Favorite Gaming Platforms: SNES
Programming Language of Choice: C/++
Location: Boston, MA
Contact:

Re: managing bullets

Post by hurstshifter »

Do a search for things like "handling bullets" or "projectiles". I've seen many topics like this one on this forum in the past year or two. If I can find any I will post the links.
"Time is an illusion. Lunchtime, doubly so."
http://www.thenerdnight.com
User avatar
WSPSNIPER
Chaos Rift Regular
Chaos Rift Regular
Posts: 145
Joined: Sun Jan 03, 2010 6:19 pm
Current Project: top down shooter
Favorite Gaming Platforms: ps3
Programming Language of Choice: c++

Re: managing bullets

Post by WSPSNIPER »

Ginto8 wrote:look up quadtrees. That is all.

Thanks
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: managing bullets

Post by eatcomics »

Make sure you always have a full clip in your weapon, and make sure you have at least 3 other fully loaded clips on you. Hopefully you also have an emergency side arm, I have found this to be the best method of bullet management, and it is highly effective against the zombie menace
Image
User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

Re: managing bullets

Post by ibly31 »

Haha eatcomics, thats what I thought he was talking about. When I first saw this I'm like "WTF, uuhmm, aim for heads, dont spray..." isn't that kind of obvious?
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
User avatar
WSPSNIPER
Chaos Rift Regular
Chaos Rift Regular
Posts: 145
Joined: Sun Jan 03, 2010 6:19 pm
Current Project: top down shooter
Favorite Gaming Platforms: ps3
Programming Language of Choice: c++

Re: managing bullets

Post by WSPSNIPER »

eatcomics wrote:Make sure you always have a full clip in your weapon, and make sure you have at least 3 other fully loaded clips on you. Hopefully you also have an emergency side arm, I have found this to be the best method of bullet management, and it is highly effective against the zombie menace

lol, im sorry i may not have clearly stated the question. i ment managing bullets as in handling collisions and such in the code...
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: managing bullets

Post by eatcomics »

I knew what you meant, but it was late and i thought someone explained it... just look on this forum and on google there are a LOT of tutorials on the subject, once you wrap your head around it it becomes second nature... But I could be more helpful if you would explain what kind of game you are doing? Like a 2D space shooter or 3D FPS and so on

Edit: oh you said top down shooter... really I think your method should be efficient enough, but as ginto said quadtrees would be helpful as well
Image
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: managing bullets

Post by Ginto8 »

eatcomics wrote:really I think your method should be efficient enough, but as ginto said quadtrees would be helpful as well
It could be. But as there are probably going to end up being both a large number of bullets and entities simultaneously active, the chances of a naive bruteforce being efficient is low. A correctly populated and sorted quadtree can significantly reduce the number of collision tests he does, and will also be a good learning experience (quadtrees and their 3D companions octtrees are used a ton in game dev).
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: managing bullets

Post by eatcomics »

yep, and I didn't even know about them until recently... But you are certainly right that is why I suggested it along with you. and there are ways you could optimize it to only check things on screen and such if that's what you want, but quad trees are definitely my suggestion
Image
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: managing bullets

Post by Ginto8 »

eatcomics wrote:yep, and I didn't even know about them until recently... But you are certainly right that is why I suggested it along with you. and there are ways you could optimize it to only check things on screen and such if that's what you want, but quad trees are definitely my suggestion
Well unless things are only alive when they're on the screen, you want to check more than just the screen, because otherwise you can have all sorts of mess ups with the game logic (for example, you walk away from an NPC and the npc walks into/through a wall, and suddenly your collision has a seizure when it comes back onscreen because it doesn't know how to handle it).
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: managing bullets

Post by eatcomics »

this was about bullet collision, not NPC I was suggesting just deleting them offscreen. That's also not foolproof but it would work, and for some game types that's the way it should be done

edit: but to elaborate, for your needs quadtrees would be the best solution
Image
Post Reply