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 / Bullet Question

Author
Message
SFCBias
15
Years of Service
User Offline
Joined: 8th Aug 2009
Location: Hephzibah, GA, USA
Posted: 25th Aug 2009 00:09 Edited at: 25th Aug 2009 00:11
okay, so i have made a simple founction for shooting, but i decided to change it where the player shoots individual "bullets". I made the function where when the user clicks it creates spheres but i can only get on sphere to move at a time(ie i shoot one it moves, but when i shoot another the first one stops and the second one moves) how can i fix that?



nd in the main loop i have dbMoveObject(iBullet,3)
(its just set to 3 for test purposes)
randal
16
Years of Service
User Offline
Joined: 18th Nov 2008
Location:
Posted: 25th Aug 2009 15:17
you have to use dbMoveObject on all your active bullets, not only one.
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 26th Aug 2009 16:44
I have the same exact problem. Randal can you please show how that looks like in code? I really have no idea how to do it.

I just love the smell of code in the morning...
Mista Wilson
16
Years of Service
User Offline
Joined: 27th Aug 2008
Location: Brisbane, Australia
Posted: 26th Aug 2009 17:01
you would have your bullets stored in a container of some sort, lets say, they are represented by a data structure called "BULLET"...you could have a vector of bullets like this :




then you would put some bullets in :



that would provide you with a vector of 10 BULLET objects.
you could then iterate through it when you wanted to move them :



Above is just a very simple way to iterate through a container of objects...(im pretty sure its syntax correct but ive just typed it off the top off my head-use it as an example, I dont think its a very good way to do it, but its easy to expand on the concept)

Of course, a better way would be to build all of the functions that the bullets need into the BULLET structure and just iterate through them once to call an "update" function, that would move them and check for collision and whatever else you wanted them to do.

If it ain't broke.... DONT FIX IT !!!
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 26th Aug 2009 23:03
I'm going to continue this thread, I hope you don't mind SFCBias.
I have a similar problem but in my case the number of bullets is infinite. So i don't know how to set up the "for" function.
I simply wan't my battleship to shoot bullets constantly as you hold down the space button. I've made a separate code just to figure this out so the position of the bullets is not important. The problem is the same as SFCbias' the bullets stop when the next bullet comes out.
here's the code:



Can you please show me how it's done in code? And don't do something complicated, please add it into my code cause otherwise i probably won't understand it, like it didn't Mista Wilsons post.
Thank you!

I just love the smell of code in the morning...
Mista Wilson
16
Years of Service
User Offline
Joined: 27th Aug 2008
Location: Brisbane, Australia
Posted: 27th Aug 2009 00:46
hmm, ok, maybe I can simplifiy the concept I presented above for you, but code-wise, its about as simple as it gets lol

Basically, you need to keep a list somwhere of all of your bullets. You then need to cycle through that list, to move them all. There is no magic command to make all of the sprites/objects or whatever you are using move on their own, you need to actually tell each bullet to move when you want it too.... or setup a function to update them like I said above.

You said you have an infinite amount of bullets, thats not a very good way to have the setup, eventually you will run out of ID's to use with your objects and will have to reset the ID anyway not to mention that eventually you will have more objects than GDK can handle, there is a limit. So you might aswell reuse the objects to save performace of re-creating them over and over, and have a finite list to cycle through.

Check out the DarkDungeon example that comes with GDK. Its a simple FPS, but it has shooting and you could use its technique for your bullets if you wanted to.

If it ain't broke.... DONT FIX IT !!!
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 28th Aug 2009 00:04
Ok i figured it out. Tnx Mista Wilson! I made it work with making the id of the bullet turn back to 0 after it reaches a certain number like 10. So there are only 10 sprites on the screen at the same time.

I just love the smell of code in the morning...
SFCBias
15
Years of Service
User Offline
Joined: 8th Aug 2009
Location: Hephzibah, GA, USA
Posted: 28th Aug 2009 00:22
i actually made a header file quickly that will setup the bullet collision up to 1000 bullets and move each bullet.

if you just set the first bullets ID 301 or higher it will be fine.

NOTE: theres a bug where it checks if the object exists first and if it does than it will move it, if you cant see the problem already , say your map has an ID of 350, then it will move XD

Login to post a reply

Server time is: 2024-11-20 17:35:42
Your offset time is: 2024-11-20 17:35:42