 Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki Blog Search Turing Chat Room Members
help with pool       Author Message
thoughtful  Posted: Sat Oct 11, 2003 1:36 am   Post subject: help with pool

Hello,
I am trying to make a pool game for my isp. So far i saw Tony's tutorial. I wrote this code from it. It is supposed to have one ball moving at the start. When the first one hits a second ball, the firs tone stops and the second one starts moving. Now my balls dont move at all. If some one can help me with this, or even show me another way, to make pool, ill be grateful.

====Code Starts====
 code: var balls_x : array 1 .. 7 of int var balls_y : array 1 .. 7 of int var balls_xsp : array  1 .. 7 of int %ball speeds var balls_ysp : array  1 .. 7 of int var distance : real balls_x(1):=0 balls_y(1):=0 balls_xsp(1):=5 balls_ysp(1):=5 for i:2..7 balls_x(i):=Rand.Int(10,(maxx-10)) balls_y(i):=Rand.Int(10,(maxy-10)) balls_xsp(i):=0 balls_ysp(i):=0 end for loop     for i : 1 .. 7         %movement of balls         balls_x (i) += balls_xsp(i)         balls_y (i) += balls_ysp(i)     end for     for i : 1 .. 7         for k : 1 .. 7             if i not= k then                 %calculating distance between                 distance := ((balls_x (i) - balls_x (k)) * (balls_x (i) - balls_x (k)) + (balls_y (i) - balls_y (k)) * (balls_y (i) - balls_y (k))) ** 0.5                 if distance < 10 %if collision                         then                     balls_xsp (i) := round ((balls_x (k) * balls_x (k) + balls_y (k) * balls_y (k)) ** 0.5 * ((balls_x (i) - balls_x (k)) / (balls_x (i) - balls_x (k) + balls_y (i) - balls_y (k))))                     balls_ysp (i) := round ((balls_x (k) * balls_x (k) + balls_y (k) * balls_y (k)) ** 0.5 * ((balls_y (i) - balls_y (k)) / (balls_x (i) - balls_x (k) + balls_y (i) - balls_y (k))))                     balls_xsp (k) := 0 %first ball instantly stops, though in fact it should hit back with                     balls_ysp (k) := 0 %atleast some energy... but we live in a perfect world  :wink:                 end if             end if         end for     end for     for i : 1 .. 7 %for the walls         if balls_x (i) < 10 then             balls_xsp (i) -= balls_xsp (i)         end if         if balls_y (i) < 10 then             balls_ysp (i) -= balls_ysp (i)         end if         if balls_x (i) > (maxx - 10) then             balls_xsp (i) -= balls_xsp (i)         end if         if balls_y (i) > (maxy - 10) then             balls_ysp (i) -= balls_ysp (i)         end if     end for     for i : 1 .. 7         drawfilloval (balls_x (i), balls_y (i), 10, 10, i)     end for end loop

====Code Ends====    Tony  Posted: Sat Oct 11, 2003 2:44 pm   Post subject: (No subject)

well if you set your vector to 10,10 (instead of 5,5) it starts moving. I'm not too sure why though...

Ether way... some things to consider changing:

 code: if balls_x (i) < 10 then             balls_xsp (i) -= balls_xsp (i) end if

for wall collisions... This would with success stop the ball. When you subtract itself from something, you get 0 It should be
 code: balls_xsp(i) *= -1

Invert the value, make it go the other way.

There's something defenatly wrong with the collision. The other ball just FLIES though the table Another thing to consider... with the velocity of over 10, the ball can jump over another ball... You might have to move all the balls pixel by pixel, and use vecolity to determine friction and delay I'd have to admit, that demo I wrote is far from anything good. It was writen a long time ago...

I think Catalyst wrote a pool game in turing, check out submissions section to make sure. Tony's programming blog. DWITE - a programming contest. Homer_simpson  Posted: Sat Oct 11, 2003 3:17 pm   Post subject: (No subject)

this is one i wrote long time ago... but i got bored and didn't finish it... but u might wanna take a look =/
http://www.compsci.ca/v2/viewtopic.php?t=856&highlight=pool thoughtful  Posted: Sat Oct 11, 2003 7:26 pm   Post subject: WEll..

Thnx both of you, well i actually have made pool, in which the balls intercollide & one can shoot the white ball. I havent yet made it so they can fall in the pockets.

Anyways i wanted to know if ne one can tell me an equation to find the real angles,(i.e if the ball hits at a slanted angle the other ball's angle should be different than when it hits at a straight angle)

hope someone know how this can be figured out. I saw tony's tutorial on this, also got his message but couldn't quite get it to work from n e angle. Jus wondering is someone already knows how to do this, else ill have to put my empty head to work Tony  Posted: Sat Oct 11, 2003 7:39 pm   Post subject: (No subject)

well the way I figured... you compare change of X and change of Y values between two balls collided.

The balls vecolity is split up between X and Y components at same ratio of the difference of X and Y values. Tony's programming blog. DWITE - a programming contest. Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First        Page 1 of 1  [ 5 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: