Jump to content



Photo
- - - - -

Casio Pool Simulator


  • Please log in to reply
6 replies to this topic

#1 Menno

Menno

    Casio Freak

  • Members
  • PipPipPipPip
  • 184 posts
  • Gender:Male
  • Location:Netherlands

  • Calculators:
    Casio 880P
    Casio Graph 25+
    Casio fx-9860g sd

Posted 21 October 2006 - 07:09 AM

Hello,

This is my first post here and i like to introduce myself with a little game i wrote. I added it to the file sharing area.

I hope you will enjoy the game

Posted Image

Download Pool Simulator

#2 kucalc

kucalc

    Casio Maniac

  • [Legends]
  • PipPipPipPipPipPipPipPip
  • 1422 posts
  • Gender:Male
  • Location:USA
  • Interests:Programming: C/C++, Fortran, LISP, COBOL 85 Standard, PHP, x86 and SH3 Assembly

    Computer graphics

  • Calculators:
    fx-9860G / fx-7400G Plus / Algebra FX 2.0+ / fx-9770G / CFX-9850G / CFX-9850GB+ / TI-89 / TI-nSpire

Posted 21 October 2006 - 11:16 AM

Hey Menno, welcome to the forum and your game looks cool. May I add it to my website at: http://kucalc.frih.net?

#3 Menno

Menno

    Casio Freak

  • Members
  • PipPipPipPip
  • 184 posts
  • Gender:Male
  • Location:Netherlands

  • Calculators:
    Casio 880P
    Casio Graph 25+
    Casio fx-9860g sd

Posted 22 October 2006 - 05:15 AM

Hey Menno, welcome to the forum and your game looks cool. May I add it to my website at: http://kucalc.frih.net?



Hey of course, everyone is free to do with it what feels right ;)

I made a big deal about the collisions (upward, head on, downward) and the distribution of force and angles of two moving and colliding objects, so i would like erm criticism (I am dutch, so my english is funny)

anyhow, yes you are free to use it

i have some more apps also, like calculations used to find out the water vapour concentration in air using a wet bulb thermometer, and a moonphase calculator, but in that calculation is still an error, when i found it i will post it here also.

I should demand that anyone who uses my code should mention me in the software remarks, but then again, who cares ;) i would like an email though ;)

one thing, the pool game is protected by a password the password is caspool

(you only need the password to alter the code in the calculator)

All of my software is always free to use and alter.

edit:

i have an description/howto on how i did my collision detection and angle and force distribution, if there is anyone who would like to read it, i will post it in this thread, the text is also free to alter and use anywhere you like

#4 Menno

Menno

    Casio Freak

  • Members
  • PipPipPipPip
  • 184 posts
  • Gender:Male
  • Location:Netherlands

  • Calculators:
    Casio 880P
    Casio Graph 25+
    Casio fx-9860g sd

Posted 22 October 2006 - 05:30 AM

First i fill a Matrix A with some data according like described below, each object has its own line of data.

[[x,y,angle,i/o,force]]->Mat A (you need to add as many [..] lines as there are objects)

In this matrix de first two positions describe the x an y coordinate, For an angle I use fractions of PI() (UnitCircle)

when i want to move the object i use a code like

-----------------------------------------------------
{7,5}-> Dim Mat A

Lbl 1

For 1->I to 7 Step 1
Mat A[I,1]+cos (Mat A[I,3]*PI)->Mat A [I,1]
Mat A[I,2]+sin (Mat A[I,3]*PI)->Mat A [I,2]
PlotOn Mat A[I,1],Mat A[I,2]
Next

Goto 1
----------------------------------------------------

Now the objects (dots) start moving along their angle
Eventually the objects will disappear from the screen, and this can be good, but i want them to bounce within a box.

So we create a box,

---------------------------------------------------
Lbl 0
Cls
F-Line 1,63,100,63
F-Line 1,63,1,1
F-Line 1,1,100,1
F-Line 100,1,100,63
StoPict 1
---------------------------------------------------

Now we have a visual box but the dots do not see it, so we need to check whether there is a border.

Because i want the dots to bounce and no assimilate into the border before reflecting, i make the actual box one dot smaller than the visible box.

For every I in Lbl 1 i now need to check wether its X an Y are within the box.

Mat A[I,1]<2=>1-Mat A[I,3]->Mat A[I,3]
Mat A[I,1]>99=>1-Mat A[I,3]->Mat A[I,3]
Mat A[I,2]<2=>2-Mat A[I,3]->Mat A[I,3]
Mat A[I,2]>62=>2-Mat A[I,3]->Mat A[I,3]

With four sides it is not necessary to put the values into a matrix, but when you have more then four sides it can pay of to put the min and max X and Y values in a matrix and count with another counter J inside the I counter. (see the collision section further)

The code in Lbl 1 becomes,
----------------------------------------------
{7,5}-> Dim Mat A

Lbl 1

For 1->I to 7 Step 1

'Reflection
Mat A[I,1]<2=>1-Mat A[I,3]->Mat A[I,3]
Mat A[I,1]>99=>1-Mat A[I,3]->Mat A[I,3]
Mat A[I,2]<2=>2-Mat A[I,3]->Mat A[I,3]
Mat A[I,2]>62=>2-Mat A[I,3]->Mat A[I,3]

'Movement
Mat A[I,1]+cos (Mat A[I,3]*PI)->Mat A [I,1]
Mat A[I,2]+sin (Mat A[I,3]*PI)->Mat A [I,2]

'Drawdot
PlotOn Mat A[I,1],Mat A[I,2]
Next

Goto 1
----------------------------------------------

We now have bouncing dots but they do not interact so we have to detect if they collide. We have every X and Y of every particle, to check if they are near each other we say that if the distance between two dots is less the 2 dots they collide. I will therefore have to check each object relative to another (X1-X2 and Y1-Y2) and evaluate if they are near each other.

'ColissionDetection
For 1->I To 7 Step 1
For 1->J To 7 Step 1
If I<>J
Then
Mat A[I,1]-Mat A[J,1]->A
Mat A[I,2]-Mat A[J,2]->B
If Abs A=<2 And Abs B=<2
Then Goto 2
IfEnd
IfEnd
Next
Next

We can integrate this also into Lbl 1 (without the I counter because its there already) (i also Add Lbl 0)

----------------------------------------------
{7,5}-> Dim Mat A

Lbl 0
Cls
F-Line 1,63,100,63
F-Line 1,63,1,1
F-Line 1,1,100,1
F-Line 100,1,100,63
StoPict 1

Lbl 1
RclPict 1
For 1->I to 7 Step 1

'ClearParticle
PlotOff Mat A[I,1],Mat A[I,2]

'Reflection
Mat A[I,1]<2=>1-Mat A[I,3]->Mat A[I,3]
Mat A[I,1]>99=>1-Mat A[I,3]->Mat A[I,3]
Mat A[I,2]<2=>2-Mat A[I,3]->Mat A[I,3]
Mat A[I,2]>62=>2-Mat A[I,3]->Mat A[I,3]

'Movement
Mat A[I,1]+cos (Mat A[I,3]*PI)->Mat A [I,1]
Mat A[I,2]+sin (Mat A[I,3]*PI)->Mat A [I,2]

'Drawdot
PlotOn Mat A[I,1],Mat A[I,2]

'ColissionDetection
For 1->J To 7 Step 1
If I<>J ‘prevention of selfdetection
Then
Mat [I,1]-Mat A[J,1]->A
Mat A[I,2]-Mat A[J,2]->B
If Abs A=<2 And Abs B=<2
Then Goto 2
IfEnd
IfEnd
Next

Next

Goto 1
----------------------------------------------

Adding a 'PlotOff Mat A[I,1],Mat A[I,2]' Before the movement section make the dot appear as dot and not as a line.

Now in Label 2 we need to determine what kind of collision we are dealing with. In a head on collision the direction of particle I is directed to particle J and particle I will get reversed (force will be evaluated later on). In a head on collision the angle of impact and the angle of the impact-plane to the center of ball J are each others mirror. (-><- = <- ->)

If the impact angle (Mat A[I,3]) differs from the mirrored impact-plane-angle the particles will each travel with a fraction of 0,25 PI minus or plus the impact direction (0,25PI is 45 degrees, the particles travel like a Y-shape)

When particle I hits particle J head on:
Mat A[I,3]->Mat A[J,3]
Mat A[I,3]+1->Mat A[I,3]

When Particle I hits particle J on the top:
Mat A[I,3]-0.25->Mat A[J,3]
Mat A[I,3]+0.25->Mat A[I,3]

When Particle I hits particle J on the bottom:
Mat A[I,3]+0.25->Mat A[J,3]
Mat A[I,3]-0.25->Mat A[I,3]

But we still do not know where the particles hit each other, let alone the impact-plane-angle. But with A and B from the impact detection and the X and Y coordinate of particle J we can derive what angle it could have been.

Stay tuned ;)

but be warned the next part will be a bit.....difficult

#5 Menno

Menno

    Casio Freak

  • Members
  • PipPipPipPip
  • 184 posts
  • Gender:Male
  • Location:Netherlands

  • Calculators:
    Casio 880P
    Casio Graph 25+
    Casio fx-9860g sd

Posted 22 October 2006 - 06:14 AM

Ok,

First of all:

Posted Image

The longer arrow represents the direction, the shorter angle represents the angle of impact

In this situation one ball is moving and one ball is not, it is also a non head on collision, so both will be moving after the collision in a new direction.

The travelling angle of ball I is known, and also the x and y coordinate of the collision. With invtan((Y/X)/PI()) we can calculate the angle of impact for most collisions (but not for X=0).

When ball J is moving this is also true, but in that case we need to calculate the common angle.

---------------------------------------------------------------
'InterCollision
0->K
0->Z

'GetAngles
Mat A[I,3]->C
Mat A[J,3]->D

'NumberOfPeriods
Int (Abs (C/2))->E
Int (Abs (D/2))->F

'NormalizeAngles
If C<0
Then 2+(C+(2*E))->C
IfEnd
If C>0
Then C-(2*E)->C
IfEnd
If D<0
Then 2+(D+(2*F))->D
IfEnd
If D>0
Then D-(2*F)->D
IfEnd

'TwoMovingBallCommonAngle
If Mat A[I,5]>1 And Mat A[J,5]>1
Then (C-D)->E
(C+D)/2->F
RndFix(E,1)->E
If E>1 Or E<-1
Then 1+F->F
IfEnd
If E=1
Then 1->Z
C->F
IfEnd
IfEnd

'OneMovingBall
If Mat A[I,5]<1 And Z=0
Then D->F
Mat A[I,1]-Mat A[J,1]->A
Mat A[I,2]-Mat A[J,2]->B
IfEnd
If Mat A[J,5]<1 And Z=0
Then C->F
Mat A[J,1]-Mat A[I,1]->A
Mat A[J,2]-Mat A[I,2]->B
IfEnd

'PreventDivisionByZero
If A=0 And Z=0
Then
If cos (F*PI())=0
Then 1->Z
IfEnd
If cos (F*PI())>0
Then 2->Z
IfEnd
If cos (FPI())<0
Then 3->Z
IfEnd
IfEnd

0->K

'ImpactPLaneAngle
If A<>0 And Z=0
Then RndFix(tan^-1 ((B/A)PI()),2)->K
If A<0
Then 1+K->K
IfEnd
K<-2=>2+K->K
K>2=>K-2->K
F<-2=>2+F->F
If F=K
Then 1->Z
IfEnd
If F>K
Then 2->Z
IfEnd
If F<K
Then 3->Z
IfEnd
IfEnd

'CommonForce
Mat A[I,5]+Mat A[J,5]->Y

'ThreeWaysToCollide

'HeadOnCollision
If Z=1
Then F->Mat A[J,3]
F+1->Mat A[I,3]
Y*0.9->Mat A[J,5]
Y*0.1->Mat A[I,5]
IfEnd

'BallIHitsJWithBottom
If Z=2
Then F-0.25->Mat A[J,3]
F+0.25->Mat A[I,3]
Y*0.7->Mat A[J,5]
Y*0.3->Mat A[I,5]
IfEnd

'BallIHitsJWithTop
If Z=3
Then F+0.25->Mat A[J,3]
F-0.25->Mat A[I,3]
Y*0.7->Mat A[J,5]
Y*0.3->Mat A[I,5]
IfEnd

'ClearParticles
PlotOff Mat A[I,1],Mat A[I,2]
PlotOff Mat A[J,1],Mat A[J,2]

'PreventDoubleCollisionDetection
Mat A[I,1]+cos (Mat A[I,3]*PI())->Mat A[I,1]
Mat A[I,2]+sin (Mat A[I,3]*PI())->Mat A[I,2]
Mat A[J,1]+cos (Mat A[J,3]*PI())->Mat A[J,1]
Mat A[J,2]+sin (Mat A[J,3]*PI())->Mat A[J,2]
PlotOn Mat A[I,1],Mat A[I,2]
PlotOn Mat A[J,1],Mat A[J,2]

Goto 1
------------------------------------------------------------------

I have added the model to the filesharing section, it is slightly altered comapred to this thread, but it should be clear how it works. I hope i have helped someone with this

Download the model

#6 Menno

Menno

    Casio Freak

  • Members
  • PipPipPipPip
  • 184 posts
  • Gender:Male
  • Location:Netherlands

  • Calculators:
    Casio 880P
    Casio Graph 25+
    Casio fx-9860g sd

Posted 09 December 2006 - 05:59 PM

:roflol:

It became third in the jeuxcasio contest

Click

:roflol:

B)

#7 Andy.Davies

Andy.Davies

    Forum Ghost

  • [Legends]
  • PipPipPipPipPipPipPipPip
  • 1547 posts
  • Gender:Male
  • Location:Dorset, England
  • Interests:Age: 18
    Studying: MEng in cybernetics at Reading uni
    Interests: Progaming (VB, VB.Net, C#, Casio Basic)
    Computers UBBD (Using, Building, Breaking &amp; Destroying)
    Gaming (FPS, RTS, RPG)
    Electronics
    Rock Music (Preferably Loud)
    Riley's (Pool &amp; Snooker Bar)
    Driving (Preferably fast)
    Aikedo (Martial Art)

  • Calculators:
    Algebra FX 2.0 ROM 1.01, FX9750G

Posted 17 December 2006 - 09:54 PM

congratulations :)


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users