Commit ab02536e authored by Monika's avatar Monika
Browse files

set correct position on start for rackets + fix position of ball according who is on serve

parent 3ce033e2
......@@ -15,11 +15,11 @@ module.exports = function() {
height: 20,
defaults:{
team0:{
x:350,
x:700,
y:350
},
team1:{
x:700,
x:350,
y:350
}
}
......@@ -53,12 +53,13 @@ module.exports = function() {
attributes.x += attributes.vx;
attributes.y += attributes.vy;
},
reset: function( scoredTeam ){
reset: function(serveTeam){
this.setVectors(0,0);
if(scoredTeam){
this.setAxis(attributes.defaults.team0.x,attributes.defaults.team0.y);
}else{
//console.log(serveTeam, 'teeam');
if(serveTeam){
this.setAxis(attributes.defaults.team1.x,attributes.defaults.team1.y);
}else{
this.setAxis(attributes.defaults.team0.x,attributes.defaults.team0.y);
}
}
......
......@@ -8,7 +8,8 @@ module.exports = function(Ball, playgroundDimension){
'team0': 0,
'team1': 0,
'ball': Ball,
'playgroundDimension': playgroundDimension
'playgroundDimension': playgroundDimension,
'resetTeam' : 0
};
return {
......@@ -18,6 +19,9 @@ module.exports = function(Ball, playgroundDimension){
increaseScoreTeam1: function(){
attributes.team1++;
},
setResetTeam: function(resetTeam) {
attributes.resetTeam = resetTeam;
},
getScore: function(){
return {
team0: attributes.team0,
......@@ -28,27 +32,24 @@ module.exports = function(Ball, playgroundDimension){
return attributes.team0 + attributes.team1;
},
getWinTeam: function() {
console.log(attributes.team0, 's0');
console.log(attributes.team1, 's1');
if(attributes.team0 > attributes.team1){
return 'Team 0';
} else if (attributes.team1 > attributes.team0){
return 'Team 1';
} else {
return "Draw";
}
},
collision: function(){
var ballAxis = attributes.ball.getAxis();
//console.log(ballAxis,attributes.playgroundDimension.w);
if((ballAxis.x + 10) > attributes.playgroundDimension.w){
this.increaseScoreTeam0();
attributes.ball.reset(0);
this.increaseScoreTeam1();
return true;
}
if((ballAxis.x - 10) < 0){
this.increaseScoreTeam1();
attributes.ball.reset(1);
this.increaseScoreTeam0();
return true;
}
......
......@@ -61,7 +61,7 @@ module.exports = function (PlayersColliction, Score) {
}
}
console.log(this.getNext(), 'serve');
_score.setResetTeam(_whichTeam);
return this.getNext();
}
};
......
......@@ -63,7 +63,7 @@ module.exports = function (PlayersColliction, Score) {
} else {
_whichTeam = 1;
}
console.log(this.getNext(), 'turn');
//console.log(this.getNext(), 'turn');
return this.getNext();
}
};
......
......@@ -2,13 +2,13 @@ $(function () {
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function( callback ){
return window.setTimeout(callback, 1000 / 60);
};
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function( callback ){
return window.setTimeout(callback, 1000 / 60);
};
})();
// Initialize varibles
......@@ -92,6 +92,7 @@ $(function () {
if(!connected){
user.setId(data.id);
user.setTeam(data.team);
//console.log(data, 'turn');
if(data.id == data.whoIsOnTurn){
user.setIsTurn(true);
......@@ -141,7 +142,6 @@ $(function () {
socket.on('user joined', function (data) {
log.add(data.username + ' joined');
log.add(data.username + ' is team ' + data.team);
user.setTeam(data.team);
drawAllRackets(data);
//console.log(data);
});
......
......@@ -43,7 +43,7 @@
<div id="table"></div>
<div class="rackets">
</div>
<div class="score"><span class="team0">0</span>:<span class="team1">0</span></div>
<div class="score"><span class="team1">0</span>:<span class="team0">0</span></div>
<div id="ball"></div>
......
......@@ -39,9 +39,11 @@ setInterval(function () {
winTeam: score.getWinTeam()
});
}
var whoIsOnServeId = whoIsOnServe.getWhoIsOnServe();
ball.reset(whoIsOnServe.getTeam());
io.emit('change score', {
'score': score.getScore(),
'userId': whoIsOnServe.getWhoIsOnServe()
'userId': whoIsOnServeId
});
whoIsTurn.resetTeamAccordingServe(whoIsOnServe.getActId(), whoIsOnServe.getTeam());
}
......@@ -93,6 +95,7 @@ io.on('connection', function (socket) {
numUsers: PlayersCollection.getCount(),
username: newPlayer.getName(),
id: newPlayer.getId(),
team: newPlayer.getTeam(),
allIds: PlayersCollection.getIds(),
whoIsOnTurn: whoIsOnTurnId,
whoIsOnServe: whoIsOnServeId
......
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