Author Topic: Pool Nspire  (Read 33462 times)

0 Members and 1 Guest are viewing this topic.

Offline Loulou 54

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 165
  • Rating: +39/-0
    • View Profile
    • Mes programmes sur TI bank.
Pool Nspire
« on: July 23, 2012, 07:25:10 pm »
Hi all !  :D

I've already thought long ago about making a billiard game.. But that seemed too complicated (balls collisions, ...) and TI Basic on TI 89 would have been too slow.. (I didn't know C at this time ! :P )

But I remembered this idee some days ago and tried with Lua. ;)

I already managed to do the physics which seem quite real !  ;D

(Moreover my code worked at the first try !! AMAZING :P )

I'm now making the gameplay and so on.. Actually, I think there is a lot of work if I want to make a complete game !  ^-^

A screen ?  ;)

EDIT :
- It's a 256 color GIF, so... x)
- There are only 7 balls right now and no hole, but it's coming, obviously ! :P

EDIT 2 : a newer version (but still a bad gif sorry ! :P) with 3D ! ;)
« Last Edit: July 19, 2013, 07:34:55 pm by Loulou 54 »
Some of my program available here.. :)
http://ti.bank.free.fr/index.php?mod=archives&ac=voir2&id=1471

     

Offline Loulou 54

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 165
  • Rating: +39/-0
    • View Profile
    • Mes programmes sur TI bank.
Re: Pool Nspire
« Reply #1 on: July 23, 2012, 07:30:34 pm »
First LabyRoll', then Pool, and next... :)

Offline Eiyeron

  • Urist McEiyolobster
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1430
  • Rating: +130/-10
  • (-_(//));
    • View Profile
    • Rétro-Actif : Rétro/Prog/Blog
Re: Pool Nspire
« Reply #2 on: July 23, 2012, 07:38:35 pm »
Please could you helpme understand the physics o theballs?

Offline cyanophycean314

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 363
  • Rating: +43/-1
  • It's You!
    • View Profile
Re: Pool Nspire
« Reply #3 on: July 23, 2012, 08:07:28 pm »
That looks really cool, especially the animation of hitting it. Great physics btw!  :D

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: Pool Nspire
« Reply #4 on: July 23, 2012, 09:51:44 pm »
Looks quite nice so far Loulou! =)

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Pool Nspire
« Reply #5 on: July 24, 2012, 12:17:08 am »
Nice !

Levak and I were actually creating one using physics too x)
(started like 3 days ago)


Edit : 3.2's Physics Engine.
« Last Edit: July 24, 2012, 04:22:30 am by adriweb »
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline 3rik

  • LV3 Member (Next: 100)
  • ***
  • Posts: 92
  • Rating: +8/-0
  • My TI-84+ SE
    • View Profile
Re: Pool Nspire
« Reply #6 on: July 24, 2012, 12:21:33 am »
This seems really nice. I look forward to seeing how it turns out.  :)
« Last Edit: July 24, 2012, 08:45:52 am by 3rik »
Userbars

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Pool Nspire
« Reply #7 on: July 24, 2012, 02:11:51 am »
That sounds really nice already :D
But does that use the physics library of the OS 3.2 ?
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline Reo

  • LV3 Member (Next: 100)
  • ***
  • Posts: 64
  • Rating: +15/-0
    • View Profile
Re: Pool Nspire
« Reply #8 on: July 24, 2012, 03:12:30 am »
Judging by the non-smoothed font, this must be running on 3.1. It looks great.

Offline parserp

  • Hero Extraordinaire
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1455
  • Rating: +88/-7
  • The King Has Returned
    • View Profile
Re: Pool Nspire
« Reply #9 on: July 24, 2012, 11:45:02 am »
Dude, this is one friggin epic game. :D
Can't wait for more progress!

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Pool Nspire
« Reply #10 on: July 24, 2012, 01:36:19 pm »
Wow looks great :D. Do you re-use some code from Labyroll, such as the 360° movement and stuff? Can't wait to try it :)

Offline Nick

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1166
  • Rating: +161/-3
  • You just got omnom'd
    • View Profile
    • Nick Steen
Re: Pool Nspire
« Reply #11 on: July 24, 2012, 01:43:37 pm »
ok, i might be a little (or a lot) slow, but is this made using the physics engine from 3.2? or did you write your own part of colliding code?

Offline Loulou 54

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 165
  • Rating: +39/-0
    • View Profile
    • Mes programmes sur TI bank.
Re: Pool Nspire
« Reply #12 on: July 24, 2012, 02:51:54 pm »
That sounds really nice already :D
But does that use the physics library of the OS 3.2 ?

No I made all by myself and so it can work on any "Lua supporting OS" ! :)

Nice !

Levak and I were actually creating one using physics too x)
(started like 3 days ago)


Edit : 3.2's Physics Engine.

Really ? ^^
Yes the 3.2's Physics Engine could be usefull for such a project ! :)

Please could you helpme understand the physics o theballs?

Collisions with walls aren't very difficult, but between balls it's kinda complicated..
Each ball is characterized by its coordinates and velocity. (no use to consider any acceleration) So I have a table like this which contains these informations for each ball :
balls={{x1,y1,vx1,vy1},{x2,y2,vx2,vy2},...,{xn,yn,vxn,vyn}}

First of all, you have to consider all couple of balls which could collide and test if they collide. The number of couple is thereby "2 among n". (nCr(n,2), binomial coefficiant)

For example the list of collision for 4 balls is :
{{1,2},{1,3},{1,4},{2,3},{2,4},{3,4}}  (6 collision possibilities = nCr(4,2))

Now, lets consider two balls wich could collide :
ball1 with x1,y1,vx1,vy1
ball2 with x2,y2,vx2,vy2
Their radius is r.

They collide if (x2-x1)^2+(y2-y1)^2 < (2*r)^2.

If they do, we have to calculate the new velocity of each ball.

By velocity subtraction, we can bring us to a more simple problem with :
- the ball 2 moving at the velocity {vx2-vx1,vy2-vy1}
- the ball 1 wich is immobile.

Now, after thinking, that's how I modeled the behavior of a moving ball hitting an other wich is motionless :

- the direction of the new velocity of the ball 1 is collinear with the vector defined by the center of gravity of each ball. (we will call this vector g2g1)
That's it :

from wikipédia

About the norm of the new velocity of the ball 1 (v1) : if v2 is the velocity of the moving ball (ball 2) and a is the angle between the direction of the vector g2g1 and the vector v :
v1 = v2*cos(a)

Thus, for example, if you hit the ball in the center, g2g1 and v are colinear and cos(a)=1 and the entire velocity of ball 2 is transmitted to the ball 1.
If they touch softly when g2g1 and v are almost perpendicular, ball 1 won't move much.

So we have defined the new velocity of ball 1 and  to have the velocity of ball 2 (the moving ball) you just have to subtract the velocity transmitted to the ball 1.
v2=v2-v2*cos(a)
(I haven't considered loses of power in ball-ball collisions since the coefficient of restitution between two balls is pretty high, and I don't want to do useless calculations..) However I have considered friction with table and a restitution of 75% in a ball-wall collision. ;)

So if we want these results in the case where ball 1 and ball 2 have their own velocity, we can have this result :

v1=v1+norm_v*cos(a)
v2=v2-norm_v*cos(a)
where v1 and v2 are vectors and norm_v = |v2-v1|

and as we want this on x/y, we have :

vx1=vx1+norm_v*cos(a)*cos(b)
vy1=vy1+norm_v*cos(a)*sin(b)
where b is the angle between Ox axis and the vector v1, which is colinear, as we said before, with the vector g2g1.
vx2=vx2-norm_v*cos(a)*cos(b)
vy2=vy2-norm_v*cos(a)*sin(b)

But how to calculate a and b angles ? (actually, cos(a), cos(b) and sin(b))
With the scalar product and so on we can have very good simplifications ! (no cos, no sin, no norm_v ;) )

And here is how looks the program for this part :

Code: [Select]
gx=boul[combi[i][2]][1]-boul[combi[i][1]][1]
gy=boul[combi[i][2]][2]-boul[combi[i][1]][2]
norm_g=gx^2 + gy^2

if math.floor(math.sqrt(norm_g)) < 2*r then
vx=boul[combi[i][2]][3]-boul[combi[i][1]][3]
vy=boul[combi[i][2]][4]-boul[combi[i][1]][4]
scal=gx*vx+gy*vy

boul[combi[i][1]][3]=boul[combi[i][1]][3]+math.floor(scal*gx/norm_g) -- vx + norm_v*cos((g,v))*cos((Ox,g))
boul[combi[i][1]][4]=boul[combi[i][1]][4]+math.floor(scal*gy/norm_g) -- vy + norm_v*cos((g,v))*sin((Ox,g))

boul[combi[i][2]][3]=boul[combi[i][2]][3]-math.floor(scal*gx/norm_g)
boul[combi[i][2]][4]=boul[combi[i][2]][4]-math.floor(scal*gy/norm_g)

end

It's a bit confuse but I hope you got some things.. ^^

So this is how I modelized collisions ! I don't know if it's right but it seems to be not bad at all ! :P
« Last Edit: July 24, 2012, 02:57:45 pm by Loulou 54 »
Some of my program available here.. :)
http://ti.bank.free.fr/index.php?mod=archives&ac=voir2&id=1471

     

Offline Loulou 54

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 165
  • Rating: +39/-0
    • View Profile
    • Mes programmes sur TI bank.
Re: Pool Nspire
« Reply #13 on: July 24, 2012, 03:00:50 pm »
And thanks for compliments !  :thumbsup:
Some of my program available here.. :)
http://ti.bank.free.fr/index.php?mod=archives&ac=voir2&id=1471

     

Offline apcalc

  • The Game
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1393
  • Rating: +120/-2
  • VGhlIEdhbWUh (Base 64 :))
    • View Profile
Re: Pool Nspire
« Reply #14 on: July 24, 2012, 07:15:01 pm »
Wow, looks great!  Nice work! :)