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 / Making a dodging game - need some help, random factor

Author
Message
Zaibatsu
18
Years of Service
User Offline
Joined: 1st May 2006
Location: Lost in Thought
Posted: 4th Oct 2007 01:48
Anyways as the title says, I'm making a simple dodging game where the camera is behind the player, and you have to move left and right to dodge the incoming cubes. I have some of the code already done, but as the title indicated, I need help with the random factor.

Go ahead and test the code to see what it's like.



I want those red boxes to come towards the player like that in random positions in 1,5 second time intervals.

can someone please help me with this? keep in mind I don't want someone to just do it and leave, I want them to explain it so I can do stuff like it in later, better, more complicated projects.

Thank you in advance,

Brett Snow.

"I admire its purity, a survivor, unclouded by conscience, remorse, or delusions of morality"

PresFox
19
Years of Service
User Offline
Joined: 28th Aug 2005
Location:
Posted: 4th Oct 2007 10:16
For random youd use the rand command, inside your main loop, add a timer that runs a gosub to launch a new box every 1.5 seconds. In that gosub youd generate a random number between the values you want, and spawn the box at that point

youd have to edit your movement code too though, to move all boxes on the screen

Microsoft isnt evil, they just make really crappy operating systems -- Linus torvalds
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 4th Oct 2007 16:48
Here's a couple of code lines that will help you...

RANDOMIZE TIMER()

will ensure your game is different every time

RND(3000)

would pick a number between 1 and 3000. So...

RND(3000) + 2000

would pick a number between 2000 and 3000. As the timer works in milliseconds, you can work out from this how to create random times.

Insert Name Here
17
Years of Service
User Offline
Joined: 20th Mar 2007
Location: Worcester, England
Posted: 4th Oct 2007 19:08 Edited at: 4th Oct 2007 19:08
Quote: "RND(3000) + 2000"

Shouldn't that be RND(1000) + 2000?

Quote: "Everyone's entitled to an opinion...but your opinions are wrong."

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 4th Oct 2007 23:28
yes...and no. The typo is the "between 2000 and 3000" should read "between 2000 and 5000"

Zaibatsu
18
Years of Service
User Offline
Joined: 1st May 2006
Location: Lost in Thought
Posted: 5th Oct 2007 00:38 Edited at: 5th Oct 2007 18:56
Quote: "Here's a couple of code lines that will help you...

RANDOMIZE TIMER()

will ensure your game is different every time

RND(3000)

would pick a number between 1 and 3000. So...

RND(3000) + 2000

would pick a number between 2000 and 3000. As the timer works in milliseconds, you can work out from this how to create random times.
"


Thanks, that would help if I understood how to use timers in the slightest.

EDIT:

I don't know how to use timers in the slightest. can someone help please.

"I admire its purity, a survivor, unclouded by conscience, remorse, or delusions of morality"

Login to post a reply

Server time is: 2024-09-27 05:18:01
Your offset time is: 2024-09-27 05:18:01