Moving Two Balls Simultaneously
Author |
Message |
Pearse
|
Posted: Thu Oct 29, 2009 12:52 pm Post subject: Moving Two Balls Simultaneously |
|
|
What is it you are trying to achieve?
A user can control one ball, while another ball is moving in a fixed direction, looping. The point is that you are suppose to avoid the second ball, and reach the other side of the screen.
What is the problem you are having?
Im able to put the two balls onto the screen, but i cannot move the one that is suppose to move. The one that is moving in the fixed direction is moving properly so far, and i have not added in any collision yet. I want to figure this out first.
Describe what you have tried to solve this problem
Putting the balls in procedures, and calling them.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing: |
var y : int := 200
var x : int := 30
var char1 : array char of boolean
View.Set ("graphics: 400;400")
proc level1
loop
drawline (30, 185, 200, 185, red)
drawline (200, 185, 200, 125, red)
drawline (200, 125, 250, 125, green)
drawline (250, 185, 250, 125, red)
drawline (250, 185, 350, 185, red)
Input.KeyDown (char1 )
if char1 (KEY_RIGHT_ARROW) then
x := x + 10
elsif char1 (KEY_LEFT_ARROW) then
x := x - 10
end if
if x < 30 then
x := 30
elsif x > 350 then
x := 350
elsif y < 0 then
y := 400
elsif y > 400 then
y := 0
end if
drawfilloval (x, y, 15, 15, blue)
delay (50)
cls
end loop
end level1
procedure ball
loop
drawfilloval (x, y, 15, 15, blue)
drawfilloval (225, 150, 15, 15, yellow)
drawline (30, 185, 200, 185, red)
drawline (200, 185, 200, 125, red)
drawline (200, 125, 250, 125, green)
drawline (250, 185, 250, 125, red)
drawline (250, 185, 350, 185, red)
delay (100)
cls
drawfilloval (x, y, 15, 15, blue)
drawfilloval (225, 160, 15, 15, yellow)
drawline (30, 185, 200, 185, red)
drawline (200, 185, 200, 125, red)
drawline (200, 125, 250, 125, green)
drawline (250, 185, 250, 125, red)
drawline (250, 185, 350, 185, red)
delay (100)
cls
drawline (30, 185, 200, 185, red)
drawline (200, 185, 200, 125, red)
drawline (200, 125, 250, 125, green)
drawline (250, 185, 250, 125, red)
drawline (250, 185, 350, 185, red)
drawfilloval (x, y, 15, 15, blue)
drawfilloval (225, 170, 15, 15, yellow)
delay (100)
cls
drawline (30, 185, 200, 185, red)
drawline (200, 185, 200, 125, red)
drawline (200, 125, 250, 125, green)
drawline (250, 185, 250, 125, red)
drawline (250, 185, 350, 185, red)
drawfilloval (x, y, 15, 15, blue)
drawfilloval (225, 180, 15, 15, yellow)
delay (100)
cls
drawline (30, 185, 200, 185, red)
drawline (200, 185, 200, 125, red)
drawline (200, 125, 250, 125, green)
drawline (250, 185, 250, 125, red)
drawline (250, 185, 350, 185, red)
drawfilloval (x, y, 15, 15, blue)
drawfilloval (225, 190, 15, 15, yellow)
delay (100)
cls
drawline (30, 185, 200, 185, red)
drawline (200, 185, 200, 125, red)
drawline (200, 125, 250, 125, green)
drawline (250, 185, 250, 125, red)
drawline (250, 185, 350, 185, red)
drawfilloval (x, y, 15, 15, blue)
drawfilloval (225, 200, 15, 15, yellow)
delay (100)
cls
drawline (30, 185, 200, 185, red)
drawline (200, 185, 200, 125, red)
drawline (200, 125, 250, 125, green)
drawline (250, 185, 250, 125, red)
drawline (250, 185, 350, 185, red)
drawfilloval (x, y, 15, 15, blue)
drawfilloval (225, 210, 15, 15, yellow)
delay (100)
cls
drawline (30, 185, 200, 185, red)
drawline (200, 185, 200, 125, red)
drawline (200, 125, 250, 125, green)
drawline (250, 185, 250, 125, red)
drawline (250, 185, 350, 185, red)
drawfilloval (x, y, 15, 15, blue)
drawfilloval (225, 220, 15, 15, yellow)
delay (100)
cls
end loop
level1
end ball
ball
|
Please specify what version of Turing you are using
Turing 4.1.1 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Murphman
|
Posted: Thu Oct 29, 2009 1:33 pm Post subject: Re: Moving Two Balls Simultaneously |
|
|
I am new to Turing but to save you time and alot of Unnecessary code. You code try breaking it up into for loops. And you probaly know this but to make the one ball that is always moving to not be glicthy you can add in setscreen ("setoffscreenonly") and in the loop add View.Update |
|
|
|
|
![](images/spacer.gif) |
DemonWasp
|
Posted: Thu Oct 29, 2009 1:38 pm Post subject: RE:Moving Two Balls Simultaneously |
|
|
What you want to do is have a drawBall procedure that draws the ball at a single position (not several times with delays in-between, as you have now). Then:
code: |
loop
cls
moveBall ( ball 1 ... )
moveBall ( ball 2 ... )
drawBall ( ball 1 ... )
drawBall ( ball 2 ... )
delay ( 100 )
end loop
|
Then, on each iteration of the outer loop, will move the balls each a slight amount and redraw them. You probably want to give each ball a position and a speed (velocity, to be precise) which you can then base movement speeds off of. |
|
|
|
|
![](images/spacer.gif) |
|
|