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.

DarkBASIC Discussion / Just some questions of organization

Author
Message
Dark Asmodeous
19
Years of Service
User Offline
Joined: 21st Feb 2007
Location:
Posted: 22nd Feb 2007 04:08
After my last fit of frustration with Dark Basic had me leave it for another day, I'm once again trying to make some headway.

On to the question. Recently I started making a program based on the early monster hunter tutorial lessons for the sake of understanding collision, making better use of For To statements, and better understanding functions, and my current project, and problem, has to do with "bullets".

I began by asking myself the initial questions of how I would control object deletion, speed of fire, collision detection, and all fo these basics, and in the end I was forced to ues the same code for each bullet and simply have the condition that the previous bullet had already been flagged as on and that a crtain amount of time had passed, here is my code for this subroutine (called with space):



My question is, can I do this more efficiently?

I disagree.
Krilik
20
Years of Service
User Offline
Joined: 16th Mar 2006
Location: Arizona, USA
Posted: 23rd Feb 2007 06:26 Edited at: 23rd Feb 2007 06:32
Yup, you can.

The best way to do it would be to create a loop and check all your bullets that way.

I would set it up into three parts, one part will handle creating the bullet, the other part will handle moving bullets that already exist, and the third will detect if the bullet has hit anything.

To create a bullet you'll need to check if your shoot button is fired like you do in your original code, then you can send your program to a subroutine.

So something like this:



For the createbullet subroutine you'll need to check a range of bullets so you don't accidently create a bullet that exists already. The best way to do this is to define a variable that you'll use as your bullet number and increment it one everytime you create a bullet so then next bullet will have a different number. You should also try and specify a range of numbers so you don't create an infinte amount of bullets using up all your object numbers. So with the example I'm going to show you, you should define the variable bullet# before you run your game and set it to 800.

So your subroutine should look something like this:



Next you need to move your bullet. This can be done with a loop, I like using a For loop because its easier for me to work with. What a For loop will do is repeat a loop a set number of times. In this case we need to repeat it 50 times for all 50 bullets.

So like this:



And lastly you need to check to see if your bullet has hit something. Using the same concept of moving the bullet all you would need to do is remove the move object command and replace it with your collision detection code.

So:



I would put all those into subroutines and call them once during your main loop. You may also want to check to see if your bullet already exists when creating it, so your program doesn't run into any errors. And maybe make it a bit more flexible so you can check the bullet distance with an array and delete bullets that are out of range.
Zotoaster
21
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 23rd Feb 2007 14:04
It would be GOSUB, not GOTO lol. I don't recommend GOTOs, noone does actually. I once didn't pass a computing excercise because I used GOTO.

Use functions

Dark Asmodeous
19
Years of Service
User Offline
Joined: 21st Feb 2007
Location:
Posted: 23rd Feb 2007 17:22
Thanks for the reply!

I won't get a chance to test it out right away, I just got vista so I need to wait for my new copy of DBP to get here

I disagree.
Krilik
20
Years of Service
User Offline
Joined: 16th Mar 2006
Location: Arizona, USA
Posted: 24th Feb 2007 00:12
Quote: "It would be GOSUB, not GOTO lol. I don't recommend GOTOs, noone does actually. I once didn't pass a computing excercise because I used GOTO."


Whoops. You're right. I gotta stop posting when I need sleep.
NanoGamez guy
19
Years of Service
User Offline
Joined: 13th Jan 2007
Location: Closer than you think...
Posted: 24th Feb 2007 19:01 Edited at: 2nd Mar 2007 17:17
You could store the data (e.g. position) in an array or a series of arrays. An array is basically a list of variables that you can access by saying the number of the variable stored in the array.
So you'd have to make the arrays, like this:



Note: I made the variable 'numbullets' because if you want to change the number of bullets you can just change it, rather than having to change4 all of the numbers.

note: You can make more arrays like 'bulletspeed'

Next you'd want to dtect when to make the bullet. You could use the creatbullet subroutine but store the position in the arrays. Like this:



Note: The reason we have the array 'bulletexist' is because we can use it later in the game if needs be.

I'll let you do the rest. Remeber, the good thing about arrays is that they are very good in for loops. Like this:



[edit] woops I just saw you post saying that you've just got DBP! oh well, mabye it'll be usefull to you or someone who sees this post.

I can see you...
TDK
Retired Moderator
23
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 2nd Mar 2007 03:35
Quote: "dim bulletexist(bullet)=1
dim bulletxpos#(bullet)=gunx#
dim bulletypos#(bullet)=guny#
dim bulletzpos#(bullet)=gunz#
"


What's with all the = bits on the end of the dimensioning?

TDK_Man

NanoGamez guy
19
Years of Service
User Offline
Joined: 13th Jan 2007
Location: Closer than you think...
Posted: 2nd Mar 2007 17:16
wwps! sorry, just forgot to take away the 'dim's! sorry!

I can see you...

Login to post a reply

Server time is: 2026-07-05 22:39:16
Your offset time is: 2026-07-05 22:39:16