# java: biliard game shoot power

Page 1 of 1

## 4 Replies - 3120 Views - Last Post: 23 July 2011 - 07:44 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=240713&amp;s=7949453844053fc097791339f183b677&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 gilvim

Reputation: 0
• Posts: 3
• Joined: 20-July 11

# java: biliard game shoot power

Posted 23 July 2011 - 10:12 AM

I'm creating a java billiard game and trying to make power indicator which will say how fast ball needs to move...
i have code which move the ball, but here i move ball by the position of the mouse.. and cannot figure it out how to move it by the power.
```
double power = 9;
int x1 = p2.x - p1.x, y1 = p2.y - p1.y;
shoot.start(p2,x1,y1, player));

```

p2 - ball position x and y (Point)
p1 - mouse position
x1 and y1 - how much ball will be moving to x or y

Is This A Good Question/Topic? 0

## Replies To: java: biliard game shoot power

### #2 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 12267
• Posts: 45,362
• Joined: 27-December 08

## Re: java: biliard game shoot power

Posted 23 July 2011 - 11:14 AM

Power isn't a good measurement, IMO. Take a look at momentum instead, as it is easier to work with for collisions. Remember that power is the Integral(force dx) and momentum is the Integral(force dt). I have some tutorials on collision handling that you may find helpful:
http://www.dreaminco...-1d-collisions/
http://www.dreaminco...-2d-collisions/

### #3 gilvim

Reputation: 0
• Posts: 3
• Joined: 20-July 11

## Re: java: biliard game shoot power

Posted 23 July 2011 - 01:28 PM

it's about collision, i already have made that part... now i need to calculate a shoot.. i was thinking to extend a line between ball position and mouse and then take just a section of it. but i don't know how to proper extend that line.

### #4 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 12267
• Posts: 45,362
• Joined: 27-December 08

## Re: java: biliard game shoot power

Posted 23 July 2011 - 01:33 PM

Take a look at some trig instead. Power still isn't what you want to use here- momentum is. Think about a two-dimensional collision between the ball and the stick. Think about the conservation of momentum, and think about the angle at which the stick is striking the ball. You can use that to break up the momentum using polar coordinates.

### #5 anonymous26

• D.I.C Lover

Reputation: 2
• Posts: 3,638
• Joined: 26-November 10

## Re: java: biliard game shoot power

Posted 23 July 2011 - 07:44 PM

Be careful not to over think this problem, I don't think an accurate simulation is required.

Put simply, the more power you charge in the power bar, the less time the ball will take to get from point A (the point at which the cue hits the ball) to point B (the point where the cue ball hits the other ball), so this is a function of time more than anything else.

As an initial thought you need to first determine the minimum and terminal speed for the cue ball for a given distance. This can be any fixed distance that will be normalized according to the actual distance between the two balls.

Where the force vs momentum debate comes in is the point at which the balls collide and the rules that govern their physical properties, but that is another debate.