scheduled upgrade maintenance

Commit 04d1199a authored by Monika's avatar Monika
Browse files

set collision racket and ball

parent d11d6335
......@@ -29,11 +29,11 @@ function ClientBall($el) {
y:attributes.y
};
},
getWidth: function() {
return attributes.width;
},
getHeight: function() {
return attributes.height;
getDimension: function() {
return {
'width': attributes.width,
'height': attributes.height
}
},
getVectors: function(){
return {
......@@ -54,7 +54,7 @@ function ClientBall($el) {
attributes.y += attributes.vy;
},
redraw: function () {
console.log(attributes.x, attributes.y, 'ball');
//console.log(attributes.x, attributes.y, 'ball');
attributes.el.css('top', attributes.y);
attributes.el.css('left', attributes.x);
},
......
......@@ -37,6 +37,7 @@ function ClientCollision(Ball, Racket, User) {
collision: function () {
var ballAxis = attributes.ball.getAxis();
var ballVectors = attributes.ball.getVectors();
var ballDimension = attributes.ball.getDimension();
var racketVector = attributes.racket.getVector();
var racketAxis = attributes.racket.getAxis();
var racketDimension = attributes.racket.getDimension();
......@@ -44,12 +45,22 @@ function ClientCollision(Ball, Racket, User) {
* Racket collision
*/
if (
attributes.racket.getIsActive()
&&
//attributes.user.getIsTurn()
//&&
(ballAxis.x > racketAxis.x && ballAxis.x < racketAxis.x + racketDimension.width) //x coordinate
// (ballAxis.x > racketAxis.x && ballAxis.x < racketAxis.x + racketDimension.width) //x coordinate
// &&
// (ballAxis.y < racketAxis.y && ballAxis.y > racketAxis.y - racketDimension.height) //y coordinate
(ballAxis.x >= (racketAxis.x - ballDimension.width))
&&
(ballAxis.x <= (racketAxis.x + ballDimension.width))
&&
(ballAxis.y >= (racketAxis.y - ballDimension.height))
&&
(ballAxis.y < racketAxis.y && ballAxis.y > racketAxis.y - racketDimension.height) //y coordinate
(ballAxis.y <= (racketAxis.y + ballDimension.height))
) {
attributes.racket.setIsActive(false);
console.log('collision ball with racket');
var BD = racketAxis, // bod dotyku (poz. lopticky)
vR = racketVector, //vektor rakety
......
......@@ -65,7 +65,9 @@ $(function () {
d.x = playgroundHalf;
}
racket.setAxis(event.pageX - $playground.offset().left,event.pageY - $playground.offset().top);
if(racket.getIsActive()){
racket.setAxis(event.pageX - $playground.offset().left,event.pageY - $playground.offset().top);
}
drawRacket(d);
socket.emit('move racket', d);
......@@ -76,6 +78,11 @@ $(function () {
};
});
$playground.click(function (event) {
racket.setIsActive(true);
racket.setPrevAxis(event.pageX - $playground.offset().left,event.pageY - $playground.offset().top);
});
var $rackets = $(".rackets");
// Whenever the server emits 'login', log the login message
socket.on('login', function (data) {
......
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