Please, need help with a driving simulation
Author |
Message |
talyboy
|
Posted: Fri Jun 06, 2008 10:44 pm Post subject: Please, need help with a driving simulation |
|
|
I have to create the illusion that my car is driving. To do this i'm moving the yellow bars down my screen. My variable "speed" goes down and up depending on whether the user clicks on the up or down arrow keys. My problem is moving the actual yellow bar. The bar moves down using increments of variable "speed". But for some reason, even though you can see the speed going up in the speedometer, the actually yellow rectangle does not move faster. How come? Can anyone help PLEASE!!!!!!!!!!
Quote: procedure userInput
var speed : int := 0
var horizontalLocation : int := 0
var key : string (1)
var delaySpeed : int
delaySpeed := 90 - speed
drawfillbox (0, 0, 704, 704, 26) %The road
drawfillarc (100, 0, 75, 75, 0, 180, 2) %Original speedometer
locate (43, 13)
put speed .. %original drawing of speed
loop
loop
%Gets keyboard input
getch (key)
%Measures speed (up and down arrows)
if key = chr (200) and speed < 640 then %Up arrow key
speed := speed + 1
delay (0) %Acceleration speed. delay (0) means 0 - 80 km/h in 3 seconds.
elsif key = chr (208) and speed > 0 then %Down arrow key
speed := speed - 1
end if
drawfillarc (100, 0, 75, 75, 0, 180, 2) %Drawing the speedometer
locate (43, 13)
put speed .. %Changing speed
%Measures horizontal placement on screen (left and right arrows)
if key = chr (205) and horizontalLocation < 200 then %Right arrow key
horizontalLocation := horizontalLocation + 10
elsif key = chr (203) and horizontalLocation > 0 then %left arrow key
horizontalLocation := horizontalLocation - 10
end if
drawfillbox (300, 700-1*speed, 325, 640-1*speed , 26)
drawfillbox (300, 699-1*speed, 325, 639-1*speed, 14)
delay (60 - speed)
end loop
end loop
end userInput
userInput
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
DemonWasp
|
Posted: Thu Jun 12, 2008 8:31 pm Post subject: RE:Please, need help with a driving simulation |
|
|
This is a logic problem. You appear to be drawing the yellow line with one of these calls:
This is your problem. Instead of always starting from the base coordinates of 700 to 640 (or 699 to 639, whichever), you need to keep track of where each line is (use a variable).
Essentially, the reason it doesn't move any faster is because "speed" isn't being used as a speed - it's being used as an offset.
What you want is more along these lines (pseudocode...don't copy-paste and expect it to work):
code: |
var lineY : int := 700
var lineLength : int := 60
...
loop
% Other drawing stuff
% Yellow Median drawing stuff
lineY = lineY - speed
drawfillbox (300, lineY, 325, lineY-lineLength , 26)
end loop
|
Of course, you'll have to figure out what happens when that line gets to the bottom of the screen, and also what happens when it should go behind the dashboard and so on. But that's a start. |
|
|
|
|
![](images/spacer.gif) |
|
|