Commit 2bba5e30 authored by Monika's avatar Monika
Browse files

whoIsOnTurn

parent a071cdeb
......@@ -5,7 +5,7 @@
module.exports = function (PlayersColliction, Score) {
var _playersColliction = PlayersColliction;
var _score = Score;
var _whichTeam = 0;
var _whichTeam = 1;
var _team0 = [];
var _team1 = [];
......@@ -24,20 +24,18 @@ module.exports = function (PlayersColliction, Score) {
getNext: function () {
var next;
console.log(_team0, _team1);
if (_whichTeam) {
if (_team1[0] == undefined) {
if (_team1.length == 0) {
this.resetTeamStack(1);
}
next = _team1[0];
delete _team1[0];
_team1.splice(0, 1);
} else {
if (_team1[0] == undefined) {
if (_team0.length == 0) {
this.resetTeamStack(0);
}
next = _team0[0];
delete _team0[0];
_team0.splice(0, 1);
}
return next;
......
......@@ -27,9 +27,11 @@ function ClientCollision(Ball, Racket, User) {
},
normalize: function (v) {
var len = this.getLength(v);
v.vx /= len;
v.vy /= len;
return v;
var vx = v.vx;
var vy = v.vy;
vx /= len;
vy /= len;
return {vx:vx,vy:vy};
},
getLength: function (v) {
return Math.sqrt(v.vx * v.vx + v.vy * v.vy);
......@@ -68,7 +70,9 @@ function ClientCollision(Ball, Racket, User) {
if (vL2.x == 0 && vL2.y == 0) {
attributes.ball.setVectors(1, 1);
}
console.log(ballVectors, 'ball');
console.log(attributes.racket.getAttributes(), 'getAttributes');
console.log(racketVector, 'racketVector');
attributes.user.setIsTurn(false);
return true;
}
......
......@@ -92,7 +92,7 @@ $(function () {
if(!connected){
user.setId(data.id);
if(data.id == data.isOnTurn){
if(data.id == data.whoIsOnTurn){
user.setIsTurn(true);
}
for (var i=0; i < data.allIds.length; i++){// if we need later to send all players whe can directly from them take ids
......
......@@ -17,37 +17,40 @@ function ClientRacket() {
attributes.width = el.width();
attributes.height = el.height();
},
getDimension: function() {
getDimension: function () {
return {
'width': attributes.width,
'height': attributes.height
}
},
setPrevAxis: function(x, y) {
setPrevAxis: function (x, y) {
attributes.prevX = x;
attributes.prevY = y;
console.log(x, y);
},
setAxis: function(x, y) {
setAxis: function (x, y) {
attributes.x = x;
attributes.y = y;
},
getAxis: function() {
getAxis: function () {
return {
'x': attributes.x,
'y': attributes.y
}
},
setIsActive: function(isActive) {
setIsActive: function (isActive) {
attributes.isActive = isActive;
},
getIsActive: function() {
getIsActive: function () {
return attributes.isActive;
},
getAttributes: function () {
return attributes;
},
getVector: function () {
//console.log(attributes.x - attributes.prevX, attributes.y - attributes.prevY, 'lala');
// console.log(attributes.x - attributes.prevX, attributes.y - attributes.prevY, 'lala');
return {
vx: attributes.x - attributes.prevX,
vx: attributes.prevX - attributes.x,
vy: attributes.y - attributes.prevY
}
}
......
Supports Markdown
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