Commit 9c277aa4 authored by DoNaTio s.r.o.'s avatar DoNaTio s.r.o.
Browse files

main changing

parent 4dd39547
......@@ -21,11 +21,21 @@ module.exports = function() {
return _players[id];
},
stringify: function(){
var strUser = {};
for (var key in _players) {
var obj = _players[key];
for (var prop in obj) {
// important check that this is objects own property
// not from prototype prop inherited
if(obj.hasOwnProperty(prop)){
strUser[prop] = obj.stringify()
}
}
}
return JSON.stringify({
'_players': _players,
'_countPlayers': _countPlayers,
'_players': strUser,
'_countPlayers': _countPlayers
})
}
};
......
......@@ -20,10 +20,10 @@ module.exports = function() {
},
stringify: function(){
var that = this;
return {
return JSON.stringify({
x:that.getX(),
y:that.getY()
};
});
}
};
}
\ No newline at end of file
......@@ -44,6 +44,14 @@ io.on('connection', function (socket) {
var r = player.getRacket();
r.setX(data.x);
r.setY(data.y);
var col = PlayersCollection.stringify();
socket.broadcast.emit('show racket', {
'id': data.id,
'x':data.x,
'y':data.y
});
})
});
......
......@@ -6,6 +6,15 @@
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="rackets">
<div class="racket racket1"></div>
<div class="racket racket2"></div>
<div class="racket racket3"></div>
<div class="racket racket4"></div>
<div class="racket racket5"></div>
<div class="racket racket6"></div>
</div>
<ul class="pages">
<li class="chat page">
<div class="chatArea">
......
......@@ -66,11 +66,13 @@ $(function () {
$(document).mousemove(function(event){
//console.log('user');
//console.log(user);
socket.emit('move racket', {
var d = {
id:user.id,
x:event.pageX,
y:event.pageY
});
};
drawRacket(d)
socket.emit('move racket', d);
});
// Whenever the server emits 'login', log the login message
......@@ -78,7 +80,7 @@ $(function () {
connected = true;
user = JSON.parse(data.user);
console.log(user);
// Display the welcome message
var message = "Welcome to PiPo – Multiplayer awesome ping pong!!!";
log(message, {
......@@ -87,6 +89,12 @@ $(function () {
addParticipantsMessage(data);
});
socket.on('show racket', function(data){
//console.log(data);
//var racket = JSON.parse(data.playersCollection);
drawRacket(data);
})
// Whenever the server emits 'user joined', log it in the chat body
socket.on('user joined', function (data) {
log(data.username + ' joined');
......@@ -98,4 +106,9 @@ $(function () {
log(data.username + ' left');
addParticipantsMessage(data);
});
function drawRacket(data){
var id = data.id;
$('div.racket'+id).css({ left:data.x, top: data.y});
}
});
......@@ -148,3 +148,17 @@ ul {
right: 0;
width: 100%;
}
.rackets .racket{
position: absolute;
left:0;
top:0;
width: 30px;
height: 30px;
}
.racket1{ background: url(images/racket.png) no-repeat; }
.racket2{ background: url(images/racket-green.png) no-repeat; }
.racket3{ background: url(images/racket-blue.png) no-repeat; }
.racket4{ background: url(images/azure.png) no-repeat; }
.racket5{ background: pink; }
.racket6{ background: gray; }
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