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 / Using RND between specific values ??

Author
Message
JesterDev
21
Years of Service
User Offline
Joined: 22nd Jun 2003
Location:
Posted: 15th Jul 2003 04:32
I have two rows or sprites, that I want to shot at random times. They are numbered 100 - 116. How would I use RND to use just the numbers between 100 and 116 and tell which one shot?

Here's some sample code:


This only shoots a bullet from one sprite. But what I want to do is add 1 to fired untill it reaches 16 then: Gosub Bullets which pastes the bullet sprites back in place to be fired again. Any ideas?
andrew11
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 15th Jul 2003 04:49
Here's a pretty simple function. You can take it out of the function if you want. I just used it to make it easier to understand.



Rnd() goes from 0 To whatever's between the (). I just find the difference of the lowest and highest, and add the lowest back on.

"All programmers are playwrites and all computers are lousy actors" -Anon
Carlitos
21
Years of Service
User Offline
Joined: 8th Jul 2003
Location: United States
Posted: 15th Jul 2003 15:20
Or you can even simplify it even more and do

this will make the number stay in the hundreds place and also add 0-16 to it
Hope that hlps
--carlitos
JesterDev
21
Years of Service
User Offline
Joined: 22nd Jun 2003
Location:
Posted: 16th Jul 2003 02:59 Edited at: 16th Jul 2003 03:01
Thanks for the help.

Is there a way I can tell which sprite number was randomly chosen?
I need to know so that I can work out the collision. My current method just tells me that the sprite dosent exist.

First I paste the sprites for the top row:


Then I try and detect the collision:


I know this would work if I put the first code into the loop, but that's needlesly creating the bullets over and over.

Carlitos
21
Years of Service
User Offline
Joined: 8th Jul 2003
Location: United States
Posted: 16th Jul 2003 15:24
Well, is the code from an anemy or a player?
If its from an enemy::
1)You might want to figure out how often to shoot, or only when the enemy gets close.
2)If its firing often then, hmmmm, let me just make a short tutorial for you...be back...

--carlitos
Carlitos
21
Years of Service
User Offline
Joined: 8th Jul 2003
Location: United States
Posted: 16th Jul 2003 16:12
Here it is a quick little tutorial i came up with for ya, hope it helps.

--carlitos
JesterDev
21
Years of Service
User Offline
Joined: 22nd Jun 2003
Location:
Posted: 18th Jul 2003 01:44
Thank you. That was very helpful.

Login to post a reply

Server time is: 2024-11-24 23:05:40
Your offset time is: 2024-11-24 23:05:40