Car help
Author |
Message |
mikeelio
|
Posted: Sun Dec 08, 2013 2:27 pm Post subject: Car help |
|
|
I found how to make a car on turing and i need help on how to make it automatically move this is the example code i used to make my own but plz help how to make it look like its traveling across the screen ive been at this for 2 days now
plz use this example i used to make my own car to help make the movement
drawline (0, 20, 0, 40, 7) %back of the car
drawline (0, 40, 40, 40, 7)
drawline (40, 40, 60, 60, 7)
drawline (60, 60, 120, 60, 7)
drawline (120, 60, 140, 40, 7)
drawline (140, 40, 180, 40, 7)
drawline (180, 40, 180, 20, 7)
drawline (180, 20, 140, 20, 7)
drawoval (120, 20, 20, 20, 7) %front tire
drawline (100, 20, 80, 20, 7)
drawoval (60, 20, 20, 20, 7) %back tire
drawline (40, 20, 0, 20, 7)
drawfill (110, 50, 40, 7) %fills the car
drawfill (120, 20, 7, 7) %fills front tire
drawfill (60, 20, 7, 7) %fills back tire
drawfilloval (120, 20, 10, 10, 0) %front tire inner ring
drawfilloval (60, 20, 10, 10, 0) %back tire inner ring
%%%mirror
drawline (55, 45, 65, 55, 7)
drawline (65, 55, 115, 55, 7)
drawline (115, 55, 125, 45, 7)
drawline (125, 45, 55, 45, 7)
drawfill (90, 52, 54, 7) %fills the mirror |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Zren
![](http://compsci.ca/v3/uploads/user_avatars/1110053965512db6185954b.png)
|
Posted: Sun Dec 08, 2013 2:49 pm Post subject: RE:Car help |
|
|
Let's simplify things first. How do you get a single circle to animate from left to right across the screen?
You draw it in one position, clear the screen then draw it in another position. Example: Stop motion animation. With programming though, we can simplify things, but we'll get to that.
Now before you try to draw each frame like so (This is WRONG WAY to do it):
Turing: |
cls % Clear the screen
Draw.Oval(0, 100, 5, 5, black)
View.Update()
delay(1000 div 60) % Wait a 60th of a second
cls
Draw.Oval(10, 100, 5, 5, black)
View.Update()
delay(1000 div 60) % Wait a 60th of a second
cls
Draw.Oval(20, 100, 5, 5, black)
View.Update()
delay(1000 div 60) % Wait a 60th of a second
cls % Clear the screen
...
|
Now, to do this for a compicated picture would be very aggrevating and take quite a while. You might notice a pattern though, with the first parameter in the Draw.Oval procedure. You could replace those numbers with a variable and use a loop. A for loop to be precise in this case, as only the x coordinate is changing for each frame.
Eg:
Now it's just a matter of making the circle more complicated.
If you've learnt about procedures and passing them arguments, I suggest doing something like so:
Turing: |
procedure drawCar (x: int, y: int)
Draw.Oval(x, y, 5, 5, black)
.. .
end drawCar
for x : 0 .. 100 by 10
cls % Clear the screen
drawCar (x, 100)
View.Update()
delay(1000 div 60) % Wait a 60th of a second
end for
|
|
|
|
|
|
![](images/spacer.gif) |
mikeelio
|
Posted: Wed Dec 11, 2013 11:33 am Post subject: Re: Car help |
|
|
Thx |
|
|
|
|
![](images/spacer.gif) |
|
|