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 car stop when out of gas?

Author
Message
sskethan
16
Years of Service
User Offline
Joined: 20th Sep 2008
Location: Oshawa, ON. Canada
Posted: 4th Jan 2010 05:17
Hello,
I bought DBP a long time back but just started into it this month. I'm trying to put together a driving game. Here is some of the code i have picked up from the forums here and pieced together. My question is how would i make the car stop when the fuel gauge reached empty and go again when the fuel is refilled?
Please and Thank you

Attachments

Login to view attachments
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 4th Jan 2010 11:11
something like this


where you have the throttle control put in something like



the above has not been tested but I think you might get how to use it.

Dark Physics makes any hot drink go cold.
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 4th Jan 2010 11:21
I guess creating a variable called Fuel# with some value at start let's say Fuel#=100.0.

Then put
If Fuel#>0.001 then Fuel#=Fuel#-0.001
at the beginning of the Do-Loop

and put
If Fuel#<0.001 then return
at the beginning of the driveCar: sub-routine

Or:
create a specific sub-routine for car stopping when Fuel# is below a certain value:

pseudo code:
If Fuel#<0.001 then slow down car till stop

my 2 cents
cheers
sskethan
16
Years of Service
User Offline
Joined: 20th Sep 2008
Location: Oshawa, ON. Canada
Posted: 4th Jan 2010 19:01
Thank you for the ideas.
I still can't seem to make the car stop.
I was thinking of maybe a simpler way that if the fuel reached zero then the brake would be applied and if the fuel was above 0 the the brake would be released. But im not sure how to get the keystate to apply when the fuel reaches 0. something like...
if CurHp# < MaxHP# then keystate(57)=1
if CurHP# > MaxHP# then keystate(57)=0
but ofcourse that doesnt work
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 5th Jan 2010 13:18
You can stop the car or whatever, just updating variable to zero while pressing a key.



learning every day
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 5th Jan 2010 17:54 Edited at: 5th Jan 2010 17:54
Quote: "I was thinking of maybe a simpler way that if the fuel reached zero then the brake would be applied"


That's overcomplicating it.

As has already been said, simply use a variable which holds the starting amount of petrol/gas and only allow the user to use the accellerator if that value contains a value greater than 0 (zero).

When the player uses the accellerator, then deduct a tiny amount from the fuel variable. An on-screen display can show how much is left 'in the tank'.

When the fuel runs out, disable the accellerator and friction/gravity slows the car to a halt.

Using this method, you also have the ability to stop the car on a petrol station square which refills the tank while you sit there.

TDK

Daniel wright 2311
User Banned
Posted: 5th Jan 2010 19:39 Edited at: 5th Jan 2010 19:43
if you put the gas vallue to 100, then do this

if gas=1 to 100 and upkey()=1
move car 3,3
endif

if gas=0 then move car 3,0

its truly this easy

edit: you also should subtact the value of the gas as the upkey is pressed to, this way you run out of gas

if upkey()=1 then gas=gas-1

sskethan
16
Years of Service
User Offline
Joined: 20th Sep 2008
Location: Oshawa, ON. Canada
Posted: 6th Jan 2010 01:34
Ohh I got it .. Thank you everyone .. great group here.

Login to post a reply

Server time is: 2024-09-28 14:27:40
Your offset time is: 2024-09-28 14:27:40