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 / Tracking and making bullets

Author
Message
negi
13
Years of Service
User Offline
Joined: 16th Feb 2011
Location:
Posted: 4th May 2012 04:02
Hay I am trying to make a simple shooter game like Alien shooter, but cannot seem to find a way to make and track bullets when your firing a gun, how do you do this? I am totally stumped

Thanks for any help

All is revealed with time.
DeadTomGC
13
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 6th May 2012 17:18 Edited at: 6th May 2012 17:31
Well, I would recommend this. Make and array of size, um... 200? something pretty big. Then, define an end var that is a location in the array. Then, when you update all the bullets, you start at the 0 location in the array and end at the end location in the array. If a bullet is created, move the end forward one, and when a bullet is destroyed, delete the info on it, move the info on the bullet at location end to the location of the deleted bullet and then move end back one.

This process will minimize the processing you need to do, and it will allow you a max of 200 bullets at one time.

Here is a picture explaining the process.

BTW, you may want to use a 2D array to store necessary info on the bullets. Or you could use a sort of array of classes. I forget what they are called. The same basic principle will apply though.

EDIT:fixed I think


Attachments

Login to view attachments
negi
13
Years of Service
User Offline
Joined: 16th Feb 2011
Location:
Posted: 6th May 2012 23:04
I totally understand how to do this now thank you so much you were a great help

All is revealed with time.
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 12th May 2012 03:05
Here is a discussion on the subject:
http://forum.thegamecreators.com/?m=forum_view&t=192871&b=22
This method will allow you to have multiple bullets (almost infinite) that can travel independantly and can be destroyed in any sequence. This is, of course, not the only way to do it, but it's the most flexible/dynamic. The "linked list" is a well tested method. The huge array is useful only if you have a maximum number you will be dealing with and you will have to search the array for an empty spot when creating a new bullet.

The fastest code is the code never written.
DeadTomGC
13
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 14th May 2012 21:57
Quote: "you will have to search the array for an empty spot when creating a new bullet."


No, actually, the next spot to use will always be stored in a variable.
There is very little processing that actually needs to be done. However, it does have a size limit, and it takes up quite a bit of memory(I've never had a memory issue though).


Login to post a reply

Server time is: 2024-04-24 01:03:47
Your offset time is: 2024-04-24 01:03:47