Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
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:=u-5
i:=i-5
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:

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

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
ballX
ballY
ballSize
ballXspeed
ballYspeed

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.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 2 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: