Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
DoNaTio s.r.o.
PiPo
Commits
ab02536e
Commit
ab02536e
authored
Dec 25, 2014
by
Monika
Browse files
set correct position on start for rackets + fix position of ball according who is on serve
parent
3ce033e2
Changes
7
Hide whitespace changes
Inline
Side-by-side
Ball.js
View file @
ab02536e
...
...
@@ -15,11 +15,11 @@ module.exports = function() {
height
:
20
,
defaults
:{
team0
:{
x
:
35
0
,
x
:
70
0
,
y
:
350
},
team1
:{
x
:
70
0
,
x
:
35
0
,
y
:
350
}
}
...
...
@@ -53,12 +53,13 @@ module.exports = function() {
attributes
.
x
+=
attributes
.
vx
;
attributes
.
y
+=
attributes
.
vy
;
},
reset
:
function
(
scored
Team
){
reset
:
function
(
serve
Team
){
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
);
}
}
...
...
Score.js
View file @
ab02536e
...
...
@@ -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
;
}
...
...
WhoIsOnServe.js
View file @
ab02536e
...
...
@@ -61,7 +61,7 @@ module.exports = function (PlayersColliction, Score) {
}
}
console
.
log
(
this
.
getNext
(),
'
serve
'
);
_score
.
setResetTeam
(
_whichTeam
);
return
this
.
getNext
();
}
};
...
...
WhoIsTurn.js
View file @
ab02536e
...
...
@@ -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
();
}
};
...
...
public/ClientMain.js
View file @
ab02536e
...
...
@@ -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);
});
...
...
public/index.html
View file @
ab02536e
...
...
@@ -43,7 +43,7 @@
<div
id=
"table"
></div>
<div
class=
"rackets"
>
</div>
<div
class=
"score"
><span
class=
"team
0
"
>
0
</span>
:
<span
class=
"team
1
"
>
0
</span></div>
<div
class=
"score"
><span
class=
"team
1
"
>
0
</span>
:
<span
class=
"team
0
"
>
0
</span></div>
<div
id=
"ball"
></div>
...
...
server.js
View file @
ab02536e
...
...
@@ -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
'
:
whoIsOnServe
Id
});
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment