Moving an object in Turing
Author |
Message |
Don
|
Posted: Sat Jan 17, 2009 12:03 pm Post subject: Moving an object in Turing |
|
|
Ok I need help animating how to move an object from left to right and keep going. Can someone tell me please how to move? Ok here is my program I want to animate across the screen and keep moving until the user closes it.
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
F22.T |
Filesize: |
1.18 KB |
Downloaded: |
83 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
saltpro15
![](http://compsci.ca/v3/uploads/user_avatars/9776171634ced6278d14c2.png)
|
Posted: Sat Jan 17, 2009 12:29 pm Post subject: Re: Moving an object in Turing |
|
|
It would be a lot easier to just find a JPEG image of an F22 and animate that using Input.KeyDown and Sprite.Animate, unless the plane has to be drawn with drawlines?[/syntax]
|
|
|
|
|
![](images/spacer.gif) |
saltpro15
![](http://compsci.ca/v3/uploads/user_avatars/9776171634ced6278d14c2.png)
|
Posted: Sat Jan 17, 2009 12:30 pm Post subject: Re: Moving an object in Turing |
|
|
It would be a lot easier to just find a JPEG image of an F22 and animate that using Input.KeyDown and Sprite.Animate, unless the plane has to be drawn with drawlines?
|
|
|
|
|
![](images/spacer.gif) |
saltpro15
![](http://compsci.ca/v3/uploads/user_avatars/9776171634ced6278d14c2.png)
|
Posted: Sat Jan 17, 2009 12:30 pm Post subject: RE:Moving an object in Turing |
|
|
sorry about the triple post, something went wrong
|
|
|
|
|
![](images/spacer.gif) |
Don
|
Posted: Sat Jan 17, 2009 12:31 pm Post subject: RE:Moving an object in Turing |
|
|
No the plane has to be drawn tho.
|
|
|
|
|
![](images/spacer.gif) |
copthesaint
![](http://compsci.ca/v3/uploads/user_avatars/15853548854c9c056fda48d.jpg)
|
Posted: Sat Jan 17, 2009 12:40 pm Post subject: Re: Moving an object in Turing |
|
|
Ok to do this you need two variables.
1 will move you drawing
1 will switch the position it's going
eg
code: |
var x, direction : int := 0
loop
if direction = 0 then
x+=1
if x >= maxx then
direction := 1
end if
elsif direction = 1 then
x-=1
if x <= 0 then
direction := 0
end if
end if
Draw.FillBox ( x-1, maxy div 2 - 1, x+1, maxy div 2 +1, black)
View.Update
cls
end loop
end loop |
|
|
|
|
|
![](images/spacer.gif) |
Euphoracle
![](http://compsci.ca/v3/uploads/user_avatars/11170373664bf5f25f636f1.png)
|
Posted: Sat Jan 17, 2009 12:45 pm Post subject: RE:Moving an object in Turing |
|
|
If you include a variable to 'add' to the draw coordinates, you can wrap it in a procedure and draw it wherever you want. I used a macro to add them in, and the other code is just garble to move it around in silly ways.
Turing: | setscreen ("offscreenonly")
proc DrawThePlaneHurr (x, y : int)
drawline (50 + x, 200 + y, 120 + x, 220 + y, 16)
drawline (50 + x, 200 + y, 200 + x, 150 + y, 16)
drawline (200 + x, 150 + y, 450 + x, 150 + y, 16)
drawline (450 + x, 150 + y, 565 + x, 180 + y, 16)
drawline (450 + x, 220 + y, 470 + x, 200 + y, 16)
drawline (450 + x, 220 + y, 475 + x, 350 + y, 16)
drawline (475 + x, 350 + y, 530 + x, 350 + y, 16)
drawline (530 + x, 350 + y, 550 + x, 220 + y, 16)
drawline (475 + x, 350 + y, 550 + x, 350 + y, 16)
drawline (550 + x, 350 + y, 580 + x, 220 + y, 16)
drawline (580 + x, 220 + y, 550 + x, 220 + y, 16)
drawline (550 + x, 220 + y, 450 + x, 220 + y, 16)
drawline (510 + x, 220 + y, 580 + x, 170 + y, 16)
drawline (580 + x, 170 + y, 540 + x, 220 + y, 16)
drawline (558 + x, 220 + y, 580 + x, 190 + y, 16)
drawline (580 + x, 190 + y, 595 + x, 200 + y, 16)
drawline (595 + x, 200 + y, 620 + x, 200 + y, 16)
drawline (620 + x, 200 + y, 577 + x, 220 + y, 16)
drawline (450 + x, 220 + y, 280 + x, 220 + y, 16)
drawline (280 + x, 220 + y, 240 + x, 240 + y, 16)
drawline (120 + x, 220 + y, 140 + x, 240 + y, 16)
drawline (190 + x, 259 + y, 240 + x, 240 + y, 16)
drawline (120 + x, 220 + y, 252 + x, 235 + y, 16)
drawline (50 + x, 200 + y, 200 + x, 200 + y, 16)
drawline (200 + x, 200 + y, 210 + x, 187 + y, 16)
drawline (210 + x, 187 + y, 280 + x, 187 + y, 16)
drawline (280 + x, 187 + y, 350 + x, 170 + y, 16)
drawline (350 + x, 170 + y, 470 + x, 200 + y, 16)
drawline (210 + x, 187 + y, 220 + x, 150 + y, 16)
drawarc (190 + x, 239 + y, 50, 20, 90, 180, 16)
end DrawThePlaneHurr
% You can ignore everything below this line, it's just to move it
% around in stupid ways
const R := 10
type Point :
record
x, y : int
end record
fcn P (x, y : int) : Point
var t : Point
t.x := x
t.y := y
result t
end P
fcn GetStep (p, t, r : int) : int
result (abs (t - p ) div r )
end GetStep
fcn NextTarget () : Point
result P (Rand.Int (0, maxx) - 300, Rand.Int (0, maxy) - 125)
end NextTarget
fcn ApproachVal (v, t, s : int) : int
if (v < t ) then
if ((v + s ) > t ) then
result t
else
result (v + s )
end if
elsif (v > t ) then
if ((v - s ) < t ) then
result t
else
result (v - s )
end if
end if
result t
end ApproachVal
proc Approach (var p : Point, var t : Point )
var stepx := GetStep (p.x, t.x, R )
var stepy := GetStep (p.y, t.y, R )
p.x := ApproachVal (p.x, t.x, stepx )
p.y := ApproachVal (p.y, t.y, stepy )
if (((stepx + stepy ) div 2) < 2) then
t := NextTarget ()
end if
end Approach
var position := P (0, 0)
var target := NextTarget ()
loop
Approach (position, target )
cls
DrawThePlaneHurr (position.x, position.y ) % Yeah...
View.Update ()
Time.DelaySinceLast (20)
end loop
|
|
|
|
|
|
![](images/spacer.gif) |
copthesaint
![](http://compsci.ca/v3/uploads/user_avatars/15853548854c9c056fda48d.jpg)
|
Posted: Sat Jan 17, 2009 12:47 pm Post subject: RE:Moving an object in Turing |
|
|
wow someone went over kill lol
were you bored?
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Euphoracle
![](http://compsci.ca/v3/uploads/user_avatars/11170373664bf5f25f636f1.png)
|
Posted: Sat Jan 17, 2009 12:49 pm Post subject: RE:Moving an object in Turing |
|
|
I ripped it from an example collection I'm working on for my peer tutor position at my highschool. Originally... it was a target that you had to throw darts at.
|
|
|
|
|
![](images/spacer.gif) |
copthesaint
![](http://compsci.ca/v3/uploads/user_avatars/15853548854c9c056fda48d.jpg)
|
Posted: Sat Jan 17, 2009 12:49 pm Post subject: RE:Moving an object in Turing |
|
|
lol thats funny
I think that's a bit more then he needed.... :p
|
|
|
|
|
![](images/spacer.gif) |
Don
|
Posted: Sat Jan 17, 2009 12:57 pm Post subject: RE:Moving an object in Turing |
|
|
Turing: | setscreen ("offscreenonly")
proc DrawThePlaneHurr (x, y : int)
drawline (50 + x, 200 + y, 120 + x, 220 + y, 16)
drawline (50 + x, 200 + y, 200 + x, 150 + y, 16)
drawline (200 + x, 150 + y, 450 + x, 150 + y, 16)
drawline (450 + x, 150 + y, 565 + x, 180 + y, 16)
drawline (450 + x, 220 + y, 470 + x, 200 + y, 16)
drawline (450 + x, 220 + y, 475 + x, 350 + y, 16)
drawline (475 + x, 350 + y, 530 + x, 350 + y, 16)
drawline (530 + x, 350 + y, 550 + x, 220 + y, 16)
drawline (475 + x, 350 + y, 550 + x, 350 + y, 16)
drawline (550 + x, 350 + y, 580 + x, 220 + y, 16)
drawline (580 + x, 220 + y, 550 + x, 220 + y, 16)
drawline (550 + x, 220 + y, 450 + x, 220 + y, 16)
drawline (510 + x, 220 + y, 580 + x, 170 + y, 16)
drawline (580 + x, 170 + y, 540 + x, 220 + y, 16)
drawline (558 + x, 220 + y, 580 + x, 190 + y, 16)
drawline (580 + x, 190 + y, 595 + x, 200 + y, 16)
drawline (595 + x, 200 + y, 620 + x, 200 + y, 16)
drawline (620 + x, 200 + y, 577 + x, 220 + y, 16)
drawline (450 + x, 220 + y, 280 + x, 220 + y, 16)
drawline (280 + x, 220 + y, 240 + x, 240 + y, 16)
drawline (120 + x, 220 + y, 140 + x, 240 + y, 16)
drawline (190 + x, 259 + y, 240 + x, 240 + y, 16)
drawline (120 + x, 220 + y, 252 + x, 235 + y, 16)
drawline (50 + x, 200 + y, 200 + x, 200 + y, 16)
drawline (200 + x, 200 + y, 210 + x, 187 + y, 16)
drawline (210 + x, 187 + y, 280 + x, 187 + y, 16)
drawline (280 + x, 187 + y, 350 + x, 170 + y, 16)
drawline (350 + x, 170 + y, 470 + x, 200 + y, 16)
drawline (210 + x, 187 + y, 220 + x, 150 + y, 16)
drawarc (190 + x, 239 + y, 50, 20, 90, 180, 16)
end DrawThePlaneHurr |
Yo this thing doesnt work I even set up new varibles to see if it works but it doesnt give any warning. It doesnt run.
Mod Edit: Remember to use syntax tags! Thanks code: | [syntax="turing"]Code Here[/syntax] |
|
|
|
|
|
![](images/spacer.gif) |
copthesaint
![](http://compsci.ca/v3/uploads/user_avatars/15853548854c9c056fda48d.jpg)
|
Posted: Sat Jan 17, 2009 1:01 pm Post subject: RE:Moving an object in Turing |
|
|
you need to loop this drawing
use my example and it will move your drawing
|
|
|
|
|
![](images/spacer.gif) |
Don
|
Posted: Sat Jan 17, 2009 1:09 pm Post subject: RE:Moving an object in Turing |
|
|
Ok I got it to move then I put in a picture and now its blinks so much that you cant even see. Plus it moves left to right and then right to left. I want it to move from left and keep going on screen.
|
|
|
|
|
![](images/spacer.gif) |
copthesaint
![](http://compsci.ca/v3/uploads/user_avatars/15853548854c9c056fda48d.jpg)
|
Posted: Sat Jan 17, 2009 1:13 pm Post subject: RE:Moving an object in Turing |
|
|
just set it so when the x variable get to like - 1000 then x will = +1000
but this doesn't require 2 variable to move the plan
|
|
|
|
|
![](images/spacer.gif) |
Don
|
Posted: Sat Jan 17, 2009 1:21 pm Post subject: RE:Moving an object in Turing |
|
|
Ok thanks.
|
|
|
|
|
![](images/spacer.gif) |
|
|