Author Topic: Pool  (Read 6513 times)

0 Members and 1 Guest are viewing this topic.

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 336
  • Karma: 15
  • kiss that sound that pounds your senses
    • View Profile
    • Facebook
Pool
« on: February 10, 2007 »


Wow.. I just needa finish Green Boxcopter - then I have finished a game...
I will do this later, because'a I'm'a tryin' ta mak'a pool game'a.

Basic information:
  There are 15 balls (one black, 7 red, 7 yellow) with one white ball;
  I have the visuals of the table;
  I have set up a check system to see what each balls status is (current position, direction, etc.);
  Hopefully I can be taught how to make circlular collisions with defractions of the balls to the angle where the white ball has hit them.

I have the visuals - like normal I code the easy stuff. I just need to make it so the balls collide and rebound of of each other and stuff like that.
I won't be able to put the code up for awhile because I have it on the other - non internet connected computer.
When I get it on this computer, I will post it. But in the mean time, hopefully someone can give me a low down on making balls collide and rebound and stuff. And to make it so the balls go off on angles porportional to where they have been hit? Dig it??? (Hope so!)
Also, I am having real trouble with the white ball collisions... when I hit it (I have coded a little bit on breaking, with the power of the hit decreasing as it rolls, and decreasing more if it hits a wall), it is hitting the top of the table and turning right? Not suppose to happen as it hasn't hit a side wall yet?
Also, if someone would be kind enough to teach me how to make it so that you can more you 'cue' (I think that's the stick?) around in a circle, and to hit the ball of on an angle?

I will try and get the code up here as soon as I can... most probably tomorrow (hopefully)

Thanks.
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Online Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5098
  • Karma: 380
    • View Profile
Re: Pool
« Reply #1 on: February 10, 2007 »
Fryer put quite a bit of work into this problem a few years ago.  I don't think we were particularly satisfied with the results.  It's not too bad colliding one ball against another, but when you have a pack of balls it can be very difficult.

Post it up and we can all have a look.

Jim
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 16787
  • Karma: 439
  • evil/good
    • View Profile
    • My Homepage
Re: Pool
« Reply #2 on: February 10, 2007 »
If you can solve the problems of a game like this Clanky, I will personally give you a +50 Karma boost! Whatever happens, you'll learn a lot from it!! If you manage to impliment top and backspin and sidespin properly I'll boost your Karma by 100.

A great project. I can forsee problems of balls geting stuck inside each other etc... *shudders*
Shockwave ^ Codigos
Challenge Trophies Won:

Offline rdc

  • Pentium
  • *****
  • Posts: 1480
  • Karma: 138
    • View Profile
    • Clark Productions
Re: Pool
« Reply #3 on: February 10, 2007 »

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3052
  • Karma: 174
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Pool
« Reply #4 on: February 10, 2007 »
I would be delighted to help you on this one, in fact if you dont mind it being a team effort I would be happy to take on half the burden. I have already attempted a pool game not as far as putting backspin on the cue but got all the balls bouncing around correctly things went to pot for me when I thought it would be nice to make it 3D. Anyway I will type my old one out on the PC (its on my memory card atm) if you want a look at the code. I will post it here if you do.

Edit: Pool game attached at last. Graphics are a little modified from Clankys, It was the swept collision between the balls and the walls that held the whole show up, Sorry for the long wait. Thanks to everyone who had helped to make this happen.

Better late than never ;D
« Last Edit: October 14, 2009 by rain_storm »

Challenge Trophies Won:

Online Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5098
  • Karma: 380
    • View Profile
Re: Pool
« Reply #5 on: February 10, 2007 »
Nice link rdc - in snooker it can be simplified a bit because all the balls are the same size and you can just set both ball masses to 1 and ignore them.

Jim
Challenge Trophies Won:

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 336
  • Karma: 15
  • kiss that sound that pounds your senses
    • View Profile
    • Facebook
Re: Pool
« Reply #6 on: February 11, 2007 »
Ok, heres the visual side of the game... I had to make the power and shot code just for this demo - it only goes straight ahead. but, it isn't really calculated at all... it's only the visuals.

Thanx for everything guys.
And I agree, this will be heaps hard... and I did think about having spin and stuff - I will see if i can make it so you have a ball with the position of where the cue will hit the ball on a side panel.

Hopefully this can be a DBF Team Game.
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 336
  • Karma: 15
  • kiss that sound that pounds your senses
    • View Profile
    • Facebook
Re: Pool
« Reply #7 on: February 11, 2007 »
Thanx rcd... that page has really inspired me to make this game!
I did year 12 physics, so the momentum aspects of the collisions were a flash back *cries in happyness*... good Mr. Newton with his fundemental law for momentum - "after collision: both balls will have equal magnitude with opposite direction..." or something (and hopefully Mr. Newton's law)
I actually had two books complete on physics - with loads of information about collisions and momenta... but, there gone - bummer!!!
I guess this will be hard...
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Online Stonemonkey

  • Pentium
  • *****
  • Posts: 1215
  • Karma: 92
    • View Profile
Re: Pool
« Reply #8 on: February 11, 2007 »
This was as far as I got with this, exe and source for b3d but it doesn't use b3d collisions or anything like that. I never quite worked out the right way of calculating the results of the sphere-sphere collisions but it works fairly well.

http://www.stonemonkie.pwp.blueyonder.co.uk/pool3d_3.zip

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 16787
  • Karma: 439
  • evil/good
    • View Profile
    • My Homepage
Re: Pool
« Reply #9 on: February 11, 2007 »
Holy shit Fryer! That's mentally good! Check your Karma.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Paul

  • Pentium
  • *****
  • Posts: 1490
  • Karma: 47
    • View Profile
Re: Pool
« Reply #10 on: February 11, 2007 »
I did a simple ball bounce code for a fire demo(haven't posted it because i haven't got any music to go with it). but it doesn't work to well, probably not well enough at all.  :(

the .exe is really nice and works perfectly but the sourcecode freezes







« Last Edit: February 11, 2007 by Paul »
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Online Stonemonkey

  • Pentium
  • *****
  • Posts: 1215
  • Karma: 92
    • View Profile
Re: Pool
« Reply #11 on: February 11, 2007 »
Sorry about that Paul. atm I don't have b3d installed so i'd probably been messing around with something at the time of working on it. I'll look out something that works.

Online Stonemonkey

  • Pentium
  • *****
  • Posts: 1215
  • Karma: 92
    • View Profile
Re: Pool
« Reply #12 on: February 11, 2007 »
installed b3d but can't work out why it's freezing atm but here's an earlier source, it doesn't have the pockets.
« Last Edit: February 11, 2007 by Stonemonkey »

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3052
  • Karma: 174
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Pool
« Reply #13 on: February 11, 2007 »
pool3d3 is amazing but I couldnt get pool3d2 to run its says error texture not found or something to that effect but the routines should prove invaluable looks like this little project has generated quite a bit of interest

Challenge Trophies Won:

Online Stonemonkey

  • Pentium
  • *****
  • Posts: 1215
  • Karma: 92
    • View Profile
Re: Pool
« Reply #14 on: February 11, 2007 »
Sorry again, I've added the texture to the above attachment.

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3052
  • Karma: 174
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Pool
« Reply #15 on: February 11, 2007 »
its workin perfect now I love the shadows

Challenge Trophies Won:

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 336
  • Karma: 15
  • kiss that sound that pounds your senses
    • View Profile
    • Facebook
Re: Pool
« Reply #16 on: February 12, 2007 »
Very nice pool program Stonemonkey! Beautiful... just you can't sink the balls  :( lol


I've got a cue in my program now - copied Jim Shaw's rotation bit out of his Physics Sample. It rotates, but I need some help with creating an angle so the ball moves in the direction the cue is pointing.

Then, some help with making collisions... I tried using the information from the site rdc gave, but it seems YaBASIC doesn't allow normalise() or dotpoint() **or something**

I added really nice shadow effects to the balls today. This was really a nice addition because it gave it a 3D feel to the balls. I also added a spin factor... g2g - lightning comming!! eeee
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Online Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5098
  • Karma: 380
    • View Profile
Re: Pool
« Reply #17 on: February 12, 2007 »
Moving a ball in the direction of an arrow:
If a ball is going in direction 'angle' then if you say
Code: [Select]
xpos = xpos + cos(angle) * speed
ypos = ypos + sin(angle) * speed
that will move it the right way.  In yabasic, angles are in radians.
Code: [Select]
radians = degrees/180*3.14159
and
Code: [Select]
degrees = radians*3.14159/180

Normalising a vector:
If you want to make a vector have length 1 (that is, if you apply Pythagoras' Theorem to the x,y,z of the vector it comes out as 1) then you need to say
Code: [Select]
length = sqr(x*x + y*y + z*z) : rem Pythagoras
x = x / length
y = y / length
z = z / length

Vector dot product:
This calculates the amount of one vector that lies in the direction of another vector.  It's also useful for finding out the angle between two vectors.  If you have two vectors x1,y1,z1 and x2,y2,z2 then
Code: [Select]
dot = x1 * x2 + y1 * y2 + z1 * z2

If you're working in 2d (like in this pool game) just remove all the z terms from the last 2 equations, ie
Code: [Select]
length = sqr(x*x + y*y) : rem Pythagoras
x = x / length
y = y / length
Code: [Select]
dot = x1 * x2 + y1 * y2

Jim
Challenge Trophies Won:

Offline rdc

  • Pentium
  • *****
  • Posts: 1480
  • Karma: 138
    • View Profile
    • Clark Productions
Re: Pool
« Reply #18 on: February 12, 2007 »
Useful stuff, Jim.

Offline Paul

  • Pentium
  • *****
  • Posts: 1490
  • Karma: 47
    • View Profile
Re: Pool
« Reply #19 on: February 12, 2007 »
the code is working for me now, wonder why it freezed instead of MAV'ing
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won: