Turbo for a car game
Blitz3D Forums/Blitz3D Beginners Area/Turbo for a car game
| ||
Hi, can someone help me, i need to do a turbo function to a car game, but really don't know how... Thanks! MB |
| ||
(I apologize in advance if this comes across negatively. I'm having a bad morning and normally wouldn't post in this state of mind but you really need to hear this and amend your question.) Your question is difficult to answer/cannot be answered because it isn't asked very well. I see questions like this which are pretty much impossible to answer all the time. Reasons why your question is no good (and which you should correct by posting again) include: it doesn't explain the game you are creating (what do you mean by "car game?") it doesn't explain what you are trying to do (what do you mean by "turbo function?") it doesn't even say if you are working in 2D or 3D. Your post is just generally too vague. In order for anyone to help you need to give us specific information about your problem/what you are trying to do. I really wish the description for this forum (or somewhere newbies would see it) there was a little disclaimer about being as specific as possible when asking questions. ******** Now that that's off my chest, you'll probably end up doing something like this to alter the car's speed when the spacebar is pressed: If KeyDown(57) speed=10 Else speed=5 Endif |
| ||
Please could you give a bit more detail? I am assuming you wish to give the car a burst of speed but only for a short time that takes it above the normal top speed. just briefly, here's a rough idea: Set a variable for the turbo topspeed Set a variable whether turbo is 'on' or 'off' IF nitro remains and keypress=activate turbo THEN turn turbo 'on' If turbo is 'on', ignore topspeed limit, but use turbo topspeed If turbo is 'on' decrease amount of nitro/time left If nitro runs out or time runs out set turbo to off |
| ||
Sorry.... Well i made a turbo for my 3d car race. Car race = just a cube race only for now... The turbo is this function: ; if space hit and have a turbo left If KeyHit( 57 ) And turbo > 0 turbo = turbo - 1 turboAcionado = 1 EndIf then if turboAcionado = 1 in the car movement it get's aceleration + 0.001 (double the value) But i can't do a timecounter to set just 3 seconds for turbo, and then disable the turbo... Help me please! Thanks! MB PS: If my question is a crap please tell me and i'll try to say in other way! |
| ||
try changing acceleration to acceleration# first, so it will handle the float. try this, it checks the system time when turbo is pressed. I inserted And turboAcionado=0to make sre it doesn't keep resetting the timer if you hold Spacebar down. ; if space hit and have a turbo left If KeyHit( 57 ) And turboAcionado=0 and turbo > 0 turbo_timer=millisecs() turbo = turbo - 1 turboAcionado = 1 EndIf then somewhere else in your main loop check to see if 3 seconds have passed. If (millisecs()-turbo_timer)>=3000 then turboAcionado=0 (Assuming turboAcionado=1 for active turbo and =0 for inactive) |
| ||
Thanks, that is much more specific (ie. how to have the turbo only last for 3 seconds.) You will want to do something like Malice described; create a variable to keep track of how long the turbo has been on and shut it off when time is up. Adding to your code... At the top declare a variable called turboLeft. When the key is hit set that to 1000 (or whatever amount you want.) In other words your function changes to: ; if space hit and have a turbo left If KeyHit( 57 ) And turbo > 0 turbo = turbo - 1 turboAcionado = 1 turboLeft=1000 EndIf Then amend the "if turboAcionado..." statment to If turboAcionado=1 aceleration=aceleration+0.001 turboLeft=turboLeft-1 If turboLeft<0 turboAcionado=0 Endif In other words every frame that turbo is applied reduce turboLeft, and if turboLeft drops below 0 switch turbo off. EDIT: cross-post. You could use milliseconds directly as he does but I generally prefer to go off frames. You can figure out how many frames should elapse based on your frame limiting code or, if you use a delta time system like I do, you simply have the amount turboLeft goes down every frame scale according to the framerate. |
| ||
Yeah, like Joe I'm a little wary of using millisecs directly - what if the computer has a hiccup, or the game loses focus for some reason? You don't want to steal the poor player's turbo. |