Posted: Sat May 21, 2005 1:46 pm Post subject: Need help with tabletennis program
Hey..wha'ts up
I'm trying to create a tabletennis program on turing. So far i got the tabletennis table and my paddle moving where i want it to move with the mouse. I'm having problems with how to hit the ball with my paddle..
If anyone knows how to fix this prob. please help me..
Sponsor Sponsor
illu45
Posted: Sat May 21, 2005 1:48 pm Post subject: (No subject)
well, I've never made a tabletennis program, but since I'm guessing you're using co-ordinates to draw the ball, use an if statment:
code:
if Ballx+Ballradius = PaddleX and Bally+Ballradius = PaddleY then
%make ball change direction
end if
Something like that... As I said, I've never tried table tennis before...
Could you let us see what you've got so far, and what exactly you're having problems with?
PhOtO!
Posted: Sat May 21, 2005 2:11 pm Post subject: (No subject)
Thanks for the reply.. but i havn't used turing too long, and i don't really the help you gave me...
kk this is my program so far,
can you tell me how i can add the hint you gave me in the program? I suppose i'll have to use memory cells, and i haven't really learned how to use memory cells in graphics mode.
%moving the paddle with mouse
var x, y, button : int
mousewhere (x, y, button)
if y < 450 then
drawfilloval (x,y,25,30,12)
delay (100)
drawfilloval (x,y,25,30,9)
end if
end loop
------------------------------------------------------------------------
MysticVegeta
Posted: Sat May 21, 2005 3:42 pm Post subject: (No subject)
You need to use Math.Distance to determine when the ball hits the pad. Also, Press F10, go under index, and then locate Music.PlayFileLoop and see the second example. It has a bouncing star on angles of the screen, you might need that for the ball.
PhOtO!
Posted: Sun May 22, 2005 9:48 am Post subject: (No subject)
thanks for the help, but i have turing 4.01 and it doesn't have the command math.distance. And the example from the Music.PlayFileLoop doesn't work either, i think it's because of the version.
Please help me if you know how to solve the prob. in 4.01, or if you have a version those commands work on, can you please send it to me by mail at tanweer_bhayani@hotmail.com
Thanks alot..
Cervantes
Posted: Sun May 22, 2005 10:01 am Post subject: (No subject)
Make your own distance function:
Turing:
function MathDistance (x1, y1, x2, y2 :real):real result((x2 - x1)**2 + (y2 - y1)**2)** 0.5 end MathDistance
PhOtO!
Posted: Sun May 22, 2005 4:52 pm Post subject: (No subject)
ok, i created the mathdistance function but i'm not too sure on how to use it. Can u please tell me how i can use it and where to use it in my program.
thanks for the reply..
Cervantes
Posted: Sun May 22, 2005 5:02 pm Post subject: (No subject)
Lots of these way to many, this isn't related to your problem but you need to do somethign like this!
code:
var x1,y1,x2,y2 : int
for i : 1.. 'how ever many lines you have'
drawline (x1,y1,x2,y2,0)
end for
You need to fix that, well not fix but more improve.
I understand you haven't done turing in a while but that is one stepyou must take to get back in the grove.
PhOtO!
Posted: Tue May 24, 2005 4:02 pm Post subject: (No subject)
Thanks for the help cervantes, I'm still having some problems with it, but i'll probably be able to figure it out in some time.
and stargate, i'm still trying to figure out how to use your help. I know it looks really long and ugly like this.
ok this is an example from my program i changed, but there still seems to be something wrong with it.
for i : 1..5
a := a + 1
drawline (150+a,235,200+a,700,0)
end for
Can u please send me an example from my program.
k thanks
var a : int := 1
Bacchus
Posted: Tue May 24, 2005 4:05 pm Post subject: (No subject)
uhh, those drawlines all have diff coords, he would have to use the variable from the for statment to change the placement of the line. sice the change is constant its quite easy
for i:1..5
drawline(strint("15"+intstr(i)),235,strint("20"+intstr(i)),700,7)
end for
PhOtO!
Posted: Tue May 24, 2005 5:01 pm Post subject: (No subject)
arite thanks alot bacchus i got it now
Cervantes
Posted: Tue May 24, 2005 6:02 pm Post subject: (No subject)
Bacchus wrote:
uhh, those drawlines all have diff coords, he would have to use the variable from the for statment to change the placement of the line. sice the change is constant its quite easy
for i:1..5
drawline(strint("15"+intstr(i)),235,strint("20"+intstr(i)),700,7)
end for
Right, but why so complicated?
Newer:
for i : 0 .. 4
drawline (150 + i, 235, 200 + i, 700, 0)
end for
Bacchus
Posted: Tue May 24, 2005 6:07 pm Post subject: (No subject)
lol ya i screwed up with the numbers 1..5 oops didnt see the 0 in 150
but at first i started to use strint and stuff cause i was going to do the middle number change but the bit i copied changed the last number, and now i can even realize the i could have done i*10 for that lol. i over think things way to much
PhOtO!
Posted: Tue May 24, 2005 8:07 pm Post subject: (No subject)
yea.. i used the same way u did cervantes.. oh yea and i'm still having troubles with using the math distance command.. can you give me an example of how i can use it in my program pls?..
thanks..