Turing Pong Help (bounce)
Author 
Message 
turingplop

Posted: Tue Jan 09, 2018 9:24 am Post subject: Turing Pong Help (bounce) 


What is it you are trying to achieve?
I am trying to do 2 things. One, I need to find out how to make a ball bounce on the paddles and not go through them. Two, I need to know how to display a variable on the screen to keep score every time the ball hits the edges.
What is the problem you are having?
The problem is that I don't know how to do these things.
Describe what you have tried to solve this problem
I haven't tried anything as I don't want to ruin my code that I already wrote.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
setscreen ("graphics:800;600,offscreenonly")
var x, y, a, b, r, q, e, w,u,i,ustep,ystep , istep,qstep, wstep, xstep, random200 : int
var chars : array char of boolean
function Collision (x1 : int, y1 : int, x2 : int, y2 : int, xcircle : int, ycircle : int, radius : int) : int
var closestX : int
var closestY : int
if (xcircle > x2) then
closestX := x2
elsif (xcircle < x1) then
closestX := x1
else
closestX := xcircle
end if
if (ycircle >= y2) then
closestY := y2
elsif (ycircle <= y1) then
closestY := y1
else
closestY := ycircle
end if
put closestX, " ", closestY
if ((closestX  xcircle) * (closestX  xcircle) + (closestY  ycircle) * (closestY  ycircle) <= radius * radius) then
if closestX = x1 or closestX = x2 then
if closestY = y1 or closestY = y2 then
result 3
else
result 1
end if
else
result 2
end if
else
result 0
end if
end Collision
%%
q := 300
w := 150
qstep := 3
wstep := 3
u := 300
i:= 150
ustep:=3
istep:=3
x := 300
y := 150
xstep := 3
ystep := 3
loop
cls
Input.KeyDown (chars)
if chars (KEY_DOWN_ARROW) then
w := w  5
q := q  5
end if
if chars ('w')then
u:=u+5
i:=i+5
end if
if chars ('s') then
u:=u5
i:=i5
end if
if chars (KEY_UP_ARROW) then
w := w + 5
q := q + 5
end if
r := 50
if (x > 800  r) then
x:= 400
y:= 300
end if
if (x < r) then
x:= 400
y:= 300
end if
if (y > 600  r) then
ystep := ystep
end if
if (y < r) then
ystep := ystep
end if
x := x + xstep
y := y + ystep
drawfilloval (x, y, r, r, green)
drawfillbox (20, q, 40, w, 11)
drawfillbox (780, u, 760, i, 11)
if (y > 100 and y < 200 and x < 70 and x > 5) then
xstep := xstep
end if
if (q > 100 and q < 200 and w < 70 and w > 5) then
qstep := qstep
end if
View.Update
delay (17)
end loop
%%
cls
Input.KeyDown (chars)
if chars (KEY_F1) then
w := w  2
q := q  2
end if
if chars (KEY_UP_ARROW) then
w := w + 2
q := q + 2
end if
w := w + w
View.Update
drawfillbox (20, w, 40, w+100, 11)
if (w > 100 and q < 200 and q < 70 and q > 5) then
qstep := qstep
end if
View.Update
delay (17)
Turing: 
<Add your code here>

Please specify what version of Turing you are using
The best one.






Sponsor Sponsor



TokenHerbz

Posted: Wed Jan 10, 2018 3:58 am Post subject: RE:Turing Pong Help (bounce) 


i don't get what you are doing, you have to visualize how turings graphical interface is, how the objects (circle/rectangles) are generated, then use logic to counteract that to make it work how you want it to.
you seem to have alot of useless variables for a pong game, all you require is the following:
score
paddleX
paddleY
paddleXSize
paddleYSize
ballX
ballY
ballSize
ballXspeed
ballYspeed
paddleYSpeed
(double paddle vars for 2nd paddle)
check how turing draws these by pressing F10 or F9?? and searching the function.
reember where x,y vals are for the paddle/ball and how they are created make sure to add or subtract those as required for the collosion check. (dont forget their X/Y sizes)
if you do need more direction post i wont be so avoident. cheers. GL
Furthermore, if your not able to write code that reads itself, which alot of people esp new cant, please use comments to help others assist in debugging.
you can use those by placing these %%% and write what that section/variable is used for/purpose.







