
-----------------------------------
PhOtO!
Sat May 21, 2005 1:46 pm

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..

-----------------------------------
illu45
Sat May 21, 2005 1:48 pm


-----------------------------------
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:


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!
Sat May 21, 2005 2:11 pm


-----------------------------------
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.

--------------------------------------------------------------------------
setscreen ("graphics")
loop
% Court lines


drawfill (500,360,9,9)                      
drawfillbox (400,700,405,235, 0)

drawfillbox (200,700,590,705,0)
drawfillbox (150,240,650,235,0)


drawline (150,235,200,700,0) 
drawline (151,235,201,700,0)
drawline (152,235,202,700,0)
drawline (153,235,203,700,0)
drawline (154,235,204,700,0)

drawline (650,235,590,700,0) 
drawline (649,235,589,700,0)
drawline (648,235,588,700,0)
drawline (647,235,587,700,0)
drawline (646,235,586,700,0)


%Net
drawline (180,468,615,468,0) %Horizontal lines
drawline (180,467,615,467,0)
drawline (180,477,615,477,0)
drawline (180,487,615,487,0)
drawline (180,497,615,497,0)





drawline (184,497,184,467,0) %Vertical lines
drawline (194,497,194,467,0)
drawline (204,497,204,467,0)
drawline (214,497,214,467,0)
drawline (224,497,224,467,0)
drawline (234,497,234,467,0)
drawline (244,497,244,467,0)
drawline (254,497,254,467,0)
drawline (264,497,264,467,0)
drawline (274,497,274,467,0)
drawline (284,497,284,467,0)
drawline (294,497,294,467,0)
drawline (304,497,304,467,0)
drawline (314,497,314,467,0)
drawline (324,497,324,467,0)
drawline (334,497,334,467,0)
drawline (344,497,344,467,0)
drawline (354,497,354,467,0)
drawline (364,497,364,467,0)
drawline (374,497,374,467,0)
drawline (384,497,384,467,0)
drawline (394,497,394,467,0)
drawline (404,497,404,467,0)
drawline (414,497,414,467,0)
drawline (424,497,424,467,0)
drawline (434,497,434,467,0)
drawline (444,497,444,467,0)
drawline (454,497,454,467,0)
drawline (464,497,464,467,0)
drawline (474,497,474,467,0)
drawline (484,497,484,467,0)
drawline (494,497,494,467,0)
drawline (504,497,504,467,0)
drawline (514,497,514,467,0)
drawline (524,497,524,467,0)
drawline (534,497,534,467,0)
drawline (544,497,544,467,0)
drawline (554,497,554,467,0)
drawline (564,497,564,467,0)
drawline (574,497,574,467,0)
drawline (584,497,584,467,0)
drawline (594,497,594,467,0)
drawline (604,497,604,467,0)
drawline (614,497,614,467,0)


%tabletennis ball
drawfilloval (50,300,5,5,12)


%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
Sat May 21, 2005 3:42 pm


-----------------------------------
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!
Sun May 22, 2005 9:48 am


-----------------------------------
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
Sun May 22, 2005 10:01 am


-----------------------------------
Make your own distance function:


function MathDistance (x1, y1, x2, y2 : real) : real
  result ((x2 - x1) **2 + (y2 - y1)**2) ** 0.5
end MathDistance


-----------------------------------
PhOtO!
Sun May 22, 2005 4:52 pm


-----------------------------------
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
Sun May 22, 2005 5:02 pm


-----------------------------------
That would be exactly like explaining how to use Math.Distance.  I'll leave that to [url=http://www.compsci.ca/v2/viewtopic.php?t=75]the second post, by Tony, in Dan's collision detection tutorial.

-----------------------------------
StarGateSG-1
Tue May 24, 2005 11:24 am


-----------------------------------
As I was scrolling down there is this ugly thing.


drawline (284,497,284,467,0) 
drawline (294,497,294,467,0) 
drawline (304,497,304,467,0) 
drawline (314,497,314,467,0) 
drawline (324,497,324,467,0) 
drawline (334,497,334,467,0) 
drawline (344,497,344,467,0) 


Lots of these way to many, this isn't related to your problem but you need to do somethign like this!


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!
Tue May 24, 2005 4:02 pm


-----------------------------------
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
Tue May 24, 2005 4:05 pm


-----------------------------------
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

drawline (150,235,200,700,0)
drawline (151,235,201,700,0)
drawline (152,235,202,700,0)
drawline (153,235,203,700,0)
drawline (154,235,204,700,0) 

for i:1..5
drawline(strint("15"+intstr(i)),235,strint("20"+intstr(i)),700,7)
end for

-----------------------------------
PhOtO!
Tue May 24, 2005 5:01 pm


-----------------------------------
arite thanks alot bacchus i got it now

-----------------------------------
Cervantes
Tue May 24, 2005 6:02 pm


-----------------------------------
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

drawline (150,235,200,700,0)
drawline (151,235,201,700,0)
drawline (152,235,202,700,0)
drawline (153,235,203,700,0)
drawline (154,235,204,700,0) 

for i:1..5
drawline(strint("15"+intstr(i)),235,strint("20"+intstr(i)),700,7)
end for
Right, but why so complicated?

for i : 0 .. 4
  drawline (150 + i, 235, 200 + i, 700, 0)
end for


-----------------------------------
Bacchus
Tue May 24, 2005 6:07 pm


-----------------------------------
lol ya i screwed up with the numbers 1..5 oops didnt see the 0 in 150   :oops: 
 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!
Tue May 24, 2005 8:07 pm


-----------------------------------
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..

-----------------------------------
PhOtO!
Thu May 26, 2005 10:02 am


-----------------------------------
ok, in the tutorial, the x and y cooridinates of the circles, or the things that have to be colided are random. How can i make the x and y coordinates be where i move my mouse?
