-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c092de5
commit 0677857
Showing
10 changed files
with
74 additions
and
53 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
canvas { | ||
border: 10px solid #999; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> | ||
<title>Balls with canvas</title> | ||
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen"> | ||
</head> | ||
<body> | ||
<section class="content"> | ||
|
||
<h2>Hit some balls!</h2> | ||
<canvas id="myCanvas" width="500" height="500"> | ||
</canvas> | ||
|
||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> | ||
<script src="js/cue.js"></script> | ||
<script src="js/game.js"></script> | ||
|
||
</section> | ||
</body> | ||
</html> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
function Cue (x, y) { | ||
this.x = x; | ||
this.y = y; | ||
this.vx = 0; | ||
this.vy = 0; | ||
this.move=move; | ||
function move(){ | ||
friction = 0.995 | ||
this.vx *= friction; | ||
this.vy *= friction; | ||
if (this.vy < 0.1 && this.vy > -0.1 && this.vx < 0.1 && this.vx > -0.1) {this.vx = 0; this.vy = 0;} | ||
// displace the ball | ||
if( this.x<20 || this.x>width-20) this.vx=-this.vx; | ||
if( this.y<20 || this.y>height-20) this.vy=-this.vy; | ||
this.x+=this.vx; | ||
this.y+=this.vy; | ||
}; | ||
this.checkCollision = false; | ||
} | ||
|
||
function calculateCuePull(){ | ||
// dx and dy are the x and y components of the cue vector | ||
var distX = mx - cue.x; | ||
var distY = my - cue.y; | ||
|
||
// h is the distance of the cue pull | ||
var h = Math.sqrt(Math.pow(distX, 2) + Math.pow(distY, 2)); | ||
|
||
// If the cue is being pulled further than the maxCuePull | ||
if (h>maxCuePull){ | ||
// scaleMultiplier is the amount that the x and y coordinates must scale down by to make the pull equal the maxCuePull | ||
var scaleMultiplier = maxCuePull/h; | ||
// Scale the x and y components of the pull down | ||
distX = distX*scaleMultiplier; | ||
distY = distY*scaleMultiplier; | ||
} | ||
|
||
mx = (cue.x+distX); | ||
my = (cue.y+distY); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.