Constructor
new Ball(x, y, vx, vy, r, m)
Create a Ball
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The initial x location of the Ball. |
y |
number | The initial y location of the Ball. |
vx |
number | The initial x velocity of the Ball. |
vy |
number | The initial y velocity of the Ball. |
r |
number | The radius of the Ball. |
m |
number | The mass of the Ball. |
Methods
applyForce(fx, fy, dt)
Applies a single force to the Ball.
Parameters:
Name | Type | Description |
---|---|---|
fx |
number | The x component of the force. |
fy |
number | The y component of the force. |
dt |
number | The time step. |
checkEdges()
Checks to see if the Ball has left the boundaries of the canvas. If
they have the ball will bounce back with 90% of it's original speed.
collidePhysics(ball)
Applies physics for elastic collision between balls.
Parameters:
Name | Type | Description |
---|---|---|
ball |
number | The ball to do the collision against. |
hits(ball)
Checks to see if the given ball collides with this ball.
Parameters:
Name | Type | Description |
---|---|---|
ball |
number | The ball to check the collision against. |
setVelX(newVelX)
Sets the x velocity of the ball.
Parameters:
Name | Type | Description |
---|---|---|
newVelX |
number | The new x velocity of the ball. |
setVelY(newVelY)
Sets the y velocity of the ball.
Parameters:
Name | Type | Description |
---|---|---|
newVelY |
number | The new y velocity of the ball. |
setX(newX)
Sets the x position of the ball.
Parameters:
Name | Type | Description |
---|---|---|
newX |
number | The new x value of the ball. |
setY(newY)
Sets the y position of the ball.
Parameters:
Name | Type | Description |
---|---|---|
newY |
number | The new y value of the ball. |
show()
Draws a white ellipse at the Balls position on the canvas