Skip to content

Commit

Permalink
Merge pull request #82 from Darsh2987/increase-friction#81
Browse files Browse the repository at this point in the history
Increase friction #81
  • Loading branch information
sleddog authored Apr 22, 2018
2 parents c6f4d41 + ad76fe1 commit f14a696
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
var PowerSlider;

//When document is ready add an event listener onto the #power-slider
document.addEventListener("DOMContentLoaded", function(event) {
document.addEventListener("DOMContentLoaded", function(event) {

//We assign the power slider after the DOM has loaded
PowerSlider = document.getElementById('power-slider');
Expand All @@ -35,7 +35,7 @@
processPowerSlider(); //If we released space just now, we call the process function for the powerslider.
}, false);

//The processPowerSlider handles generally the power slider and here it's tied to change event on the actual DOM slider so it processes mouse slider drag too.
//The processPowerSlider handles generally the power slider and here it's tied to change event on the actual DOM slider so it processes mouse slider drag too.
document.getElementById("power-slider").addEventListener("change",processPowerSlider);
});

Expand Down Expand Up @@ -111,12 +111,12 @@
rackY: 320,
cueX: 200,
cueY: 320,

minVelocity: 1,
maxVelocity: 30,
ballRadius: 20,
ballMass: parseFloat(1),
ballFriction: 0.991,
ballFriction: 0.987,
bumperWidth: 25,
showStickAt: 0.03,
restitution: 0.85
Expand Down Expand Up @@ -170,7 +170,7 @@
/**
* Map the velocity of a collision (involving one or two balls)
* to a sound volume suitable for use in a call to playSound()
*
*
* Note: Pass the ball indices here, rather than passing the ball objects
* directly
*/
Expand Down Expand Up @@ -211,7 +211,7 @@
var distanceSquared = dx * dx + dy * dy; // use squared distance to avoid sqrt

if (distanceSquared < (ball1.radius + ball1.radius) * (ball1.radius + ball1.radius)) {

var dist = ball1.position.nsub(ball2.position);
var vel = ball2.velocity.nsub(ball1.velocity);

Expand All @@ -230,14 +230,14 @@
// get the mtd
var pos1 = ball1.position.clone();
var pos2 = ball2.position.clone();

// move balls out of each other based on their current speed...

var speedBall1 = ball1.velocity.length();
var speedBall2 = ball2.velocity.length();
var speedSum = speedBall1 + speedBall2;

// current distance between balls
// current distance between balls
var distanceVector = pos1.nsub(pos2);
// distance that each ball has to move so that balls get seperated
var toMoveDistanceBall1 = (2.0 * PREFS.ballRadius - distanceVector.length()) * (speedBall1 / speedSum);
Expand Down Expand Up @@ -273,7 +273,7 @@
// new velocity is sum of both collisions
ball1.velocity = a1.nadd(a2);
ball1.update();

ball2.velocity = b1.nadd(b2);
ball2.update();
}
Expand Down Expand Up @@ -411,11 +411,11 @@
};
var ballToCollideWithDistance = Number.MAX_VALUE;

// iterate through ball list
// iterate through ball list
for (var i = 0; i < ballList.balls.length; i++) {
var currentBall = ballList.balls[i];

// skip cue ball and potted balls
// skip cue ball and potted balls
if (currentBall.potted || currentBall.type == CUE) {
continue;
}
Expand Down Expand Up @@ -510,7 +510,7 @@
(currentBall.position.x - result.pos.x),
(currentBall.position.y - result.pos.y)
);
// set length of trajectory vector to 1250, becaus that should be
// set length of trajectory vector to 1250, becaus that should be
// long enough
trajectory = normalizeVector(trajectory);
trajectory = new Vector(
Expand Down Expand Up @@ -579,7 +579,7 @@


function onloadHandler()
{
{
// get the canvas DOM element
var canvas = document.getElementById('canvas'),
ctx = canvas.getContext("2d"),
Expand All @@ -589,10 +589,10 @@
// data structures - generate initial balls
ballList = new BallList();
ballList.balls = getRack();

var gui = new dat.GUI();
dat.GUI.toggleHide();

var appearance = gui.addFolder('Appearance');
var sounds = gui.addFolder('Sounds');
var physics = gui.addFolder('Physics');
Expand All @@ -614,9 +614,9 @@
appearance.add(PREFS, 'cueY', 0, Y_MAX).onChange(function(color) {
ballList.balls = getRack();
});

sounds.add(PREFS, 'mute', 0, 1);

physics.add(PREFS, 'minVelocity', 0, 500);
physics.add(PREFS, 'maxVelocity', 0, 500);
physics.add(PREFS, 'ballRadius', 10, 30).onChange(function() {
Expand All @@ -629,12 +629,12 @@
physics.add(PREFS, 'bumperWidth', 0, 75);
physics.add(PREFS, 'showStickAt', 0, 5);
physics.add(PREFS, 'restitution', 0, 5);

appearance.open();
sounds.open();
physics.open();



function getRack() {
var radius = PREFS.ballRadius;
Expand Down Expand Up @@ -838,7 +838,7 @@
}

// event handlers

var mouseMove = function(e)
{
var cue_ball = ballList.balls[0];
Expand Down Expand Up @@ -1087,7 +1087,7 @@
ctx.restore();

allBallsAreStationary &= this.balls[i].isStationary();
}
}

if (allBallsAreStationary && !placingCue){
var x = this.balls[0].position.x - this.mousex,
Expand All @@ -1097,7 +1097,7 @@
var norm_y = y / Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));

if(this.showGhostBall) {

drawShootPreview(
ctx,
this.balls[0].position,
Expand Down Expand Up @@ -1144,7 +1144,7 @@
ctx.strokeStyle = WHITE;
ctx.moveTo(0, 0);
ctx.lineTo(norm_x * 20, norm_y * 20);
ctx.stroke();
ctx.stroke();
ctx.closePath();

//draw the tip
Expand All @@ -1153,7 +1153,7 @@
ctx.strokeStyle = BLACK;
ctx.moveTo(0, 0);
ctx.lineTo(norm_x * 10, norm_y * 10);
ctx.stroke();
ctx.stroke();
ctx.closePath();

ctx.restore();
Expand Down Expand Up @@ -1387,7 +1387,7 @@
<canvas id="canvas" width="1190" height="640"></canvas>
</div>
</div>

<table><tr>
<td>
<div id="custom-area" style="display:none">
Expand All @@ -1397,14 +1397,14 @@
</div>
<div class="pos-area">
<span>x:</span><input type="text" id="cue_x" value="1.0" style="width: 60px"/>
<span>y:</span><input type="text" id="cue_y" value="0" style="width: 60px"/>
<span>y:</span><input type="text" id="cue_y" value="0" style="width: 60px"/>
</div>

</div>
</td>
<td>
<div id="linkDiv">
Options ('<b>H</b>' key) &nbsp;&nbsp;|&nbsp;&nbsp;
Options ('<b>H</b>' key) &nbsp;&nbsp;|&nbsp;&nbsp;
<a id="link" href="https://github.com/sleddog/pool" target="_blank">github.com/sleddog/pool</a>
</div>
</td>
Expand Down

0 comments on commit f14a696

Please sign in to comment.