METAL: Circle collisions
Swap velocities but do something like this:
so you loose some speed.
also maybe you should have a max speed you can hit the ball with. If you have 2 screens like I do you can drag the mouse way to far away and it wizzes around until at least 1 ball go's in the hole.
Code:
if sprite collides(ball1,ball2) then swap b1xs*.9,b2xs : swap b1ys*.9,b2ys
also maybe you should have a max speed you can hit the ball with. If you have 2 screens like I do you can drag the mouse way to far away and it wizzes around until at least 1 ball go's in the hole.
Here's a simple code:
Assuming the vx1,vy1 and vx2,vy2 are the horizontal and vertical speeds of the objects,
if theycollide then
swap vx1,vx2
swap vy1,vy2
endif
Now don't forget that the balls should loose speed all the time (or they will move til the end of days!). Use something like
vx1=vx1*0.9
vy1=vy1*0.9
in your mainloop. Experiment with the value (0.9) to get it looking realistic.
By the way, you got the code of FLOWMOTION, check that, there the blocks also swap speed, but they don't get slower.
Hope that helped.
Assuming the vx1,vy1 and vx2,vy2 are the horizontal and vertical speeds of the objects,
if theycollide then
swap vx1,vx2
swap vy1,vy2
endif
Now don't forget that the balls should loose speed all the time (or they will move til the end of days!). Use something like
vx1=vx1*0.9
vy1=vy1*0.9
in your mainloop. Experiment with the value (0.9) to get it looking realistic.
By the way, you got the code of FLOWMOTION, check that, there the blocks also swap speed, but they don't get slower.
Hope that helped.
That works great for boxes or rectangles, but for a pool game those physics don't cut it. Do you know what I mean kemal?
for elastic collisions
yes I am aware there are a lot of unneccesary variable defining in there.
Code:
if(Hit(b1,b2)) //if hit, bounce them
{
double n[2]={b1>Xb2>X,b1>Yb2>Y};
double v1[2]={b1>XV,b1>YV};
double v2[2]={b2>XV,b2>YV};
double v3[2];
double v4[2];
double temp[2];
double m=magnitude(n);
double a1,a2;
double optp;
n[0]/=m; //normalize n
n[1]/=m;
a1=dot(v1,n,2);
a2=dot(v2,n,2);
optp=(2.0*(a1a2))/(2*circmass);
temp[0]=optp*circmass*n[0];temp[1]=optp*circmass*n[1];
v3[0]=v1[0]temp[0];v3[1]=v1[1]temp[1];
v4[0]=v2[0]+temp[0];v4[1]=v2[1]+temp[1];
b1>XV=v3[0];b1>YV=v3[1];
b2>XV=v4[0];b2>YV=v4[1];
}
yes I am aware there are a lot of unneccesary variable defining in there.
I don't program in C, but will that code work for a pool game (are the physics correct, or is that just another way to get it to kinda work)
You're right, my example works only for square objects.
When the objects are round, the angle has to be considered.
What I can think of, without knowing the correct physics, is:
Draw a line between the two centers of the balls. This is the angle which has to be added to the angle of the movement of both balls I think.
In order to calculate this, you have to get away from the simple xspeed and yspeed rule and use a total speed and an angleparameter. Then you can switch the angles and speeds when the balls collide, detect the hitangle (from the centers of the balls) and add that to both angles. That should work fine.
But, other idea: I think there are a lot of standardpoolgames outside. Why not do one with squareballs? "Squool"? Maybe I'll adapt Flowmotion to that, should be very easy indeed.
When the objects are round, the angle has to be considered.
What I can think of, without knowing the correct physics, is:
Draw a line between the two centers of the balls. This is the angle which has to be added to the angle of the movement of both balls I think.
In order to calculate this, you have to get away from the simple xspeed and yspeed rule and use a total speed and an angleparameter. Then you can switch the angles and speeds when the balls collide, detect the hitangle (from the centers of the balls) and add that to both angles. That should work fine.
But, other idea: I think there are a lot of standardpoolgames outside. Why not do one with squareballs? "Squool"? Maybe I'll adapt Flowmotion to that, should be very easy indeed.
I see what you mean by the angel/velocity oposed to xy velocitys, but I have already came up with a solution to the problem. Here is what I have with ball i and j colliding.
balls(i,1) is the x location
balls(i,2) is the y location
balls(i,3) is the x speed
balls(i,4) is the y speed
v(i,whatever) = the new speed of the ball (added at the end of the loop)
This code works actualy pretty good, the pool game is realistic and you can cut balls and give them specific angles, just like in real life.
balls(i,1) is the x location
balls(i,2) is the y location
balls(i,3) is the x speed
balls(i,4) is the y speed
v(i,whatever) = the new speed of the ball (added at the end of the loop)
This code works actualy pretty good, the pool game is realistic and you can cut balls and give them specific angles, just like in real life.
Code:
ix = balls(i,1)
jx = balls(j,1)
iy = balls(i,2)
jy = balls(j,2)
v(i,3) = v(i,3) + ((ixjx)/16)*sqr(balls(j,3)^2+balls(j,4)^2)+.05+((iyjy)/16)*balls(i,3)
v(i,4) = v(i,4) + ((iyjy)/16)*sqr(balls(j,3)^2+balls(j,4)^2)+.05+((ixjx)/16)*balls(i,4)
v(j,3) = v(j,3) + ((jxix)/16)*sqr(balls(i,3)^2+balls(i,4)^2)+.05+((jyiy)/16)*balls(j,3)
v(j,4) = v(j,4) + ((jyiy)/16)*sqr(balls(i,3)^2+balls(i,4)^2)+.05+((jxix)/16)*balls(j,4)
That's good!
I'm currently making the FLOWMOTION game with music, sound and gfx assets. It's really cool.
What will you do with the Poolgame when finished?
I'm currently making the FLOWMOTION game with music, sound and gfx assets. It's really cool.
What will you do with the Poolgame when finished?
I don't know what I am going to do with it when Im finished. I might add some trick shots and give it away as freeware on my site.
Are you going to make your new game shareware kemal?
Are you going to make your new game shareware kemal?
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
How would you do *real* collisions?  leRiCl  3  4,368 
Mar 19, 2007 05:29 PM Last Post: Aressera 

METAL  Graphics with OSX / LCDs  wardd13  4  4,304 
Oct 26, 2006 02:39 PM Last Post: bronxbomber92 

multiple "done:'s" in Metal BASIC?  john8520  2  3,876 
Feb 6, 2006 03:37 PM Last Post: Leisure Suit Lurie 

METAL and tiger  mika  4  4,704 
Jun 9, 2005 12:05 PM Last Post: mika 

METAL: Grabbing jpegs  DudetheCreator  4  5,680 
Mar 12, 2005 03:48 PM Last Post: hazelden 