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.

Newcomers DBPro Corner / need help with my laser routine

Author
Message
zootan
14
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 12th Apr 2010 21:34
hi , im my space game i need to make my laser beam firing routine for many ships at the same time, but i want them to be independantly firing (not all at the same time) my code works for just one ship very well and i even coded this for 30 ships to fire independantly but the long way ie typing out 30x the code and altering for each ship object number at least i got to see it working as i wanted but now i need to move on and wish there to be maye 100 or more ships possibly firing at once how can i do this but only have to write one functon for all ships ? for my lasers im using an object made with 2 plains with red texture possitioned at each ship position , to fire them i made a counter and when counter is lesthan 15 the laser object scales up its z axis , so i need to make a function that will make a counter for each ship .Any help would be welcome thanks.
Gingerkid Jack
19
Years of Service
User Offline
Joined: 15th May 2005
Location: UK
Posted: 12th Apr 2010 23:12
why dont you use a variable called otherships and set it to like 500, then when you check them you could use a for, next loop or a inc otherships, 1 which will increase the object number.

Gingerkid Jack - Aspiring Game Designer\3d Modeler
zootan
14
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 13th Apr 2010 07:00
could you give me an example please ?
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 13th Apr 2010 15:15
zootan,

100 ships firing at one time would be hard to avoid!

Typically, I will write a function or subroutine to accept input from human players and will write a separate function / subroutine for AI firing of missiles. Another function / subroutine is then written to move them and check collision.

You will need an array at minimum (or could use TYPE variables, which is better, but is a more advanced topic) to hold the values of the positions and other data about the missiles.

Please post the working code you have.

zootan
14
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 13th Apr 2010 20:41
ive looked at the array intro but i cant apply what is shown to what i need, could someone show me how to structure an array to make my counters?
zootan
14
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 13th Apr 2010 22:18
hmmm would it look something like this?...


dim counters(4)
counter(1)=200
counter(2)=200
counter(3)=200
counter(4)=200
for eng1 = 10000 to 10004
for eng2 = 20000 to 20004
if object collision ((eng1),(eng2))= 1
dec counter(eng1-10000),.01
if counter(eng1-10000)=<0 then counter(eng1-10000)=200
endif
next eng1
next eng2

am i on the right track ?this isnot a code snip just a basic idea.
zootan
14
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 14th Apr 2010 10:01
OK i got it now
dim counter(29)
counter(0)=200
counter(1)=200
counter(2)=200
counter(3)=200
counter(4)=200
counter(5)=200
counter(6)=200
counter(7)=200
counter(8)=200
counter(9)=200
counter(10)=200
counter(11)=200
counter(12)=200
counter(13)=200
counter(14)=200
counter(15)=200
counter(16)=200
counter(17)=200
counter(18)=200
counter(19)=200
counter(20)=200
counter(21)=200
counter(22)=200
counter(23)=200
counter(24)=200
counter(25)=200
counter(26)=200
counter(27)=200
counter(28)=200
counter(29)=200

do
for eng1 = 10100 to 10114
for eng2 = 20100 to 20114
if object collision (eng1,eng2)=1
counter(eng1-10100)=counter(eng1-10100)-1
if counter((eng1)-10100)=<0 then counter((eng1)-10100)=200
if counter((eng1)-10100)< 15 then scale object ((eng1)+100),100,100,500
if counter((eng1)-10100)> 15 then scale object ((eng1)+100),100,100,0
endif
next (eng1)
next (eng2)
loop
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 14th Apr 2010 18:22
First off, please use the edit button instead of making multiple posts. Secondly, when posting code on the forum, click the CODE button, copy and paste your code and then click the CODE button again.

I put together some basic code to try and help you with this, as I don't think what you have posted will work. Please bear in mind, you cannot simply plug this code into the editor and run it as is. It is a framework to help you and you will need to add your player object and stuff to it in order for it to work. I have added comments to the code to help you with it. If you have questions or need further assistance, please post them again.



zootan
14
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 15th Apr 2010 05:25
why dont u think it will work? fyi my code is working perfectly well, the array i eventualy got my head around works fine , i even set it multy dim so it holds the counter value and a shield value . Its been so long that i banged my head on the wall over arrays and now the penny droped i cant think how it confused me so much .
BTW i already made a missile and projectie demo long time ago projectile worked with multiple ships no problem unlike the lasers because it didnt use a timer .
and thanks but alot of that you wrote is unneccesary , i dont have a "player object" ect , to use your code i would need to totaly change my program ive already made missile and bullet codes and now i can DO arrayS my program will be able to incorporate them no probs . (HELP IS ACTUALY ONLY HELPFUL IF ITS NEEDED SO PLEASE READ POSTS CAREFULY)
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 18th Apr 2010 06:25 Edited at: 18th Apr 2010 06:26
Hey, just a tip instead of writing all of this:



You could do this:



Could save some time . Good luck with your game!

<-- Spell based team dueling game!
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK

Login to post a reply

Server time is: 2024-11-23 16:42:28
Your offset time is: 2024-11-23 16:42:28