Commit 40579e29 authored by DoNaTio s.r.o.'s avatar DoNaTio s.r.o.
Browse files

fix collision

parent 82b84156
......@@ -6,7 +6,7 @@
* @constructor
*/
function ClientCollision(Playground, Ball){
function ClientCollision(Playground, Ball) {
var attributes = {
'ball': Ball,
......@@ -14,34 +14,34 @@ function ClientCollision(Playground, Ball){
};
return {
collision: function(){
collision: function () {
var ballAxis = attributes.ball.getAxis();
var ballVectors = attributes.ball.getVectors();
var playgroundDimension = attributes.playground.getDimension();
if(ballAxis.y > playgroundDimension.h) {
if (ballAxis.y > playgroundDimension.h) {
ballVectors.vy = -ballVectors.vy;
ballAxis.y = playgroundDimension.h;
attributes.ball.setAxis(ballAxis.x, ballAxis.y);
}
else if(ballAxis.y < 0) {
else if (ballAxis.y < 0) {
ballVectors.vy = -ballVectors.vy;
ballAxis.y = 0;
}
// If ball strikes the vertical walls, invert the
// x-velocity vector of ball
if(ballAxis.x > playgroundDimension.w) {
if (ballAxis.x > playgroundDimension.w) {
ballVectors.vx = -ballVectors.vx;
ballAxis.x = playgroundDimension.w;
}
else if(ballAxis.x < 0) {
else if (ballAxis.x < 0) {
ballVectors.vx = -ballVectors.vx;
ballAxis.x = 0;
}
attributes.ball.setAxis(ballAxis.x,ballAxis.y);
attributes.ball.setAxis(ballAxis.x, ballAxis.y);
attributes.ball.setVectors(ballVectors.vx, ballVectors.vy);
}
......
......@@ -90,7 +90,6 @@ body {
}
#playground {
padding: 100px;
background-color: silver;
background: url(images/parkety.jpg);
width: 968px;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment